@@ -185,8 +185,12 @@ char displaymode = 'T'; /* 'T' = text, 'D' = draw */
185
185
char barmono = 0 ; /* boolean: bar without categories? */
186
186
/* name in case of parseable output */
187
187
188
- char prependenv = 0 ; /* boolean: prepend selected */
188
+ char prependenv = 0 ; /* boolean: prepend selected */
189
189
/* environment variables to cmdline */
190
+
191
+ char connectgpud = 0 ; /* boolean: connect to atopgpud */
192
+ char connectnetatop = 0 ; /* boolean: connect to netatop(bpf) */
193
+
190
194
regex_t envregex ;
191
195
192
196
unsigned short hertz ;
@@ -493,6 +497,14 @@ main(int argc, char *argv[])
493
497
prependenv = 1 ;
494
498
break ;
495
499
500
+ case 'k' : /* try to open TCP connection to atopgpud */
501
+ connectgpud = 1 ;
502
+ break ;
503
+
504
+ case 'K' : /* try to open connection to netatop/netatop-bpf */
505
+ connectnetatop = 1 ;
506
+ break ;
507
+
496
508
default : /* gather other flags */
497
509
flaglist [i ++ ] = c ;
498
510
}
@@ -621,7 +633,8 @@ main(int argc, char *argv[])
621
633
/*
622
634
** open socket to the IP layer to issue getsockopt() calls later on
623
635
*/
624
- netatop_ipopen ();
636
+ if (connectnetatop )
637
+ netatop_ipopen ();
625
638
626
639
/*
627
640
** since privileged activities are finished now, there is no
@@ -735,11 +748,15 @@ engine(void)
735
748
736
749
/*
737
750
** open socket to the atopgpud daemon for GPU statistics
751
+ ** if explicitly required
738
752
*/
739
- nrgpus = gpud_init ();
753
+ if (connectgpud )
754
+ {
755
+ nrgpus = gpud_init ();
740
756
741
- if (nrgpus )
742
- supportflags |= GPUSTAT ;
757
+ if (nrgpus )
758
+ supportflags |= GPUSTAT ;
759
+ }
743
760
744
761
/*
745
762
** MAIN-LOOP:
@@ -786,7 +803,10 @@ engine(void)
786
803
** send request for statistics to atopgpud
787
804
*/
788
805
if (nrgpus )
789
- gpupending = gpud_statrequest ();
806
+ {
807
+ if ((gpupending = gpud_statrequest ()) == 0 )
808
+ nrgpus = 0 ;
809
+ }
790
810
791
811
/*
792
812
** take a snapshot of the current system-level metrics
@@ -818,28 +838,8 @@ engine(void)
818
838
// connection lost or timeout on receive?
819
839
if (nrgpuproc == -1 )
820
840
{
821
- int ng ;
822
-
823
- // try to reconnect
824
- ng = gpud_init ();
825
-
826
- if (ng != nrgpus ) // no success
827
- nrgpus = 0 ;
828
-
829
- if (nrgpus )
830
- {
831
- // request for stats again
832
- if (gpud_statrequest ())
833
- {
834
- // receive stats response
835
- nrgpuproc = gpud_statresponse (nrgpus ,
836
- cursstat -> gpu .gpu , & gp );
837
-
838
- // persistent failure?
839
- if (nrgpuproc == -1 )
840
- nrgpus = 0 ;
841
- }
842
- }
841
+ nrgpus = 0 ;
842
+ supportflags &= ~GPUSTAT ;
843
843
}
844
844
845
845
cursstat -> gpu .nrgpus = nrgpus ;
@@ -929,7 +929,7 @@ engine(void)
929
929
/*
930
930
** merge GPU per-process stats with other per-process stats
931
931
*/
932
- if (nrgpus && nrgpuproc )
932
+ if (nrgpus && nrgpuproc > 0 )
933
933
gpumergeproc (curtpres , ntaskpres ,
934
934
curpexit , nprocexit ,
935
935
gp , nrgpuproc );
@@ -976,8 +976,8 @@ engine(void)
976
976
if ((supportflags & NETATOPD ) && (nprocexitnet > 0 ))
977
977
netatop_exiterase ();
978
978
979
- if (gp )
980
- free ( gp );
979
+ free (gp );
980
+ gp = NULL ; // avoid double free
981
981
982
982
if (lastcmd == MRESET ) /* reset requested ? */
983
983
{
@@ -1033,6 +1033,9 @@ prusage(char *myname)
1033
1033
"non-screen output\n" );
1034
1034
printf ("\t -z prepend regex matching environment variables to "
1035
1035
"command line\n" );
1036
+ printf ("\t -k try to connect to external atopgpud daemon (default: do not connect)\n" );
1037
+ printf ("\t -K try to connect to netatop/netatop-bpf interface (default: do not connect)\n" );
1038
+
1036
1039
1037
1040
if (vis .show_usage )
1038
1041
(* vis .show_usage )();
0 commit comments