67
67
#define CNTR_NOT_SUPPORTED "<not supported>"
68
68
#define CNTR_NOT_COUNTED "<not counted>"
69
69
70
- static void print_stat (int argc , const char * * argv );
71
- static void print_counter_aggr (struct perf_evsel * counter , char * prefix );
72
- static void print_counter (struct perf_evsel * counter , char * prefix );
73
- static void print_aggr (char * prefix );
70
+ static void print_counters (struct timespec * ts , int argc , const char * * argv );
74
71
75
72
/* Default events used for perf stat -T */
76
73
static const char * transaction_attrs = {
@@ -365,53 +362,14 @@ static void read_counters(bool close)
365
362
366
363
static void process_interval (void )
367
364
{
368
- static int num_print_interval ;
369
- struct perf_evsel * counter ;
370
365
struct timespec ts , rs ;
371
- char prefix [64 ];
372
366
373
367
read_counters (false);
374
368
375
369
clock_gettime (CLOCK_MONOTONIC , & ts );
376
370
diff_timespec (& rs , & ts , & ref_time );
377
- sprintf (prefix , "%6lu.%09lu%s" , rs .tv_sec , rs .tv_nsec , csv_sep );
378
-
379
- if (num_print_interval == 0 && !csv_output ) {
380
- switch (aggr_mode ) {
381
- case AGGR_SOCKET :
382
- fprintf (output , "# time socket cpus counts %*s events\n" , unit_width , "unit" );
383
- break ;
384
- case AGGR_CORE :
385
- fprintf (output , "# time core cpus counts %*s events\n" , unit_width , "unit" );
386
- break ;
387
- case AGGR_NONE :
388
- fprintf (output , "# time CPU counts %*s events\n" , unit_width , "unit" );
389
- break ;
390
- case AGGR_GLOBAL :
391
- default :
392
- fprintf (output , "# time counts %*s events\n" , unit_width , "unit" );
393
- }
394
- }
395
-
396
- if (++ num_print_interval == 25 )
397
- num_print_interval = 0 ;
398
371
399
- switch (aggr_mode ) {
400
- case AGGR_CORE :
401
- case AGGR_SOCKET :
402
- print_aggr (prefix );
403
- break ;
404
- case AGGR_NONE :
405
- evlist__for_each (evsel_list , counter )
406
- print_counter (counter , prefix );
407
- break ;
408
- case AGGR_GLOBAL :
409
- default :
410
- evlist__for_each (evsel_list , counter )
411
- print_counter_aggr (counter , prefix );
412
- }
413
-
414
- fflush (output );
372
+ print_counters (& rs , 0 , NULL );
415
373
}
416
374
417
375
static void handle_initial_delay (void )
@@ -901,9 +859,35 @@ static void print_counter(struct perf_evsel *counter, char *prefix)
901
859
}
902
860
}
903
861
904
- static void print_stat (int argc , const char * * argv )
862
+ static void print_interval (char * prefix , struct timespec * ts )
863
+ {
864
+ static int num_print_interval ;
865
+
866
+ sprintf (prefix , "%6lu.%09lu%s" , ts -> tv_sec , ts -> tv_nsec , csv_sep );
867
+
868
+ if (num_print_interval == 0 && !csv_output ) {
869
+ switch (aggr_mode ) {
870
+ case AGGR_SOCKET :
871
+ fprintf (output , "# time socket cpus counts %*s events\n" , unit_width , "unit" );
872
+ break ;
873
+ case AGGR_CORE :
874
+ fprintf (output , "# time core cpus counts %*s events\n" , unit_width , "unit" );
875
+ break ;
876
+ case AGGR_NONE :
877
+ fprintf (output , "# time CPU counts %*s events\n" , unit_width , "unit" );
878
+ break ;
879
+ case AGGR_GLOBAL :
880
+ default :
881
+ fprintf (output , "# time counts %*s events\n" , unit_width , "unit" );
882
+ }
883
+ }
884
+
885
+ if (++ num_print_interval == 25 )
886
+ num_print_interval = 0 ;
887
+ }
888
+
889
+ static void print_header (int argc , const char * * argv )
905
890
{
906
- struct perf_evsel * counter ;
907
891
int i ;
908
892
909
893
fflush (stdout );
@@ -929,36 +913,53 @@ static void print_stat(int argc, const char **argv)
929
913
fprintf (output , " (%d runs)" , run_count );
930
914
fprintf (output , ":\n\n" );
931
915
}
916
+ }
917
+
918
+ static void print_footer (void )
919
+ {
920
+ if (!null_run )
921
+ fprintf (output , "\n" );
922
+ fprintf (output , " %17.9f seconds time elapsed" ,
923
+ avg_stats (& walltime_nsecs_stats )/1e9 );
924
+ if (run_count > 1 ) {
925
+ fprintf (output , " " );
926
+ print_noise_pct (stddev_stats (& walltime_nsecs_stats ),
927
+ avg_stats (& walltime_nsecs_stats ));
928
+ }
929
+ fprintf (output , "\n\n" );
930
+ }
931
+
932
+ static void print_counters (struct timespec * ts , int argc , const char * * argv )
933
+ {
934
+ struct perf_evsel * counter ;
935
+ char buf [64 ], * prefix = NULL ;
936
+
937
+ if (interval )
938
+ print_interval (prefix = buf , ts );
939
+ else
940
+ print_header (argc , argv );
932
941
933
942
switch (aggr_mode ) {
934
943
case AGGR_CORE :
935
944
case AGGR_SOCKET :
936
- print_aggr (NULL );
945
+ print_aggr (prefix );
937
946
break ;
938
947
case AGGR_GLOBAL :
939
948
evlist__for_each (evsel_list , counter )
940
- print_counter_aggr (counter , NULL );
949
+ print_counter_aggr (counter , prefix );
941
950
break ;
942
951
case AGGR_NONE :
943
952
evlist__for_each (evsel_list , counter )
944
- print_counter (counter , NULL );
953
+ print_counter (counter , prefix );
945
954
break ;
946
955
default :
947
956
break ;
948
957
}
949
958
950
- if (!csv_output ) {
951
- if (!null_run )
952
- fprintf (output , "\n" );
953
- fprintf (output , " %17.9f seconds time elapsed" ,
954
- avg_stats (& walltime_nsecs_stats )/1e9 );
955
- if (run_count > 1 ) {
956
- fprintf (output , " " );
957
- print_noise_pct (stddev_stats (& walltime_nsecs_stats ),
958
- avg_stats (& walltime_nsecs_stats ));
959
- }
960
- fprintf (output , "\n\n" );
961
- }
959
+ if (!interval && !csv_output )
960
+ print_footer ();
961
+
962
+ fflush (output );
962
963
}
963
964
964
965
static volatile int signr = -1 ;
@@ -1407,13 +1408,13 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
1407
1408
1408
1409
status = run_perf_stat (argc , argv );
1409
1410
if (forever && status != -1 ) {
1410
- print_stat ( argc , argv );
1411
+ print_counters ( NULL , argc , argv );
1411
1412
perf_stat__reset_stats ();
1412
1413
}
1413
1414
}
1414
1415
1415
1416
if (!forever && status != -1 && !interval )
1416
- print_stat ( argc , argv );
1417
+ print_counters ( NULL , argc , argv );
1417
1418
1418
1419
perf_evlist__free_stats (evsel_list );
1419
1420
out :
0 commit comments