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
@@ -298,6 +298,7 @@ static const char rcsid[] = "$Id: atop.c,v 1.49 2010/10/23 14:01:00 gerlof Exp $
298
298
#include "showgeneric.h"
299
299
#include "parseable.h"
300
300
#include "gpucom.h"
301
+ #include "photobpf.h"
301
302
302
303
#define allflags "ab:cde:fghijklmnopqrstuvwxyz1ABCDEFGHIJKL:MNOP:QRSTUVWXYZ"
303
304
#define MAXFL 64 /* maximum number of command-line flags */
@@ -323,6 +324,16 @@ char usecolors = 1; /* boolean: colors for high occupation */
323
324
char threadview = 0 ; /* boolean: show individual threads */
324
325
char calcpss = 0 ; /* boolean: read/calculate process PSS */
325
326
327
+ /*
328
+ ** arguments for bpf stats sampling
329
+ ** We enable bpf stats for bpfsampleinterval seconds every bpfsamplerate
330
+ ** atop intervals. bpfsampleinterval must be smaller than atop interval.
331
+ **
332
+ ** If bpfsamplerate == 0, disable sampling of bpf stats.
333
+ */
334
+ unsigned int bpfsamplerate = 1 ;
335
+ unsigned int bpfsampleinterval = 1 ;
336
+
326
337
unsigned short hertz ;
327
338
unsigned int pagesize ;
328
339
unsigned int nrgpus ;
@@ -392,6 +403,9 @@ void do_almostcrit(char *, char *);
392
403
void do_atopsarflags (char * , char * );
393
404
void do_pacctdir (char * , char * );
394
405
void do_perfevents (char * , char * );
406
+ void do_bpflines (char * , char * );
407
+ void do_bpfsamplerate (char * , char * );
408
+ void do_bpfsampleinterval (char * , char * );
395
409
396
410
static struct {
397
411
char * tag ;
@@ -441,6 +455,9 @@ static struct {
441
455
{ "atopsarflags" , do_atopsarflags , 0 , },
442
456
{ "perfevents" , do_perfevents , 0 , },
443
457
{ "pacctdir" , do_pacctdir , 1 , },
458
+ { "bpflines" , do_bpflines , 0 , },
459
+ { "bpfsamplerate" , do_bpfsamplerate , 0 , },
460
+ { "bpfsampleinterval" , do_bpfsampleinterval , 0 , },
444
461
};
445
462
446
463
/*
@@ -467,6 +484,8 @@ main(int argc, char *argv[])
467
484
exit (42 );
468
485
}
469
486
487
+ photo_bpf_check ();
488
+
470
489
/*
471
490
** preserve command arguments to allow restart of other version
472
491
*/
@@ -498,12 +517,12 @@ main(int argc, char *argv[])
498
517
if ( memcmp (p , "atopsar" , 7 ) == 0 )
499
518
return atopsar (argc , argv );
500
519
501
- /*
502
- ** interpret command-line arguments & flags
520
+ /*
521
+ ** interpret command-line arguments & flags
503
522
*/
504
523
if (argc > 1 )
505
524
{
506
- /*
525
+ /*
507
526
** gather all flags for visualization-functions
508
527
**
509
528
** generic flags will be handled here;
@@ -582,17 +601,17 @@ main(int argc, char *argv[])
582
601
}
583
602
584
603
/*
585
- ** get optional interval-value and optional number of samples
604
+ ** get optional interval-value and optional number of samples
586
605
*/
587
606
if (optind < argc && optind < MAXFL )
588
607
{
589
608
if (!numeric (argv [optind ]))
590
609
prusage (argv [0 ]);
591
-
610
+
592
611
interval = atoi (argv [optind ]);
593
-
612
+
594
613
optind ++ ;
595
-
614
+
596
615
if (optind < argc )
597
616
{
598
617
if (!numeric (argv [optind ]) )
@@ -748,6 +767,7 @@ engine(void)
748
767
gpupending = 0 ; /* boolean: request sent */
749
768
750
769
struct gpupidstat * gp = NULL ;
770
+ struct bstats * bstats = NULL ;
751
771
752
772
/*
753
773
** initialization: allocate required memory dynamically
@@ -799,6 +819,8 @@ engine(void)
799
819
if (nrgpus )
800
820
supportflags |= GPUSTAT ;
801
821
822
+ if (system_support_bpf ())
823
+ supportflags |= BPFSTAT ;
802
824
/*
803
825
** MAIN-LOOP:
804
826
** - Wait for the requested number of seconds or for other trigger
@@ -820,11 +842,15 @@ engine(void)
820
842
/*
821
843
** if the limit-flag is specified:
822
844
** check if the next sample is expected before midnight;
823
- ** if not, stop atop now
845
+ ** if not, stop atop now
824
846
*/
825
847
if (midnightflag && (curtime + interval ) > timelimit )
826
848
break ;
827
849
850
+ if ((supportflags & BPFSTAT ) &&
851
+ bpfsamplerate && sampcnt % bpfsamplerate == 0 )
852
+ bstats = get_devbstats ();
853
+
828
854
/*
829
855
** wait for alarm-signal to arrive (except first sample)
830
856
** or wait for SIGUSR1/SIGUSR2
@@ -841,13 +867,13 @@ engine(void)
841
867
curtime = time (0 ); /* seconds since 1-1-1970 */
842
868
843
869
/*
844
- ** send request for statistics to atopgpud
870
+ ** send request for statistics to atopgpud
845
871
*/
846
872
if (nrgpus )
847
873
gpupending = gpud_statrequest ();
848
874
849
875
/*
850
- ** take a snapshot of the current system-level statistics
876
+ ** take a snapshot of the current system-level statistics
851
877
** and calculate the deviations (i.e. calculate the activity
852
878
** during the last sample)
853
879
*/
@@ -900,7 +926,7 @@ engine(void)
900
926
curtime - pretime > 0 ? curtime - pretime : 1 );
901
927
902
928
/*
903
- ** take a snapshot of the current task-level statistics
929
+ ** take a snapshot of the current task-level statistics
904
930
** and calculate the deviations (i.e. calculate the activity
905
931
** during the last sample)
906
932
**
@@ -995,10 +1021,14 @@ engine(void)
995
1021
** the deviations
996
1022
*/
997
1023
lastcmd = (vis .show_samp )( curtime ,
998
- curtime - pretime > 0 ? curtime - pretime : 1 ,
999
- & devtstat , devsstat ,
1000
- nprocexit , noverflow , sampcnt == 0 );
1024
+ curtime - pretime > 0 ? curtime - pretime : 1 ,
1025
+ & devtstat , devsstat , bstats ,
1026
+ nprocexit , noverflow , sampcnt == 0 );
1001
1027
1028
+ if (bstats ) {
1029
+ free (bstats -> bpfall );
1030
+ bstats = NULL ;
1031
+ }
1002
1032
/*
1003
1033
** release dynamically allocated memory
1004
1034
*/
@@ -1047,7 +1077,7 @@ prusage(char *myname)
1047
1077
printf ("\t -%c show version information\n" , MVERSION );
1048
1078
printf ("\t -%c show or log all processes (i.s.o. active processes "
1049
1079
"only)\n" , MALLPROC );
1050
- printf ("\t -%c calculate proportional set size (PSS) per process\n" ,
1080
+ printf ("\t -%c calculate proportional set size (PSS) per process\n" ,
1051
1081
MCALCPSS );
1052
1082
printf ("\t -P generate parseable output for specified label(s)\n" );
1053
1083
printf ("\t -L alternate line length (default 80) in case of "
@@ -1126,6 +1156,18 @@ do_linelength(char *name, char *val)
1126
1156
linelen = get_posval (name , val );
1127
1157
}
1128
1158
1159
+ void
1160
+ do_bpfsamplerate (char * name , char * val )
1161
+ {
1162
+ bpfsamplerate = get_posval (name , val );
1163
+ }
1164
+
1165
+ void
1166
+ do_bpfsampleinterval (char * name , char * val )
1167
+ {
1168
+ bpfsampleinterval = get_posval (name , val );
1169
+ }
1170
+
1129
1171
/*
1130
1172
** read RC-file and modify defaults accordingly
1131
1173
*/
@@ -1176,7 +1218,7 @@ readrc(char *path, int syslevel)
1176
1218
default :
1177
1219
if (tagname [0 ] == '#' )
1178
1220
continue ;
1179
-
1221
+
1180
1222
if (tagvalue [0 ] != '#' )
1181
1223
break ;
1182
1224
0 commit comments