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
 | 
					3.1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Fixed bug where wmSMPmon would crash if no swap is enabled/present
 | 
					- Fixed bug where wmSMPmon would crash if no swap is enabled/present
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,7 +5,9 @@
 | 
				
			||||||
BINDIR=/usr/local/bin/
 | 
					BINDIR=/usr/local/bin/
 | 
				
			||||||
MANDIR=/usr/local/share/man/
 | 
					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
 | 
					EXE = wmSMPmon
 | 
				
			||||||
MAN = wmSMPmon.1
 | 
					MAN = wmSMPmon.1
 | 
				
			||||||
OBJ = $(SRC:.c=.o)
 | 
					OBJ = $(SRC:.c=.o)
 | 
				
			||||||
| 
						 | 
					@ -16,6 +18,14 @@ CC = gcc
 | 
				
			||||||
CFLAGS = -Wall -O2 -g
 | 
					CFLAGS = -Wall -O2 -g
 | 
				
			||||||
LIB = -L/usr/X11R6/lib -lXpm -lXext -lX11
 | 
					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)
 | 
					all: $(OBJ)
 | 
				
			||||||
	$(CC) -o $(EXE) $(OBJ) $(LIB)
 | 
						$(CC) -o $(EXE) $(OBJ) $(LIB)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -23,7 +23,7 @@ CURRENT MAINTAINER: Thomas Ribbrock <emgaron@gmx.net>
 | 
				
			||||||
#include	"standards.h"
 | 
					#include	"standards.h"
 | 
				
			||||||
#include        "sysinfo-linux.h"
 | 
					#include        "sysinfo-linux.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define		VERSION		"3.1"
 | 
					#define		VERSION		"3.2"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*###### Dividers for redraw-loops ######################################*/
 | 
					/*###### Dividers for redraw-loops ######################################*/
 | 
				
			||||||
#define		DIV1		6
 | 
					#define		DIV1		6
 | 
				
			||||||
| 
						 | 
					@ -44,8 +44,8 @@ int main(int argc, char **argv)
 | 
				
			||||||
   unsigned int		t0[TAILLE_T], /* history for CPU 0 -> Graph */
 | 
					   unsigned int		t0[TAILLE_T], /* history for CPU 0 -> Graph */
 | 
				
			||||||
      			t1[TAILLE_T], /* history for CPU 1 -> Graph */
 | 
					      			t1[TAILLE_T], /* history for CPU 1 -> Graph */
 | 
				
			||||||
                        tm[TAILLE_T], /* history for CPU 0+1 -> Graph */
 | 
					                        tm[TAILLE_T], /* history for CPU 0+1 -> Graph */
 | 
				
			||||||
   			c1 = 6,
 | 
					   			c1 = DIV1,
 | 
				
			||||||
      			c2 = 9,
 | 
					      			c2 = DIV2,
 | 
				
			||||||
                        etat = 1,
 | 
					                        etat = 1,
 | 
				
			||||||
      			lecture = 1,
 | 
					      			lecture = 1,
 | 
				
			||||||
 			delay = 250000,
 | 
					 			delay = 250000,
 | 
				
			||||||
| 
						 | 
					@ -54,7 +54,7 @@ int main(int argc, char **argv)
 | 
				
			||||||
                        load0o = 0,
 | 
					                        load0o = 0,
 | 
				
			||||||
                        load1o = 0,
 | 
					                        load1o = 0,
 | 
				
			||||||
                        no_swap = FAUX,
 | 
					                        no_swap = FAUX,
 | 
				
			||||||
                        draw_graph = FAUX,
 | 
					                        draw_graph = VRAI,
 | 
				
			||||||
                        NumCPUs,      /* number of CPUs */
 | 
					                        NumCPUs,      /* number of CPUs */
 | 
				
			||||||
                        i = 0,        /* counter */
 | 
					                        i = 0,        /* counter */
 | 
				
			||||||
                        mem = 0, /* current memory/swap scaled to 0-100 */
 | 
					                        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 long	load0t=0, load1t=0 ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   unsigned int         *CPU_Load; /* CPU load per CPU array */
 | 
					   unsigned int         *CPU_Load; /* CPU load per CPU array */
 | 
				
			||||||
 | 
					   unsigned int		t_idx = 0; /* Index to load history tables */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
       /********** Initialisation **********/
 | 
					       /********** Initialisation **********/
 | 
				
			||||||
  NumCPUs = NumCpus_DoInit();
 | 
					  NumCPUs = NumCpus_DoInit();
 | 
				
			||||||
