wmSMPmon: Solaris support, load aggregation
I wanted to use it on Solaris which has different way to obtain system statistics. I build a support file and changed Makefile to take the operating system into account. Then I moved to fixing the widget. The comments in the code said that it supports only 2 CPUs. I've added an aggregation so that it still shows two graphs but represents all CPUs. Lastly, I some programmatic flaws - like multiple loops for one task - cleaning up the code a bit. It should also speed up the widget a little.
This commit is contained in:
		
							parent
							
								
									13243aa489
								
							
						
					
					
						commit
						c8eb4a3762
					
				
					 3 changed files with 74 additions and 58 deletions
				
			
		| 
						 | 
				
			
			@ -1,3 +1,9 @@
 | 
			
		|||
3.2
 | 
			
		||||
 | 
			
		||||
- Added Solaris support.
 | 
			
		||||
- Added CPU load aggreggation so that they fit into two columns.
 | 
			
		||||
- A bit of code clean-up to speed up things.
 | 
			
		||||
 | 
			
		||||
3.1
 | 
			
		||||
 | 
			
		||||
- Fixed bug where wmSMPmon would crash if no swap is enabled/present
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,7 +5,9 @@
 | 
			
		|||
BINDIR=/usr/local/bin/
 | 
			
		||||
MANDIR=/usr/local/share/man/
 | 
			
		||||
 | 
			
		||||
SRC = general.c sysinfo-linux.c ../wmgeneral/wmgeneral.c wmSMPmon.c 
 | 
			
		||||
OS := $(shell uname -s)
 | 
			
		||||
 | 
			
		||||
SRC = general.c ../wmgeneral/wmgeneral.c wmSMPmon.c
 | 
			
		||||
EXE = wmSMPmon
 | 
			
		||||
MAN = wmSMPmon.1
 | 
			
		||||
OBJ = $(SRC:.c=.o)
 | 
			
		||||
| 
						 | 
				
			
			@ -16,6 +18,14 @@ CC = gcc
 | 
			
		|||
CFLAGS = -Wall -O2 -g
 | 
			
		||||
LIB = -L/usr/X11R6/lib -lXpm -lXext -lX11
 | 
			
		||||
 | 
			
		||||
ifeq ($(OS),Linux)
 | 
			
		||||
SRC += sysinfo-linux.c
 | 
			
		||||
endif
 | 
			
		||||
ifeq ($(OS),SunOS)
 | 
			
		||||
SRC += sysinfo-solaris.c
 | 
			
		||||
LIB += -lkstat
 | 
			
		||||
endif
 | 
			
		||||
 | 
			
		||||
all: $(OBJ)
 | 
			
		||||
	$(CC) -o $(EXE) $(OBJ) $(LIB)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -23,7 +23,7 @@ CURRENT MAINTAINER: Thomas Ribbrock <emgaron@gmx.net>
 | 
			
		|||
#include	"standards.h"
 | 
			
		||||
#include        "sysinfo-linux.h"
 | 
			
		||||
 | 
			
		||||
#define		VERSION		"3.1"
 | 
			
		||||
#define		VERSION		"3.2"
 | 
			
		||||
 | 
			
		||||
/*###### Dividers for redraw-loops ######################################*/
 | 
			
		||||
#define		DIV1		6
 | 
			
		||||
| 
						 | 
				
			
			@ -44,8 +44,8 @@ int main(int argc, char **argv)
 | 
			
		|||
   unsigned int		t0[TAILLE_T], /* history for CPU 0 -> Graph */
 | 
			
		||||
      			t1[TAILLE_T], /* history for CPU 1 -> Graph */
 | 
			
		||||
                        tm[TAILLE_T], /* history for CPU 0+1 -> Graph */
 | 
			
		||||
   			c1 = 6,
 | 
			
		||||
      			c2 = 9,
 | 
			
		||||
   			c1 = DIV1,
 | 
			
		||||
      			c2 = DIV2,
 | 
			
		||||
                        etat = 1,
 | 
			
		||||
      			lecture = 1,
 | 
			
		||||
 			delay = 250000,
 | 
			
		||||
