-
Notifications
You must be signed in to change notification settings - Fork 21
/
nmon.c
6251 lines (5874 loc) · 184 KB
/
nmon.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
/*
* lmon.c -- Curses based Performance Monitor for Linux
* Developer: Nigel Griffiths.
*/
/*
* Use the following Makefile (for Linux on POWER)
CFLAGS=-g -D JFS -D GETUSER -Wall -D LARGEMEM -D POWER
LDFLAGS=-lcurses
nmon: lnmon.o
* end of Makefile
*/
/* #define POWER 1 */
/* #define KERNEL_2_6_18 1 */
/* This adds the following to the disk stats
pi_num_threads,
pi_rt_priority,
pi_policy,
pi_delayacct_blkio_ticks
*/
#define RAW(member) (long)((long)(p->cpuN[i].member) - (long)(q->cpuN[i].member))
#define RAWTOTAL(member) (long)((long)(p->cpu_total.member) - (long)(q->cpu_total.member))
#define VERSION "14g"
char version[] = VERSION;
static char *SccsId = "nmon " VERSION;
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#include <ncurses.h>
#include <signal.h>
#include <pwd.h>
#include <fcntl.h>
#include <math.h>
#include <time.h>
#include <sys/errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/utsname.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <sys/wait.h>
/* for Disk Busy rain style output covering 100's of diskss on one screen */
const char disk_busy_map_ch[] =
"_____.....----------++++++++++oooooooooo0000000000OOOOOOOOOO8888888888XXXXXXXXXX##########@@@@@@@@@@*";
/*"00000555551111111111222222222233333333334444444444555555555566666666667777777777888888888899999999991"*/
int extended_disk = 0; /* report additional data from /proc/diskstats to spreadsheet output */
#define FLIP(variable) if(variable) variable=0; else variable=1;
#ifdef MALLOC_DEBUG
#define MALLOC(argument) mymalloc(argument,__LINE__)
#define FREE(argument) myfree(argument,__LINE__)
#define REALLOC(argument1,argument2) myrealloc(argument1,argument2,__LINE__)
void *mymalloc(int size, int line)
{
void * ptr;
ptr= malloc(size);
fprintf(stderr,"0x%x = malloc(%d) at line=%d\n",ptr,size,line);
return ptr;
}
void myfree(void *ptr,int line)
{
fprintf(stderr,"free(0x%x) at line=%d\n",ptr,line);
free(ptr);
}
void *myrealloc(void *oldptr, int size, int line)
{
void * ptr;
ptr= realloc(oldptr,size);
fprintf(stderr,"0x%x = realloc(0x%x, %d) at line=%d\n",ptr,oldptr,size,line);
return ptr;
}
#else
#define MALLOC(argument) malloc(argument)
#define FREE(argument) free(argument)
#define REALLOC(argument1,argument2) realloc(argument1,argument2)
#endif /* MALLOC STUFF */
#define P_CPUINFO 0
#define P_STAT 1
#define P_VERSION 2
#define P_MEMINFO 3
#define P_UPTIME 4
#define P_LOADAVG 5
#define P_NFS 6
#define P_NFSD 7
#define P_VMSTAT 8 /* new in 13h */
#define P_NUMBER 9 /* one more than the max */
char *month[12] = { "JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG",
"SEP", "OCT", "NOV", "DEC" };
/* Cut of everything after the first space in callback
* Delete any '&' just before the space
*/
char *check_call_string(char* callback, const char* name) {
char * tmp_ptr = callback;
if (strlen(callback) > 256) {
fprintf(stderr, "ERROR nmon: ignoring %s - too long\n", name);
return (char *) NULL ;
}
for (; *tmp_ptr != '\0' && *tmp_ptr != ' ' && *tmp_ptr != '&'; ++tmp_ptr)
;
*tmp_ptr = '\0';
if (tmp_ptr == callback)
return (char *) NULL ;
else
return callback;
}
/* Remove error output to this buffer and display it if NMONDEBUG=1 */
char errorstr[70];
int error_on = 0;
void error(char *err) {
strncpy(errorstr, err, 69);
}
/* Default size for smaller files */
#define PROC_MAXBUF (1024*4)
/* /proc/stat size for 50-ish bytes per CPU */
#define STAT_MAXBUF (1024*64)
/* /proc/cpuinfo can be 512 bytes per CPU and we allow 256 CPUs */
/* and 20 lines per CPU so boost the buffers for this one */
#define CPUINFO_MAXBUF (512*256)
#define PROC_MAXLINES (20*256*sizeof(char *))
int proc_cpu_done = 0; /* Flag if we have run function proc_cpu() already in this interval */
int reread = 0;
struct {
FILE *fp;
char *filename;
int lines;
char *line[PROC_MAXLINES];
char *buf;
int read_this_interval; /* track updates for each update to stop double data collection */
} proc[P_NUMBER];
void proc_init() {
int i;
/* Initialise the file pointers */
for (i = 0; i < P_NUMBER; i++) {
proc[i].fp = 0;
proc[i].read_this_interval = 0;
if (i == P_CPUINFO)
proc[i].buf = (char *) malloc(CPUINFO_MAXBUF);
else if (i == P_STAT)
proc[i].buf = (char *) malloc(STAT_MAXBUF);
else
proc[i].buf = (char *) malloc(PROC_MAXBUF);
}
proc[P_CPUINFO].filename = "/proc/cpuinfo";
proc[P_STAT].filename = "/proc/stat";
proc[P_VERSION].filename = "/proc/version";
proc[P_MEMINFO].filename = "/proc/meminfo";
proc[P_UPTIME].filename = "/proc/uptime";
proc[P_LOADAVG].filename = "/proc/loadavg";
proc[P_NFS].filename = "/proc/net/rpc/nfs";
proc[P_NFSD].filename = "/proc/net/rpc/nfsd";
proc[P_VMSTAT].filename = "/proc/vmstat";
}
void proc_read(int num) {
int i;
int size;
int found;
char buf[1024];
int bytes;
if (proc[num].read_this_interval == 1)
return;
if (proc[num].fp == 0) {
if ((proc[num].fp = fopen(proc[num].filename, "r")) == NULL ) {
sprintf(buf, "failed to open file %s", proc[num].filename);
error(buf);
proc[num].fp = 0;
return;
}
}
rewind(proc[num].fp);
/* We re-read P_STAT, now flag proc_cpu() that it has to re-process that data */
if (num == P_STAT)
proc_cpu_done = 0;
if (num == P_CPUINFO)
bytes = CPUINFO_MAXBUF - 1;
else if (num == P_STAT)
bytes = STAT_MAXBUF - 1;
else
bytes = PROC_MAXBUF - 1;
size = fread(proc[num].buf, 1, bytes, proc[num].fp);
proc[num].buf[size] = 0;
proc[num].lines = 0;
proc[num].line[0] = &proc[num].buf[0];
if (num == P_VERSION) {
found = 0;
for (i = 0; i < size; i++) { /* remove some weird stuff found the hard way in various Linux versions and device drivers */
/* place ") (" on two lines */
if (found == 0 && proc[num].buf[i] == ')'
&& proc[num].buf[i + 1] == ' '
&& proc[num].buf[i + 2] == '(') {
proc[num].buf[i + 1] = '\n';
found = 1;
} else {
/* place ") #" on two lines */
if (proc[num].buf[i] == ')' && proc[num].buf[i + 1] == ' '
&& proc[num].buf[i + 2] == '#') {
proc[num].buf[i + 1] = '\n';
}
/* place "#1" on two lines */
if (proc[num].buf[i] == '#' && proc[num].buf[i + 2] == '1') {
proc[num].buf[i] = '\n';
}
}
}
}
for (i = 0; i < size; i++) {
/* replace Tab characters with space */
if (proc[num].buf[i] == '\t') {
proc[num].buf[i] = ' ';
} else if (proc[num].buf[i] == '\n') {
/* replace newline characters with null */
proc[num].lines++;
proc[num].buf[i] = '\0';
proc[num].line[proc[num].lines] = &proc[num].buf[i + 1];
}
if (proc[num].lines == PROC_MAXLINES - 1)
break;
}
if (reread) {
fclose(proc[num].fp);
proc[num].fp = 0;
}
/* Set flag so we do not re-read the data even if called multiple times in same interval */
proc[num].read_this_interval = 1;
}
#include <dirent.h>
struct procsinfo {
int pi_pid;
char pi_comm[64];
char pi_state;
int pi_ppid;
int pi_pgrp;
int pi_session;
int pi_tty_nr;
int pi_tty_pgrp;
unsigned long pi_flags;
unsigned long pi_minflt;
unsigned long pi_cmin_flt;
unsigned long pi_majflt;
unsigned long pi_cmaj_flt;
unsigned long pi_utime;
unsigned long pi_stime;
long pi_cutime;
long pi_cstime;
long pi_pri;
long pi_nice;
#ifndef KERNEL_2_6_18
long junk /* removed */;
#else
long pi_num_threads;
#endif
long pi_it_real_value;
unsigned long pi_start_time;
unsigned long pi_vsize;
long pi_rss; /* - 3 */
unsigned long pi_rlim_cur;
unsigned long pi_start_code;
unsigned long pi_end_code;
unsigned long pi_start_stack;
unsigned long pi_esp;
unsigned long pi_eip;
/* The signal information here is obsolete. */
unsigned long pi_pending_signal;
unsigned long pi_blocked_sig;
unsigned long pi_sigign;
unsigned long pi_sigcatch;
unsigned long pi_wchan;
unsigned long pi_nswap;
unsigned long pi_cnswap;
int pi_exit_signal;
int pi_cpu;
#ifdef KERNEL_2_6_18
unsigned long pi_rt_priority;
unsigned long pi_policy;
unsigned long long pi_delayacct_blkio_ticks;
#endif
unsigned long statm_size; /* total program size */
unsigned long statm_resident; /* resident set size */
unsigned long statm_share; /* shared pages */
unsigned long statm_trs; /* text (code) */
unsigned long statm_drs; /* data/stack */
unsigned long statm_lrs; /* library */
unsigned long statm_dt; /* dirty pages */
};
#include <mntent.h>
#include <fstab.h>
#include <sys/stat.h>
#include <sys/statfs.h>
#include <net/if.h>
int debug = 0;
time_t timer; /* used to work out the hour/min/second */
/* Counts of resources */
int cpus = 1; /* number of CPUs in system (lets hope its more than zero!) */
int old_cpus = 1; /* Number of CPU seen in previuos interval */
int max_cpus = 1; /* highest number of CPUs in DLPAR */
int networks = 0; /* number of networks in system */
int partitions = 0; /* number of partitions in system */
int partitions_short = 0; /* partitions file data short form (i.e. data missing) */
int disks = 0; /* number of disks in system */
int seconds = -1; /* pause interval */
int maxloops = -1; /* stop after this number of updates */
char hostname[256];
char run_name[256];
int run_name_set = 0;
char fullhostname[256];
int loop;
#define DPL 150 /* Disks per line for file output to ensure it
does not overflow the spreadsheet input line max */
int disks_per_line = DPL;
#define NEWDISKGROUP(disk) ( (disk) % disks_per_line == 0)
/* Mode of output variables */
int show_aaa = 1;
int show_para = 1;
int show_headings = 1;
int show_cpu = 0;
int show_smp = 0;
int show_longterm = 0;
int show_disk = 0;
#define SHOW_DISK_NONE 0
#define SHOW_DISK_STATS 1
#define SHOW_DISK_GRAPH 2
int show_diskmap = 0;
int show_memory = 0;
int show_large = 0;
int show_kernel = 0;
int show_nfs = 0;
int show_net = 0;
int show_neterror = 0;
int show_partitions = 0;
int show_help = 0;
int show_top = 0;
int show_topmode = 1;
#define ARGS_NONE 0
#define ARGS_ONLY 1
int show_args = 0;
int show_all = 1; /* 1=all procs& disk 0=only if 1% or more busy */
int show_verbose = 0;
int show_jfs = 0;
int flash_on = 0;
int first_huge = 1;
long huge_peak = 0;
int welcome = 1;
int dotline = 0;
int show_rrd = 0;
int show_lpar = 0;
int show_vm = 0;
int show_dgroup = 0; /* disk groups */
int dgroup_loaded = 0; /* 0 = no, 1=needed, 2=loaded */
int show_raw = 0;
#define RRD if(show_rrd)
double ignore_procdisk_threshold = 0.1;
double ignore_io_threshold = 0.1;
/* Curses support */
#define CURSE if(cursed) /* Only use this for single line curses calls */
#define COLOUR if(colour) /* Only use this for single line colour curses calls */
int cursed = 1; /* 1 = using curses and
0 = loging output for a spreadsheet */
int colour = 1; /* 1 = using colour curses and
0 = using black and white curses (see -b flag) */
#define MVPRINTW(row,col,string) {move((row),(col)); \
attron(A_STANDOUT); \
printw(string); \
attroff(A_STANDOUT); }
FILE *fp; /* filepointer for spreadsheet output */
char *timestamp(int loop, time_t eon) {
static char string[64];
if (show_rrd)
sprintf(string, "%ld", (long) eon);
else
sprintf(string, "T%04d", loop);
return string;
}
#define LOOP timestamp(loop,timer)
char *easy[5] = { "not found", 0, 0, 0, 0 };
char *lsb_release[5] = { "not found", 0, 0, 0, 0 };
void find_release() {
FILE *pop;
int i;
char tmpstr[71];
pop = popen("cat /etc/*ease 2>/dev/null", "r");
if (pop != NULL ) {
tmpstr[0] = 0;
for (i = 0; i < 4; i++) {
if (fgets(tmpstr, 70, pop) == NULL )
break;
tmpstr[strlen(tmpstr) - 1] = 0; /* remove newline */
easy[i] = malloc(strlen(tmpstr) + 1);
strcpy(easy[i], tmpstr);
}
pclose(pop);
}
pop = popen("/usr/bin/lsb_release -idrc 2>/dev/null", "r");
if (pop != NULL ) {
tmpstr[0] = 0;
for (i = 0; i < 4; i++) {
if (fgets(tmpstr, 70, pop) == NULL )
break;
tmpstr[strlen(tmpstr) - 1] = 0; /* remove newline */
lsb_release[i] = malloc(strlen(tmpstr) + 1);
strcpy(lsb_release[i], tmpstr);
}
pclose(pop);
}
}
/* Full Args Mode stuff here */
#define ARGSMAX 1024*8
#define CMDLEN 4096
struct {
int pid;
char *args;
} arglist[ARGSMAX];
void args_output(int pid, int loop, char *progname) {
FILE *pop;
int i, j, n;
char tmpstr[CMDLEN];
static int arg_first_time = 1;
if (pid == 0)
return; /* ignore init */
for (i = 0; i < ARGSMAX - 1; i++) { /* clear data out */
if (arglist[i].pid == pid) {
return;
}
if (arglist[i].pid == 0) /* got to empty slot */
break;
}
sprintf(tmpstr, "ps -p %d -o args 2>/dev/null", pid);
pop = popen(tmpstr, "r");
if (pop == NULL ) {
return;
} else {
if (fgets(tmpstr, CMDLEN, pop) == NULL ) { /* throw away header */
pclose(pop);
return;
}
tmpstr[0] = 0;
if (fgets(tmpstr, CMDLEN, pop) == NULL ) {
pclose(pop);
return;
}
tmpstr[strlen(tmpstr) - 1] = 0;
if (tmpstr[strlen(tmpstr) - 1] == ' ')
tmpstr[strlen(tmpstr) - 1] = 0;
arglist[i].pid = pid;
if (arg_first_time) {
fprintf(fp, "UARG,+Time,PID,ProgName,FullCommand\n");
arg_first_time = 0;
}
n = strlen(tmpstr);
for (i = 0; i < n; i++) {
/*strip out stuff that confused Excel i.e. starting with maths symbol*/
if (tmpstr[i] == ','
&& ((tmpstr[i + 1] == '-') || tmpstr[i + 1] == '+'))
tmpstr[i + 1] = '_';
/*strip out double spaces */
if (tmpstr[i] == ' ' && tmpstr[i + 1] == ' ') {
for (j = 0; j < n - i; j++)
tmpstr[i + j] = tmpstr[i + j + 1];
i--; /* rescan to remove triple space etc */
}
}
fprintf(fp, "UARG,%s,%07d,%s,%s\n", LOOP, pid, progname, tmpstr);
pclose(pop);
return;
}
}
void args_load() {
FILE *pop;
int i;
char tmpstr[CMDLEN];
for (i = 0; i < ARGSMAX; i++) { /* clear data out */
if (arglist[i].pid == -1)
break;
if (arglist[i].pid != 0) {
arglist[i].pid = -1;
free(arglist[i].args);
}
}
pop = popen("ps -eo pid,args 2>/dev/null", "r");
if (pop == NULL ) {
return;
} else {
if (fgets(tmpstr, CMDLEN, pop) == NULL ) { /* throw away header */
pclose(pop);
return;
}
for (i = 0; i < ARGSMAX; i++) {
tmpstr[0] = 0;
if (fgets(tmpstr, CMDLEN, pop) == NULL ) {
pclose(pop);
return;
}
tmpstr[strlen(tmpstr) - 1] = 0;
if (tmpstr[strlen(tmpstr) - 1] == ' ')
tmpstr[strlen(tmpstr) - 1] = 0;
arglist[i].pid = atoi(tmpstr);
arglist[i].args = malloc(strlen(tmpstr));
strcpy(arglist[i].args, &tmpstr[6]);
}
pclose(pop);
}
}
char *args_lookup(int pid, char *progname) {
int i;
for (i = 0; i < ARGSMAX; i++) {
if (arglist[i].pid == pid)
return arglist[i].args;
if (arglist[i].pid == -1)
return progname;
}
return progname;
}
/* end args mode stuff here */
void linux_bbbp(char *name, char *cmd, char *err) {
int i;
int len;
#define STRLEN 4096
char str[STRLEN];
FILE * pop;
static int lineno = 0;
pop = popen(cmd, "r");
if (pop == NULL ) {
fprintf(fp, "BBBP,%03d,%s failed to run %s\n", lineno++, cmd, err);
} else {
fprintf(fp, "BBBP,%03d,%s\n", lineno++, name);
for (i = 0; i < 2048 && (fgets(str, STRLEN, pop) != NULL ); i++) {
/* 2048=sanity check only */
len = strlen(str);
if (len > STRLEN)
len = STRLEN;
if (str[len - 1] == '\n') /*strip off the newline */
str[len - 1] = 0;
/* fix lsconf style output so it does not confuse spread sheets */
if (str[0] == '+')
str[0] = 'p';
if (str[0] == '*')
str[0] = 'm';
if (str[0] == '-')
str[0] = 'n';
if (str[0] == '/')
str[0] = 'd';
if (str[0] == '=')
str[0] = 'e';
fprintf(fp, "BBBP,%03d,%s,\"%s\"\n", lineno++, name, str);
}
pclose(pop);
}
}
#define WARNING "needs root permission or file not present"
/* Global name of programme for printing it */
char *progname;
/* Main data structure for collected stats.
* Two versions are previous and current data.
* Often its the difference that is printed.
* The pointers are swaped i.e. current becomes the previous
* and the previous over written rather than moving data around.
*/
struct cpu_stat {
long long user;
long long sys;
long long wait;
long long idle;
long long irq;
long long softirq;
long long steal;
long long nice;
long long intr;
long long ctxt;
long long btime;
long long procs;
long long running;
long long blocked;
float uptime;
float idletime;
float mins1;
float mins5;
float mins15;
};
#define ulong unsigned long
struct dsk_stat {
char dk_name[32];
int dk_major;
int dk_minor;
long dk_noinfo;
ulong dk_reads;
ulong dk_rmerge;
ulong dk_rmsec;
ulong dk_rkb;
ulong dk_writes;
ulong dk_wmerge;
ulong dk_wmsec;
ulong dk_wkb;
ulong dk_xfers;
ulong dk_bsize;
ulong dk_time;
ulong dk_inflight;
ulong dk_11;
ulong dk_partition;
ulong dk_blocks; /* in /proc/partitions only */
ulong dk_use;
ulong dk_aveq;
};
struct mem_stat {
long memtotal;
long memfree;
long memshared;
long buffers;
long cached;
long swapcached;
long active;
long inactive;
long hightotal;
long highfree;
long lowtotal;
long lowfree;
long swaptotal;
long swapfree;
#ifdef LARGEMEM
long dirty;
long writeback;
long mapped;
long slab;
long committed_as;
long pagetables;
long hugetotal;
long hugefree;
long hugesize;
#else
long bigfree;
#endif /*LARGEMEM*/
};
struct vm_stat {
long long nr_dirty;
long long nr_writeback;
long long nr_unstable;
long long nr_page_table_pages;
long long nr_mapped;
long long nr_slab;
long long pgpgin;
long long pgpgout;
long long pswpin;
long long pswpout;
long long pgalloc_high;
long long pgalloc_normal;
long long pgalloc_dma;
long long pgfree;
long long pgactivate;
long long pgdeactivate;
long long pgfault;
long long pgmajfault;
long long pgrefill_high;
long long pgrefill_normal;
long long pgrefill_dma;
long long pgsteal_high;
long long pgsteal_normal;
long long pgsteal_dma;
long long pgscan_kswapd_high;
long long pgscan_kswapd_normal;
long long pgscan_kswapd_dma;
long long pgscan_direct_high;
long long pgscan_direct_normal;
long long pgscan_direct_dma;
long long pginodesteal;
long long slabs_scanned;
long long kswapd_steal;
long long kswapd_inodesteal;
long long pageoutrun;
long long allocstall;
long long pgrotated;
};
char *nfs_v2_names[18] = { "null", "getattr", "setattr", "root", "lookup",
"readlink", "read", "wrcache", "write", "create", "remove", "rename",
"link", "symlink", "mkdir", "rmdir", "readdir", "fsstat" };
char *nfs_v3_names[22] = { "null", "getattr", "setattr", "lookup", "access",
"readlink", "read", "write", "create", "mkdir", "symlink", "mknod",
"remove", "rmdir", "rename", "link", "readdir", "readdirplus", "fsstat",
"fsinfo", "pathconf", "commit" };
char *nfs_v4s_names[40] = { "op0-unused", "op1-unused", "op2-future", "access",
"close", "commit", "create", "delegpurge", "delegreturn", "getattr",
"getfh", "link", "lock", "lockt", "locku", "lookup", "lookup_root",
"nverify", "open", "openattr", "open_conf", "open_dgrd", "putfh",
"putpubfh", "putrootfh", "read", "readdir", "readlink", "remove",
"rename", "renew", "restorefh", "savefh", "secinfo", "setattr",
"setcltid", "setcltidconf", "verify", "write", "rellockowner" };
char *nfs_v4c_names[35] = { "null", "read", "write", "commit", "open",
"open_conf", "open_noat", "open_dgrd", "close", "setattr", "fsinfo",
"renew", "setclntid", "confirm", "lock", "lockt", "locku", "access",
"getattr", "lookup", "lookup_root", "remove", "rename", "link",
"symlink", "create", "pathconf", "statfs", "readlink", "readdir",
"server_caps", "delegreturn", "getacl", "setacl", "fs_locations" };
int nfs_v2c_found = 0;
int nfs_v2s_found = 0;
int nfs_v3c_found = 0;
int nfs_v3s_found = 0;
int nfs_v4c_found = 0;
int nfs_v4s_found = 0;
int nfs_clear = 0;
struct nfs_stat {
long v2c[18]; /* verison 2 client */
long v3c[22]; /* verison 3 client */
long v4c[35]; /* verison 4 client */
long v2s[18]; /* verison 2 server */
long v3s[22]; /* verison 3 server */
long v4s[40]; /* verison 4 server */
};
#define NETMAX 32
struct net_stat {
unsigned long if_name[17];
unsigned long long if_ibytes;
unsigned long long if_obytes;
unsigned long long if_ipackets;
unsigned long long if_opackets;
unsigned long if_ierrs;
unsigned long if_oerrs;
unsigned long if_idrop;
unsigned long if_ififo;
unsigned long if_iframe;
unsigned long if_odrop;
unsigned long if_ofifo;
unsigned long if_ocarrier;
unsigned long if_ocolls;
};
#ifdef PARTITIONS
#define PARTMAX 256
struct part_stat {
int part_major;
int part_minor;
unsigned long part_blocks;
char part_name[16];
unsigned long part_rio;
unsigned long part_rmerge;
unsigned long part_rsect;
unsigned long part_ruse;
unsigned long part_wio;
unsigned long part_wmerge;
unsigned long part_wsect;
unsigned long part_wuse;
unsigned long part_run;
unsigned long part_use;
unsigned long part_aveq;
};
#endif /*PARTITIONS*/
#ifdef POWER
/* XXXXXXX need to test if rewind() worked or not for lparcfg */
int lparcfg_reread=1;
/* Reset at end of each interval so LPAR cfg is only read once each interval
* even if proc_lparcfg() is called multiple times
* Note: lparcfg is not read via proc_read() !
*/
int lparcfg_processed=0;
struct {
char version_string[16]; /*lparcfg 1.3 */
int version;
char serial_number[16]; /*HAL,0210033EA*/
char system_type[16]; /*HAL,9124-720*/
int partition_id; /*11*/
/*
R4=0x14
R5=0x0
R6=0x800b0000
R7=0x1000000040004
*/
int BoundThrds; /*=1*/
int CapInc; /*=1*/
long long DisWheRotPer; /*=2070000*/
int MinEntCap; /*=10*/
int MinEntCapPerVP; /*=10*/
int MinMem; /*=2048*/
int DesMem; /*=4096*/
int MinProcs; /*=1*/
int partition_max_entitled_capacity; /*=400*/
int system_potential_processors; /*=4*/
/**/
int partition_entitled_capacity; /*=20*/
int system_active_processors; /*=4*/
int pool_capacity; /*=4*/
int unallocated_capacity_weight; /*=0*/
int capacity_weight; /*=0*/
int capped; /*=1*/
int unallocated_capacity; /*=0*/
long long pool_idle_time; /*=0*/
long long pool_idle_saved;
long long pool_idle_diff;
int pool_num_procs; /*=0*/
long long purr; /*=0*/
long long purr_saved;
long long purr_diff;
long long timebase;
int partition_active_processors; /*=1*/
int partition_potential_processors; /*=40*/
int shared_processor_mode; /*=1*/
int smt_mode; /* 1: off, 2: SMT-2, 4: SMT-4 */
int cmo_enabled; /* 1 means AMS is Active */
int entitled_memory_pool_number; /* pool number = 0 */
int entitled_memory_weight; /* 0 to 255 */
long cmo_faults; /* Hypervisor Page-in faults = big number */
long cmo_faults_save; /* above saved */
long cmo_faults_diff; /* delta */
long cmo_fault_time_usec; /* Hypervisor time in micro seconds = big */
long cmo_fault_time_usec_save; /* above saved */
long cmo_fault_time_usec_diff; /* delta */
long backing_memory; /* AIX pmem in bytes */
long cmo_page_size; /* AMS page size in bytes */
long entitled_memory_pool_size; /* AMS whole pool size in bytes */
long entitled_memory_loan_request; /* AMS requesting more memory loaning */
#ifdef EXPERIMENTAL
/* new data in SLES11 for POWER 2.6.27 (may be a little earlier too) */
long DesEntCap;
long DesProcs;
long DesVarCapWt;
long DedDonMode;
long group;
long pool;
long entitled_memory;
long entitled_memory_group_number;
long unallocated_entitled_memory_weight;
long unallocated_io_mapping_entitlement;
/* new data in SLES11 for POWER 2.6.27 */
#endif /* EXPERIMENTAL */
}lparcfg;
int lpar_count=0;
#define LPAR_LINE_MAX 50
#define LPAR_LINE_WIDTH 80
char lpar_buffer[LPAR_LINE_MAX][LPAR_LINE_WIDTH];
int lpar_sanity=55;
char *locate(char *s)
{
int i;
int len;
len=strlen(s);
for(i=0;i<lpar_count;i++)
if( !strncmp(s,lpar_buffer[i],len))
return lpar_buffer[i];
return "";
}
#define NUMBER_NOT_VALID -999
long long read_longlong(char *s)
{
long long x;
int ret;
int len;
int i;
char *str;
str = locate(s);
len=strlen(str);
if(len == 0) {
return NUMBER_NOT_VALID;
}
for(i=0;i<len;i++) {
if(str[i] == '=') {
ret = sscanf(&str[i+1], "%lld", &x);
if(ret != 1) {
fprintf(stderr,"sscanf for %s failed returned = %d line=%s\n", s, ret, str);
return -1;
}
/* fprintf(fp,"DEBUG read %s value %lld\n",s,x);*/
return x;
}
}
fprintf(stderr,"read_long_long failed returned line=%s\n", str);
return -2;
}
/* Return of 0 means data not available */
int proc_lparcfg()
{
static FILE *fp = (FILE *)-1;
/* Only try to read /proc/ppc64/lparcfg once - remember if it's readable */
static int lparinfo_not_available=0;
char *str;
/* If we already read and processed /proc/lparcfg in this interval - just return */
if( lparcfg_processed == 1)
return 1;
if( lparinfo_not_available == 1)
return 0;
if( fp == (FILE *)-1) {
if( (fp = fopen("/proc/ppc64/lparcfg","r")) == NULL) {
error("failed to open - /proc/ppc64/lparcfg");
fp = (FILE *)-1;
lparinfo_not_available = 1;
return 0;
}
}
for(lpar_count=0;lpar_count<LPAR_LINE_MAX-1;lpar_count++) {
if(fgets(lpar_buffer[lpar_count],LPAR_LINE_WIDTH-1,fp) == NULL)
break;
}
if(lparcfg_reread) { /* XXXX unclear is close open is necessary - unfortunately this requires version on Linux on POWER install to test early releases */
fclose(fp);
fp = (FILE *)-1;
} else rewind(fp);
str=locate("lparcfg"); sscanf(str, "lparcfg %s", lparcfg.version_string);
str=locate("serial_number"); sscanf(str, "serial_number=%s", lparcfg.serial_number);
str=locate("system_type"); sscanf(str, "system_type=%s", lparcfg.system_type);
#define GETDATA(variable) lparcfg.variable = read_longlong( __STRING(variable) );
GETDATA(partition_id);
GETDATA(BoundThrds);
GETDATA(CapInc);
GETDATA(DisWheRotPer);
GETDATA(MinEntCap);
GETDATA(MinEntCapPerVP);
GETDATA(MinMem);
GETDATA(DesMem);
GETDATA(MinProcs);
GETDATA(partition_max_entitled_capacity);
GETDATA(system_potential_processors);
GETDATA(partition_entitled_capacity);
GETDATA(system_active_processors);
GETDATA(pool_capacity);
GETDATA(unallocated_capacity_weight);
GETDATA(capacity_weight);
GETDATA(capped);
GETDATA(unallocated_capacity);