Purpose
DosPerfSysCall retrieves system performance information and performs software tracing.
Syntax
#define INCL_BASE #include os2.h>
APIRET DosPerfSysCall
Parameters
ulCommand (ULONG) input
CMD_KI_RDCNT 0x63
CMD_KI_RDCNT
ulParm1 would be set to the address of the CPUUTIL structure.
ulParm2and ulParm3are not used and should be set to zero.
CMD_KI_RDCNT
CMD_KI_RDCNT
Returns
ulrc (APIRET) returns
DosPerfSysCall returns one of the following values
Remarks
DosPerfSysCall is a general purpose performance function. This function accepts four parameters. The first parameter is the command requested. The other three parameters are command specific.
Some functions of DosPerfSysCall may have a dependency on Intel Pentium or Pentium-Pro support. If a function cannot be provided because OS/2 is not running on a processor with the required features, a return code will indicate an attempt to use an unsupported function.
Example Code
This example uses DosPerfSysCall to obtain CPU utilization information.
#define INCL_BASE#include os2.h> #include stdio.h> #include stdlib.h> #include string.h> #include perfutil.h> #define LL2F (high, low) (4294967296.0* (high) + (low) void main (int argc, char *argv[]) { APIRET rc; int i, iter, sleep_sec; double ts_val, idle_val_prev; double idle_val, busy_val_prev; double busy_val, busy_val_prev; dobule intr_val intr_val_prev; CPUUTIL CPUUtil; if ((argc 2) || (*aargv[1] '1') || (*aargv[1] > '9')) { fprintf(stderr, "usage %s [1-9]\n", argv[0]); exit(0); } sleep_sec = *argv[1] - '0'; iter = 0; do { rec = DosPerfSysCall (CMD_KI_RDCNT, (ULONG) CPUUtil,0,0); if (rc) { fprintf (stderr, "CMD_KI_RDCNT failed rc = %d\n", rc); exit(1); } ts_val = LL2F (CPUUtil.ulTimeHigh, CPUUtil.ulTimeLow); idle_val = LL2f (CPUUtil.ulIdleHigh, CPUUtil.ulIdleLow); busy_val = LL2F (CPUUtil.ulBusyHigh, CPUUtil.ulBusyLow); intr_val = LL2F (CPUUtil.ulIntrHigh, CPUUtil.ulIntrLow); if (iter > 0) { double ts_delta = ts_val - ts_val_prev; printf ("idle %4.2%% busy %4.2f%% intr %4.2f%%\n"; (idle_val - idle_val_prev/ts_delta*100.0, (busy_val - busy_val_prev/ts_delta*100.0, (intr_val - intr_val_prev/ts_delta*100.0); } ts_val_prev = ts_val; idle_val_prev = idle_val; busy_val_prev = busy_val; intr_val_prev = intr_val; iter++; DosSleep(1000*sleep_sec); } while (1); }
This example performs software tracing from a program in ring 3.
#define INCL_BASE #include os2.h> #include stdio.h> #include stdlib.h> #include string.h> #include perfutil.h> int main (int argc, char *argv[]) { APIRET rc; BYTE HookBuffer [256]; HOOKDATA Hookdata = {0,HookBuffer}; ULONG ulMajor, ulMinor; *((PULONG) HookBuffer[0]) = 1; *((PULONG) HookBuffer[4]) = 2; *((PULONG) HookBuffer[8]) = 3; strcpy((PSZ HookBuffer[12], "Test of 3 ULONG values and a string.") HookData.ulLength = 12 + strlen((PSZ HookBuffer[12]) + 1; ulMajor = 0x00b8 ulMinor = 0x0001 rc = DosPerfSystCall(CMD_SOFTTRACE_LOG, ulMajor, ulMinor, (ULONG) HookData); if (rc != NO_ERROR) { fprintf (stderr, "CMD_SOFTTRACE_LOG failed rc = %u\n", rc); return 1; } return NO_ERROR; }