-
Notifications
You must be signed in to change notification settings - Fork 0
/
showsys.c
3382 lines (2874 loc) · 99.8 KB
/
showsys.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
** ATOP - System & Process Monitor
**
** The program 'atop' offers the possibility to view the activity of
** the system on system-level as well as process-level.
**
** This source-file contains the Linux-specific functions to calculate
** figures to be visualized.
** ==========================================================================
** Author: JC van Winkel - AT Computing, Nijmegen, Holland
** E-mail: [email protected]
** Date: November 2009
** --------------------------------------------------------------------------
** Copyright (C) 2009 JC van Winkel
**
** This program is free software; you can redistribute it and/or modify it
** under the terms of the GNU General Public License as published by the
** Free Software Foundation; either version 2, or (at your option) any
** later version.
**
** This program is distributed in the hope that it will be useful, but
** WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
** --------------------------------------------------------------------------
*/
#include <sys/types.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <signal.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdarg.h>
#include <curses.h>
#include <pwd.h>
#include <grp.h>
#include <regex.h>
#include "atop.h"
#include "photoproc.h"
#include "photosyst.h"
#include "showgeneric.h"
#include "showlinux.h"
/*******************************************************************/
/*
** print the label of a system-statistics line and switch on
** colors if needed
*/
static int
syscolorlabel(char *labeltext, unsigned int badness)
{
if (screen)
{
if (badness >= 100)
{
attron (A_BLINK);
if (usecolors)
{
attron(COLOR_PAIR(COLORCRIT));
printg(labeltext);
attroff(COLOR_PAIR(COLORCRIT));
}
else
{
attron(A_BOLD);
printg(labeltext);
attroff(A_BOLD);
}
attroff(A_BLINK);
return COLORCRIT;
}
if (almostcrit && badness >= almostcrit)
{
if (usecolors)
{
attron(COLOR_PAIR(COLORALMOST));
printg(labeltext);
attroff(COLOR_PAIR(COLORALMOST));
}
else
{
attron(A_BOLD);
printg(labeltext);
attroff(A_BOLD);
}
return COLORALMOST;
}
}
/*
** no colors required or no reason to show colors
*/
printg(labeltext);
return 0;
}
static char *sysprt_BLANKBOX(struct sstat *sstat, extraparam *notused, int, int *);
void
addblanks(double *charslackused, double *charslackover)
{
*charslackused+=*charslackover;
while (*charslackused>0.5)
{
printg(" ");
*charslackused-=1;
}
}
/*
* showsysline
* print an array of sys_printpair things. If the screen contains too
* few character columns, lower priority items are removed
*
*/
#define MAXELEMS 40
void
showsysline(sys_printpair* elemptr,
struct sstat* sstat, extraparam *extra,
char *labeltext, unsigned int badness)
{
sys_printdef *curelem;
int maxw = screen ? COLS : linelen;
// every 15-char item is printed as:
// >>>> | datadatadata<<<<<
// 012345678901234
/* how many items will fit on one line? */
int avail = (maxw-5)/15;
syscolorlabel(labeltext, badness);
/* count number of items */
sys_printpair newelems[MAXELEMS];
int nitems;
for (nitems=0; nitems < MAXELEMS-1 && elemptr[nitems].f != 0; ++nitems)
newelems[nitems]=elemptr[nitems];
newelems[nitems].f=0;
/* remove lowest priority box to make room as needed */
while (nitems > avail)
{
int lowestprio=999999;
int lowestprio_index=-1;
int i;
for (i=0; i<nitems; ++i)
{
if (newelems[i].prio < lowestprio)
{
lowestprio=newelems[i].prio;
lowestprio_index=i;
}
}
// lowest priority item found, remove from newelems;
memmove(newelems+lowestprio_index,
newelems+lowestprio_index+1,
(nitems-lowestprio_index)* sizeof(sys_printpair));
// also copies final 0 entry
nitems--;
}
/*
* ``item shortage'' is used to make entire blank boxes
* these boxes are spread out as much as possible
* remaining slack is used to add spaces around the vertical
* bars
*/
double slackitemsover;
if (nitems >1)
{
slackitemsover=(double)(avail-nitems)/(nitems);
}
else
{
slackitemsover=(avail-nitems)/2;
}
// charslack: the slack in characters after using as many
// items as possible
double charslackover = screen ? ((COLS - 5) % 15) : ((linelen - 5) %15);
// two places per items where blanks can be added
charslackover /= (avail * 2);
double charslackused=0.0;
double itemslackused=0.0;
elemptr=newelems;
while ((curelem=elemptr->f)!=0)
{
char *itemp;
int color;
/*
** by default no color is shown for this field (color = 0)
**
** the format-function can set a color-number (color > 0)
** when a specific color is wanted or the format-function
** can leave the decision to display with a color to the piece
** of code below (color == -1)
*/
color = 0;
itemp = curelem->doformat(sstat, extra, badness, &color);
if (!itemp)
{
itemp = " ?";
}
printg(" | ");
addblanks(&charslackused, &charslackover);
if (screen)
{
if (color == -1) // default color wanted
{
color = 0;
if (badness >= 100)
color = COLORCRIT;
else if (almostcrit && badness >= almostcrit)
color = COLORALMOST;
}
if (color) // after all: has a color been set?
{
if (usecolors)
attron(COLOR_PAIR(color));
else
attron(A_BOLD);
}
}
printg("%s", itemp);
if (color && screen) // color set for this value?
{
if (usecolors)
attroff(COLOR_PAIR(color));
else
attroff(A_BOLD);
}
itemslackused+=slackitemsover;
while (itemslackused>0.5)
{
addblanks(&charslackused, &charslackover);
printg(" | ");
printg("%s", sysprt_BLANKBOX(0, 0, 0, 0));
addblanks(&charslackused, &charslackover);
itemslackused-=1;
}
elemptr++;
addblanks(&charslackused, &charslackover);
}
printg(" |");
if (!screen)
{
printg("\n");
}
}
/*******************************************************************/
/* SYSTEM PRINT FUNCTIONS */
/*******************************************************************/
static char *
sysprt_PRCSYS(struct sstat *notused, extraparam *as, int badness, int *color)
{
static char buf[15]="sys ";
val2cpustr(as->totst * 1000/hertz, buf+6);
return buf;
}
sys_printdef syspdef_PRCSYS = {"PRCSYS", sysprt_PRCSYS, NULL};
/*******************************************************************/
static char *
sysprt_PRCUSER(struct sstat *notused, extraparam *as, int badness, int *color)
{
static char buf[15]="user ";
val2cpustr(as->totut * 1000/hertz, buf+6);
return buf;
}
sys_printdef syspdef_PRCUSER = {"PRCUSER", sysprt_PRCUSER, NULL};
/*******************************************************************/
static char *
sysprt_PRCNPROC(struct sstat *notused, extraparam *as, int badness, int *color)
{
static char buf[15]="#proc ";
val2valstr(as->nproc - as->nexit, buf+6, 6, 0, 0);
return buf;
}
sys_printdef syspdef_PRCNPROC = {"PRCNPROC", sysprt_PRCNPROC, NULL};
/*******************************************************************/
static char *
sysprt_PRCNRUNNING(struct sstat *notused, extraparam *as, int badness, int *color)
{
static char buf[15]="#trun ";
val2valstr(as->ntrun, buf+6, 6, 0, 0);
return buf;
}
sys_printdef syspdef_PRCNRUNNING = {"PRCNRUNNING", sysprt_PRCNRUNNING, NULL};
/*******************************************************************/
static char *
sysprt_PRCNSLEEPING(struct sstat *notused, extraparam *as, int badness, int *color)
{
static char buf[15]="#tslpi ";
val2valstr(as->ntslpi, buf+8, 4, 0, 0);
return buf;
}
sys_printdef syspdef_PRCNSLEEPING = {"PRCNSLEEPING", sysprt_PRCNSLEEPING, NULL};
/*******************************************************************/
static char *
sysprt_PRCNDSLEEPING(struct sstat *notused, extraparam *as, int badness, int *color)
{
static char buf[15]="#tslpu ";
val2valstr(as->ntslpu, buf+8, 4, 0, 0);
return buf;
}
sys_printdef syspdef_PRCNDSLEEPING = {"PRCNDSLEEPING", sysprt_PRCNDSLEEPING, NULL};
/*******************************************************************/
static char *
sysprt_PRCNZOMBIE(struct sstat *notused, extraparam *as, int badness, int *color)
{
static char buf[15]="#zombie ";
if (as->nzomb > 30)
*color = COLORALMOST;
if (as->nzomb > 50)
*color = COLORCRIT;
val2valstr(as->nzomb, buf+8, 4, 0, 0);
return buf;
}
sys_printdef syspdef_PRCNZOMBIE = {"PRCNZOMBIE", sysprt_PRCNZOMBIE, NULL};
/*******************************************************************/
static char *
sysprt_PRCNNEXIT(struct sstat *notused, extraparam *as, int badness, int *color)
{
static char firstcall = 1;
static char buf[15]="#exit ";
if (supportflags & ACCTACTIVE)
{
if (as->noverflow)
{
*color = COLORCRIT;
buf[6] = '>';
val2valstr(as->nexit, buf+7, 5, as->avgval, as->nsecs);
}
else
{
val2valstr(as->nexit, buf+6, 6, as->avgval, as->nsecs);
}
return buf;
}
else
{
if (firstcall)
{
*color = COLORCRIT;
firstcall = 0;
}
else
{
*color = COLORINFO;
}
switch (acctreason)
{
case 1:
return "no procacct"; // "no acctread";
case 2:
return "no procacct"; // "no acctwant";
case 3:
return "no procacct"; // "no acctsema";
case 4:
return "no procacct"; // "no acctmkdir";
case 5:
return "no procacct"; // "no rootprivs";
default:
return "no procacct";
}
}
}
sys_printdef syspdef_PRCNNEXIT = {"PRCNNEXIT", sysprt_PRCNNEXIT, NULL};
/*******************************************************************/
static char *
sysprt_CPUSYS(struct sstat *sstat, extraparam *as, int badness, int *color)
{
static char buf[15];
float perc = (sstat->cpu.all.stime * 100.0) / as->percputot;
if (perc > 1.0)
*color = -1;
sprintf(buf, "sys %6.0f%%", perc);
return buf;
}
sys_printdef syspdef_CPUSYS = {"CPUSYS", sysprt_CPUSYS, NULL};
/*******************************************************************/
static char *
sysprt_CPUUSER(struct sstat *sstat, extraparam *as, int badness, int *color)
{
static char buf[15];
float perc = (sstat->cpu.all.utime + sstat->cpu.all.ntime)
* 100.0 / as->percputot;
if (perc > 1.0)
*color = -1;
sprintf(buf, "user %6.0f%%", perc);
return buf;
}
sys_printdef syspdef_CPUUSER = {"CPUUSER", sysprt_CPUUSER, NULL};
/*******************************************************************/
static char *
sysprt_CPUIRQ(struct sstat *sstat, extraparam *as, int badness, int *color)
{
static char buf[15];
float perc = (sstat->cpu.all.Itime + sstat->cpu.all.Stime)
* 100.0 / as->percputot;
if (perc > 1.0)
*color = -1;
sprintf(buf, "irq %6.0f%%", perc);
return buf;
}
sys_printdef syspdef_CPUIRQ = {"CPUIRQ", sysprt_CPUIRQ, NULL};
/*******************************************************************/
static char *
sysprt_CPUIDLE(struct sstat *sstat, extraparam *as, int badness, int *color)
{
static char buf[15];
sprintf(buf, "idle %6.0f%%",
(sstat->cpu.all.itime * 100.0) / as->percputot);
return buf;
}
sys_printdef syspdef_CPUIDLE = {"CPUIDLE", sysprt_CPUIDLE, NULL};
/*******************************************************************/
static char *
sysprt_CPUWAIT(struct sstat *sstat, extraparam *as, int badness, int *color)
{
static char buf[15];
sprintf(buf, "wait %6.0f%%",
(sstat->cpu.all.wtime * 100.0) / as->percputot);
return buf;
}
sys_printdef syspdef_CPUWAIT = {"CPUWAIT", sysprt_CPUWAIT, NULL};
/*******************************************************************/
static char *
sysprt_CPUISYS(struct sstat *sstat, extraparam *as, int badness, int *color)
{
static char buf[15];
float perc = sstat->cpu.cpu[as->index].stime * 100.0
/ as->percputot;
if (perc > 1.0)
*color = -1;
sprintf(buf, "sys %6.0f%%", perc);
return buf;
}
sys_printdef syspdef_CPUISYS = {"CPUISYS", sysprt_CPUISYS, NULL};
/*******************************************************************/
static char *
sysprt_CPUIUSER(struct sstat *sstat, extraparam *as, int badness, int *color)
{
static char buf[15];
float perc = (sstat->cpu.cpu[as->index].utime +
sstat->cpu.cpu[as->index].ntime)
* 100.0 / as->percputot;
if (perc > 1.0)
*color = -1;
sprintf(buf, "user %6.0f%%", perc);
return buf;
}
sys_printdef syspdef_CPUIUSER = {"CPUIUSER", sysprt_CPUIUSER, NULL};
/*******************************************************************/
static char *
sysprt_CPUIIRQ(struct sstat *sstat, extraparam *as, int badness, int *color)
{
static char buf[15];
float perc = (sstat->cpu.cpu[as->index].Itime +
sstat->cpu.cpu[as->index].Stime)
* 100.0 / as->percputot;
if (perc > 1.0)
*color = -1;
sprintf(buf, "irq %6.0f%%", perc);
return buf;
}
sys_printdef syspdef_CPUIIRQ = {"CPUIIRQ", sysprt_CPUIIRQ, NULL};
/*******************************************************************/
static char *
sysprt_CPUIIDLE(struct sstat *sstat, extraparam *as, int badness, int *color)
{
static char buf[15];
sprintf(buf, "idle %6.0f%%",
(sstat->cpu.cpu[as->index].itime * 100.0) / as->percputot);
return buf;
}
sys_printdef syspdef_CPUIIDLE = {"CPUIIDLE", sysprt_CPUIIDLE, NULL};
/*******************************************************************/
static char *
sysprt_CPUIWAIT(struct sstat *sstat, extraparam *as, int badness, int *color)
{
static char buf[15];
sprintf(buf, "cpu%03d w%3.0f%%",
sstat->cpu.cpu[as->index].cpunr,
(sstat->cpu.cpu[as->index].wtime * 100.0) / as->percputot);
return buf;
}
sys_printdef syspdef_CPUIWAIT = {"CPUIWAIT", sysprt_CPUIWAIT, NULL};
/*******************************************************************/
static char *
dofmt_cpufreq(char *buf, count_t maxfreq, count_t cnt, count_t ticks)
{
// if ticks != 0, do full output
if (ticks)
{
count_t curfreq = cnt/ticks;
strcpy(buf, "avgf ");
val2Hzstr(curfreq, buf+5);
}
else if (cnt) // no max, no %. if freq is known: print it
{
strcpy(buf, "curf ");
val2Hzstr(cnt, buf+5);
}
else // nothing is known: suppress
{
buf = NULL;
}
return buf;
}
/*
* sumscaling: sum scaling info for all processors
*
*/
void sumscaling(struct sstat *sstat, count_t *maxfreq,
count_t *cnt, count_t *ticks)
{
count_t mymaxfreq = 0;
count_t mycnt = 0;
count_t myticks = 0;
int n=sstat->cpu.nrcpu;
int i;
for (i=0; i < n; ++i)
{
mymaxfreq+= sstat->cpu.cpu[i].freqcnt.maxfreq;
mycnt += sstat->cpu.cpu[i].freqcnt.cnt;
myticks += sstat->cpu.cpu[i].freqcnt.ticks;
}
*maxfreq= mymaxfreq;
*cnt = mycnt;
*ticks = myticks;
}
static char *
dofmt_cpuscale(char *buf, count_t maxfreq, count_t cnt, count_t ticks)
{
if (ticks)
{
count_t curfreq = cnt/ticks;
int perc = maxfreq ? 100 * curfreq / maxfreq : 0;
strcpy(buf, "avgscal ");
sprintf(buf+7, "%4d%%", perc);
}
else if (maxfreq) // max frequency is known so % can be calculated
{
strcpy(buf, "curscal ");
sprintf(buf+7, "%4lld%%", 100 * cnt / maxfreq);
}
else // nothing is known: suppress
{
buf = NULL;
}
return buf;
}
/*******************************************************************/
static char *
sysprt_CPUFREQ(struct sstat *sstat, extraparam *as, int badness, int *color)
{
static char buf[15];
count_t maxfreq;
count_t cnt;
count_t ticks;
int n = sstat->cpu.nrcpu;
sumscaling(sstat, &maxfreq, &cnt, &ticks);
return dofmt_cpufreq(buf, maxfreq/n, cnt/n, ticks/n);
}
static int
sysval_CPUFREQ(struct sstat *sstat)
{
char buf[15];
count_t maxfreq;
count_t cnt;
count_t ticks;
int n = sstat->cpu.nrcpu;
sumscaling(sstat, &maxfreq, &cnt, &ticks);
if (dofmt_cpufreq(buf, maxfreq/n, cnt/n, ticks/n))
return 1;
else
return 0;
}
sys_printdef syspdef_CPUFREQ = {"CPUFREQ", sysprt_CPUFREQ, sysval_CPUFREQ};
/*******************************************************************/
static char *
sysprt_CPUIFREQ(struct sstat *sstat, extraparam *as, int badness, int *color)
{
static char buf[15];
count_t maxfreq = sstat->cpu.cpu[as->index].freqcnt.maxfreq;
count_t cnt = sstat->cpu.cpu[as->index].freqcnt.cnt;
count_t ticks = sstat->cpu.cpu[as->index].freqcnt.ticks;
return dofmt_cpufreq(buf, maxfreq, cnt, ticks);
}
sys_printdef syspdef_CPUIFREQ = {"CPUIFREQ", sysprt_CPUIFREQ, sysval_CPUFREQ};
/*******************************************************************/
static char *
sysprt_CPUSCALE(struct sstat *sstat, extraparam *as, int badness, int *color)
{
static char buf[32] = "scaling ?";
count_t maxfreq;
count_t cnt;
count_t ticks;
int n = sstat->cpu.nrcpu;
sumscaling(sstat, &maxfreq, &cnt, &ticks);
dofmt_cpuscale(buf, maxfreq/n, cnt/n, ticks/n);
return buf;
}
static int
sysval_CPUSCALE(struct sstat *sstat)
{
char buf[32];
count_t maxfreq;
count_t cnt;
count_t ticks;
int n = sstat->cpu.nrcpu;
sumscaling(sstat, &maxfreq, &cnt, &ticks);
if (dofmt_cpuscale(buf, maxfreq/n, cnt/n, ticks/n))
return 1;
else
return 0;
}
sys_printdef syspdef_CPUSCALE = {"CPUSCALE", sysprt_CPUSCALE, sysval_CPUSCALE};
/*******************************************************************/
static char *
sysprt_CPUISCALE(struct sstat *sstat, extraparam *as, int badness, int *color)
{
static char buf[32] = "scaling ?";
count_t maxfreq = sstat->cpu.cpu[as->index].freqcnt.maxfreq;
count_t cnt = sstat->cpu.cpu[as->index].freqcnt.cnt;
count_t ticks = sstat->cpu.cpu[as->index].freqcnt.ticks;
dofmt_cpuscale(buf, maxfreq, cnt, ticks);
return buf;
}
sys_printdef syspdef_CPUISCALE = {"CPUISCALE", sysprt_CPUISCALE, sysval_CPUSCALE};
/*******************************************************************/
static char *
sysprt_CPUSTEAL(struct sstat *sstat, extraparam *as, int badness, int *color)
{
static char buf[15];
float perc = sstat->cpu.all.steal * 100.0 / as->percputot;
if (perc > 1.0)
*color = -1;
sprintf(buf, "steal %5.0f%%", perc);
return buf;
}
sys_printdef syspdef_CPUSTEAL = {"CPUSTEAL", sysprt_CPUSTEAL, NULL};
/*******************************************************************/
static char *
sysprt_CPUISTEAL(struct sstat *sstat, extraparam *as, int badness, int *color)
{
static char buf[15];
float perc = sstat->cpu.cpu[as->index].steal * 100.0
/ as->percputot;
if (perc > 1.0)
*color = -1;
sprintf(buf, "steal %5.0f%%", perc);
return buf;
}
sys_printdef syspdef_CPUISTEAL = {"CPUISTEAL", sysprt_CPUISTEAL, NULL};
/*******************************************************************/
static char *
sysprt_CPUGUEST(struct sstat *sstat, extraparam *as, int badness, int *color)
{
static char buf[15];
float perc = sstat->cpu.all.guest * 100.0 / as->percputot;
if (perc > 1.0)
*color = -1;
sprintf(buf, "guest %5.0f%%", perc);
return buf;
}
sys_printdef syspdef_CPUGUEST = {"CPUGUEST", sysprt_CPUGUEST, NULL};
/*******************************************************************/
static char *
sysprt_CPUIGUEST(struct sstat *sstat, extraparam *as, int badness, int *color)
{
static char buf[15];
float perc = sstat->cpu.cpu[as->index].guest * 100.0 / as->percputot;
if (perc > 1.0)
*color = -1;
sprintf(buf, "guest %5.0f%%", perc);
return buf;
}
sys_printdef syspdef_CPUIGUEST = {"CPUIGUEST", sysprt_CPUIGUEST, NULL};
/*******************************************************************/
static char *
sysprt_CPUIPC(struct sstat *sstat, extraparam *as, int badness, int *color)
{
static char buf[15];
float ipc = 0.0;
switch (sstat->cpu.all.cycle)
{
case 0:
sprintf(buf, "ipc notavail");
break;
case 1:
*color = COLORINFO;
sprintf(buf, "ipc initial");
break;
default:
ipc = sstat->cpu.all.instr * 100 / sstat->cpu.all.cycle / 100.0;
sprintf(buf, "ipc %8.2f", ipc);
}
return buf;
}
static int
sysval_IPCVALIDATE(struct sstat *sstat)
{
return sstat->cpu.all.cycle;
}
sys_printdef syspdef_CPUIPC = {"CPUIPC", sysprt_CPUIPC, sysval_IPCVALIDATE};
/*******************************************************************/
static char *
sysprt_CPUIIPC(struct sstat *sstat, extraparam *as, int badness, int *color)
{
static char buf[15];
float ipc = 0.0;
switch (sstat->cpu.all.cycle)
{
case 0:
sprintf(buf, "ipc notavail");
break;
case 1:
*color = COLORINFO;
sprintf(buf, "ipc initial");
break;
default:
if (sstat->cpu.cpu[as->index].cycle)
ipc = sstat->cpu.cpu[as->index].instr * 100 /
sstat->cpu.cpu[as->index].cycle / 100.0;
sprintf(buf, "ipc %8.2f", ipc);
}
return buf;
}
sys_printdef syspdef_CPUIIPC = {"CPUIIPC", sysprt_CPUIIPC, sysval_IPCVALIDATE};
/*******************************************************************/
static char *
sysprt_CPUCYCLE(struct sstat *sstat, extraparam *as, int badness, int *color)
{
static char buf[15] = "cycl ";
switch (sstat->cpu.all.cycle)
{
case 0:
sprintf(buf+5, "missing");
break;
case 1:
*color = COLORINFO;
sprintf(buf+5, "initial");
break;
default:
val2Hzstr(sstat->cpu.all.cycle/1000000/as->nsecs/
sstat->cpu.nrcpu, buf+5);
}
return buf;
}
sys_printdef syspdef_CPUCYCLE = {"CPUCYCLE", sysprt_CPUCYCLE, sysval_IPCVALIDATE};
/*******************************************************************/
static char *
sysprt_CPUICYCLE(struct sstat *sstat, extraparam *as, int badness, int *color)
{
static char buf[15] = "cycl ";
switch (sstat->cpu.all.cycle)
{
case 0:
sprintf(buf+5, "missing");
break;
case 1:
*color = COLORINFO;
sprintf(buf+5, "initial");
break;
default:
val2Hzstr(sstat->cpu.cpu[as->index].cycle/1000000/
as->nsecs, buf+5);
}
return buf;
}
sys_printdef syspdef_CPUICYCLE = {"CPUICYCLE", sysprt_CPUICYCLE, sysval_IPCVALIDATE};
/*******************************************************************/
static char *
sysprt_CPLAVG1(struct sstat *sstat, extraparam *notused, int badness, int *color)
{
static char buf[17]="avg1 ";
if (sstat->cpu.lavg1 > 999999.0)
{
sprintf(buf+5, ">999999");
}
else if (sstat->cpu.lavg1 > 999.0)
{
sprintf(buf+5, "%7.0f", sstat->cpu.lavg1);
}
else
{
sprintf(buf+5, "%7.2f", sstat->cpu.lavg1);
}
return buf;
}
sys_printdef syspdef_CPLAVG1 = {"CPLAVG1", sysprt_CPLAVG1, NULL};
/*******************************************************************/
static char *
sysprt_CPLAVG5(struct sstat *sstat, extraparam *notused, int badness, int *color)
{
static char buf[15]="avg5 ";
if (sstat->cpu.lavg5 > 999999.0)
{
sprintf(buf+5, ">999999");
}
else if (sstat->cpu.lavg5 > 999.0)
{
sprintf(buf+5, "%7.0f", sstat->cpu.lavg5);
}
else
{
sprintf(buf+5, "%7.2f", sstat->cpu.lavg5);
}
return buf;
}
sys_printdef syspdef_CPLAVG5 = {"CPLAVG5", sysprt_CPLAVG5, NULL};
/*******************************************************************/
static char *
sysprt_CPLAVG15(struct sstat *sstat, extraparam *notused, int badness, int *color)
{
static char buf[15]="avg15 ";
if (sstat->cpu.lavg15 > (2 * sstat->cpu.nrcpu) )
*color = COLORALMOST;
if (sstat->cpu.lavg15 > 99999.0)
{
sprintf(buf+6, ">99999");
}
else if (sstat->cpu.lavg15 > 999.0)
{
sprintf(buf+6, "%6.0f", sstat->cpu.lavg15);
}
else
{
sprintf(buf+6, "%6.2f", sstat->cpu.lavg15);
}
return buf;
}
sys_printdef syspdef_CPLAVG15 = {"CPLAVG15", sysprt_CPLAVG15, NULL};
/*******************************************************************/
static char *
sysprt_CPLCSW(struct sstat *sstat, extraparam *as, int badness, int *color)
{
static char buf[16]="csw ";
val2valstr(sstat->cpu.csw, buf+4 , 8,as->avgval,as->nsecs);
return buf;
}
sys_printdef syspdef_CPLCSW = {"CPLCSW", sysprt_CPLCSW, NULL};
/*******************************************************************/
static char *
sysprt_PRCCLONES(struct sstat *sstat, extraparam *as, int badness, int *color)