wmSMPmon: Code formating cleanup

This commit is contained in:
Milan Čermák 2013-01-19 10:17:30 +01:00 committed by Carlos R. Mafra
parent cb8524e80a
commit d914561f0c
5 changed files with 601 additions and 615 deletions

View file

@ -13,17 +13,18 @@
# #
######################################################################*/
# include "standards.h"
# include "general.h"
#include "standards.h"
#include "general.h"
/*
* The usual program end --
* called only by functions in this section. */
void bye_bye (int eno, const char *str)
void bye_bye(int eno, const char *str)
{
fflush(stdout);
if (str) {
if (eno) perror(str);
if (eno)
perror(str);
else {
fputs(str, stderr);
eno = 1;
@ -32,10 +33,10 @@ void bye_bye (int eno, const char *str)
exit(eno);
}
/*
/*
* This routine simply formats whatever the caller wants and
* returns a pointer to the resulting 'const char' string... */
const char *fmtmk (const char *fmts, ...)
const char *fmtmk(const char *fmts, ...)
{
static char buf[BIGBUFSIZ]; /* with help stuff, our buffer */
va_list va; /* requirements exceed 1k */
@ -43,13 +44,12 @@ const char *fmtmk (const char *fmts, ...)
va_start(va, fmts);
vsnprintf(buf, sizeof(buf), fmts, va);
va_end(va);
return (const char *)buf;
return ((const char *)buf);
}
/*
/*
* Standard error handler to normalize the look of all err o/p */
void std_err (const char *str)
void std_err(const char *str)
{
static char buf[SMLBUFSIZ];
@ -64,15 +64,16 @@ void std_err (const char *str)
bye_bye(0, buf);
}
/*
/*
* Handle our own memory stuff without the risk of leaving the
* user's terminal in an ugly state should things go sour. */
void *alloc_c (unsigned numb)
void *alloc_c(unsigned numb)
{
void * p;
if (!numb) ++numb;
if (!numb)
++numb;
if (!(p = calloc(1, numb)))
std_err("failed memory allocate");
return p;
return (p);
}

View file

@ -31,7 +31,7 @@ static int meminfo_fd = -1;
static char buf[1024];
/* assume no IO-wait stats (default kernel 2.4.x),
/* assume no IO-wait stats (default kernel 2.4.x),
overridden if linux 2.5.x or 2.6.x */
static const char *States_fmts = STATES_line2x4;
@ -40,21 +40,21 @@ static const char *States_fmts = STATES_line2x4;
* that successive calls to the functions are more efficient.
* It also reads the current contents of the file into the global buf.
*/
#define FILE_TO_BUF(filename, fd) do{ \
#define FILE_TO_BUF(filename, fd) do { \
static int local_n; \
if (fd == -1 && (fd = open(filename, O_RDONLY)) == -1) { \
if (fd == -1 && (fd = open(filename, O_RDONLY)) == -1) {\
fprintf(stderr, BAD_OPEN_MESSAGE); \
fflush(NULL); \
_exit(102); \
} \
lseek(fd, 0L, SEEK_SET); \
if ((local_n = read(fd, buf, sizeof buf - 1)) < 0) { \
if ((local_n = read(fd, buf, sizeof buf - 1)) < 0) {\
perror(filename); \
fflush(NULL); \
_exit(103); \
} \
buf[local_n] = '\0'; \
}while(0)
} while(0)
#define LINUX_VERSION(x,y,z) (0x10000*(x) + 0x100*(y) + z)
@ -83,18 +83,17 @@ unsigned int NumCpus_DoInit(void)
if (linux_version_code > LINUX_VERSION(2, 5, 41))
States_fmts = STATES_line2x5;
if (linux_version_code >= LINUX_VERSION(2, 6, 0)) // grrr... only
// some 2.6.0-testX :-(
if (linux_version_code >= LINUX_VERSION(2, 6, 0)) {
// grrr... only some 2.6.0-testX :-(
States_fmts = STATES_line2x6;
}
smp_num_cpus = sysconf(_SC_NPROCESSORS_CONF); // or _SC_NPROCESSORS_ONLN
if (smp_num_cpus < 1)
{
if (smp_num_cpus < 1) {
smp_num_cpus = 1; /* SPARC glibc is buggy */
}
if (smp_num_cpus > 255)
{
if (smp_num_cpus > 255) {
/* we don't support more than 255 CPUs (well, in fact no more
than two ate the moment... */
smp_num_cpus = 255;
@ -119,8 +118,10 @@ typedef struct mem_table_struct {
unsigned long *slot; /* slot in return struct */
} mem_table_struct;
static int compare_mem_table_structs(const void *a, const void *b){
return strcmp(((const mem_table_struct*)a)->name,((const mem_table_struct*)b)->name);
static int compare_mem_table_structs(const void *a, const void *b)
{
return strcmp(((const mem_table_struct *) a)->name,
((const mem_table_struct *) b)->name);
}
/* example data, following junk, with comments added:
@ -189,7 +190,8 @@ unsigned long kb_inactive;
unsigned long kb_mapped;
unsigned long kb_pagetables;
static void meminfo(void){
static void meminfo(void)
{
char namebuf[16]; /* big enough to hold any row name */
mem_table_struct findme = { namebuf, NULL};
mem_table_struct *found;
@ -225,45 +227,47 @@ static void meminfo(void){
{"Writeback", &kb_writeback}, // kB version of vmstat
// nr_writeback
};
const int mem_table_count = sizeof(mem_table)/sizeof(mem_table_struct);
const int mem_table_count =
sizeof(mem_table) / sizeof(mem_table_struct);
FILE_TO_BUF(MEMINFO_FILE,meminfo_fd);
kb_inactive = ~0UL;
head = buf;
for(;;){
for(;;) {
tail = strchr(head, ':');
if(!tail) break;
if (!tail)
break;
*tail = '\0';
if(strlen(head) >= sizeof(namebuf)){
head = tail+1;
if (strlen(head) >= sizeof(namebuf)) {
head = tail + 1;
goto nextline;
}
strcpy(namebuf,head);
strcpy(namebuf, head);
found = bsearch(&findme, mem_table, mem_table_count,
sizeof(mem_table_struct), compare_mem_table_structs
);
head = tail+1;
if(!found) goto nextline;
*(found->slot) = strtoul(head,&tail,10);
nextline:
sizeof(mem_table_struct), compare_mem_table_structs);
head = tail + 1;
if (!found)
goto nextline;
*(found->slot) = strtoul(head, &tail, 10);
nextline:
tail = strchr(head, '\n');
if(!tail) break;
head = tail+1;
if (!tail)
break;
head = tail + 1;
}
if(!kb_low_total){ /* low==main except with large-memory support */
if (!kb_low_total) { /* low==main except with large-memory support */
kb_low_total = kb_main_total;
kb_low_free = kb_main_free;
}
if(kb_inactive==~0UL){
if (kb_inactive == ~0UL) {
kb_inactive = kb_inact_dirty + kb_inact_clean + kb_inact_laundry;
}
kb_swap_used = kb_swap_total - kb_swap_free;
kb_main_used = kb_main_total - kb_main_free;
}
/*************************************************************************/
/*
* This guy's modeled on libproc's 'five_cpu_numbers' function except
@ -275,6 +279,7 @@ static CPU_t *cpus_refresh (CPU_t *cpus, unsigned int Cpu_tot)
{
static FILE *fp = NULL;
int i;
// enough for a /proc/stat CPU line (not the intr line)
char buf[SMLBUFSIZ];
@ -282,7 +287,8 @@ static CPU_t *cpus_refresh (CPU_t *cpus, unsigned int Cpu_tot)
(sorry Linux, but you'll have to close it for us) */
if (!fp) {
if (!(fp = fopen("/proc/stat", "r")))
std_err(fmtmk("Failed /proc/stat open: %s", strerror(errno)));
std_err(fmtmk("Failed /proc/stat open: %s",
strerror(errno)));
/* note: we allocate one more CPU_t than Cpu_tot so that the
last slot can hold tics representing the /proc/stat cpu
summary (the first line read) -- that slot supports our
@ -293,15 +299,17 @@ static CPU_t *cpus_refresh (CPU_t *cpus, unsigned int Cpu_tot)
fflush(fp);
// first value the last slot with the cpu summary line
if (!fgets(buf, sizeof(buf), fp)) std_err("failed /proc/stat read");
if (!fgets(buf, sizeof(buf), fp))
std_err("failed /proc/stat read");
cpus[Cpu_tot].x = 0; // FIXME: can't tell by kernel version number
cpus[Cpu_tot].y = 0; // FIXME: can't tell by kernel version number
if (4 > sscanf(buf, CPU_FMTS_JUST1, &cpus[Cpu_tot].u, &cpus[Cpu_tot].n, &cpus[Cpu_tot].s, &cpus[Cpu_tot].i, &cpus[Cpu_tot].w, &cpus[Cpu_tot].x, &cpus[Cpu_tot].y))
if (4 > sscanf(buf, CPU_FMTS_JUST1, &cpus[Cpu_tot].u, &cpus[Cpu_tot].n,
&cpus[Cpu_tot].s, &cpus[Cpu_tot].i, &cpus[Cpu_tot].w,
&cpus[Cpu_tot].x, &cpus[Cpu_tot].y))
std_err("failed /proc/stat read");
// and just in case we're 2.2.xx compiled without SMP support...
if (1 == Cpu_tot)
{
if (1 == Cpu_tot) {
/* do it "manually", otherwise we overwrite charge and total */
cpus[0].u = cpus[1].u;
cpus[0].n = cpus[1].n;
@ -312,14 +320,15 @@ static CPU_t *cpus_refresh (CPU_t *cpus, unsigned int Cpu_tot)
cpus[0].y = cpus[1].y;
}
// now value each separate cpu's tics
for (i = 0; 1 < Cpu_tot && i < Cpu_tot; i++) {
if (!fgets(buf, sizeof(buf), fp)) std_err("failed /proc/stat read");
if (!fgets(buf, sizeof(buf), fp))
std_err("failed /proc/stat read");
cpus[i].x = 0; // FIXME: can't tell by kernel version number
cpus[i].y = 0; // FIXME: can't tell by kernel version number
if (4 > sscanf(buf, CPU_FMTS_MULTI, &cpus[i].u, &cpus[i].n, &cpus[i].s, &cpus[i].i, &cpus[i].w, &cpus[i].x, &cpus[i].y))
if (4 > sscanf(buf, CPU_FMTS_MULTI, &cpus[i].u,
&cpus[i].n, &cpus[i].s, &cpus[i].i, &cpus[i].w,
&cpus[i].x, &cpus[i].y))
std_err("failed /proc/stat read");
}
return cpus;
@ -329,17 +338,17 @@ unsigned int *Get_CPU_Load(unsigned int *load, unsigned int Cpu_tot)
{
static CPU_t *smpcpu = NULL;
unsigned int j;
register unsigned long charge, total = 0 ;
register unsigned long charge, total = 0;
smpcpu = cpus_refresh(smpcpu, Cpu_tot);
for(j = 0 ; j < Cpu_tot ; j ++)
{
charge = smpcpu[j].u+smpcpu[j].s+smpcpu[j].n;
for (j = 0; j < Cpu_tot; j ++) {
charge = smpcpu[j].u + smpcpu[j].s + smpcpu[j].n;
total = charge + smpcpu[j].i;
/* scale cpu to a maximum of HAUTEUR */
load[j] = ((HAUTEUR * (charge - smpcpu[j].charge)) / (total - smpcpu[j].total + 0.001)) + 1 ;
load[j] = ((HAUTEUR * (charge - smpcpu[j].charge)) /
(total - smpcpu[j].total + 0.001)) + 1 ;
smpcpu[j].total = total ;
smpcpu[j].charge = charge ;
}
@ -351,15 +360,15 @@ unsigned int Get_Memory(void)
{
meminfo();
return (kb_main_used - kb_main_cached) / (kb_main_total / 100) ;
return ((kb_main_used - kb_main_cached) / (kb_main_total / 100));
/* should be between 0 and 100 now */
}
unsigned int Get_Swap(void)
{
/* returns swap usage as value between 0 and 100 OR 999 if no swap
* present */
/* returns swap usage as value between 0 and 100
* OR 999 if no swap present */
meminfo();
return ( kb_swap_total == 0 ? 999 : kb_swap_used / (kb_swap_total / 100) );
return (kb_swap_total == 0 ? 999 : kb_swap_used / (kb_swap_total / 100));
}

View file

@ -5,13 +5,14 @@
#include <sys/utsname.h>
/* These are the possible fscanf formats used in /proc/stat
/* These are the possible fscanf formats used in /proc/stat
reads during history processing.
( 5th number only for Linux 2.5.41 and above ) */
#define CPU_FMTS_JUST1 "cpu %Lu %Lu %Lu %Lu %Lu %Lu %Lu"
#define CPU_FMTS_MULTI "cpu%*d %Lu %Lu %Lu %Lu %Lu %Lu %Lu"
/* Summary Lines specially formatted string(s) -- see 'show_special' for syntax details + other cautions. */
/* Summary Lines specially formatted string(s) --
see 'show_special' for syntax details + other cautions. */
#define STATES_line2x4 "%s\03" \
" %#5.1f%% \02user,\03 %#5.1f%% \02system,\03 %#5.1f%% \02nice,\03 %#5.1f%% \02idle\03\n"
#define STATES_line2x5 "%s\03" \
@ -19,10 +20,10 @@
#define STATES_line2x6 "%s\03" \
" %#4.1f%% \02us,\03 %#4.1f%% \02sy,\03 %#4.1f%% \02ni,\03 %#4.1f%% \02id,\03 %#4.1f%% \02wa,\03 %#4.1f%% \02hi,\03 %#4.1f%% \02si\03\n"
/* These typedefs attempt to ensure consistent 'ticks' handling */
/* These typedefs attempt to ensure consistent 'ticks' handling */
typedef unsigned long long TIC_t;
/* This structure stores a frame's cpu tics used in history
/* This structure stores a frame's cpu tics used in history
calculations. It exists primarily for SMP support but serves
all environments. */
typedef struct CPU_t {
@ -30,4 +31,4 @@ typedef struct CPU_t {
TIC_t charge, total;
} CPU_t;
#endif /* SYSINFO_H */
#endif /* LINUX_SYSINFO_H */

View file

@ -1,6 +1,6 @@
/***************************************************************************
wmSMPmon III - Window Maker system monitor
VERSION : 3.1
VERSION : 3.2
DATE : 2005-11-06
ORIGINAL AUTHORS : redseb <redseb@goupilfr.org> and
PhiR <phir@gcu-squad.org>
@ -21,7 +21,6 @@ CURRENT MAINTAINER: Thomas Ribbrock <emgaron@gmx.net>
#include "wmSMPmon_mask.xbm"
#include "general.h"
#include "standards.h"
#include "sysinfo-linux.h"
#define VERSION "3.2"
@ -39,7 +38,7 @@ void usage(int cpus, const char *str);
/*###### MAIN PROGRAM ###################################################*/
int main(int argc, char **argv)
{
XEvent Event ;
XEvent Event;
unsigned int t0[TAILLE_T], /* history for CPU 0 -> Graph */
t1[TAILLE_T], /* history for CPU 1 -> Graph */
@ -62,7 +61,7 @@ int main(int argc, char **argv)
prec_swap = 0, /* swap from previous round */
load_width = 3; /* width of load bar: 3 for SMP, 8 for UP */
unsigned long load0t=0, load1t=0 ;
unsigned long load0t = 0, load1t = 0;
unsigned int *CPU_Load; /* CPU load per CPU array */
unsigned int t_idx = 0; /* Index to load history tables */
@ -71,65 +70,56 @@ int main(int argc, char **argv)
NumCPUs = NumCpus_DoInit();
CPU_Load = alloc_c((NumCPUs) * sizeof(int));
if(NumCPUs == 1)
{
if(NumCPUs == 1) {
load_width = 8;
}
else
{
} else {
load_width = 3;
}
Myname = strrchr(argv[0], '/');
if (Myname) ++Myname; else Myname = argv[0];
if (Myname)
++Myname;
else
Myname = argv[0];
/* process command line args */
i = 1; /* skip program name (i=0) */
while(argc > i)
{
if(!strncmp(argv[i], "-r", 2))
{
i ++ ;
if(i == argc)
{
while (argc > i) {
if (!strncmp(argv[i], "-r", 2)) {
i++;
if (i == argc) {
/* parameter missing! */
usage(NumCPUs, "no refresh rate given when using -r!");
}
else
{
usage(NumCPUs,
"no refresh rate given when using -r!");
} else {
delay = atol(argv[i]) ;
}
i ++ ;
i++;
continue;
}
if(!strncmp(argv[i], "-h", 2))
{
usage(NumCPUs, NULL) ;
if (!strncmp(argv[i], "-h", 2)) {
usage(NumCPUs, NULL);
}
if(!strncmp(argv[i], "-g", 2) && NumCPUs > 1)
{
if (!strncmp(argv[i], "-g", 2) && NumCPUs > 1) {
/* we only support this on SMP systems */
i ++ ;
if(i == argc)
{
i++;
if (i == argc) {
/* parameter missing! */
usage(NumCPUs, "no graph style given when using -g!");
}
else
{
etat = atoi(argv[i]) ;
usage(NumCPUs,
"no graph style given when using -g!");
} else {
etat = atoi(argv[i]);
}
if(1 > etat || etat > 3)
usage(NumCPUs, "Unknown graph style") ;
i ++ ;
if (1 > etat || etat > 3)
usage(NumCPUs, "Unknown graph style");
i++;
continue;
}
if(!strncmp(argv[i], "-no-swap", 8))
{
puts(MSG_NO_SWAP) ;
no_swap = VRAI ;
i ++ ;
if (!strncmp(argv[i], "-no-swap", 8)) {
puts(MSG_NO_SWAP);
no_swap = VRAI;
i++;
continue;
}
@ -138,44 +128,41 @@ int main(int argc, char **argv)
}
/* open initial window */
if(NumCPUs == 1)
{
if (NumCPUs == 1) {
/* we only have a single CPU - change the mask accordingly
NOTE: The for loop was derived from the differences between
wmSMPmon_mask.xbm and wmSMPmon_mask-single.xbm.
wmSMPmon_mask-single.xbm as such is NOT used in this
program! */
for (i = 33; i <= 289; i = i+8)
{
* NOTE: The for loop was derived from the differences between
* wmSMPmon_mask.xbm and wmSMPmon_mask-single.xbm.
* wmSMPmon_mask-single.xbm as such is NOT used in this
* program!
*/
for (i = 33; i <= 289; i = i+8) {
wmSMPmon_mask_bits[i] = 0xDF;
}
}
openXwindow(argc,argv,wmSMPmon_master_xpm,wmSMPmon_mask_bits,wmSMPmon_mask_width,wmSMPmon_mask_height) ;
openXwindow(argc, argv, wmSMPmon_master_xpm, wmSMPmon_mask_bits,
wmSMPmon_mask_width, wmSMPmon_mask_height);
if(NumCPUs >= 2)
{
if(NumCPUs >= 2) {
/* we have two CPUs -> draw separator between CPU load bars */
copyXPMArea(12, 4, 2, HAUTEUR + 2, 7, 4) ;
copyXPMArea(12, 4, 2, HAUTEUR + 2, 7, 4);
}
delay = delay / 2 ;
for(i = 0 ; i < TAILLE_T ; i ++) {
t0[i] = 0 ;
t1[i] = 0 ;
tm[i] = 0 ;
for (i = 0; i < TAILLE_T; i ++) {
t0[i] = 0;
t1[i] = 0;
tm[i] = 0;
}
/* -no-swap option was given */
if(no_swap)
copyXPMArea(60, 63, 60, 10, 6, 50) ;
if (no_swap)
copyXPMArea(60, 63, 60, 10, 6, 50);
/* MAIN LOOP */
while(VRAI)
{
if(lecture)
{
while (VRAI) {
if (lecture) {
CPU_Load = Get_CPU_Load(CPU_Load, NumCPUs);
load = CPU_Load[0];
@ -184,17 +171,16 @@ int main(int argc, char **argv)
}
load = load / i;
load0t = load0t + load;
if(load != load0o)
{
if (load != load0o) {
/* redraw only if cpu load changed */
delta = HAUTEUR - load ;
copyXPMArea(108, 0, load_width, HAUTEUR, 4, 5) ;
copyXPMArea(108, delta + 32, load_width, load, 4, 5 + delta) ;
delta = HAUTEUR - load;
copyXPMArea(108, 0, load_width, HAUTEUR, 4, 5);
copyXPMArea(108, delta + 32, load_width, load,
4, 5 + delta);
load0o = load;
}
if(NumCPUs >= 2)
{
if (NumCPUs >= 2) {
/* we have two CPUs -> do CPU 1 */
load = 0;
for (; i < NumCPUs; i++) {
@ -202,152 +188,140 @@ int main(int argc, char **argv)
}
load = load / (NumCPUs >> 1);
if(load != load1o)
{
if (load != load1o) {
/* redraw only if cpu load changed */
delta = HAUTEUR - load ;
copyXPMArea(108, 0, 3, HAUTEUR, 9, 5) ;
copyXPMArea(108, delta + 32, 3, load, 9, 5 + delta) ;
delta = HAUTEUR - load;
copyXPMArea(108, 0, 3, HAUTEUR, 9, 5);
copyXPMArea(108, delta + 32, 3, load,
9, 5 + delta);
load1o = load;
}
}
/* we have to set load1t in any case to get the correct
graph below. With only one CPU, 'load' will still be
CPU_Load[0], on a SMP system, it will be CPU_Load[1]. */
load1t = load1t + load ;
* graph below. With only one CPU, 'load' will still be
* CPU_Load[0], on a SMP system, it will be CPU_Load[1].
*/
load1t = load1t + load;
if(c1 > DIV1)
{
if (c1 > DIV1) {
mem = Get_Memory();
if(mem != prec_mem)
{
if (mem != prec_mem) {
/* redraw only if mem changed */
copyXPMArea(30, 63, 30, 8, 29, 39) ;
copyXPMArea(0, 63, (mem * 30 / 100), 8, 29, 39) ;
prec_mem = mem ;
copyXPMArea(30, 63, 30, 8, 29, 39);
copyXPMArea(0, 63, (mem * 30 / 100), 8,
29, 39);
prec_mem = mem;
}
if(!no_swap)
{
if (!no_swap) {
mem = Get_Swap();
if(mem != prec_swap)
{
if (mem != prec_swap) {
/* redraw if there was a change */
if(mem == 999)
{
if (mem == 999) {
/* swap is disabled => show "none" */
copyXPMArea(60, 63, 60, 10, 6, 50);
}
else
{
} else {
/* draw swap usage */
copyXPMArea(30, 63, 30, 8, 29, 50) ;
copyXPMArea(0, 63, (mem * 30 / 100), 8, 29, 50) ;
copyXPMArea(30, 63, 30, 8, 29, 50);
copyXPMArea(0, 63, (mem * 30 / 100), 8, 29, 50);
}
prec_swap = mem ;
prec_swap = mem;
}
}
c1 = 0;
}
if(c2 > DIV2) {
if((t0[t_idx] = load0t / c2) > HAUTEUR)
t0[t_idx] = HAUTEUR ;
if (c2 > DIV2) {
if ((t0[t_idx] = load0t / c2) > HAUTEUR)
t0[t_idx] = HAUTEUR;
t0[t_idx] /= 2;
if((t1[t_idx] = load1t / c2) > HAUTEUR)
t1[t_idx] = HAUTEUR ;
if ((t1[t_idx] = load1t / c2) > HAUTEUR)
t1[t_idx] = HAUTEUR;
t1[t_idx] /= 2;
if((tm[t_idx] = (load0t + load1t) / (2 * c2)) > HAUTEUR)
tm[t_idx] = HAUTEUR ;
load0t = 0 ;
load1t = 0 ;
if ((tm[t_idx] = (load0t + load1t) / (2 * c2)) > HAUTEUR)
tm[t_idx] = HAUTEUR;
load0t = 0;
load1t = 0;
t_idx = (t_idx + 1) % TAILLE_T;
draw_graph = VRAI ;
draw_graph = VRAI;
c2 = 0;
}
if(draw_graph)
{
if (draw_graph) {
/* draw graph */
switch(etat)
{
switch (etat) {
case 1 :
copyXPMArea(64, 32, TAILLE_T, HAUTEUR, 15, 5) ;
for(i = 0, load = t_idx ; i < TAILLE_T ; i ++, load++)
copyXPMArea(116, 0, 1, tm[load % TAILLE_T], 15 + i, HAUTEUR + 5 - tm[load % TAILLE_T]) ;
break ;
copyXPMArea(64, 32, TAILLE_T, HAUTEUR, 15, 5);
for (i = 0, load = t_idx; i < TAILLE_T; i ++, load++)
copyXPMArea(116, 0, 1, tm[load % TAILLE_T], 15 + i, HAUTEUR + 5 - tm[load % TAILLE_T]);
break;
case 2 :
copyXPMArea(64, 0, TAILLE_T, HAUTEUR, 15, 5) ;
for(i = 0, load = t_idx ; i < TAILLE_T ; i ++, load++) {
copyXPMArea(116, 0, 1, t0[load % TAILLE_T], 15 + i, HAUTEUR/2 + 5 - t0[load % TAILLE_T]) ;
copyXPMArea(116, 0, 1, t1[load % TAILLE_T], 15 + i, HAUTEUR/2 + 21 - t1[load % TAILLE_T]) ;
copyXPMArea(64, 0, TAILLE_T, HAUTEUR, 15, 5);
for (i = 0, load = t_idx; i < TAILLE_T; i ++, load++) {
copyXPMArea(116, 0, 1, t0[load % TAILLE_T], 15 + i, HAUTEUR/2 + 5 - t0[load % TAILLE_T]);
copyXPMArea(116, 0, 1, t1[load % TAILLE_T], 15 + i, HAUTEUR/2 + 21 - t1[load % TAILLE_T]);
}
break ;
break;
case 3 :
copyXPMArea(64, 0, TAILLE_T, HAUTEUR, 15, 5) ;
for(i = 0, load = t_idx ; i < TAILLE_T ; i ++, load++) {
copyXPMArea(116, 0, 1, t0[load % TAILLE_T], 15 + i, HAUTEUR/2 + 5 - t0[load % TAILLE_T]) ;
copyXPMArea(117, HAUTEUR/2 - t1[load % TAILLE_T], 1, t1[load % TAILLE_T], 15 + i, HAUTEUR/2 + 6) ;
copyXPMArea(64, 0, TAILLE_T, HAUTEUR, 15, 5);
for (i = 0, load = t_idx; i < TAILLE_T; i ++, load++) {
copyXPMArea(116, 0, 1, t0[load % TAILLE_T], 15 + i, HAUTEUR/2 + 5 - t0[load % TAILLE_T]);
copyXPMArea(117, HAUTEUR/2 - t1[load % TAILLE_T], 1, t1[load % TAILLE_T], 15 + i, HAUTEUR/2 + 6);
}
break ;
break;
}
draw_graph = FAUX ;
draw_graph = FAUX;
}
c1 ++ ;
c2 ++ ;
c1++;
c2++;
}
lecture = 1 - lecture ;
RedrawWindow() ;
if(NumCPUs >= 2 && XCheckMaskEvent(display, ButtonPressMask, &Event))
{
RedrawWindow();
if (NumCPUs >= 2 &&
XCheckMaskEvent(display, ButtonPressMask, &Event)) {
/* changing graph style not supported on single CPU systems */
if(Event.type == ButtonPress)
{
if((etat ++) >= 3)
etat = 1 ;
draw_graph = VRAI ;
if (Event.type == ButtonPress) {
if ((etat++) >= 3)
etat = 1;
draw_graph = VRAI;
}
}
usleep(delay);
}
}
/*###### Usage Message ##################################################*/
void usage(int cpus, const char *str)
{
fflush(stdout);
if (str)
{
if (str) {
fprintf(stderr, "\nERROR: %s\n", str);
}
fputs("\nwmSMPmon "VERSION" - display system load (", stderr);
if(cpus == 1)
{
if(cpus == 1) {
fputs("uniprocessor system)\n\n", stderr);
}
else
{
fputs("(multiprocessor system)\n\n", stderr);
} else {
fputs("multiprocessor system)\n\n", stderr);
}
fputs("Options : -h this help screen.\n"
" -r RATE refresh rate (in microseconds, default 250000).\n", stderr);
" -r RATE refresh rate (in microseconds, default 250000).\n",
stderr);
if(cpus > 1)
{
fputs(" -g STYLE graph style (try 2 or 3, default is 1).\n", stderr);
if(cpus > 1) {
fputs(" -g STYLE graph style (try 2 or 3, default is 1).\n",
stderr);
}
fputs(" -no-swap don't monitore swap size.\n\n"
"<redseb@goupilfr.org> http://goupilfr.org\n"
"<phir@gcu-squad.org> http://gcu-squad.org\n"
"<emgaron@gmx.net> http://www.ribbrock.org\n",
stderr) ;
exit(OK) ;
stderr);
exit(OK);
}

View file

@ -292,34 +292,31 @@ void createXBMfromXPM(char *xbm, char **xpm, int sx, int sy) {
int i,j,k;
int width, height, numcol, depth;
int zero=0;
int zero = 0;
unsigned char bwrite;
int bcount;
int curpixel;
sscanf(*xpm, "%d %d %d %d", &width, &height, &numcol, &depth);
for (k=0; k!=depth; k++)
{
for (k = 0; k != depth; k++) {
zero <<=8;
zero |= xpm[1][k];
}
for (i=numcol+1; i < numcol+sy+1; i++) {
for (i = numcol + 1; i < numcol + sy + 1; i++) {
bcount = 0;
bwrite = 0;
for (j=0; j<sx*depth; j+=depth) {
for (j = 0; j < sx * depth; j += depth) {
bwrite >>= 1;
curpixel=0;
for (k=0; k!=depth; k++)
{
for (k = 0; k != depth; k++) {
curpixel <<=8;
curpixel |= xpm[i][j+k];
}
if ( curpixel != zero ) {
if (curpixel != zero) {
bwrite += 128;
}
bcount++;
@ -343,10 +340,10 @@ void createXBMfromXPM(char *xbm, char **xpm, int sx, int sy) {
|* dx,dy: first corner of target area *|
\***************************************************************************/
void copyXPMArea(int x, int y, int sx, int sy, int dx, int dy) {
XCopyArea(display, wmgen.pixmap, wmgen.pixmap, NormalGC, x, y, sx, sy, dx, dy);
void copyXPMArea(int x, int y, int sx, int sy, int dx, int dy)
{
XCopyArea(display, wmgen.pixmap, wmgen.pixmap, NormalGC,
x, y, sx, sy, dx, dy);
}
/***************************************************************************\
@ -359,9 +356,10 @@ void copyXPMArea(int x, int y, int sx, int sy, int dx, int dy) {
|* dx,dy: first corner of target area *|
\***************************************************************************/
void copyXBMArea(int x, int y, int sx, int sy, int dx, int dy) {
XCopyArea(display, wmgen.mask, wmgen.pixmap, NormalGC, x, y, sx, sy, dx, dy);
void copyXBMArea(int x, int y, int sx, int sy, int dx, int dy)
{
XCopyArea(display, wmgen.mask, wmgen.pixmap, NormalGC,
x, y, sx, sy, dx, dy);
}
@ -369,8 +367,8 @@ void copyXBMArea(int x, int y, int sx, int sy, int dx, int dy) {
|* setMaskXY *|
\***************************************************************************/
void setMaskXY(int x, int y) {
void setMaskXY(int x, int y)
{
XShapeCombineMask(display, win, ShapeBounding, x, y, pixmask, ShapeSet);
XShapeCombineMask(display, iconwin, ShapeBounding, x, y, pixmask, ShapeSet);
}
@ -394,7 +392,7 @@ void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bit
int dummy=0;
int i, wx, wy;
for (i=1; argv[i]; i++) {
for (i = 1; argv[i]; i++) {
if (!strcmp(argv[i], "-display")) {
display_name = argv[i+1];
i++;
@ -427,16 +425,19 @@ void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bit
fore_pix = GetColor("black");
XWMGeometry(display, screen, Geometry, NULL, borderwidth, &mysizehints,
&mysizehints.x, &mysizehints.y,&mysizehints.width,&mysizehints.height, &dummy);
&mysizehints.x, &mysizehints.y, &mysizehints.width,
&mysizehints.height, &dummy);
mysizehints.width = 64;
mysizehints.height = 64;
win = XCreateSimpleWindow(display, Root, mysizehints.x, mysizehints.y,
mysizehints.width, mysizehints.height, borderwidth, fore_pix, back_pix);
mysizehints.width, mysizehints.height, borderwidth,
fore_pix, back_pix);
iconwin = XCreateSimpleWindow(display, win, mysizehints.x, mysizehints.y,
mysizehints.width, mysizehints.height, borderwidth, fore_pix, back_pix);
iconwin = XCreateSimpleWindow(display, win,
mysizehints.x, mysizehints.y, mysizehints.width, mysizehints.height,
borderwidth, fore_pix, back_pix);
/* Activate hints */
XSetWMNormalHints(display, win, &mysizehints);