QtrcWriteTextPrintF()--Write Text Trace Data Using Print Formatted


  Syntax
 #include <qtrc.h>

 int QtrcWriteTextPrintF
         (unsigned int    Coded_Level,
          const char     *Component,
          const char     *Subcomponent,
          const char     *Function,
          const char     *Format,
          ...);
  Service Program Name: QTRCMGR

  Default Public Authority: *USE

  Threadsafe: Yes

The QtrcWriteTextPrintF() function writes a component trace record as text string data, using a print formatted layout, to an active trace collection if certain trace conditions are met. Note: A prototyped call language, such as RPG, should instead use the QtrcWriteTextPPrintF() function.

The QtrcWriteTextPrintF() uses the Format parameter to process any additional parameters (Argument_List) that are specified following the Format parameter. Format specifications, which begin with a percent sign (%), are used to convert each corresponding argument list entry, and include the resulting text string in the trace record. If there are more argument list entries than there are format specifications, the extra arguments are evaluated and ignored. The results are undefined if there are not enough argument list entries for all the format specifications.

Each call to the QtrcWriteTextPrintF() function is considered a trace point. A component trace record is written to the trace collection when all the trace conditions are met for a given trace point. The trace conditions include:

Each trace point must indicate the desired trace level using the Coded_Level parameter. This trace level is compared against the active trace level that was used for the specified Component when the trace collection was started. Components are defined to the trace collection using the Start Trace (STRTRC) CL command. The Coded_Level must be one of the following values:

QTRC_LEVEL_ERROR (1) ERROR-level trace point. A component trace record is written if the Component has an active trace level of either *ERROR, *INFO, or *VERBOSE.
QTRC_LEVEL_INFO (2) INFO-level trace point. A component trace record is written if the Component has an active trace level of either *INFO or *VERBOSE.
QTRC_LEVEL_VERBOSE (3) VERBOSE-level trace point. A component trace record is written if the Component has an active trace level of *VERBOSE.

Parameters

Coded_Level
(Input)

The trace level of the trace point.

Component
(Input)

A pointer to the null-terminated component name. The component name should be 10 characters in length or less. If more than 10 characters are specified, only the first 10 characters are used.

Subcomponent
(Input)

A pointer to the null-terminated subcomponent name. The subcomponent name should be 10 characters in length or less. If more than 10 characters are specified, only the first 10 characters are used. This parameter can be set to NULL if no subcomponent is to be defined.

Function
(Input)

A pointer to the null-terminated function name. The function name should be 512 characters in length or less. If more than 512 characters are specified, only the first 512 characters are used. This parameter can be set to NULL if no function is to be defined.

Format
(Input)

A pointer to the null-terminated format string. The format string provides the format specification of the text to be written as a trace record. See the printf()--Print Formatted Characters function for a description of valid format strings and how the format specifications are used along with an argument list.

... (Argument_List)
(Input)

An optional list of arguments that contain entries to be formatted and written as part of the text string trace record.


Authorities and Locks

None.


Return Value

0
QtrcWriteTextPrintF() was successful. However, the component trace record will only be written if the trace conditions are met.
value
QtrcWriteTextPrintF() was not successful. An error condition was detected which would prevent the component trace record from ever being written.

Error Conditions

If QtrcWriteTextPrintF() was not successful, the error condition returned usually indicates one of the following errors. Under some conditions, the value returned could indicate an error other than those listed here.

Error condition Additional information
[EINVAL]

The specified Coded_Level is not one of the supported trace levels.

The specified Component is not a valid component name.

[EFAULT]  
[EUNKNOWN]  


Error Messages

None.


Usage Notes

  1. If the QtrcWriteTextPrintF() function is called multiple times, there may be a noticeable performance impact. The QtrcGetActiveLevel() API can be used, and the results saved into a variable for later, multiple uses. The variable can be used to quickly check if the specified Component is currently active at the appropriate trace level, prior to calling the QtrcWriteTextPrintF() function. The variable should be periodically updated, to ensure a current view of the component's active trace level. Refer to the QTRC Trace APIs for additional information concerning the use of trace levels.
  2. Refer to the QTRC Trace APIs for additional information concerning the Coded_Level, Component, Subcomponent, and Function parameters.
  3. The Format parameter and the corresponding Argument_List is used to write a string of characters as trace data, in the same style as the printf() function. This provides a simple way to write out text trace data with replacement values. For example, the Format could be something like "Function myLocator() returned %d" and the argument list would be the return code variable myRC, if the function was called with myRC=myLocator(). The Format string is assumed to be in the CCSID of the job.
  4. The Format parameter should only contain characters in the invariant character set. This is also true for any strings that may be used in the Argument_List.
  5. The total amount of text data that can be written as trace data is limited to 2048 characters. In order to trace more than 2048 characters of text data, the QtrcWriteHexDumpF function could be used to write the text data as hexadecimal trace data with a formatting option that includes the appropriate text representation. An alternative would be to split up the text data into multiple sections and call the QtrcWriteTextPrintF() function for each section.

