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 */
@@ -321,6 +322,16 @@ char usecolors = 1; /* boolean: colors for high occupation */
321
322
char threadview = 0 ; /* boolean: show individual threads */
322
323
char calcpss = 0 ; /* boolean: read/calculate process PSS */
323
324
325
+ /*
326
+ ** arguments for bpf stats sampling
327
+ ** We enable bpf stats for bpfsampleinterval seconds every bpfsamplerate
328
+ ** atop intervals. bpfsampleinterval must be smaller than atop interval.
329
+ **
330
+ ** If bpfsamplerate == 0, disable sampling of bpf stats.
331
+ */
332
+ unsigned int bpfsamplerate = 1 ;
333
+ unsigned int bpfsampleinterval = 1 ;
334
+
324
335
unsigned short hertz ;
325
336
unsigned int pagesize ;
326
337
unsigned int nrgpus ;
@@ -390,6 +401,9 @@ void do_almostcrit(char *, char *);
390
401
void do_atopsarflags (char * , char * );
391
402
void do_pacctdir (char * , char * );
392
403
void do_perfevents (char * , char * );
404
+ void do_bpflines (char * , char * );
405
+ void do_bpfsamplerate (char * , char * );
406
+ void do_bpfsampleinterval (char * , char * );
393
407
394
408
static struct {
395
409
char * tag ;
@@ -439,6 +453,9 @@ static struct {
439
453
{ "atopsarflags" , do_atopsarflags , 0 , },
440
454
{ "perfevents" , do_perfevents , 0 , },
441
455
{ "pacctdir" , do_pacctdir , 1 , },
456
+ { "bpflines" , do_bpflines , 0 , },
457
+ { "bpfsamplerate" , do_bpfsamplerate , 0 , },
458
+ { "bpfsampleinterval" , do_bpfsampleinterval , 0 , },
442
459
};
443
460
444
461
/*
@@ -465,6 +482,8 @@ main(int argc, char *argv[])
465
482
exit (42 );
466
483
}
467
484
485
+ photo_bpf_check ();
486
+
468
487
/*
469
488
** preserve command arguments to allow restart of other version
470
489
*/
@@ -496,12 +515,12 @@ main(int argc, char *argv[])
496
515
if ( memcmp (p , "atopsar" , 7 ) == 0 )
497
516
return atopsar (argc , argv );
498
517
499
- /*
500
- ** interpret command-line arguments & flags
518
+ /*
519
+ ** interpret command-line arguments & flags
501
520
*/
502
521
if (argc > 1 )
503
522
{
504
- /*
523
+ /*
505
524
** gather all flags for visualization-functions
506
525
**
507
526
** generic flags will be handled here;
@@ -595,17 +614,17 @@ main(int argc, char *argv[])
595
614
}
596
615
597
616
/*
598
- ** get optional interval-value and optional number of samples
617
+ ** get optional interval-value and optional number of samples
599
618
*/
600
619
if (optind < argc && optind < MAXFL )
601
620
{
602
621
if (!numeric (argv [optind ]))
603
622
prusage (argv [0 ]);
604
-
623
+
605
624
interval = atoi (argv [optind ]);
606
-
625
+
607
626
optind ++ ;
608
-
627
+
609
628
if (optind < argc )
610
629
{
611
630
if (!numeric (argv [optind ]) )
@@ -761,6 +780,7 @@ engine(void)
761
780
gpupending = 0 ; /* boolean: request sent */
762
781
763
782
struct gpupidstat * gp = NULL ;
783
+ struct bstats * bstats = NULL ;
764
784
765
785
/*
766
786
** initialization: allocate required memory dynamically
@@ -812,6 +832,8 @@ engine(void)
812
832
if (nrgpus )
813
833
supportflags |= GPUSTAT ;
814
834
835
+ if (system_support_bpf ())
836
+ supportflags |= BPFSTAT ;
815
837
/*
816
838
** MAIN-LOOP:
817
839
** - Wait for the requested number of seconds or for other trigger
@@ -833,11 +855,15 @@ engine(void)
833
855
/*
834
856
** if the limit-flag is specified:
835
857
** check if the next sample is expected before midnight;
836
- ** if not, stop atop now
858
+ ** if not, stop atop now
837
859
*/
838
860
if (midnightflag && (curtime + interval ) > timelimit )
839
861
break ;
840
862
863
+ if ((supportflags & BPFSTAT ) &&
864
+ bpfsamplerate && sampcnt % bpfsamplerate == 0 )
865
+ bstats = get_devbstats ();
866
+
841
867
/*
842
868
** wait for alarm-signal to arrive (except first sample)
843
869
** or wait for SIGUSR1/SIGUSR2
@@ -854,13 +880,13 @@ engine(void)
854
880
curtime = time (0 ); /* seconds since 1-1-1970 */
855
881
856
882
/*
857
- ** send request for statistics to atopgpud
883
+ ** send request for statistics to atopgpud
858
884
*/
859
885
if (nrgpus )
860
886
gpupending = gpud_statrequest ();
861
887
862
888
/*
863
- ** take a snapshot of the current system-level statistics
889
+ ** take a snapshot of the current system-level statistics
864
890
** and calculate the deviations (i.e. calculate the activity
865
891
** during the last sample)
866
892
*/
@@ -913,7 +939,7 @@ engine(void)
913
939
curtime - pretime > 0 ? curtime - pretime : 1 );
914
940
915
941
/*
916
- ** take a snapshot of the current task-level statistics
942
+ ** take a snapshot of the current task-level statistics
917
943
** and calculate the deviations (i.e. calculate the activity
918
944
** during the last sample)
919
945
**
@@ -1008,10 +1034,14 @@ engine(void)
1008
1034
** the deviations
1009
1035
*/
1010
1036
lastcmd = (vis .show_samp )( curtime ,
1011
- curtime - pretime > 0 ? curtime - pretime : 1 ,
1012
- & devtstat , devsstat ,
1013
- nprocexit , noverflow , sampcnt == 0 );
1037
+ curtime - pretime > 0 ? curtime - pretime : 1 ,
1038
+ & devtstat , devsstat , bstats ,
1039
+ nprocexit , noverflow , sampcnt == 0 );
1014
1040
1041
+ if (bstats ) {
1042
+ free (bstats -> bpfall );
1043
+ bstats = NULL ;
1044
+ }
1015
1045
/*
1016
1046
** release dynamically allocated memory
1017
1047
*/
@@ -1060,7 +1090,7 @@ prusage(char *myname)
1060
1090
printf ("\t -%c show version information\n" , MVERSION );
1061
1091
printf ("\t -%c show or log all processes (i.s.o. active processes "
1062
1092
"only)\n" , MALLPROC );
1063
- printf ("\t -%c calculate proportional set size (PSS) per process\n" ,
1093
+ printf ("\t -%c calculate proportional set size (PSS) per process\n" ,
1064
1094
MCALCPSS );
1065
1095
printf ("\t -P generate parseable output for specified label(s)\n" );
1066
1096
printf ("\t -L alternate line length (default 80) in case of "
@@ -1140,6 +1170,18 @@ do_linelength(char *name, char *val)
1140
1170
linelen = get_posval (name , val );
1141
1171
}
1142
1172
1173
+ void
1174
+ do_bpfsamplerate (char * name , char * val )
1175
+ {
1176
+ bpfsamplerate = get_posval (name , val );
1177
+ }
1178
+
1179
+ void
1180
+ do_bpfsampleinterval (char * name , char * val )
1181
+ {
1182
+ bpfsampleinterval = get_posval (name , val );
1183
+ }
1184
+
1143
1185
/*
1144
1186
** read RC-file and modify defaults accordingly
1145
1187
*/
@@ -1190,7 +1232,7 @@ readrc(char *path, int syslevel)
1190
1232
default :
1191
1233
if (tagname [0 ] == '#' )
1192
1234
continue ;
1193
-
1235
+
1194
1236
if (tagvalue [0 ] != '#' )
1195
1237
break ;
1196
1238
0 commit comments