2 Code based on wmppp/wmifs
6 This code was mainly put together by looking at the
10 A neat piece of equip, used to display the date
11 and time on the screen.
12 Comes with every AfterStep installation.
15 How do I create a not so solid window?
16 How do I open a window?
19 ------------------------------------------------------------
21 Authors: Martijn Pieterse (pieterse@xs4all.nl)
22 Antoine Nulle (warp@xs4all.nl)
24 This program is distributed under the GPL license.
25 (as were asclock and pppstats)
31 17/06/2012 (Rodolfo García Peñas (kix), <kix@kix.es>)
33 13/3/2012 (Barry Kelly (wbk), <coydog@devio.us>)
34 * Fixed get_statistics() I/O features to work with newer
35 /proc/diskstats instead of the old /proc/stat.
36 * Fixes to graph/meter scaling for I/O. Original code let
37 the scaling grow out of control due to inappropriate static
39 * Eliminated rounding down relatively low stats in getWidth()
40 and DrawStats_io() by using double and float types instead
41 of ints. We now round up tiny values to prevent the system
42 appearing idle when it's not.
43 * Style/readbility edits.
44 * TODO: Merge in Gentoo and possibly BSD local patches. This
45 should aid in fixing I/O monitoring on non-Linux systems.
46 * TODO: Color swapping. User supplies color values in .rc, and
47 app modifies pixmap in memory on startup. Should be simple.
48 * TODO: address compiler warnings (GCC has gotten pickier over
50 17/10/2009 (Romuald Delavergne, romuald.delavergne@free.fr)
51 * Support SMP processors in realtime CPU stress meter
52 15/05/2004 (Simon Law, sfllaw@debian.org)
53 * Support disabling of mode-cycling
54 23/10/2003 (Simon Law, sfllaw@debian.org)
55 * Eliminated exploitable static buffers
56 * Added -geometry support.
57 * /proc/meminfo support for Linux 2.6
58 18/05/1998 (Antoine Nulle, warp@xs4all.nl)
59 * MEM/SWAP/UPTIME only updated when visible
60 * Using global file descriptors to reduce file
61 system overhead, both updates are based on a diff
62 supplied by Dave Harden (dharden@wisewire.com)
63 15/05/1998 (Antoine Nulle, warp@xs4all.nl)
64 * Fixed memory overflow in the MEM gaugebar
65 * MEM gauge displays now real used mem
66 (buffered + cached mem removed)
67 14/05/1998 (Antoine Nulle, warp@xs4all.nl)
68 * Added -i & -s kludge for selecting startupmode,
69 tijno, don't hate me for this :)
70 12/05/1998 (Antoine Nulle, warp@xs4all.nl)
71 * Finetuned master-xpm, tijno don't worry, no
72 reprogramming needed this time ;-)
73 07/05/1998 (Martijn Pieterse, pieterse@xs4all.nl)
75 03/05/1998 (Antoine Nulle, warp@xs4all.nl)
76 * Added new master-xpm which contains the gfx
77 for the upcoming SysInfo part :P
78 02/05/1998 (Martijn Pieterse, pieterse@xs4all.nl)
79 * Removed a lot of code, that was put in wmgeneral
80 23/04/1998 (Martijn Pieterse, pieterse@xs4all.nl)
81 * Added zombie destroying code (aka wait :) )
82 18/04/1998 (Martijn Pieterse, pieterse@xs4all.nl)
83 * Added CPU-on-screen.
84 * Added -display command line
85 15/04/1998 (Martijn Pieterse, pieterse@xs4all.nl)
86 * Fixed a bug in the stats routine
87 (Top 3 bright pixels were not shown when 100% loaded)
88 * Changed xpm to a no-title one.
89 This included the reprogramming of all positions.
90 warpstah, i hate you! ;)
91 05/04/1998 (Martijn Pieterse, pieterse@xs4all.nl)
92 * First Working Version
103 #include <sys/wait.h>
104 #include <sys/param.h>
105 #include <sys/types.h>
107 #include <X11/Xlib.h>
109 #include <X11/extensions/shape.h>
111 #include "../wmgeneral/wmgeneral.h"
112 #include "../wmgeneral/misc.h"
114 #include "wmmon-master.xpm"
115 #include "wmmon-mask.xbm"
120 #define WMMON_VERSION "1.2.b2"
121 #define HISTORY_ENTRIES 55
122 #define HISTORY_ENTRIES 55
123 #define MAX_CPU (10) /* depends on graph height */
124 #define MAX_STAT_DEVICES (4)
126 /********************/
127 /* Global Variables */
128 /********************/
129 int stat_current
= 0; /* now global */
130 int mode_cycling
= 1; /* Allow mode-cycling */
131 int cpu_avg_max
= 0; /* CPU stress meter with average and max for SMP */
132 int show_buffers
= 0; /* wbk adding per Gentoo -b enhancement. */
137 FILE *fp_diskstats
; /* wbk new io stats API */
141 void printversion(void);
142 void DrawStats(int *, int, int, int, int);
143 void DrawStats_io(int *, int, int, int, int);
144 void wmmon_routine(int, char **);
146 int main(int argc
, char *argv
[])
149 char *name
= argv
[0];
151 /* Parse Command Line */
152 for (i
= 1; i
< argc
; i
++) {
158 if (strcmp(arg
+1, "display")) {
164 if (strcmp(arg
+1, "geometry")) {
192 wmmon_routine(argc
, argv
);
196 /*******************************************************************************\
198 \*******************************************************************************/
201 char name
[5]; /* "cpu0..cpuz", eventually.. :) */
202 int his
[HISTORY_ENTRIES
];
208 /* Processors stats */
215 stat_dev stat_device
[MAX_STAT_DEVICES
];
217 char *left_action
, *right_action
, *middle_action
;
221 unsigned long getWidth(long, long);
222 int checksysdevs(void);
223 void get_statistics(char *, long *, long *, long *, long *, long *);
224 void DrawActive(char *);
226 void update_stat_cpu(stat_dev
*, long *, long *);
227 void update_stat_io(stat_dev
*);
228 void update_stat_mem(stat_dev
*st
, stat_dev
*st2
);
229 void update_stat_swp(stat_dev
*);
231 void wmmon_routine(int argc
, char **argv
)
233 rckeys wmmon_keys
[] = {
234 { "left", &left_action
},
235 { "right", &right_action
},
236 { "middle", &middle_action
},
247 long starttime
, curtime
, nexttime
;
248 long istat
, idle
, *istat2
, *idle2
;
251 char *conffile
= NULL
;
253 int xpm_X
= 0, xpm_Y
= 0;
255 long online_time
= 0;
260 fp
= fopen("/proc/uptime", "r");
261 fp_meminfo
= fopen("/proc/meminfo", "r");
262 fp_loadavg
= fopen("/proc/loadavg", "r");
263 fp_stat
= fopen("/proc/stat", "r");
264 fp_diskstats
= fopen("/proc/diskstats", "r");
267 if (fscanf(fp
, "%ld", &online_time
) == EOF
)
268 perror("Error! fscanf() of /proc/uptime failed!\n");
273 for (i
= 0; i
< MAX_STAT_DEVICES
; i
++) {
274 for (j
= 0; j
< HISTORY_ENTRIES
; j
++)
275 stat_device
[i
].his
[j
] = 0;
277 stat_device
[i
].hisaddcnt
= 0;
280 /* wbk - I don't fully understand this. Probably just a means of providing
281 * test cases. ifdef'ing to clear compiler warnings. TODO: remove. */
284 left_action
= strdup(LEFT_ACTION
);
288 right_action
= strdup(RIGHT_ACTION
);
292 middle_action
= strdup(MIDDLE_ACTION
);
295 /* Scan through the .rc files */
296 if (asprintf(&conffile
, "/etc/wmmonrc") >= 0) {
297 parse_rcfile(conffile
, wmmon_keys
);
301 if (asprintf(&conffile
, "%s/.wmmonrc", getenv("HOME")) >= 0) {
302 parse_rcfile(conffile
, wmmon_keys
);
306 if (asprintf(&conffile
, "/etc/wmmonrc.fixed") >= 0) {
307 parse_rcfile(conffile
, wmmon_keys
);
311 stat_online
= checksysdevs();
314 stat_device
[0].cpu_stat
= calloc(nb_cpu
, sizeof(long));
315 stat_device
[0].cpu_last
= calloc(nb_cpu
, sizeof(long));
316 stat_device
[0].idle_stat
= calloc(nb_cpu
, sizeof(long));
317 stat_device
[0].idle_last
= calloc(nb_cpu
, sizeof(long));
318 if (!stat_device
[0].cpu_stat
||
319 !stat_device
[0].cpu_last
||
320 !stat_device
[0].idle_stat
||
321 !stat_device
[0].idle_last
) {
322 fprintf(stderr
, "%s: Unable to alloc memory !\n", argv
[0]);
326 istat2
= calloc(nb_cpu
, sizeof(long));
327 idle2
= calloc(nb_cpu
, sizeof(long));
328 if (!istat2
|| !idle2
) {
329 fprintf(stderr
, "%s: Unable to alloc memory !!\n", argv
[0]);
333 openXwindow(argc
, argv
, wmmon_master_xpm
, wmmon_mask_bits
,
334 wmmon_mask_width
, wmmon_mask_height
);
336 /* add mouse region */
337 AddMouseRegion(0, 12, 13, 58, 57);
338 AddMouseRegion(1, 5, 5, 24, 14);
341 nexttime
= starttime
+ 10;
343 /* Collect information on each panel */
344 for (i
= 0; i
< stat_online
; i
++) {
345 get_statistics(stat_device
[i
].name
, &k
, &istat
, &idle
, istat2
, idle2
);
346 stat_device
[i
].statlast
= istat
;
347 stat_device
[i
].idlelast
= idle
;
348 if (i
== 0 && nb_cpu
> 1) {
350 for (cpu
= 0; cpu
< nb_cpu
; cpu
++) {
351 stat_device
[i
].cpu_last
[cpu
] = istat2
[cpu
];
352 stat_device
[i
].idle_last
[cpu
] = idle2
[cpu
];
357 /* Set the mask for the current window */
358 switch (stat_current
) {
371 /* Draw statistics */
372 if (stat_current
== 0) {
373 DrawStats(stat_device
[stat_current
].his
,
374 HISTORY_ENTRIES
-1, 40, 5, 58);
375 } else if (stat_current
== 1) {
376 DrawStats_io(stat_device
[stat_current
].his
,
377 HISTORY_ENTRIES
, 40, 5, 58);
380 DrawActive(stat_device
[stat_current
].name
);
383 curtime
= time(NULL
);
385 waitpid(0, NULL
, WNOHANG
);
388 update_stat_cpu(&stat_device
[0], istat2
, idle2
);
389 update_stat_io(&stat_device
[1]);
391 if(stat_current
== 2)
392 update_stat_mem(&stat_device
[2], &stat_device
[3]);
394 if (stat_current
< 2) {
397 /* Load ding is 45 pixels hoog */
398 copyXPMArea(0, 64, 32, 12, 28, 4);
400 if (i
== 0 && nb_cpu
> 1) {
401 if (nb_cpu
> MAX_CPU
|| cpu_avg_max
) {
402 /* show average CPU */
403 j
= getWidth(stat_device
[i
].rt_stat
, stat_device
[i
].rt_idle
);
404 copyXPMArea(32, 64, j
, 6, 28, 4);
406 j
= getWidth(stat_device
[i
].cpu_stat
[cpu_max
],
407 stat_device
[i
].idle_stat
[cpu_max
]);
408 copyXPMArea(32, 70, j
, 6, 28, 10);
411 for (cpu
= 0; cpu
< nb_cpu
; cpu
++) {
412 j
= getWidth(stat_device
[i
].cpu_stat
[cpu
],
413 stat_device
[i
].idle_stat
[cpu
]);
414 copyXPMArea(32, 65, j
,
415 MAX_CPU
/ nb_cpu
, 28,
416 5 + (MAX_CPU
/ nb_cpu
) * cpu
);
420 j
= getWidth(stat_device
[i
].rt_stat
, stat_device
[i
].rt_idle
);
421 copyXPMArea(32, 64, j
, 12, 28, 4);
424 /* Nu zal ie wel 3 zijn. */
426 copyXPMArea(0, 64, 32, 12, 28+64, 4);
427 copyXPMArea(0, 64, 32, 12, 28+64, 18);
429 j
= stat_device
[2].rt_idle
;
431 j
= (stat_device
[2].rt_stat
* 100) / j
;
435 copyXPMArea(32, 64, j
, 12, 28+64, 4);
437 /*--------------------- swap? ------------------*/
438 j
= stat_device
[3].rt_idle
;
440 j
= (stat_device
[3].rt_stat
* 100) / j
;
444 copyXPMArea(32, 64, j
, 12, 28+64, 18);
446 /*----------- online tijd neerzetten! ----------*/
447 cnt_time
= time(0) - ref_time
+ online_time
;
449 /* cnt_time = uptime in seconden */
454 digits = 40,78, 6breed, 9hoog
458 copyXPMArea(40 + (i
% 10)*7, 78, 6, 9, 115, 47);
459 copyXPMArea(40 + (i
/ 10)*7, 78, 6, 9, 108, 47);
463 copyXPMArea(40 + (i
% 10)*7, 78, 6, 9, 96, 47);
464 copyXPMArea(40 + (i
/ 10)*7, 78, 6, 9, 89, 47);
468 copyXPMArea(40 + (i
% 10)*7, 78, 6, 9, 77, 47);
469 copyXPMArea(40 + (i
/ 10)*7, 78, 6, 9, 70, 47);
471 /* De rest is dagen! 5x7*/
473 copyXPMArea(66 + (i
% 10)*6, 66, 5, 7, 88, 35);
475 copyXPMArea(66 + (i
% 10)*6, 66, 5, 7, 82, 35);
477 copyXPMArea(66 + (i
% 10)*6, 66, 5, 7, 76, 35);
479 copyXPMArea(66 + (i
% 10)*6, 66, 5, 7, 70, 35);
482 if (curtime
>= nexttime
) {
485 if (curtime
> nexttime
) /* dont let APM suspends make this crazy */
488 for (i
=0; i
<stat_online
; i
++) {
489 stat_dev
*sd
= stat_device
+ i
;
491 if (sd
->his
[HISTORY_ENTRIES
-1])
492 sd
->his
[HISTORY_ENTRIES
-1] /= sd
->hisaddcnt
;
494 for (j
= 1; j
< HISTORY_ENTRIES
; j
++)
495 sd
->his
[j
-1] = sd
->his
[j
];
497 if (i
== stat_current
) {
499 DrawStats(sd
->his
, HISTORY_ENTRIES
- 1, 40, 5, 58);
501 DrawStats_io(sd
->his
, HISTORY_ENTRIES
- 1, 40, 5, 58);
503 sd
->his
[HISTORY_ENTRIES
-1] = 0;
508 RedrawWindowXY(xpm_X
, xpm_Y
);
510 while (XPending(display
)) {
511 XNextEvent(display
, &Event
);
512 switch (Event
.type
) {
514 RedrawWindowXY(xpm_X
, xpm_Y
);
517 XCloseDisplay(display
);
521 but_stat
= CheckMouseRegion(Event
.xbutton
.x
, Event
.xbutton
.y
);
524 i
= CheckMouseRegion(Event
.xbutton
.x
, Event
.xbutton
.y
);
525 if (but_stat
== i
&& but_stat
>= 0) {
528 switch (Event
.xbutton
.button
) {
531 execCommand(left_action
);
535 execCommand(middle_action
);
539 execCommand(right_action
);
546 if (stat_current
== stat_online
)
549 DrawActive(stat_device
[stat_current
].name
);
550 if (stat_current
== 0)
551 DrawStats(stat_device
[stat_current
].his
,
552 HISTORY_ENTRIES
-1, 40, 5, 58);
554 if (stat_current
== 1)
555 DrawStats_io(stat_device
[stat_current
].his
,
556 HISTORY_ENTRIES
-1, 40, 5, 58);
558 if (stat_current
== 2) {
565 RedrawWindowXY(xpm_X
, xpm_Y
);
578 void update_stat_cpu(stat_dev
*st
, long *istat2
, long *idle2
)
582 get_statistics(st
->name
, &k
, &istat
, &idle
, istat2
, idle2
);
584 st
->rt_idle
= idle
- st
->idlelast
;
587 st
->rt_stat
= istat
- st
->statlast
;
588 st
->statlast
= istat
;
592 unsigned long max
, j
;
593 cpu_max
= 0; max
= 0;
594 for (cpu
= 0; cpu
< nb_cpu
; cpu
++) {
595 st
->idle_stat
[cpu
] = idle2
[cpu
] - st
->idle_last
[cpu
];
596 st
->idle_last
[cpu
] = idle2
[cpu
];
598 st
->cpu_stat
[cpu
] = istat2
[cpu
] - st
->cpu_last
[cpu
];
599 st
->cpu_last
[cpu
] = istat2
[cpu
];
601 j
= st
->cpu_stat
[cpu
] + st
->idle_stat
[cpu
];
604 j
= (st
->cpu_stat
[cpu
] << 7) / j
;
613 st
->his
[HISTORY_ENTRIES
-1] += k
;
618 void update_stat_io(stat_dev
*st
)
620 long j
, k
, istat
, idle
;
622 /* Periodically re-sample. Sometimes we get anomalously high readings;
623 * this discards them. */
624 static int stalemax
= 300;
625 static long maxdiskio
= 0;
626 if (--stalemax
<= 0) {
631 get_statistics(st
->name
, &k
, &istat
, &idle
, NULL
, NULL
);
633 st
->rt_idle
= idle
- st
->idlelast
;
636 st
->rt_stat
= istat
- st
->statlast
;
637 st
->statlast
= istat
;
639 /* remember peak for scaling of upper-right meter. */
644 /* Calculate scaling factor for upper-right meter. "/ 5" will clip
645 * the highest peaks, but makes moderate values more visible. We are
646 * compensating for wild fluctuations which are probably caused by
647 * kernel I/O buffering.
649 st
->rt_idle
= (maxdiskio
- j
) / 5;
650 if (j
> 0 && st
->rt_idle
< 1)
651 st
->rt_idle
= 1; /* scale up tiny values so they are visible */
653 st
->his
[HISTORY_ENTRIES
-1] += st
->rt_stat
;
658 void update_stat_mem(stat_dev
*st
, stat_dev
*st2
)
660 static char *line
= NULL
;
661 static size_t line_size
= 0;
663 unsigned long swapfree
;
664 unsigned long free
, shared
, buffers
, cached
;
666 if (freopen("/proc/meminfo", "r", fp_meminfo
) == NULL
)
667 perror("freopen() of /proc/meminfo failed!)\n");
669 while ((getline(&line
, &line_size
, fp_meminfo
)) > 0) {
670 /* The original format for the first two lines of /proc/meminfo was
671 * Mem: total used free shared buffers cached
672 * Swap: total used free
674 * As of at least 2.5.47 these two lines were removed, so that the
675 * required information has to come from the rest of the lines.
676 * On top of that, used is no longer recorded - you have to work
677 * this out yourself, from total - free.
679 * So, these changes below should work. They should also work with
680 * older kernels, too, since the new format has been available for
683 if (strstr(line
, "MemTotal:"))
684 sscanf(line
, "MemTotal: %ld", &st
->rt_idle
);
685 else if (strstr(line
, "MemFree:"))
686 sscanf(line
, "MemFree: %ld", &free
);
687 else if (strstr(line
, "MemShared:"))
688 sscanf(line
, "MemShared: %ld", &shared
);
689 else if (strstr(line
, "Buffers:"))
690 sscanf(line
, "Buffers: %ld", &buffers
);
691 else if (strstr(line
, "Cached:"))
692 sscanf(line
, "Cached: %ld", &cached
);
693 else if (strstr(line
, "SwapTotal:"))
694 sscanf(line
, "SwapTotal: %ld", &st2
->rt_idle
);
695 else if (strstr(line
, "SwapFree:"))
696 sscanf(line
, "SwapFree: %ld", &swapfree
);
699 /* memory use - rt_stat is the amount used, it seems, and this isn't
700 * recorded in current version of /proc/meminfo (as of 2.5.47), so we
701 * calculate it from MemTotal - MemFree
703 st
->rt_stat
= st
->rt_idle
- free
;
705 /* wbk -b flag (from Gentoo patchkit) */
707 st
->rt_stat
-= buffers
+cached
;
708 /* As with the amount of memory used, it's not recorded any more, so
709 * we have to calculate it ourselves.
711 st2
->rt_stat
= st2
->rt_idle
- swapfree
;
714 void update_stat_swp(stat_dev
*st
)
716 static char *line
= NULL
;
717 static size_t line_size
= 0;
718 unsigned long swapfree
;
720 fseek(fp_meminfo
, 0, SEEK_SET
);
721 while ((getline(&line
, &line_size
, fp_meminfo
)) > 0) {
722 /* As with update_stat_mem(), the format change to /proc/meminfo has
723 * forced some changes here. */
724 if (strstr(line
, "SwapTotal:"))
725 sscanf(line
, "SwapTotal: %ld", &st
->rt_idle
);
726 else if (strstr(line
, "SwapFree:"))
727 sscanf(line
, "SwapFree: %ld", &swapfree
);
729 st
->rt_stat
= st
->rt_idle
- swapfree
;
732 /*******************************************************************************\
734 \*******************************************************************************/
735 void get_statistics(char *devname
, long *is
, long *ds
, long *idle
, long *ds2
, long *idle2
)
738 static char *line
= NULL
;
739 static size_t line_size
= 0;
741 char *tokens
= " \t\n";
748 if (!strncmp(devname
, "cpu", 3)) {
749 fseek(fp_stat
, 0, SEEK_SET
);
750 while ((getline(&line
, &line_size
, fp_stat
)) > 0) {
751 if (strstr(line
, "cpu")) {
752 int cpu
= -1; /* by default, cumul stats => average */
753 if (!strstr(line
, "cpu ")) {
754 sscanf(line
, "cpu%d", &cpu
);
758 p
= strtok(line
, tokens
);
759 /* 1..3, 4 == idle, we don't want idle! */
760 for (i
=0; i
<3; i
++) {
761 p
= strtok(NULL
, tokens
);
767 p
= strtok(NULL
, tokens
);
771 idle2
[cpu
] = atol(p
);
774 if ((fp_loadavg
= freopen("/proc/loadavg", "r", fp_loadavg
)) == NULL
)
775 perror("ger_statistics(): freopen(proc/loadavg) failed!\n");
777 if (fscanf(fp_loadavg
, "%f", &f
) == EOF
)
778 perror("fscanf() failed to read f\n");
779 *is
= (long) (100 * f
);
782 if (!strncmp(devname
, "i/o", 3)) {
783 if (fseek(fp_diskstats
, 0, SEEK_SET
) == -1)
784 perror("get_statistics() seek failed\n");
786 /* wbk 20120308 These are no longer in /proc/stat. /proc/diskstats
787 * seems to be the closest replacement. Under modern BSD's, /proc is
788 * now deprecated, so iostat() might be the answer.
789 * http://www.gossamer-threads.com/lists/linux/kernel/314618
790 * has good info on this being removed from kernel. Also see
791 * kernel sources Documentation/iostats.txt
793 * TODO: We will end up with doubled values. We are adding the
794 * aggregate to the individual partition, due to device selection
795 * logic. Either grab devices' stats with numbers, or without (sda
796 * OR sda[1..10]. Could use strstr() return plus offset, but would
797 * have to be careful with bounds checking since we're in a
798 * limited buffer. Or just divide by 2 (inefficient). Shouldn't
799 * matter for graphing (we care about proportions, not numbers). */
800 while ((getline(&line
, &line_size
, fp_diskstats
)) > 0) {
801 if (strstr(line
, "sd") || strstr(line
, "sr")) {
802 p
= strtok(line
, tokens
);
803 /* skip 3 tokens, then use fields from
804 `* linux/Documentation/iostats.txt */
805 for (i
= 1; i
<= 6; i
++)
806 p
= strtok(NULL
, tokens
);
809 for (i
= 7; i
<= 10; i
++)
810 p
= strtok(NULL
, tokens
);
819 /*******************************************************************************\
821 \*******************************************************************************/
822 unsigned long getWidth(long actif
, long idle
)
824 /* wbk - work with a decimal value so we don't round < 1 down to zero. */
830 j
= (actif
* 100) / j
;
834 /* round up very low positive values so they are visible. */
835 if (actif
> 0 && j
< 2)
841 r
= (unsigned long) j
;
846 /*******************************************************************************\
848 \*******************************************************************************/
851 static char *line
= NULL
;
852 static size_t line_size
= 0;
855 fseek(fp_stat
, 0, SEEK_SET
);
856 while ((getline(&line
, &line_size
, fp_stat
)) > 0) {
857 if (strstr(line
, "cpu") && !strstr(line
, "cpu "))
858 sscanf(line
, "cpu%d", &cpu
);
865 /*******************************************************************************\
867 \*******************************************************************************/
868 int checksysdevs(void) {
869 strcpy(stat_device
[0].name
, "cpu0");
870 strcpy(stat_device
[1].name
, "i/o");
871 strcpy(stat_device
[2].name
, "sys");
877 /*******************************************************************************\
878 |* void DrawActive(char *) *|
879 \*******************************************************************************/
880 void DrawActive(char *name
)
892 copyXPMArea(0, 77, 19, 10, 5, 5);
893 else if (name
[0] == 'i')
894 copyXPMArea(19, 77, 19, 10, 5, 5);
898 /*******************************************************************************\
900 \*******************************************************************************/
901 void DrawStats(int *his
, int num
, int size
, int x_left
, int y_bottom
)
903 int pixels_per_byte
, j
, k
, *p
, d
;
905 pixels_per_byte
= 100;
908 for (j
=0; j
<num
; j
++) {
909 if (p
[0] > pixels_per_byte
)
910 pixels_per_byte
+= 100;
916 for (k
=0; k
<num
; k
++) {
917 d
= (1.0 * p
[0] / pixels_per_byte
) * size
;
919 for (j
=0; j
<size
; j
++) {
921 copyXPMArea(2, 88, 1, 1, k
+x_left
, y_bottom
-j
);
923 copyXPMArea(2, 89, 1, 1, k
+x_left
, y_bottom
-j
);
925 copyXPMArea(2, 90, 1, 1, k
+x_left
, y_bottom
-j
);
930 /* Nu horizontaal op 100/200/300 etc lijntje trekken! */
931 for (j
= pixels_per_byte
-100; j
> 0; j
-=100) {
932 for (k
=0; k
<num
; k
++) {
933 d
= (40.0 / pixels_per_byte
) * j
;
935 copyXPMArea(2, 91, 1, 1, k
+x_left
, y_bottom
-d
);
941 /*******************************************************************************\
943 \*******************************************************************************/
944 void DrawStats_io(int *his
, int num
, int size
, int x_left
, int y_bottom
)
946 float pixels_per_byte
;
948 /* wbk - Use a double to avoid rounding values of d < 1 to zero. */
952 /* wbk - this should not be static. No need to track the scale, since
953 * we always calculate it on the fly anyway. This static variable did
954 * not get re-initialized when we entered this function, so the scale
955 * would always grow and never shrink.
957 /*static int global_io_scale = 1;*/
961 for (j
=0; j
<num
; j
++)
962 if (p
[j
] > io_scale
) io_scale
= p
[j
];
964 pixels_per_byte
= 1.0 * io_scale
/ size
;
965 if (pixels_per_byte
== 0)
968 for (k
=0; k
<num
; k
++) {
969 d
= (1.0 * p
[0] / pixels_per_byte
);
971 /* graph values too low for graph resolution */
972 if (d
> 0 && d
< 1) {
979 for (j
=0; j
<size
; j
++) {
981 copyXPMArea(2, 88, 1, 1, k
+x_left
, y_bottom
-j
);
983 copyXPMArea(2, 89, 1, 1, k
+x_left
, y_bottom
-j
);
985 copyXPMArea(2, 90, 1, 1, k
+x_left
, y_bottom
-j
);
987 p
+= 1; /* beware... */
992 /*******************************************************************************\
994 \*******************************************************************************/
995 void usage(char *name
)
997 printf("Usage: %s [OPTION]...\n", name
);
998 printf("WindowMaker dockapp that displays system information.\n");
1000 printf(" -display DISPLAY contact the DISPLAY X server\n");
1001 printf(" -geometry GEOMETRY position the clock at GEOMETRY\n");
1002 printf(" -l locked view - cannot cycle modes\n");
1003 printf(" -c show average and max CPU for SMP machine.\n");
1004 printf(" default if there is more than %d processors\n", MAX_CPU
);
1005 printf(" -i start in Disk I/O mode\n");
1006 printf(" -s start in System Info mode\n");
1007 printf(" -b include buffers and cache in memory usage\n");
1008 printf(" -h display this help and exit\n");
1009 printf(" -v output version information and exit\n");
1013 /*******************************************************************************\
1015 \*******************************************************************************/
1016 void printversion(void)
1018 printf("WMMon version %s\n", WMMON_VERSION
);
1020 /* vim: sw=4 ts=4 columns=82