1 /***************************************************************************
2 wmSMPmon III - Window Maker system monitor
5 ORIGINAL AUTHORS : redseb <redseb@goupilfr.org> and
6 PhiR <phir@gcu-squad.org>
7 CONTRIBUTORS : Alain Schröder <alain@parkautomat.net>
8 CURRENT MAINTAINER: Thomas Ribbrock <emgaron@gmx.net>
9 ****************************************************************************
10 This file is placed under the conditions of the GNU Library
11 General Public License, version 2, or any later version.
12 See file COPYING for information on distribution conditions.
13 ***************************************************************************/
18 #include <X11/extensions/shape.h>
19 #include <libdockapp/wmgeneral.h>
20 #include "wmSMPmon_master.xpm"
21 #include "wmSMPmon_mask.xbm"
23 #include "standards.h"
27 /*###### Dividers for redraw-loops ######################################*/
31 /*###### Messages #######################################################*/
32 #define MSG_NO_SWAP "No swap mode : Swap is not monitored.\n"
34 /*###### Funcition definitions ##########################################*/
35 void usage(int cpus
, const char *str
);
38 /*###### MAIN PROGRAM ###################################################*/
39 int main(int argc
, char **argv
)
43 unsigned int t0
[TAILLE_T
], /* history for CPU 0 -> Graph */
44 t1
[TAILLE_T
], /* history for CPU 1 -> Graph */
45 tm
[TAILLE_T
], /* history for CPU 0+1 -> Graph */
57 NumCPUs
, /* number of CPUs */
59 mem
= 0, /* current memory/swap scaled to 0-100 */
60 prec_mem
= 0, /* memory from previous round */
61 prec_swap
= 0, /* swap from previous round */
62 load_width
= 3; /* width of load bar: 3 for SMP, 8 for UP */
64 unsigned long load0t
= 0, load1t
= 0;
66 unsigned int *CPU_Load
; /* CPU load per CPU array */
67 unsigned int t_idx
= 0; /* Index to load history tables */
69 /********** Initialisation **********/
70 NumCPUs
= NumCpus_DoInit();
71 CPU_Load
= alloc_c((NumCPUs
) * sizeof(int));
79 Myname
= strrchr(argv
[0], '/');
85 /* process command line args */
86 i
= 1; /* skip program name (i=0) */
88 if (!strncmp(argv
[i
], "-r", 2)) {
91 /* parameter missing! */
93 "no refresh rate given when using -r!");
95 delay
= atol(argv
[i
]) ;
100 if (!strncmp(argv
[i
], "-h", 2)) {
101 usage(NumCPUs
, NULL
);
103 if (!strncmp(argv
[i
], "-g", 2) && NumCPUs
> 1) {
104 /* we only support this on SMP systems */
107 /* parameter missing! */
109 "no graph style given when using -g!");
111 etat
= atoi(argv
[i
]);
114 if (1 > etat
|| etat
> 3)
115 usage(NumCPUs
, "Unknown graph style");
119 if (!strncmp(argv
[i
], "-no-swap", 8)) {
126 /* if we get here, we found an illegal option */
127 usage(NumCPUs
, "Illegal option!");
130 /* open initial window */
132 /* we only have a single CPU - change the mask accordingly
133 * NOTE: The for loop was derived from the differences between
134 * wmSMPmon_mask.xbm and wmSMPmon_mask-single.xbm.
135 * wmSMPmon_mask-single.xbm as such is NOT used in this
138 for (i
= 33; i
<= 289; i
= i
+8) {
139 wmSMPmon_mask_bits
[i
] = 0xDF;
143 openXwindow(argc
, argv
, wmSMPmon_master_xpm
, wmSMPmon_mask_bits
,
144 wmSMPmon_mask_width
, wmSMPmon_mask_height
);
147 /* we have two CPUs -> draw separator between CPU load bars */
148 copyXPMArea(12, 4, 2, HAUTEUR
+ 2, 7, 4);
153 for (i
= 0; i
< TAILLE_T
; i
++) {
159 /* -no-swap option was given */
161 copyXPMArea(60, 63, 60, 10, 6, 50);
166 CPU_Load
= Get_CPU_Load(CPU_Load
, NumCPUs
);
169 for (i
= 1; i
< NumCPUs
>> 1; i
++) {
173 load0t
= load0t
+ load
;
174 if (load
!= load0o
) {
175 /* redraw only if cpu load changed */
176 delta
= HAUTEUR
- load
;
177 copyXPMArea(108, 0, load_width
, HAUTEUR
, 4, 5);
178 copyXPMArea(108, delta
+ 32, load_width
, load
,
184 /* we have two CPUs -> do CPU 1 */
186 for (; i
< NumCPUs
; i
++) {
189 load
= load
/ (NumCPUs
>> 1);
191 if (load
!= load1o
) {
192 /* redraw only if cpu load changed */
193 delta
= HAUTEUR
- load
;
194 copyXPMArea(108, 0, 3, HAUTEUR
, 9, 5);
195 copyXPMArea(108, delta
+ 32, 3, load
,
201 /* we have to set load1t in any case to get the correct
202 * graph below. With only one CPU, 'load' will still be
203 * CPU_Load[0], on a SMP system, it will be CPU_Load[1].
205 load1t
= load1t
+ load
;
210 if (mem
!= prec_mem
) {
211 /* redraw only if mem changed */
212 copyXPMArea(30, 63, 30, 8, 29, 39);
213 copyXPMArea(0, 63, (mem
* 30 / 100), 8,
221 if (mem
!= prec_swap
) {
222 /* redraw if there was a change */
224 /* swap is disabled => show "none" */
225 copyXPMArea(60, 63, 60, 10, 6, 50);
227 /* draw swap usage */
228 copyXPMArea(30, 63, 30, 8, 29, 50);
229 copyXPMArea(0, 63, (mem
* 30 / 100), 8, 29, 50);
238 if ((t0
[t_idx
] = load0t
/ c2
) > HAUTEUR
)
241 if ((t1
[t_idx
] = load1t
/ c2
) > HAUTEUR
)
244 if ((tm
[t_idx
] = (load0t
+ load1t
) / (2 * c2
)) > HAUTEUR
)
248 t_idx
= (t_idx
+ 1) % TAILLE_T
;
257 copyXPMArea(64, 32, TAILLE_T
, HAUTEUR
, 15, 5);
258 for (i
= 0, load
= t_idx
; i
< TAILLE_T
; i
++, load
++)
259 copyXPMArea(116, 0, 1, tm
[load
% TAILLE_T
], 15 + i
, HAUTEUR
+ 5 - tm
[load
% TAILLE_T
]);
262 copyXPMArea(64, 0, TAILLE_T
, HAUTEUR
, 15, 5);
263 for (i
= 0, load
= t_idx
; i
< TAILLE_T
; i
++, load
++) {
264 copyXPMArea(116, 0, 1, t0
[load
% TAILLE_T
], 15 + i
, HAUTEUR
/2 + 5 - t0
[load
% TAILLE_T
]);
265 copyXPMArea(116, 0, 1, t1
[load
% TAILLE_T
], 15 + i
, HAUTEUR
/2 + 21 - t1
[load
% TAILLE_T
]);
269 copyXPMArea(64, 0, TAILLE_T
, HAUTEUR
, 15, 5);
270 for (i
= 0, load
= t_idx
; i
< TAILLE_T
; i
++, load
++) {
271 copyXPMArea(116, 0, 1, t0
[load
% TAILLE_T
], 15 + i
, HAUTEUR
/2 + 5 - t0
[load
% TAILLE_T
]);
272 copyXPMArea(117, HAUTEUR
/2 - t1
[load
% TAILLE_T
], 1, t1
[load
% TAILLE_T
], 15 + i
, HAUTEUR
/2 + 6);
281 lecture
= 1 - lecture
;
284 XCheckMaskEvent(display
, ButtonPressMask
, &Event
)) {
285 /* changing graph style not supported on single CPU systems */
286 if (Event
.type
== ButtonPress
) {
296 /*###### Usage Message ##################################################*/
297 void usage(int cpus
, const char *str
)
302 fprintf(stderr
, "\nERROR: %s\n", str
);
305 fputs("\nwmSMPmon "VERSION
" - display system load (", stderr
);
307 fputs("uniprocessor system)\n\n", stderr
);
309 fputs("multiprocessor system)\n\n", stderr
);
311 fputs("Options : -h this help screen.\n"
312 " -r RATE refresh rate (in microseconds, default 250000).\n",
316 fputs(" -g STYLE graph style (try 2 or 3, default is 1).\n",
320 fputs(" -no-swap don't monitore swap size.\n\n"
321 "<redseb@goupilfr.org> http://goupilfr.org\n"
322 "<phir@gcu-squad.org> http://gcu-squad.org\n"
323 "<emgaron@gmx.net> http://www.ribbrock.org\n",