Seeing which jobs use the most CPU

Log in to save
SELECT JOB_NAME, AUTHORIZATION_NAME, SUBSYSTEM,
       ELAPSED_CPU_PERCENTAGE, CPU_TIME, FUNCTION
  FROM TABLE(QSYS2.ACTIVE_JOB_INFO(RESET_STATISTICS => 'YES'))
 WHERE JOB_TYPE <> 'SYS'
 ORDER BY ELAPSED_CPU_PERCENTAGE DESC
 FETCH FIRST 15 ROWS ONLY

To look at a single subsystem:

SELECT JOB_NAME, ELAPSED_CPU_PERCENTAGE, FUNCTION
  FROM TABLE(QSYS2.ACTIVE_JOB_INFO(SUBSYSTEM_LIST_FILTER => 'QBATCH'))
 ORDER BY ELAPSED_CPU_PERCENTAGE DESC

Example: "yesterday at three it was crawling"

This is the report that always arrives the day after, when there is nothing left to look at. WRKACTJOB shows now; the problem was yesterday.

A job scheduled every five minutes writing the top five consumers closes the whole category. The table is created from the query itself, so the service decides the column names and types and there is nothing to guess:

CREATE TABLE MYLIB/CPUHIST AS (
  SELECT CURRENT TIMESTAMP AS TAKEN_AT, JOB_NAME,
         AUTHORIZATION_NAME, ELAPSED_CPU_PERCENTAGE, FUNCTION
    FROM TABLE(QSYS2.ACTIVE_JOB_INFO())
) WITH NO DATA

Then the CL to schedule:

RUNSQL SQL('INSERT INTO MYLIB/CPUHIST                        +
            SELECT CURRENT TIMESTAMP AS TAKEN_AT, JOB_NAME,   +
                   AUTHORIZATION_NAME, ELAPSED_CPU_PERCENTAGE, FUNCTION +
              FROM TABLE(QSYS2.ACTIVE_JOB_INFO())            +
             WHERE JOB_TYPE <> ''SYS''                       +
             ORDER BY ELAPSED_CPU_PERCENTAGE DESC            +
             FETCH FIRST 5 ROWS ONLY') COMMIT(*NONE)

The next day the question has an answer:

SELECT * FROM MYLIB/CPUHIST
 WHERE TAKEN_AT BETWEEN '2026-08-25 14:30:00' AND '2026-08-25 15:30:00'
 ORDER BY TAKEN_AT, ELAPSED_CPU_PERCENTAGE DESC

One row every five minutes for five jobs takes almost nothing, and turns a complaint into the name of a program.

Note

ELAPSED_CPU_PERCENTAGE is the percentage over the interval since the last reset, not since the job started. With RESET_STATISTICS => 'YES' you reset it and run the query again a few seconds later: that is how you see who is consuming now, rather than who has consumed in total.

Tip

the FUNCTION column says where the job is, which program or command it is running. On a stalled job it is often the only information needed.


Releases. QSYS2.ACTIVE_JOB_INFO is available from 7.1, but the named parameters were added over time: RESET_STATISTICS and SUBSYSTEM_LIST_FILTER are not on older releases. If the call is rejected, run the function with no parameters (TABLE(QSYS2.ACTIVE_JOB_INFO())) and filter in the WHERE clause.

Il CL dell'esempio non è stato eseguito. La query che contiene sì, nella forma senza parametri.

← Back to blog

Comments

No comments yet. Be the first to comment!

You need an account to comment. Log in · Sign up