47cdc55ca1387d20003cc0bcdf477962479d7c8d
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 "../wmgeneral/wmgeneral.h"
20 #include "wmSMPmon_master.xpm"
21 #include "wmSMPmon_mask.xbm"
23 #include "standards.h"
24 #include "sysinfo-linux.h"
28 /*###### Dividers for redraw-loops ######################################*/
32 /*###### Messages #######################################################*/
33 #define MSG_NO_SWAP "No swap mode : Swap is not monitored.\n"
35 /*###### Funcition definitions ##########################################*/
36 void usage(int cpus
, const char *str
);
39 /*###### MAIN PROGRAM ###################################################*/
40 int main(int argc
, char **argv
)
44 unsigned int t0
[TAILLE_T
], /* history for CPU 0 -> Graph */
45 t1
[TAILLE_T
], /* history for CPU 1 -> Graph */
46 tm
[TAILLE_T
], /* history for CPU 0+1 -> Graph */
58 NumCPUs
, /* number of CPUs */
60 mem
= 0, /* current memory/swap scaled to 0-100 */
61 prec_mem
= 0, /* memory from previous round */
62 prec_swap
= 0, /* swap from previous round */
63 load_width
= 3; /* width of load bar: 3 for SMP, 8 for UP */
65 unsigned long load0t
=0, load1t
=0 ;
67 unsigned int *CPU_Load
; /* CPU load per CPU array */
70 /********** Initialisation **********/
71 NumCPUs
= NumCpus_DoInit();
72 CPU_Load
= alloc_c((NumCPUs
) * sizeof(int));
83 Myname
= strrchr(argv
[0], '/');
84 if (Myname
) ++Myname
; else Myname
= argv
[0];
87 /* process command line args */
88 i
= 1; /* skip program name (i=0) */
91 if(!strncmp(argv
[i
], "-r", 2))
96 /* parameter missing! */
97 usage(NumCPUs
, "no refresh rate given when using -r!");
101 delay
= atol(argv
[i
]) ;
106 if(!strncmp(argv
[i
], "-h", 2))
108 usage(NumCPUs
, NULL
) ;
110 if(!strncmp(argv
[i
], "-g", 2) && NumCPUs
> 1)
112 /* we only support this on SMP systems */
116 /* parameter missing! */
117 usage(NumCPUs
, "no graph style given when using -g!");
121 etat
= atoi(argv
[i
]) ;
124 if(1 > etat
|| etat
> 3)
125 usage(NumCPUs
, "Unknown graph style") ;
129 if(!strncmp(argv
[i
], "-no-swap", 8))
137 /* if we get here, we found an illegal option */
138 usage(NumCPUs
, "Illegal option!");
141 /* open initial window */
144 /* we only have a single CPU - change the mask accordingly
145 NOTE: The for loop was derived from the differences between
146 wmSMPmon_mask.xbm and wmSMPmon_mask-single.xbm.
147 wmSMPmon_mask-single.xbm as such is NOT used in this
149 for (i
= 33; i
<= 289; i
= i
+8)
151 wmSMPmon_mask_bits
[i
] = 0xDF;
155 openXwindow(argc
,argv
,wmSMPmon_master_xpm
,wmSMPmon_mask_bits
,wmSMPmon_mask_width
,wmSMPmon_mask_height
) ;
159 /* we have two CPUs -> draw separator between CPU load bars */
160 copyXPMArea(12, 4, 2, HAUTEUR
+ 2, 7, 4) ;
165 for(i
= 0 ; i
< TAILLE_T
; i
++)
167 for(i
= 0 ; i
< TAILLE_T
; i
++)
169 for(i
= 0 ; i
< TAILLE_T
; i
++)
172 /* -no-swap option was given */
174 copyXPMArea(60, 63, 60, 10, 6, 50) ;
181 CPU_Load
= Get_CPU_Load(CPU_Load
, NumCPUs
);
184 load0t
= load0t
+ load
;
187 /* redraw only if cpu load changed */
188 delta
= HAUTEUR
- load
;
189 copyXPMArea(108, 0, load_width
, HAUTEUR
, 4, 5) ;
190 copyXPMArea(108, delta
+ 32, load_width
, load
, 4, 5 + delta
) ;
196 /* we have two CPUs -> do CPU 1 */
197 /* FIXME: What about more CPUs? */
202 /* redraw only if cpu load changed */
203 delta
= HAUTEUR
- load
;
204 copyXPMArea(108, 0, 3, HAUTEUR
, 9, 5) ;
205 copyXPMArea(108, delta
+ 32, 3, load
, 9, 5 + delta
) ;
210 /* we have to set load1t in any case to get the correct
211 graph below. With only one CPU, 'load' will still be
212 CPU_Load[0], on a SMP system, it will be CPU_Load[1]. */
213 load1t
= load1t
+ load
;
222 /* redraw only if mem changed */
223 copyXPMArea(30, 63, 30, 8, 29, 39) ;
224 copyXPMArea(0, 63, (mem
* 30 / 100), 8, 29, 39) ;
234 /* redraw if there was a change */
237 /* swap is disabled => show "none" */
238 copyXPMArea(60, 63, 60, 10, 6, 50);
242 /* draw swap usage */
243 copyXPMArea(30, 63, 30, 8, 29, 50) ;
244 copyXPMArea(0, 63, (mem
* 30 / 100), 8, 29, 50) ;
256 for(i
= 1 ; i
< TAILLE_T
; i
++)
262 if((t0
[TAILLE_T
- 1] = load0t
/ c2
) > HAUTEUR
)
263 t0
[TAILLE_T
- 1] = HAUTEUR
;
264 if((t1
[TAILLE_T
- 1] = load1t
/ c2
) > HAUTEUR
)
265 t1
[TAILLE_T
- 1] = HAUTEUR
;
266 if((tm
[TAILLE_T
- 1] = (load0t
+ load1t
) / (2 * c2
)) > HAUTEUR
)
267 tm
[TAILLE_T
- 1] = HAUTEUR
;
275 copyXPMArea(64, 32, TAILLE_T
, HAUTEUR
, 15, 5) ;
276 for(i
= 0 ; i
< TAILLE_T
; i
++)
277 copyXPMArea(116, 0, 1, tm
[i
], 15 + i
, HAUTEUR
+ 5 - tm
[i
]) ;
280 copyXPMArea(64, 0, TAILLE_T
, HAUTEUR
, 15, 5) ;
281 for(i
= 0 ; i
< TAILLE_T
; i
++)
282 copyXPMArea(116, 0, 1, t0
[i
]/2, 15 + i
, HAUTEUR
/2 + 5 - t0
[i
]/2) ;
283 for(i
= 0 ; i
< TAILLE_T
; i
++)
284 copyXPMArea(116, 0, 1, t1
[i
]/2, 15 + i
, HAUTEUR
/2 + 21 - t1
[i
]/2) ;
287 copyXPMArea(64, 0, TAILLE_T
, HAUTEUR
, 15, 5) ;
288 for(i
= 0 ; i
< TAILLE_T
; i
++)
289 copyXPMArea(116, 0, 1, t0
[i
]/2, 15 + i
, HAUTEUR
/2 + 5 - t0
[i
]/2) ;
290 for(i
= 0 ; i
< TAILLE_T
; i
++)
291 copyXPMArea(117, (HAUTEUR
- t1
[i
])/2, 1, t1
[i
]/2, 15 + i
, HAUTEUR
/2 + 6) ;
300 lecture
= 1 - lecture
;
302 if(NumCPUs
>= 2 && XCheckMaskEvent(display
, ButtonPressMask
, &Event
))
304 /* changing graph style not supported on single CPU systems */
305 if(Event
.type
== ButtonPress
)
318 /*###### Usage Message ##################################################*/
319 void usage(int cpus
, const char *str
)
325 fprintf(stderr
, "\nERROR: %s\n", str
);
328 fputs("\nwmSMPmon "VERSION
" - display system load (", stderr
);
331 fputs("uniprocessor system)\n\n", stderr
);
335 fputs("(multiprocessor system)\n\n", stderr
);
337 fputs("Options : -h this help screen.\n"
338 " -r RATE refresh rate (in microseconds, default 250000).\n", stderr
);
342 fputs(" -g STYLE graph style (try 2 or 3, default is 1).\n", stderr
);
345 fputs(" -no-swap don't monitore swap size.\n\n"
346 "<redseb@goupilfr.org> http://goupilfr.org\n"
347 "<phir@gcu-squad.org> http://gcu-squad.org\n"
348 "<emgaron@gmx.net> http://www.ribbrock.org\n",