| 
						 | 
					@ -83,7 +83,6 @@ int main(int argc, char **argv)
 | 
				
			||||||
  Myname = strrchr(argv[0], '/');
 | 
					  Myname = strrchr(argv[0], '/');
 | 
				
			||||||
  if (Myname) ++Myname; else Myname = argv[0];
 | 
					  if (Myname) ++Myname; else Myname = argv[0];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
  /* process command line args */
 | 
					  /* process command line args */
 | 
				
			||||||
  i = 1; /* skip program name (i=0) */
 | 
					  i = 1; /* skip program name (i=0) */
 | 
				
			||||||
   while(argc > i)
 | 
					   while(argc > i)
 | 
				
			||||||
| 
						 | 
					@ -162,12 +161,11 @@ int main(int argc, char **argv)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   delay = delay / 2 ;
 | 
					   delay = delay / 2 ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   for(i = 0 ; i < TAILLE_T ; i ++)
 | 
					   for(i = 0 ; i < TAILLE_T ; i ++) {
 | 
				
			||||||
      t0[i] = 0 ;
 | 
					      t0[i] = 0 ;
 | 
				
			||||||
   for(i = 0 ; i < TAILLE_T ; i ++)
 | 
					 | 
				
			||||||
      t1[i] = 0 ;
 | 
					      t1[i] = 0 ;
 | 
				
			||||||
   for(i = 0 ; i < TAILLE_T ; i ++)
 | 
					 | 
				
			||||||
      tm[i] = 0 ;
 | 
					      tm[i] = 0 ;
 | 
				
			||||||
 | 
					   }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
       /* -no-swap option was given */
 | 
					       /* -no-swap option was given */
 | 
				
			||||||
   if(no_swap)
 | 
					   if(no_swap)
 | 
				
			||||||
