Make AddMouseRegion's index unsigned
[dockapps.git] / wmcpuload / src / cpu_irix.c
blob40fb4679e9f3cdcaffb7310b7ab5a28437c78f0a
1 /*
2 * cpu_irix.c - module to get cpu usage, for IRIX 6.5 and IRIX64 6.5
4 * Copyright (C) 2002 Jonathan C. Patschke <jp@celestrion.net>
5 * Copyright (C) 2002 Seiichi SATO <ssato@sh.rim.or.jp>
7 * licensed under the GPL
8 */
10 #ifdef HAVE_CONFIG_H
11 #include "config.h"
12 #endif
14 #include <stdio.h>
15 #include <unistd.h>
16 #include <stdlib.h>
17 #include <string.h>
18 #include "cpu.h"
20 #include <sys/types.h>
21 #include <sys/sysmp.h>
22 #include <sys/sysinfo.h>
23 #include <sys/sysget.h>
25 int cpuCount;
27 void
28 cpu_init(void)
30 cpuCount = (int)sysmp(MP_NPROCS);
31 return;
34 /* returns current CPU usage in percent */
35 int
36 cpu_get_usage(cpu_options *opts)
38 struct sgt_cookie cookie;
39 struct sysinfo info;
40 long cpuload, cputotal;
41 static long ocpuload, ocputotal;
42 int result, i;
44 if (opts->cpu_number >= cpuCount) return 0;
45 SGT_COOKIE_INIT(&cookie);
46 if (opts->cpu_number < 1) {
47 /* Get stats for all CPUs */
48 cpuload = 0;
49 cputotal = 0;
50 for (i = 0 ; i < cpuCount ; i++) {
51 SGT_COOKIE_SET_CPU(&cookie, i);
52 memset(((void *)&info), 0x00, sizeof(info));
53 sysget(SGT_SINFO_CPU, ((char *)&info), sizeof(info),
54 SGT_READ, &cookie);
55 cpuload += info.cpu[CPU_USER] + info.cpu[CPU_KERNEL] +
56 info.cpu[CPU_WAIT] + info.cpu[CPU_SXBRK] +
57 info.cpu[CPU_INTR];
58 cputotal += cpuload + info.cpu[CPU_IDLE];
60 } else {
61 SGT_COOKIE_SET_CPU(&cookie, opts->cpu_number);
62 memset(((void *)&info), 0x00, sizeof(info));
63 sysget(SGT_SINFO_CPU, ((char *)&info), sizeof(info),
64 SGT_READ, &cookie);
65 cpuload = info.cpu[CPU_USER] + info.cpu[CPU_KERNEL] +
66 info.cpu[CPU_WAIT] + info.cpu[CPU_SXBRK] +
67 info.cpu[CPU_INTR];
68 cputotal = cpuload + info.cpu[CPU_IDLE];
70 #ifdef DEBUG
71 fprintf(stderr, "!!!%d/%d: %d, %d, %d, %d, %d, %d\n", opts->cpu_number,
72 cpuCount, info.cpu[CPU_USER], info.cpu[CPU_KERNEL], info.cpu[CPU_WAIT],
73 info.cpu[CPU_SXBRK], info.cpu[CPU_INTR], info.cpu[CPU_IDLE]);
74 #endif
76 result = ((cpuload - ocpuload) * 100) / (cputotal - ocputotal);
77 ocpuload = cpuload;
78 ocputotal = cputotal;
80 return result;