Lines 42-47
Link Here
|
42 |
int niceLoad; |
42 |
int niceLoad; |
43 |
int sysLoad; |
43 |
int sysLoad; |
44 |
int idleLoad; |
44 |
int idleLoad; |
|
|
45 |
int waitLoad; |
45 |
|
46 |
|
46 |
/* To calculate the loads we need to remember the tick values for each |
47 |
/* To calculate the loads we need to remember the tick values for each |
47 |
* load type. */ |
48 |
* load type. */ |
Lines 49-54
Link Here
|
49 |
unsigned long niceTicks; |
50 |
unsigned long niceTicks; |
50 |
unsigned long sysTicks; |
51 |
unsigned long sysTicks; |
51 |
unsigned long idleTicks; |
52 |
unsigned long idleTicks; |
|
|
53 |
unsigned long waitTicks; |
52 |
} CPULoadInfo; |
54 |
} CPULoadInfo; |
53 |
|
55 |
|
54 |
typedef struct |
56 |
typedef struct |
Lines 144-172
Link Here
|
144 |
|
146 |
|
145 |
static void updateCPULoad( const char* line, CPULoadInfo* load ) |
147 |
static void updateCPULoad( const char* line, CPULoadInfo* load ) |
146 |
{ |
148 |
{ |
147 |
unsigned long currUserTicks, currSysTicks, currNiceTicks, currIdleTicks; |
149 |
unsigned long currUserTicks, currSysTicks, currNiceTicks; |
148 |
unsigned long totalTicks; |
150 |
unsigned long currIdleTicks, currWaitTicks, totalTicks; |
149 |
|
151 |
|
150 |
sscanf( line, "%*s %lu %lu %lu %lu", &currUserTicks, &currNiceTicks, |
152 |
sscanf( line, "%*s %lu %lu %lu %lu %lu", &currUserTicks, &currNiceTicks, |
151 |
&currSysTicks, &currIdleTicks ); |
153 |
&currSysTicks, &currIdleTicks, &currWaitTicks ); |
152 |
|
154 |
|
153 |
totalTicks = ( currUserTicks - load->userTicks ) + |
155 |
totalTicks = ( currUserTicks - load->userTicks ) + |
154 |
( currSysTicks - load->sysTicks ) + |
156 |
( currSysTicks - load->sysTicks ) + |
155 |
( currNiceTicks - load->niceTicks ) + |
157 |
( currNiceTicks - load->niceTicks ) + |
156 |
( currIdleTicks - load->idleTicks ); |
158 |
( currIdleTicks - load->idleTicks ) + |
|
|
159 |
( currWaitTicks - load->waitTicks ); |
157 |
|
160 |
|
158 |
if ( totalTicks > 10 ) { |
161 |
if ( totalTicks > 10 ) { |
159 |
load->userLoad = ( 100 * ( currUserTicks - load->userTicks ) ) / totalTicks; |
162 |
load->userLoad = ( 100 * ( currUserTicks - load->userTicks ) ) / totalTicks; |
160 |
load->sysLoad = ( 100 * ( currSysTicks - load->sysTicks ) ) / totalTicks; |
163 |
load->sysLoad = ( 100 * ( currSysTicks - load->sysTicks ) ) / totalTicks; |
161 |
load->niceLoad = ( 100 * ( currNiceTicks - load->niceTicks ) ) / totalTicks; |
164 |
load->niceLoad = ( 100 * ( currNiceTicks - load->niceTicks ) ) / totalTicks; |
162 |
load->idleLoad = ( 100 - ( load->userLoad + load->sysLoad + load->niceLoad ) ); |
165 |
load->idleLoad = ( 100 * ( currIdleTicks - load->idleTicks ) ) / totalTicks; |
|
|
166 |
load->waitLoad = ( 100 * ( currWaitTicks - load->waitTicks ) ) / totalTicks; |
163 |
} else |
167 |
} else |
164 |
load->userLoad = load->sysLoad = load->niceLoad = load->idleLoad = 0; |
168 |
load->userLoad = load->sysLoad = load->niceLoad = load->idleLoad = load->waitLoad = 0; |
165 |
|
169 |
|
166 |
load->userTicks = currUserTicks; |
170 |
load->userTicks = currUserTicks; |
167 |
load->sysTicks = currSysTicks; |
171 |
load->sysTicks = currSysTicks; |
168 |
load->niceTicks = currNiceTicks; |
172 |
load->niceTicks = currNiceTicks; |
169 |
load->idleTicks = currIdleTicks; |
173 |
load->idleTicks = currIdleTicks; |
|
|
174 |
load->waitTicks = currWaitTicks; |
170 |
} |
175 |
} |
171 |
|
176 |
|
172 |
static int processDisk( char* tag, char* buf, const char* label, int idx ) |
177 |
static int processDisk( char* tag, char* buf, const char* label, int idx ) |
Lines 550-558
Link Here
|
550 |
void initStat( struct SensorModul* sm ) |
555 |
void initStat( struct SensorModul* sm ) |
551 |
{ |
556 |
{ |
552 |
/* The CPU load is calculated from the values in /proc/stat. The cpu |
557 |
/* The CPU load is calculated from the values in /proc/stat. The cpu |
553 |
* entry contains 4 counters. These counters count the number of ticks |
558 |
* entry contains 7 counters. These counters count the number of ticks |
554 |
* the system has spend on user processes, system processes, nice |
559 |
* the system has spend on user processes, system processes, nice |
555 |
* processes and idle time. |
560 |
* processes, idle and IO-wait time, hard and soft interrupts. |
556 |
* |
561 |
* |
557 |
* SMP systems will have cpu1 to cpuN lines right after the cpu info. The |
562 |
* SMP systems will have cpu1 to cpuN lines right after the cpu info. The |
558 |
* format is identical to cpu and reports the information for each cpu. |
563 |
* format is identical to cpu and reports the information for each cpu. |
Lines 560-566
Link Here
|
560 |
* |
565 |
* |
561 |
* The /proc/stat file looks like this: |
566 |
* The /proc/stat file looks like this: |
562 |
* |
567 |
* |
563 |
* cpu 1586 4 808 36274 |
568 |
* cpu <user> <nice> <system> <idling> <waiting> <hardinterrupt> <softinterrupt> |
564 |
* disk 7797 0 0 0 |
569 |
* disk 7797 0 0 0 |
565 |
* disk_rio 6889 0 0 0 |
570 |
* disk_rio 6889 0 0 0 |
566 |
* disk_wio 908 0 0 0 |
571 |
* disk_wio 908 0 0 0 |
Lines 606-611
Link Here
|
606 |
registerMonitor( "cpu/nice", "integer", printCPUNice, printCPUNiceInfo, StatSM ); |
611 |
registerMonitor( "cpu/nice", "integer", printCPUNice, printCPUNiceInfo, StatSM ); |
607 |
registerMonitor( "cpu/sys", "integer", printCPUSys, printCPUSysInfo, StatSM ); |
612 |
registerMonitor( "cpu/sys", "integer", printCPUSys, printCPUSysInfo, StatSM ); |
608 |
registerMonitor( "cpu/idle", "integer", printCPUIdle, printCPUIdleInfo, StatSM ); |
613 |
registerMonitor( "cpu/idle", "integer", printCPUIdle, printCPUIdleInfo, StatSM ); |
|
|
614 |
registerMonitor( "cpu/wait", "integer", printCPUWait, printCPUWaitInfo, StatSM ); |
609 |
} else if ( strncmp( "cpu", tag, 3 ) == 0 ) { |
615 |
} else if ( strncmp( "cpu", tag, 3 ) == 0 ) { |
610 |
char cmdName[ 24 ]; |
616 |
char cmdName[ 24 ]; |
611 |
/* Load for each SMP CPU */ |
617 |
/* Load for each SMP CPU */ |
Lines 621-626
Link Here
|
621 |
registerMonitor( cmdName, "integer", printCPUxSys, printCPUxSysInfo, StatSM ); |
627 |
registerMonitor( cmdName, "integer", printCPUxSys, printCPUxSysInfo, StatSM ); |
622 |
sprintf( cmdName, "cpu%d/idle", id ); |
628 |
sprintf( cmdName, "cpu%d/idle", id ); |
623 |
registerMonitor( cmdName, "integer", printCPUxIdle, printCPUxIdleInfo, StatSM ); |
629 |
registerMonitor( cmdName, "integer", printCPUxIdle, printCPUxIdleInfo, StatSM ); |
|
|
630 |
sprintf( cmdName, "cpu%d/wait", id ); |
631 |
registerMonitor( cmdName, "integer", printCPUxWait, printCPUxWaitInfo, StatSM ); |
624 |
} else if ( strcmp( "disk", tag ) == 0 ) { |
632 |
} else if ( strcmp( "disk", tag ) == 0 ) { |
625 |
unsigned long val; |
633 |
unsigned long val; |
626 |
char* b = buf + 5; |
634 |
char* b = buf + 5; |
Lines 853-858
Link Here
|
853 |
fprintf( CurrentClient, "CPU Idle Load\t0\t100\t%%\n" ); |
861 |
fprintf( CurrentClient, "CPU Idle Load\t0\t100\t%%\n" ); |
854 |
} |
862 |
} |
855 |
|
863 |
|
|
|
864 |
void printCPUWait( const char* cmd ) |
865 |
{ |
866 |
(void)cmd; |
867 |
|
868 |
if ( Dirty ) |
869 |
processStat(); |
870 |
|
871 |
fprintf( CurrentClient, "%d\n", CPULoad.waitLoad ); |
872 |
} |
873 |
|
874 |
void printCPUWaitInfo( const char* cmd ) |
875 |
{ |
876 |
(void)cmd; |
877 |
fprintf( CurrentClient, "CPU Wait Load\t0\t100\t%%\n" ); |
878 |
} |
879 |
|
856 |
void printCPUxUser( const char* cmd ) |
880 |
void printCPUxUser( const char* cmd ) |
857 |
{ |
881 |
{ |
858 |
int id; |
882 |
int id; |
Lines 929-934
Link Here
|
929 |
fprintf( CurrentClient, "CPU%d Idle Load\t0\t100\t%%\n", id ); |
953 |
fprintf( CurrentClient, "CPU%d Idle Load\t0\t100\t%%\n", id ); |
930 |
} |
954 |
} |
931 |
|
955 |
|
|
|
956 |
void printCPUxWait( const char* cmd ) |
957 |
{ |
958 |
int id; |
959 |
|
960 |
if ( Dirty ) |
961 |
processStat(); |
962 |
|
963 |
sscanf( cmd + 3, "%d", &id ); |
964 |
fprintf( CurrentClient, "%d\n", SMPLoad[ id ].waitLoad ); |
965 |
} |
966 |
|
967 |
void printCPUxWaitInfo( const char* cmd ) |
968 |
{ |
969 |
int id; |
970 |
|
971 |
sscanf( cmd + 3, "%d", &id ); |
972 |
fprintf( CurrentClient, "CPU%d Wait Load\t0\t100\t%%\n", id ); |
973 |
} |
974 |
|
932 |
void printDiskTotal( const char* cmd ) |
975 |
void printDiskTotal( const char* cmd ) |
933 |
{ |
976 |
{ |
934 |
int id; |
977 |
int id; |