• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Guru: Application Tracing With The QTRC APIs

    May 20, 2019 Dawn May

    The IBM i operating system is extensively instrumented for diagnostic purposes to help IBM resolve issues should they arise. Instrumenting your application for diagnostics is also possible in a manner very similar to what IBM has done in the operating system.

    STRTRC and the QTRC APIs

    The operating system includes a trace facility called QTRC. This trace facility is a set of APIs (QTRC APIs) that allow you to instrument your application to collect trace data.  This trace data can be whatever you may find helpful for debugging applications in a production environment, where using a debugger is impractical.

    The Start Trace (STRTRC) command is used to turn on the trace. You specify the job to trace, which may be a single job, a set of jobs, generic jobs, or all jobs in a subsystem. STRTRC can also “Join” jobs to the trace; if you start worker jobs with spawn or are connecting to a prestart job via JDBC (for example), join trace automatically adds those jobs to the trace. This makes the trace collection dynamic based upon the flow of work for the application. There is a Join Trace API you can use for your application to join an active trace.

    The “Job Trace Type” parameter allows you to collect a call/return flow trace, collect operating system trace data, as well as specify that a component trace should be collected. The component trace is selected with the TRCTYPE parameter; when you review the available values for the TRCTYPE component parameter, you will see all sorts of selections to collect operating system component traces. This is where the QTRC APIs come into play. You can create your own component trace and specify your component on the TRCTYPE parameter. The trace level allows you to collect the trace data at three levels of detail. The trace levels are cumulative, such that at *VERBOSE, you also collect data specified at the *ERROR and *INFO levels.

    Your application checks to see if trace is active before writing any trace data; QTRC API tips recommend caching the value for fast checks, refreshing the cached value periodically. There are several QTRC APIs that allow you to write data when trace is active; you can write formatted or unformatted hexadecimal data, formatted or unformatted text data, and call stacks. The system automatically collects additional information when trace data is written including the timestamp, job name, thread ID, current user profile, and more.

    If you have an application issue and have instrumented your application with the QTRC APIs, the general flow is to start the trace, run the application until the error occurs, then end the trace with ENDTRC. With the trace complete, you have the option to select jobs from the trace collection. This may be useful if you know which jobs encountered the error. PRTTRC prints the trace data, or it can go to an output file for analysis (although IBM does not document the output file format). When you print the trace data, you can order the output by thread, or have all the trace output ordered by time. This latter option would have trace data from different threads or jobs intermixed in time order.

    STRTRC is efficient; it uses Performance Explorer (PEX) under the covers to collect the trace data. If you manage performance collections in Navigator for i, you will see the completed PEX collections generated by STRTRC.

    STRTRC also supports automatically ending the trace if a watched condition occurs. In my last article, Finding the Needle in the Haystack with Watches, I reviewed watching for messages. If a message is an indication of the application’s issue, you can specify the watched condition on the STRTRC command; when the watched condition occurs, the system will automatically end the trace for you. This can be very useful if the error is intermittent; you would start the trace with a relatively large maximum trace size, let the trace wrap when the size limit is met, and then let the trace run until the message occurs. At this point a watch is triggered and the trace automatically ends. You can also set a time limit for how long the system should watch for the message and have the trace end within that given parameter. You can optionally have a watch program that gets called so you can take some additional action.

    Below is an example of the STRTRC command. The session ID may be generated automatically by the system or you can specify the name; I prefer to use a name I can remember. The JOB parameter allows you to select the jobs you want to trace; in my example, I am tracing all jobs in the DAWNMAY subsystem. My application uses spawn() and JOINTRC(*YES) will include those spawned jobs in my trace collection. I left the JOBTRCTYPE parameter default to *ALL, so I will collect a call/return trace, any operating system trace data, as well as any components I specify on the TRCTYPE parameter. On the QTRC APIs, I have used DAWNMAY as my component and the STRTRC API allows me to specify my component ID on the TRCTYPE parameter. Notice that I am collecting detailed trace data with the *VERBOSE trace level.

    STRTRC SSNID(DAWNMAYTRC) JOB((*ALL/*ALL *ALL DAWNMAY)) JOINTRC(*YES) TRCTYPE((DAWNMAY *VERBOSE))

    The various xxxTRC commands do require *SERVICE special authority. However, the QIBM_SERVICE_TRACE function ID can authorize the use of these commands without granting the user a powerful special authority.

    RELATED RESOURCES AND STORIES

    QTRC APIs

    QTRC Tips

    Join Trace API

    Job Trace

    STRTRC, ENDTRC, PRTTRC

    Find The Needle In The Haystack With Watches

    Watch For Event Function

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags: Tags: 400guru, API, FHG, Four Hundred Guru, IBM i

    Sponsored by
    DRV Tech

    Get More Out of Your IBM i

    With soaring costs, operational data is more critical than ever. IBM shops need faster, easier ways to distribute IBM applications-based data to users more efficiently, no matter where they are.

    The Problem:

    For Users, IBM Data Can Be Difficult to Get To

    IBM Applications generate reports as spooled files, originally designed to be printed. Often those reports are packed together with so much data it makes them difficult to read. Add to that hardcopy is a pain to distribute. User-friendly formats like Excel and PDF are better, offering sorting, searching, and easy portability but getting IBM reports into these formats can be tricky without the right tools.

    The Solution:

    IBM i Reports can easily be converted to easy to read and share formats like Excel and PDF and Delivered by Email

    Converting IBM i, iSeries, and AS400 reports into Excel and PDF is now a lot easier with SpoolFlex software by DRV Tech.  If you or your users are still doing this manually, think how much time is wasted dragging and reformatting to make a report readable. How much time would be saved if they were automatically formatted correctly and delivered to one or multiple recipients.

    SpoolFlex converts spooled files to Excel and PDF, automatically emailing them, and saving copies to network shared folders. SpoolFlex converts complex reports to Excel, removing unwanted headers, splitting large reports out for individual recipients, and delivering to users whether they are at the office or working from home.

    Watch our 2-minute video and see DRV’s powerful SpoolFlex software can solve your file conversion challenges.

    Watch Video

    DRV Tech

    www.drvtech.com

    866.378.3366

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Do These Four Things to Avoid ERP Project Failure Why i Reason #87: Eschewing Performance for Its Own Sake

    Leave a Reply Cancel reply

TFH Volume: 29 Issue: 32

This Issue Sponsored By

  • iTech Solutions
  • ProData Computer Services
  • ARCAD Software
  • MITEC
  • WorksRight Software

Table of Contents

  • IBM Gives A Peek Of The Future At POWERUp 2019
  • Why i Reason #87: Eschewing Performance for Its Own Sake
  • Guru: Application Tracing With The QTRC APIs
  • Do These Four Things to Avoid ERP Project Failure
  • IBM i PTF Guide, Volume 21, Number 20

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • Meet The Next Gen Of IBMers Helping To Build IBM i
  • Looks Like IBM Is Building A Linux-Like PASE For IBM i After All
  • Will Independent IBM i Clouds Survive PowerVS?
  • Now, IBM Is Jacking Up Hardware Maintenance Prices
  • IBM i PTF Guide, Volume 27, Number 24
  • Big Blue Raises IBM i License Transfer Fees, Other Prices
  • Keep The IBM i Youth Movement Going With More Training, Better Tools
  • Remain Begins Migrating DevOps Tools To VS Code
  • IBM Readies LTO-10 Tape Drives And Libraries
  • IBM i PTF Guide, Volume 27, Number 23

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2025 IT Jungle