MainframeSupports
tip week 22/2009:

I our daily work as programmers we do not care too much about the CPU usage of our programs. And when we do we almost certainly blame DB2. In order to say anything qualified about the CPU usage an important pre-condition is to measure it. In batch jobs you can read the CPU usage for each step in the JES message log. In a CICS environment you have to use SMF records at transaction level.

If you want to measure certain parts of your program it becomes increasingly difficult. Most installations have developed assembler programs for more than 25 years ago which are able to help you. The problem with these programs are that no one can remember the names and usage of these programs and no one knows how to code assembler in order to make some new programs to replace the old ones. Fortunately it is possible to measure CPU usage directly in COBOL and COBOL is a language that most mainframe programmers still master. You may code your measurement like this:

DATA DIVISION.
WORKING-STORAGE SECTION.
01  PSA-POINTER POINTER.
01  WORKUSED PIC S9(9) BINARY.
01  LASTUSED PIC S9(9) BINARY.
01  CPUUSAGE PIC S9(9) BINARY.
LINKAGE SECTION.
01  PSA.
  02  FILLER PIC X(548).
  02  ASCB-POINTER POINTER.
01  ASCB.
  02  FILLER PIC X(64).
  02  CPUTIME PIC S9(18) BINARY.
PROCEDURE DIVISION.
...
MOVE 0 TO LASTUSED
SET PSA-POINTER TO NULL
SET ADDRESS OF PSA TO PSA-POINTER
SET ADDRESS OF ASCB TO ASCB-POINTER
COMPUTE WORKUSED = CPUTIME / 4096000
COMPUTE CPUUSAGE = WORKUSED - LASTUSED
MOVE WORKUSED TO LASTUSED
... ALL THE WORK I WANT TO MEASURE
COMPUTE WORKUSED = CPUTIME / 4096000
COMPUTE CPUUSAGE = WORKUSED - LASTUSED
MOVE WORKUSED TO LASTUSED
DISPLAY 'MEASURED CPU CONSUMPTION IN 1/1000 SECONDS = ' CPUUSAGE
...

The above piece of code may be inserted in any existing COBOL program. The field CPUTIME in the ASCB contains at any given time the number of 1/4096 microseconds the TCB in the address space has been executing on CPU's allocated to the MVS. Our normal COBOL programs in batch or in TSO are executed using the same TCB which is not shared with other users. Therefore the above piece of code will measure the exact amount of CPU used by the piece of code executed between the two COMPUTE WORKUSED = CPUTIME / 4096000 statements. Consequently WORKUSED contains the CPU usage i 1/1000 seconds since the first TCB in the address space started executing.

You may translate the above piece of code into PL/I if you have access to the new Enterprise PL/I compiler. A PIC S9(18) BINARY is the same as a FIXED BIN(63) in PL/I. And now a word of warning. The above method of measuring CPU usage will not yield the correct result when used in a CICS program. CICS executes many concurrent transactions in the same address space and also on the same TCB. Only if you have a CICS system that is all yours and no one elses you might get the correct result, but who has that?

Previous tip in english        Sidste danske tip        Tip list