
MainframeSupports tip week 12/2010:
It is less than a year ago in week 22 I wrote a tip about
how to measure the CPU usage for a piece of code in a program. I also mentioned that the
tip was likely to produce wrong results when used in a CICS environment. Now I will
reveal a piece of code that will work correctly for some CICS releases, but sadly enough
not the newest ones. It is very easy to see if it does not work, because the CPU
usage will be zero:
DATA DIVISION.
WORKING-STORAGE SECTION.
01 DFHMNTDS-POINTER POINTER.
01 WORKUSED PIC S9(9) BINARY.
01 LASTUSED PIC S9(9) BINARY.
01 CPUUSAGE PIC S9(9) BINARY.
LINKAGE SECTION.
01 DFHMNTDS.
02 FILLER PIC X(1264).
02 CPUTIME PIC S9(9) BINARY.
PROCEDURE DIVISION.
...
MOVE 0 TO LASTUSED
EXEC CICS
COLLECT STATISTICS SET(DFHMNTDS-POINTER)
MONITOR(EIBTASKN) NOHANDLE
END-EXEC
IF EIBRESP = 0
SET ADDRESS OF DFHMNTDS TO DFHMNTDS-POINTER
COMPUTE WORKUSED = CPUTIME / 62.5
COMPUTE CPUUSAGE = WORKUSED - LASTUSED
MOVE WORKUSED TO LASTUSED
ELSE
MOVE 0 TO WORKUSED
MOVE 999999999 TO CPUUSAGE
END-IF
... ALL THE WORK I WANT TO MEASURE
EXEC CICS
COLLECT STATISTICS SET(DFHMNTDS-POINTER)
MONITOR(EIBTASKN) NOHANDLE
END-EXEC
IF EIBRESP = 0
SET ADDRESS OF DFHMNTDS TO DFHMNTDS-POINTER
COMPUTE WORKUSED = CPUTIME / 62.5
COMPUTE CPUUSAGE = WORKUSED - LASTUSED
MOVE WORKUSED TO LASTUSED
ELSE
MOVE 0 TO WORKUSED
MOVE 999999999 TO CPUUSAGE
END-IF
DISPLAY 'MEASURED CPU CONSUMPTION IN 1/1000 SECONDS = ' CPUUSAGE
...
To make the above work first of all you must compile your program using compiler
option PROCESS XOPTS(XP), because EXEC CICS COLLECT is a part
of the systems progrmmer interface for CICS. If CPUUSAGE shows up as 999999999 it is
because EXEC CICS COLLECT failed. If EXEC CICS COLLECT fails one of the measurements that
needs to be set up in order to make CICS collect the CPU usage is not enabled. You need
to ask the CICS systems programmer to enable those measurements. I am pretty confident that
the correct measurements are enabled at almost all installations. If not the performance
people cannot measure the CPU usage on transaction level using SMF.
Please be aware that CPUTIME on CICS has a low "resolution". It is only updated 62.5
times for each 1/1000 of a second. Therefore it can easily happen that the CPU usage turns
out to be zero. I use the above piece of code to measure the CPU usage at transaction
level. This is a vast improvement in comparison to waiting for the performance people
to collect and distribute the same measurement.
The systems programmers I have talked to in order to make the above code work told me
that it might not work for transactions running "threadsafe". So now you are warned if you
think that the returned CPU usage does not look correct. I have compared the CPU usage
returned by my example to the CPU usage recorded in SMF and it was a match. On the other
hand I do not know if the transactions I have measured were running threadsafe or not.
A threadsafe transaction runs on a socalled L8 TCB and according to the documentation I
have been reading the L8 TCB usage is also counted in the CPUTIME field, but this may be
subject for change in newer releases. By the way the CPUTIME field is called TMRCPUT in
the assembleer macro describing the DFHMNTDS record. In SMF the same field is called USRCPUT.
Previous tip in english
Sidste danske tip
Tip list
|