| 
						 | 
					@ -180,22 +178,29 @@ int main(int argc, char **argv)
 | 
				
			||||||
      {
 | 
					      {
 | 
				
			||||||
        CPU_Load = Get_CPU_Load(CPU_Load, NumCPUs);
 | 
					        CPU_Load = Get_CPU_Load(CPU_Load, NumCPUs);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        load = CPU_Load[0];
 | 
						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)
 | 
					         if(load != load0o)
 | 
				
			||||||
         {
 | 
					         {
 | 
				
			||||||
               /* redraw only if cpu load changed */
 | 
					               /* redraw only if cpu load changed */
 | 
				
			||||||
            delta = HAUTEUR - load ;
 | 
					            delta = HAUTEUR - load ;
 | 
				
			||||||
       	    copyXPMArea(108, 0, load_width, HAUTEUR, 4, 5) ;
 | 
					            copyXPMArea(108, 0, load_width, HAUTEUR, 4, 5) ;
 | 
				
			||||||
       	    copyXPMArea(108, delta + 32, load_width, load, 4, 5 + delta) ;
 | 
					            copyXPMArea(108, delta + 32, load_width, load, 4, 5 + delta) ;
 | 
				
			||||||
            load0o = load;
 | 
					            load0o = load;
 | 
				
			||||||
         }
 | 
					         }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
         if(NumCPUs >= 2)
 | 
					         if(NumCPUs >= 2)
 | 
				
			||||||
         {
 | 
					         {
 | 
				
			||||||
               /* we have two CPUs -> do CPU 1 */
 | 
					               /* we have two CPUs -> do CPU 1 */
 | 
				
			||||||
               /* FIXME: What about more CPUs? */
 | 
					           load = 0;
 | 
				
			||||||
           load = CPU_Load[1];
 | 
						   for (; i < NumCPUs; i++) {
 | 
				
			||||||
 | 
					               load += CPU_Load[i];
 | 
				
			||||||
 | 
					           }
 | 
				
			||||||
 | 
					           load = load / (NumCPUs >> 1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
           if(load != load1o)
 | 
					           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]. */
 | 
					                CPU_Load[0], on a SMP system, it will be CPU_Load[1]. */
 | 
				
			||||||
         load1t = load1t + load ;
 | 
					         load1t = load1t + load ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
         if(c1 > DIV1)
 | 
					         if(c1 > DIV1)
 | 
				
			||||||
         {
 | 
					         {
 | 
				
			||||||
           mem = Get_Memory();
 | 
					           mem = Get_Memory();
 | 
				
			||||||
| 
						 | 
					@ -249,49 +253,46 @@ int main(int argc, char **argv)
 | 
				
			||||||
            c1 = 0;
 | 
					            c1 = 0;
 | 
				
			||||||
         }
 | 
					         }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
         if(c2 > DIV2)
 | 
					         if(c2 > DIV2) {
 | 
				
			||||||
            draw_graph = VRAI ;
 | 
					            if((t0[t_idx] = load0t / c2) > HAUTEUR)
 | 
				
			||||||
         if(draw_graph)
 | 
					               t0[t_idx] = HAUTEUR ;
 | 
				
			||||||
         {
 | 
					            t0[t_idx] /= 2;
 | 
				
			||||||
            for(i = 1 ; i < TAILLE_T ; i ++)
 | 
					            if((t1[t_idx] = load1t / c2) > HAUTEUR)
 | 
				
			||||||
            {
 | 
					               t1[t_idx] = HAUTEUR ;
 | 
				
			||||||
               t0[i - 1] = t0[i] ;
 | 
					            t1[t_idx] /= 2;
 | 
				
			||||||
               t1[i - 1] = t1[i] ;
 | 
					            if((tm[t_idx] = (load0t + load1t) / (2 * c2)) > HAUTEUR)
 | 
				
			||||||
               tm[i - 1] = tm[i] ;
 | 
					               tm[t_idx] = HAUTEUR ;
 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            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 ;
 | 
					 | 
				
			||||||
            load0t = 0 ;
 | 
					            load0t = 0 ;
 | 
				
			||||||
            load1t = 0 ;
 | 
					            load1t = 0 ;
 | 
				
			||||||
 | 
					            t_idx = (t_idx + 1) % TAILLE_T;
 | 
				
			||||||
 | 
					            draw_graph = VRAI ;
 | 
				
			||||||
 | 
					            c2 = 0;
 | 
				
			||||||
 | 
					         }
 | 
				
			||||||
 | 
					         if(draw_graph)
 | 
				
			||||||
 | 
					         {
 | 
				
			||||||
                /* draw graph */
 | 
					                /* draw graph */
 | 
				
			||||||
            switch(etat)
 | 
					            switch(etat)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
               case 1 :
 | 
					               case 1 :
 | 
				
			||||||
                  copyXPMArea(64, 32, TAILLE_T, HAUTEUR, 15, 5) ;
 | 
					                  copyXPMArea(64, 32, TAILLE_T, HAUTEUR, 15, 5) ;
 | 
				
			||||||
                  for(i = 0 ; i < TAILLE_T ; i ++)
 | 
					                  for(i = 0, load = t_idx ; i < TAILLE_T ; i ++, load++)
 | 
				
			||||||
                     copyXPMArea(116, 0, 1, tm[i], 15 + i, HAUTEUR + 5 - tm[i]) ;
 | 
					                     copyXPMArea(116, 0, 1, tm[load % TAILLE_T], 15 + i, HAUTEUR + 5 - tm[load % TAILLE_T]) ;
 | 
				
			||||||
                  break ;
 | 
					                  break ;
 | 
				
			||||||
               case 2 :
 | 
					               case 2 :
 | 
				
			||||||
                  copyXPMArea(64, 0, TAILLE_T, HAUTEUR, 15, 5) ;
 | 
					                  copyXPMArea(64, 0, TAILLE_T, HAUTEUR, 15, 5) ;
 | 
				
			||||||
                  for(i = 0 ; i < TAILLE_T ; i ++)
 | 
					                  for(i = 0, load = t_idx ; i < TAILLE_T ; i ++, load++) {
 | 
				
			||||||
                     copyXPMArea(116, 0, 1, t0[i]/2, 15 + i, HAUTEUR/2 + 5 - t0[i]/2) ;
 | 
					                     copyXPMArea(116, 0, 1, t0[load % TAILLE_T], 15 + i, HAUTEUR/2 + 5 - t0[load % TAILLE_T]) ;
 | 
				
			||||||
                  for(i = 0 ; i < TAILLE_T ; i ++)
 | 
					                     copyXPMArea(116, 0, 1, t1[load % TAILLE_T], 15 + i, HAUTEUR/2 + 21 - t1[load % TAILLE_T]) ;
 | 
				
			||||||
                     copyXPMArea(116, 0, 1, t1[i]/2, 15 + i, HAUTEUR/2 + 21 - t1[i]/2) ;
 | 
					                  }
 | 
				
			||||||
                  break ;
 | 
					                  break ;
 | 
				
			||||||
               case 3 :
 | 
					               case 3 :
 | 
				
			||||||
                  copyXPMArea(64, 0, TAILLE_T, HAUTEUR, 15, 5) ;
 | 
					                  copyXPMArea(64, 0, TAILLE_T, HAUTEUR, 15, 5) ;
 | 
				
			||||||
                  for(i = 0 ; i < TAILLE_T ; i ++)
 | 
					                  for(i = 0, load = t_idx ; i < TAILLE_T ; i ++, load++) {
 | 
				
			||||||
                     copyXPMArea(116, 0, 1, t0[i]/2, 15 + i, HAUTEUR/2 + 5 - t0[i]/2) ;
 | 
					                     copyXPMArea(116, 0, 1, t0[load % TAILLE_T], 15 + i, HAUTEUR/2 + 5 - t0[load % TAILLE_T]) ;
 | 
				
			||||||
                  for(i = 0 ; i < TAILLE_T ; i ++)
 | 
					                     copyXPMArea(117, HAUTEUR/2 - t1[load % TAILLE_T], 1, t1[load % TAILLE_T], 15 + i, HAUTEUR/2 + 6) ;
 | 
				
			||||||
                     copyXPMArea(117, (HAUTEUR - t1[i])/2, 1, t1[i]/2, 15 + i, HAUTEUR/2 + 6) ;               
 | 
					                  }
 | 
				
			||||||
                  break ;
 | 
					                  break ;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            c2 = 0 ;
 | 
					 | 
				
			||||||
            draw_graph = FAUX ;
 | 
					            draw_graph = FAUX ;
 | 
				
			||||||
         }
 | 
					         }
 | 
				
			||||||
         c1 ++ ;
 | 
					         c1 ++ ;
 | 
				
			||||||
| 
						 | 
					@ -307,7 +308,6 @@ int main(int argc, char **argv)
 | 
				
			||||||
            if((etat ++) >= 3)
 | 
					            if((etat ++) >= 3)
 | 
				
			||||||
               etat = 1 ;
 | 
					               etat = 1 ;
 | 
				
			||||||
            draw_graph = VRAI ;
 | 
					            draw_graph = VRAI ;
 | 
				
			||||||
            lecture = VRAI ;
 | 
					 | 
				
			||||||
         }
 | 
					         }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      usleep(delay);
 | 
					      usleep(delay);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue