• 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
    VISUAL LANSA 16 WEBINAR

    Trying to balance stability and agility in your IBM i environment?

    Join this webinar and explore Visual LANSA 16 – our enhanced professional low-code platform designed to help organizations running on IBM i evolve seamlessly for what’s next.

    🎙️VISUAL LANSA 16 WEBINAR

    Break Monolithic IBM i Applications and Unlock New Value

    Explore modernization without rewriting. Decouple monolithic applications and extend their value through integration with modern services, web frameworks, and cloud technologies.

    🗓️ July 10, 2025

    ⏰ 9 AM – 10 AM CDT (4 PM to 5 PM CEST)

    See the webinar schedule in your time zone

    Register to join the webinar now

    What to Expect

    • Get to know Visual LANSA 16, its core features, latest enhancements, and use cases
    • Understand how you can transition to a MACH-aligned architecture to enable faster innovation
    • Discover native REST APIs, WebView2 support, cloud-ready Azure licensing, and more to help transform and scale your IBM i applications

    Read more about V16 here.

    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

  • With Power11, Power Systems “Go To Eleven”
  • With Subscription Price, IBM i P20 And P30 Tiers Get Bigger Bundles
  • Izzi Buys CNX, Eyes Valence Port To System Z
  • IBM i Shops “Attacking” Security Concerns, Study Shows
  • IBM i PTF Guide, Volume 27, Number 26
  • Liam Allan Shares What’s Coming Next With Code For IBM i
  • From Stable To Scalable: Visual LANSA 16 Powers IBM i Growth – Launching July 8
  • VS Code Will Be The Heart Of The Modern IBM i Platform
  • The AS/400: A 37-Year-Old Dog That Loves To Learn New Tricks
  • IBM i PTF Guide, Volume 27, Number 25

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