| 
						 | 
				
			
			@ -54,7 +54,7 @@ int main(int argc, char **argv)
 | 
			
		|||
                        load0o = 0,
 | 
			
		||||
                        load1o = 0,
 | 
			
		||||
                        no_swap = FAUX,
 | 
			
		||||
                        draw_graph = FAUX,
 | 
			
		||||
                        draw_graph = VRAI,
 | 
			
		||||
                        NumCPUs,      /* number of CPUs */
 | 
			
		||||
                        i = 0,        /* counter */
 | 
			
		||||
                        mem = 0, /* current memory/swap scaled to 0-100 */
 | 
			
		||||
| 
						 | 
				
			
			@ -65,7 +65,7 @@ int main(int argc, char **argv)
 | 
			
		|||
   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 */
 | 
			
		||||
 | 
			
		||||
       /********** Initialisation **********/
 | 
			
		||||
  NumCPUs = NumCpus_DoInit();
 | 
			
		||||
| 
						 | 
				
			
			@ -83,7 +83,6 @@ int main(int argc, char **argv)
 | 
			
		|||
  Myname = strrchr(argv[0], '/');
 | 
			
		||||
  if (Myname) ++Myname; else Myname = argv[0];
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  /* process command line args */
 | 
			
		||||
  i = 1; /* skip program name (i=0) */
 | 
			
		||||
   while(argc > i)
 | 
			
		||||
| 
						 | 
				
			
			@ -162,12 +161,11 @@ int main(int argc, char **argv)
 | 
			
		|||
 | 
			
		||||
   delay = delay / 2 ;
 | 
			
		||||
 | 
			
		||||
   for(i = 0 ; i < TAILLE_T ; i ++)
 | 
			
		||||
   for(i = 0 ; i < TAILLE_T ; i ++) {
 | 
			
		||||
      t0[i] = 0 ;
 | 
			
		||||
   for(i = 0 ; i < TAILLE_T ; i ++)
 | 
			
		||||
      t1[i] = 0 ;
 | 
			
		||||
   for(i = 0 ; i < TAILLE_T ; i ++)
 | 
			
		||||
      tm[i] = 0 ;
 | 
			
		||||
   }
 | 
			
		||||
 | 
			
		||||
       /* -no-swap option was given */
 | 
			
		||||
   if(no_swap)
 | 
			
		||||