Related Information


Example

The following example uses ERROR-level, INFO-level, and VERBOSE-level trace points to write formatted text trace data for a component named MYCOMP. The QtrcGetActiveLevel function is used, since there are more than one trace points, as described in the Performance section of QTRC Trace Tips. The VERBOSE-level component trace record will be written to the active trace collection if the program is called with one parameter and the STRTRC CL command was used before calling the example, specifying TRCTYPE((MYCOMP *VERBOSE)). The INFO-level component trace records will be written to the active trace collection if the program is called with one parameter and the STRTRC CL command was used before calling the example, specifying either TRCTYPE((MYCOMP *INFO)) or TRCTYPE((MYCOMP *VERBOSE)). The ERROR-level component trace record will be written to the active trace collection if the program is called with either no parameters or more than one parameter and the STRTRC CL command was used before calling the example, specifying either TRCTYPE((MYCOMP *ERROR)), TRCTYPE((MYCOMP *INFO)), or TRCTYPE((MYCOMP *VERBOSE)).

Note: By using the code examples, you agree to the terms of the Code license and disclaimer information.

#include <qtrc.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>

int main(int argc, char *argv[])
{
  const char *myComp = "MYCOMP";
  unsigned int myCompActLvl;
  int rc;
  char *thePATH;
  const char *defaultPATH = "/usr/bin:.:/QOpenSys/usr/bin";

  /* Get active trace level now, for MYCOMP, to allow */
  /* quick checks later on                            */
  rc = QtrcGetActiveLevel(myComp, &myCompActLvl);
  if (rc != 0) {
    printf("QtrcGetActiveLevel() failed with error %d\n",
           rc);
    return -2;
  }

  if ((argc-1) == 1) {
    /* Quick check of MYCOMP active trace level */ 
    if (myCompActLvl >= QTRC_LEVEL_INFO) {
      rc = QtrcWriteTextPrintF(QTRC_LEVEL_INFO,
               myComp,
               "SUBCOMP",
               argv[0],
               "Parameter 1 is %s", argv[1]);
      if (rc != 0) {
        printf("QtrcWriteTextPrintF() failed with error %d\n",
               rc);
        return -2;
      }
    }
  }
  else {
    /* No need for quick check of MYCOMP active trace */
    /* level since this error trace point should not  */
    /* normally be reached                            */
    rc = QtrcWriteTextPrintF(QTRC_LEVEL_ERROR,
             myComp,
             "SUBCOMP",
             argv[0],
             "Number of parameters %d, return -1", (argc-1));
    if (rc != 0) {
      printf("QtrcWriteTextPrintF() failed with error %d\n",
             rc);
      return -2;
    }
    printf("Use the ENDTRC CL command with PRTTRC(*YES) in order to\n");
    printf("see the component trace records that were written to the\n");
    printf("trace collection.\n");
    return -1;
  }

  thePATH = getenv("PATH");
  if (thePATH == NULL) {
    /* PATH environment variable not set, use default PATH */
    /* Quick check of MYCOMP active trace level */ 
    if (myCompActLvl >= QTRC_LEVEL_INFO) {
      rc = QtrcWriteTextPrintF(QTRC_LEVEL_INFO,
               myComp,
               "SUBCOMP",
               argv[0],
               "PATH is not set, using %s", defaultPATH);
      if (rc != 0) {
        printf("QtrcWriteTextPrintF() failed with error %d\n",
               rc);
        return -2;
      }
    }
    thePATH = (char *)defaultPATH;
  }
  /* Quick check of MYCOMP active trace level */ 
  if (myCompActLvl >= QTRC_LEVEL_VERBOSE) {
    rc = QtrcWriteTextPrintF(QTRC_LEVEL_VERBOSE,
             myComp,
             "SUBCOMP",
             argv[0],
             "PATH is %s", thePATH);
    if (rc != 0) {
      printf("QtrcWriteTextPrintF() failed with error %d\n",
             rc);
      return -2;
    }
  }

  printf("Use the ENDTRC CL command with PRTTRC(*YES) in order to\n");
  printf("see the component trace records that were written to the\n");
  printf("trace collection.\n");

  return 0;
}
Example Output:
Use the ENDTRC CL command with PRTTRC(*YES) in order to
see the component trace records that were written to the
trace collection.

API introduced: V6R1

[ Back to top | Problem Management APIs | APIs by category ]