Writing EXECs that display CPU consumption
A common problem with EXEC performance is an EXEC exceeding the CPU thresholds set for
BMC AMI Ops Automation
.
The resulting abend can be bypassed by using IMFEXEC CNTL statement in the EXEC to reset the limits. However, this situation can potentially expose your system to excessive CPU consumption and program loops, and diagnosing a runaway situation such as this one is difficult.
One technique for diagnosing these problems involves writing some additional code in the EXEC to monitor itself.
For example:
Use the following statement when writing REXX EXECs:
TSO FUNCTION 'SYSVAR('SYSCPU')'The total amount of CPU seconds used to date for the TCB on which the EXEC is running is returned.
Use the &SYSCPU system variable when writing CLISTs.
The total amount of CPU seconds that has been used to date for the TCB on which the EXEC is running is returned.
Change the EXEC to set a control variable with the CPU value on entry.
The control variable can then be manipulated later as required.
For example:
parse arg exec_name p1 .
do x = 1 to p1 by 1
"VGET VARNAME"||x "SHARED"
"MSG 'VARNAME"||x "=" value("VARNAME"||x)"'"
end x
"EXIT CODE(0)"
exit 0
This EXEC is a subroutine that displays an array of variables from the SHARED variable pool on the subsystem journal. Occasionally, it may spike in CPU consumption because the number of array items spikes. However, this situation cannot be seen and analyzed from the EXEC Management application.
Therefore, you can modify the EXEC to identify the problem and display diagnostic data by using the SYSCPU function as shown:
entry_cpu = trunc(SYSVAR('SYSCPU')) /* Get CPU Time on entry */
parse arg exec_name p1 .
do x = 1 to p1 by 1
"VGET VARNAME"||x "SHARED"
"MSG 'VARNAME"||x "=" value("VARNAME"||x)
time_used = trunc(SYSVAR('SYSCPU')) - entry_cpu
if time_used => "CPU LIMIT SET ON THE SYSTEM" then
do
"ALERT" exec_name"@CPU 'CPU TIME AT" x "ELEMENTS IS"
time_used"'"
entry_cpu = trunc(SYSVAR('SYSCPU'))
end
end x
"EXIT CODE(0)"
exit 0
In this example, the EXEC itself does some preliminary analysis for the EXEC writer. More typically, this routine would be built into a common function that can be called.
BBSAMP member AOXCPUFI contains an example of REXX internal functions that you can easily incorporate into another EXEC to selectively call for analysis.
BBSAMP member AOXCPUSI contains an example of a REXX EXEC that uses AOXCPUFI (internally called by a REXX EXEC as CPU_FUNC) to monitor CPU utilization. This example EXEC checks CPU consumption after a defined numbers of operations in its calling routine to determine the threshold number of events that equal a predefined amount of CPU seconds.
Related topic