2013年3月31日 星期日

2013年3月14日 星期四

Measure CPU usage directly in COBOL

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?

2013年3月3日 星期日

IBM z/OS basics

Introduction to the New Mainframe: z/OS Basics