--- wmcpu-1.4/wmcpu.c.bak 2009-01-02 23:01:37.315016489 +0200 +++ wmcpu-1.4/wmcpu.c 2009-02-12 22:51:49.865545696 +0200 @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -49,6 +50,8 @@ "\t-l\tshow load as numbers\n" \ "\t-t\ttime between refresh in usec (def=250000)\n" +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) + static char *display_name = NULL; static Display *display; static Window win; @@ -59,6 +62,7 @@ static Pixmap mask; static unsigned long udelay = 250000; static int gfx_loadbar = 1; static char* geometry = NULL; +static int flag_comm; static void wmcpu_routine(void); static void redraw_window(void); @@ -79,6 +83,8 @@ int main(int argc, char **argv) gfx_loadbar = 0; else if( !strcmp( argv[par], "-t" ) && par+1 < argc ) udelay = atol(argv[++par]); + else if( !strcmp (argv[par], "-c" ) ) + flag_comm = 1; else { fputs(HELP_TEXT, stdout); exit(0); @@ -97,28 +103,30 @@ int main(int argc, char **argv) return EXIT_SUCCESS; } +#define NR_MEMLINES (10) + void wmcpu_routine(void) { int i; int tempy; - const int xoffset = 5; - const int barwidth = 54; + int xoffset; + static const int barwidth = 54; XEvent Event; FILE *fp; char str[128]; - - static float cpustat[4]; /* remember the statistics read last time */ - float info[4]; - + static unsigned long long cpustat[9]; /* remember the statistics read last time */ + unsigned long long info[9]; int old_mins = -1; - char has_meminfo = 0; - struct { - short int line; - int *var; - } memlines[4]; - int memtotal=0, memfree=0, membuffers=0, memcached=0, memuser=0; - + typedef struct { + int line; + uint64_t *var; + } memline; + memline memlines[NR_MEMLINES]; + uint64_t memtotal=0, memfree=0, membuffers=0, memcached=0, memuser=0; + uint64_t memcommitlimit=0, memcommittedas=0; + uint64_t memactive_anon=0, memactive_file=0, meminactive_anon=0, meminactive_file=0; + /* /proc/meminfo Initialization {{{ This will find which line numbers correspond to each meminfo value. This is done now to avoid @@ -127,28 +135,34 @@ void wmcpu_routine(void) short int line=0, last_item=0; struct { char *name; - int *var; - } meminfolines[4] = { - {"MemTotal:",&memtotal }, - {"MemFree:" ,&memfree }, - {"Buffers:" ,&membuffers}, - {"Cached:" ,&memcached } + uint64_t *var; + } meminfolines[NR_MEMLINES] = { + {"MemTotal:", &memtotal }, + {"MemFree:", &memfree }, + {"Buffers:", &membuffers }, + {"Cached:", &memcached }, + {"CommitLimit:", &memcommitlimit }, + {"Committed_AS:", &memcommittedas }, + {"Active(anon):", &memactive_anon }, + {"Active(file):", &memactive_file }, + {"Inactive(anon):", &meminactive_anon }, + {"Inactive(file):", &meminactive_file }, }; while(fscanf(fp," %127s%*[^\n]",str) > 0) { line++; - for(i=0; i<4; i++) + for(i=0; i=4) + if(last_item>=ARRAY_SIZE(memlines)) break; } fclose(fp); /* Next loop is just to not leave unitialized items. */ - while(last_item<4) { + while(last_item 0) { - CPUuser = fields[0] / total * (barwidth - 0.5); - CPUnice = fields[1] / total * (barwidth - 0.5); - CPUsyst = fields[2] / total * (barwidth - 0.5); + xoffset = 5; + CPUuser = ((fields[0] + fields[1]) * barwidth) / total; + CPUsyst = ((fields[2] + fields[5] + fields[6] + fields[7] + fields[8]) * barwidth) / total; + CPUiowait = (fields[4] * barwidth) / total; + copy_xpm_area(3, 93, CPUuser, 9, xoffset, 5); - copy_xpm_area(3, 75, CPUnice, 9, xoffset + CPUuser, 5); - copy_xpm_area(3, 84, CPUsyst, 9, - xoffset + CPUuser + CPUnice, 5); + xoffset += CPUuser; + copy_xpm_area(3, 75, CPUsyst, 9, xoffset, 5); + xoffset += CPUsyst; + copy_xpm_area(3, 84, CPUiowait, 9, xoffset, 5); + xoffset += CPUiowait; copy_xpm_area(3, 102, - (54 - (CPUuser + CPUnice + CPUsyst)), 9, - xoffset + CPUuser + CPUnice + CPUsyst, 5); + (barwidth - (CPUuser + CPUsyst + CPUiowait)), + 9, xoffset, 5); } } - for (i = 0; i < 4; i++) + for (i = 0; i < 9; i++) cpustat[i] = info[i]; } /* /proc/stat kernel/system statistics }}} */ @@ -215,9 +237,9 @@ void wmcpu_routine(void) oldv = info[0]; if (gfx_loadbar) { oldv = ftmp; - i = MIN(54, (ftmp * 54)); + i = MIN(barwidth, (ftmp * barwidth)); copy_xpm_area(3, 75, i, 9, 5, 33); - copy_xpm_area(3, 102, 54 - i, 9, 5 + i, 33); + copy_xpm_area(3, 102, barwidth - i, 9, 5 + i, 33); } else { tempx = ftmp * 100; if (tempx > 9999) @@ -248,27 +270,38 @@ void wmcpu_routine(void) the system as well as the shared memory and buffers used by the kernel. */ if (has_meminfo && (fp = fopen("/proc/meminfo", "r")) != NULL) { - short int line=0, last_item=0; - int oldtotal, oldfree, oldbuffers, oldcached, olduser; - int barbuffers, barcached, baruser; + int line=0, last_item=0; + uint64_t oldtotal, oldfree, oldbuffers, oldcached, olduser; + uint64_t oldcommitlimit, oldcommittedas; + uint64_t oldactive_anon, oldactive_file, oldinactive_anon, oldinactive_file; + int barbuffers, barcached, baruser; + int baractive_anon, baractive_file, barinactive_anon, barinactive_file, barother; oldtotal =memtotal; oldfree =memfree; oldbuffers=membuffers; oldcached =memcached; olduser =memuser; /* Note: value of this var is calculated from other vars. */ + oldcommitlimit = memcommitlimit; + oldcommittedas = memcommittedas; + oldactive_anon = memactive_anon; + oldactive_file = memactive_file; + oldinactive_anon = meminactive_anon; + oldinactive_file = meminactive_file; + while( fgets(str,128,fp) ) { line++; if(line == memlines[last_item].line) { - sscanf(str,"%*s%d",memlines[last_item].var); + sscanf(str,"%*s%lu",memlines[last_item].var); last_item++; } - if(last_item >= 4 || memlines[last_item].line==0) + if(last_item >= ARRAY_SIZE(memlines) || memlines[last_item].line==0) break; } fclose(fp); memuser = memtotal - memfree - membuffers - memcached; + xoffset = 5; if ( memfree != oldfree || membuffers != oldbuffers || memcached != oldcached || memtotal != oldtotal ) { @@ -277,18 +310,48 @@ void wmcpu_routine(void) barbuffers = (membuffers * barwidth) / memtotal; copy_xpm_area(3, 111, baruser , 9, xoffset, 19); - copy_xpm_area(3, 120, barbuffers, 9, xoffset + baruser, 19); - copy_xpm_area(3, 84, barcached , 9, xoffset + baruser + barbuffers, 19); + xoffset += baruser; + copy_xpm_area(3, 120, barbuffers, 9, xoffset, 19); + xoffset += barbuffers; + copy_xpm_area(3, 84, barcached , 9, xoffset, 19); + xoffset += barcached; copy_xpm_area(3, 102, barwidth - (baruser + barbuffers + barcached), 9, - xoffset + (baruser + barbuffers + barcached), 19); + xoffset, 19); + } + + if (flag_comm && (oldcommitlimit != memcommitlimit || + oldcommittedas != memcommittedas || oldactive_anon != memactive_anon || + oldactive_file != memactive_file || oldinactive_anon != meminactive_anon || + oldinactive_file != meminactive_file)) { + xoffset = 5; + baractive_anon = (memactive_anon * barwidth) / memcommitlimit; + baractive_file = (memactive_file * barwidth) / memcommitlimit; + barinactive_anon = (meminactive_anon * barwidth) / memcommitlimit; + barinactive_file = (meminactive_file * barwidth) / memcommitlimit; + barother = ((memcommittedas - baractive_anon - baractive_file - + barinactive_anon - barinactive_file) * barwidth) / memcommitlimit; + + copy_xpm_area(3, 111, baractive_anon, 9, xoffset, 49); + xoffset += baractive_anon; + copy_xpm_area(3, 129, baractive_file, 9, xoffset, 49); + xoffset += baractive_file; + copy_xpm_area(3, 93, barinactive_anon, 9, xoffset, 49); + xoffset += barinactive_anon; + copy_xpm_area(3, 120, barinactive_file, 9, xoffset, 49); + xoffset += barinactive_file; + copy_xpm_area(3, 75, barother, 9, xoffset, 49); + xoffset += barother; + copy_xpm_area(3, 102, (barwidth - (baractive_anon + baractive_file + + barinactive_anon + barinactive_file + barother)), + 9, xoffset, 49); } } /* /proc/meminfo }}} */ /* /proc/uptime {{{ Tell how long the system has been running. */ - if ((fp = fopen("/proc/uptime", "r")) != NULL) { + if (!flag_comm && ((fp = fopen("/proc/uptime", "r")) != NULL)) { int upt, days, hours, mins; fscanf(fp, "%d", &upt); fclose(fp);