1
1
/*
2
2
** ATOP - System & Process Monitor
3
3
**
4
- ** The program 'atop' offers the possibility to view the activity of
4
+ ** The program 'atop' offers the possibility to view the activity of
5
5
** the system on system-level as well as process-level.
6
6
**
7
7
** This source-file contains the main-function, which verifies the
8
- ** calling-parameters and takes care of initialization.
8
+ ** calling-parameters and takes care of initialization.
9
9
** The engine-function drives the main sample-loop in which after the
10
10
** indicated interval-time a snapshot is taken of the system-level and
11
11
** process-level counters and the deviations are calculated and
35
35
** --------------------------------------------------------------------------
36
36
**
37
37
** After initialization, the main-function calls the ENGINE.
38
- ** For every cycle (so after another interval) the ENGINE calls various
38
+ ** For every cycle (so after another interval) the ENGINE calls various
39
39
** functions as shown below:
40
40
**
41
41
** +---------------------------------------------------------------------+
48
48
** | | ^ | ^ | ^ | ^ | | |
49
49
** +---|-----|--------|-----|--------|----|--------|----|--------|----|--+
50
50
** | | | | | | | | | |
51
- ** +--V-----|--+ +--V-----|--+ +--V----|--+ +--V----|--+ +--V----|-+
51
+ ** +--V-----|--+ +--V-----|--+ +--V----|--+ +--V----|--+ +--V----|-+
52
52
** | | | | | | | | | |
53
53
** | photosyst | | photoproc | | acct | | deviate | | print |
54
54
** | | | | |photoproc | | ...syst | | |
55
55
** | | | | | | | ...proc | | |
56
- ** +-----------+ +-----------+ +----------+ +----------+ +---------+
56
+ ** +-----------+ +-----------+ +----------+ +----------+ +---------+
57
57
** ^ ^ ^ ^ |
58
58
** | | | | |
59
- ** | | | V V
59
+ ** | | | V V
60
60
** ______ _________ __________ ________ _________
61
61
** / \ / \ / \ / \ / \
62
62
** /proc /proc accounting task screen or
84
84
** When all counters have been gathered, functions are called to calculate
85
85
** the difference between the current counter-values and the counter-values
86
86
** of the previous cycle. These functions operate on the system-level
87
- ** as well as on the task-level counters.
88
- ** These differences are stored in a new structure(-table).
87
+ ** as well as on the task-level counters.
88
+ ** These differences are stored in a new structure(-table).
89
89
**
90
90
** - deviatsyst()
91
91
** Calculates the differences between the current system-level
98
98
** task-database; this "database" is implemented as a linked list
99
99
** of taskinfo structures in memory (so no disk-accesses needed).
100
100
** Within this linked list hash-buckets are maintained for fast searches.
101
- ** The entire task-database is handled via a set of well-defined
101
+ ** The entire task-database is handled via a set of well-defined
102
102
** functions from which the name starts with "pdb_..." (see the
103
103
** source-file procdbase.c).
104
104
** The processes which have been finished during the last cycle
112
112
** these addresses can be modified in the main-function depending on particular
113
113
** flags. In this way various representation-layers (ASCII, graphical, ...)
114
114
** can be linked with 'atop'; the one to use can eventually be chosen
115
- ** at runtime.
115
+ ** at runtime.
116
116
**
117
117
** $Log: atop.c,v $
118
118
** Revision 1.49 2010/10/23 14:01:00 gerlof
296
296
#include "showgeneric.h"
297
297
#include "parseable.h"
298
298
#include "gpucom.h"
299
+ #include "photobpf.h"
299
300
300
301
#define allflags "ab:cde:fghijklmnopqrstuvwxyz1ABCDEFGHIJKL:MNOP:QRSTUVWXYZ"
301
302
#define MAXFL 64 /* maximum number of command-line flags */
@@ -322,6 +323,16 @@ char threadview = 0; /* boolean: show individual threads */
322
323
char calcpss = 0 ; /* boolean: read/calculate process PSS */
323
324
char getwchan = 0 ; /* boolean: obtain wchan string */
324
325
326
+ /*
327
+ ** arguments for bpf stats sampling
328
+ ** We enable bpf stats for bpfsampleinterval seconds every bpfsamplerate
329
+ ** atop intervals. bpfsampleinterval must be smaller than atop interval.
330
+ **
331
+ ** If bpfsamplerate == 0, disable sampling of bpf stats.
332
+ */
333
+ unsigned int bpfsamplerate = 1 ;
334
+ unsigned int bpfsampleinterval = 1 ;
335
+
325
336
unsigned short hertz ;
326
337
unsigned int pagesize ;
327
338
unsigned int nrgpus ;
@@ -391,6 +402,9 @@ void do_almostcrit(char *, char *);
391
402
void do_atopsarflags (char * , char * );
392
403
void do_pacctdir (char * , char * );
393
404
void do_perfevents (char * , char * );
405
+ void do_bpflines (char * , char * );
406
+ void do_bpfsamplerate (char * , char * );
407
+ void do_bpfsampleinterval (char * , char * );
394
408
395
409
static struct {
396
410
char * tag ;
@@ -440,6 +454,9 @@ static struct {
440
454
{ "atopsarflags" , do_atopsarflags , 0 , },
441
455
{ "perfevents" , do_perfevents , 0 , },
442
456
{ "pacctdir" , do_pacctdir , 1 , },
457
+ { "bpflines" , do_bpflines , 0 , },
458
+ { "bpfsamplerate" , do_bpfsamplerate , 0 , },
459
+ { "bpfsampleinterval" , do_bpfsampleinterval , 0 , },
443
460
};
444
461
445
462
/*
@@ -466,6 +483,8 @@ main(int argc, char *argv[])
466
483
exit (42 );
467
484
}
468
485
486
+ photo_bpf_check ();
487
+
469
488
/*
470
489
** preserve command arguments to allow restart of other version
471
490
*/
@@ -497,12 +516,12 @@ main(int argc, char *argv[])
497
516
if ( memcmp (p , "atopsar" , 7 ) == 0 )
498
517
return atopsar (argc , argv );
499
518
500
- /*
501
- ** interpret command-line arguments & flags
519
+ /*
520
+ ** interpret command-line arguments & flags
502
521
*/
503
522
if (argc > 1 )
504
523
{
505
- /*
524
+ /*
506
525
** gather all flags for visualization-functions
507
526
**
508
527
** generic flags will be handled here;
@@ -600,17 +619,17 @@ main(int argc, char *argv[])
600
619
}
601
620
602
621
/*
603
- ** get optional interval-value and optional number of samples
622
+ ** get optional interval-value and optional number of samples
604
623
*/
605
624
if (optind < argc && optind < MAXFL )
606
625
{
607
626
if (!numeric (argv [optind ]))
608
627
prusage (argv [0 ]);
609
-
628
+
610
629
interval = atoi (argv [optind ]);
611
-
630
+
612
631
optind ++ ;
613
-
632
+
614
633
if (optind < argc )
615
634
{
616
635
if (!numeric (argv [optind ]) )
@@ -766,6 +785,7 @@ engine(void)
766
785
gpupending = 0 ; /* boolean: request sent */
767
786
768
787
struct gpupidstat * gp = NULL ;
788
+ struct bstats * bstats = NULL ;
769
789
770
790
/*
771
791
** initialization: allocate required memory dynamically
@@ -817,6 +837,8 @@ engine(void)
817
837
if (nrgpus )
818
838
supportflags |= GPUSTAT ;
819
839
840
+ if (system_support_bpf ())
841
+ supportflags |= BPFSTAT ;
820
842
/*
821
843
** MAIN-LOOP:
822
844
** - Wait for the requested number of seconds or for other trigger
@@ -838,11 +860,15 @@ engine(void)
838
860
/*
839
861
** if the limit-flag is specified:
840
862
** check if the next sample is expected before midnight;
841
- ** if not, stop atop now
863
+ ** if not, stop atop now
842
864
*/
843
865
if (midnightflag && (curtime + interval ) > timelimit )
844
866
break ;
845
867
868
+ if ((supportflags & BPFSTAT ) &&
869
+ bpfsamplerate && sampcnt % bpfsamplerate == 0 )
870
+ bstats = get_devbstats ();
871
+
846
872
/*
847
873
** wait for alarm-signal to arrive (except first sample)
848
874
** or wait for SIGUSR1/SIGUSR2
@@ -859,13 +885,13 @@ engine(void)
859
885
curtime = time (0 ); /* seconds since 1-1-1970 */
860
886
861
887
/*
862
- ** send request for statistics to atopgpud
888
+ ** send request for statistics to atopgpud
863
889
*/
864
890
if (nrgpus )
865
891
gpupending = gpud_statrequest ();
866
892
867
893
/*
868
- ** take a snapshot of the current system-level statistics
894
+ ** take a snapshot of the current system-level statistics
869
895
** and calculate the deviations (i.e. calculate the activity
870
896
** during the last sample)
871
897
*/
@@ -918,7 +944,7 @@ engine(void)
918
944
curtime - pretime > 0 ? curtime - pretime : 1 );
919
945
920
946
/*
921
- ** take a snapshot of the current task-level statistics
947
+ ** take a snapshot of the current task-level statistics
922
948
** and calculate the deviations (i.e. calculate the activity
923
949
** during the last sample)
924
950
**
@@ -1013,10 +1039,14 @@ engine(void)
1013
1039
** the deviations
1014
1040
*/
1015
1041
lastcmd = (vis .show_samp )( curtime ,
1016
- curtime - pretime > 0 ? curtime - pretime : 1 ,
1017
- & devtstat , devsstat ,
1018
- nprocexit , noverflow , sampcnt == 0 );
1042
+ curtime - pretime > 0 ? curtime - pretime : 1 ,
1043
+ & devtstat , devsstat , bstats ,
1044
+ nprocexit , noverflow , sampcnt == 0 );
1019
1045
1046
+ if (bstats ) {
1047
+ free (bstats -> bpfall );
1048
+ bstats = NULL ;
1049
+ }
1020
1050
/*
1021
1051
** release dynamically allocated memory
1022
1052
*/
@@ -1065,7 +1095,7 @@ prusage(char *myname)
1065
1095
printf ("\t -%c show version information\n" , MVERSION );
1066
1096
printf ("\t -%c show or log all processes (i.s.o. active processes "
1067
1097
"only)\n" , MALLPROC );
1068
- printf ("\t -%c calculate proportional set size (PSS) per process\n" ,
1098
+ printf ("\t -%c calculate proportional set size (PSS) per process\n" ,
1069
1099
MCALCPSS );
1070
1100
printf ("\t -%c determine WCHAN (string) per thread\n" , MGETWCHAN );
1071
1101
printf ("\t -P generate parseable output for specified label(s)\n" );
@@ -1146,6 +1176,18 @@ do_linelength(char *name, char *val)
1146
1176
linelen = get_posval (name , val );
1147
1177
}
1148
1178
1179
+ void
1180
+ do_bpfsamplerate (char * name , char * val )
1181
+ {
1182
+ bpfsamplerate = get_posval (name , val );
1183
+ }
1184
+
1185
+ void
1186
+ do_bpfsampleinterval (char * name , char * val )
1187
+ {
1188
+ bpfsampleinterval = get_posval (name , val );
1189
+ }
1190
+
1149
1191
/*
1150
1192
** read RC-file and modify defaults accordingly
1151
1193
*/
@@ -1196,7 +1238,7 @@ readrc(char *path, int syslevel)
1196
1238
default :
1197
1239
if (tagname [0 ] == '#' )
1198
1240
continue ;
1199
-
1241
+
1200
1242
if (tagvalue [0 ] != '#' )
1201
1243
break ;
1202
1244
0 commit comments