| 
						 | 
				
			
			@ -181,7 +179,11 @@ int main(int argc, char **argv)
 | 
			
		|||
        CPU_Load = Get_CPU_Load(CPU_Load, NumCPUs);
 | 
			
		||||
 | 
			
		||||
	load = CPU_Load[0];
 | 
			
		||||
        load0t = load0t + load ;
 | 
			
		||||
	for (i = 1; i < NumCPUs >> 1; i++) {
 | 
			
		||||
	    load += CPU_Load[i];
 | 
			
		||||
	}
 | 
			
		||||
	load = load / i;
 | 
			
		||||
        load0t = load0t + load;
 | 
			
		||||
         if(load != load0o)
 | 
			
		||||
         {
 | 
			
		||||
               /* redraw only if cpu load changed */
 | 
			
		||||
| 
						 | 
				
			
			@ -194,8 +196,11 @@ int main(int argc, char **argv)
 | 
			
		|||
         if(NumCPUs >= 2)
 | 
			
		||||
         {
 | 
			
		||||
               /* we have two CPUs -> do CPU 1 */
 | 
			
		||||
               /* FIXME: What about more CPUs? */
 | 
			
		||||
           load = CPU_Load[1];
 | 
			
		||||
           load = 0;
 | 
			
		||||
	   for (; i < NumCPUs; i++) {
 | 
			
		||||
               load += CPU_Load[i];
 | 
			
		||||
           }
 | 
			
		||||
           load = load / (NumCPUs >> 1);
 | 
			
		||||
 | 
			
		||||
           if(load != load1o)
 | 
			
		||||
             {
 | 
			
		||||
| 
						 | 
				
			
			@ -212,7 +217,6 @@ int main(int argc, char **argv)
 | 
			
		|||
                CPU_Load[0], on a SMP system, it will be CPU_Load[1]. */
 | 
			
		||||
         load1t = load1t + load ;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
         if(c1 > DIV1)
 | 
			
		||||
         {
 | 
			
		||||
           mem = Get_Memory();
 | 
			
		||||
| 
						 | 
				
			
			@ -249,49 +253,46 @@ int main(int argc, char **argv)
 | 
			
		|||
            c1 = 0;
 | 
			
		||||
         }
 | 
			
		||||
 | 
			
		||||
         if(c2 > DIV2)
 | 
			
		||||
            draw_graph = VRAI ;
 | 
			
		||||
         if(draw_graph)
 | 
			
		||||
         {
 | 
			
		||||
            for(i = 1 ; i < TAILLE_T ; i ++)
 | 
			
		||||
            {
 | 
			
		||||
               t0[i - 1] = t0[i] ;
 | 
			
		||||
               t1[i - 1] = t1[i] ;
 | 
			
		||||
               tm[i - 1] = tm[i] ;
 | 
			
		||||
            }
 | 
			
		||||
            if((t0[TAILLE_T - 1] = load0t / c2) > HAUTEUR)
 | 
			
		||||
               t0[TAILLE_T - 1] = HAUTEUR ;
 | 
			
		||||
            if((t1[TAILLE_T - 1] = load1t / c2) > HAUTEUR)
 | 
			
		||||
               t1[TAILLE_T - 1] = HAUTEUR ;
 | 
			
		||||
            if((tm[TAILLE_T - 1] = (load0t + load1t) / (2 * c2)) > HAUTEUR)
 | 
			
		||||
               tm[TAILLE_T - 1] = 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 ;
 | 
			
		||||
            t1[t_idx] /= 2;
 | 
			
		||||
            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 ;
 | 
			
		||||
            c2 = 0;
 | 
			
		||||
         }
 | 
			
		||||
         if(draw_graph)
 | 
			
		||||
         {
 | 
			
		||||
                /* draw graph */
 | 
			
		||||
            switch(etat)
 | 
			
		||||
            {
 | 
			
		||||
               case 1 :
 | 
			
		||||
                  copyXPMArea(64, 32, TAILLE_T, HAUTEUR, 15, 5) ;
 | 
			
		||||
                  for(i = 0 ; i < TAILLE_T ; i ++)
 | 
			
		||||
                     copyXPMArea(116, 0, 1, tm[i], 15 + i, HAUTEUR + 5 - tm[i]) ;
 | 
			
		||||
                  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 ; i < TAILLE_T ; i ++)
 | 
			
		||||
                     copyXPMArea(116, 0, 1, t0[i]/2, 15 + i, HAUTEUR/2 + 5 - t0[i]/2) ;
 | 
			
		||||
                  for(i = 0 ; i < TAILLE_T ; i ++)
 | 
			
		||||
                     copyXPMArea(116, 0, 1, t1[i]/2, 15 + i, HAUTEUR/2 + 21 - t1[i]/2) ;
 | 
			
		||||
                  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 ;
 | 
			
		||||
               case 3 :
 | 
			
		||||
                  copyXPMArea(64, 0, TAILLE_T, HAUTEUR, 15, 5) ;
 | 
			
		||||
                  for(i = 0 ; i < TAILLE_T ; i ++)
 | 
			
		||||
                     copyXPMArea(116, 0, 1, t0[i]/2, 15 + i, HAUTEUR/2 + 5 - t0[i]/2) ;
 | 
			
		||||
                  for(i = 0 ; i < TAILLE_T ; i ++)
 | 
			
		||||
                     copyXPMArea(117, (HAUTEUR - t1[i])/2, 1, t1[i]/2, 15 + i, HAUTEUR/2 + 6) ;               
 | 
			
		||||
                  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 ;
 | 
			
		||||
            }
 | 
			
		||||
            c2 = 0 ;
 | 
			
		||||
            draw_graph = FAUX ;
 | 
			
		||||
         }
 | 
			
		||||
         c1 ++ ;
 | 
			
		||||
| 
						 | 
				
			
			@ -307,7 +308,6 @@ int main(int argc, char **argv)
 | 
			
		|||
            if((etat ++) >= 3)
 | 
			
		||||
               etat = 1 ;
 | 
			
		||||
            draw_graph = VRAI ;
 | 
			
		||||
            lecture = VRAI ;
 | 
			
		||||
         }
 | 
			
		||||
      }
 | 
			
		||||
      usleep(delay);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue