1818#include "trace_helpers.h"
1919
2020struct env {
21- bool count ;
21+ bool cpu ;
2222 bool distributed ;
2323 bool nanoseconds ;
2424 time_t interval ;
@@ -42,18 +42,19 @@ const char *argp_program_bug_address =
4242const char argp_program_doc [] =
4343"Summarize hard irq event time as histograms.\n"
4444"\n"
45- "USAGE: hardirqs [--help] [-T] [-N] [-d] [interval] [count] [-c CG]\n"
45+ "USAGE: hardirqs [--help] [-T] [-N] [-d] [-C] [ interval] [count] [-c CG]\n"
4646"\n"
4747"EXAMPLES:\n"
4848" hardirqs # sum hard irq event time\n"
4949" hardirqs -d # show hard irq event time as histograms\n"
5050" hardirqs 1 10 # print 1 second summaries, 10 times\n"
5151" hardirqs -c CG # Trace process under cgroupsPath CG\n"
5252" hardirqs --cpu 1 # only stat irq on cpu 1\n"
53+ " hardirqs -C # display separately by CPU\n"
5354" hardirqs -NT 1 # 1s summaries, nanoseconds, and timestamps\n" ;
5455
5556static const struct argp_option opts [] = {
56- { "count " , 'C' , NULL , 0 , "Show event counts instead of timing " , 0 },
57+ { "CPU " , 'C' , NULL , 0 , "Display separately by CPU " , 0 },
5758 { "distributed" , 'd' , NULL , 0 , "Show distributions as histograms" , 0 },
5859 { "cgroup" , 'c' , "/sys/fs/cgroup/unified" , 0 , "Trace process in cgroup path" , 0 },
5960 { "cpu" , 's' , "CPU" , 0 , "Only stat irq on selected cpu" , 0 },
@@ -79,7 +80,7 @@ static error_t parse_arg(int key, char *arg, struct argp_state *state)
7980 env .distributed = true;
8081 break ;
8182 case 'C' :
82- env .count = true;
83+ env .cpu = true;
8384 break ;
8485 case 's' :
8586 errno = 0 ;
@@ -142,14 +143,16 @@ static int print_map(struct bpf_map *map)
142143{
143144 struct irq_key lookup_key = {}, next_key ;
144145 struct info info ;
146+ const char * units = env .nanoseconds ? "nsecs" : "usecs" ;
145147 int fd , err ;
146148
147- if (env .count ) {
148- printf ("%-26s %11s\n" , "HARDIRQ" , "TOTAL_count" );
149- } else if (!env .distributed ) {
150- const char * units = env .nanoseconds ? "nsecs" : "usecs" ;
151-
152- printf ("%-26s %6s%5s\n" , "HARDIRQ" , "TOTAL_" , units );
149+ if (!env .distributed ) {
150+ printf ("%-33s %11s %6s%5s %4s%5s" , "HARDIRQ" , "TOTAL_count" ,
151+ "TOTAL_" , units , "MAX_" , units );
152+ if (env .cpu )
153+ printf (" %3s\n" , "CPU" );
154+ else
155+ printf ("\n" );
153156 }
154157
155158 fd = bpf_map__fd (map );
@@ -160,10 +163,15 @@ static int print_map(struct bpf_map *map)
160163 return -1 ;
161164 }
162165 if (!env .distributed )
163- printf ("%-26s %11llu\n" , next_key .name , info .count );
166+ if (env .cpu )
167+ printf ("%-33s %11llu %11llu %9llu %3u\n" , next_key .name ,
168+ info .count , info .total_time , info .max_time , next_key .cpu );
169+ else
170+ printf ("%-33s %11llu %11llu %9llu\n" , next_key .name ,
171+ info .count , info .total_time , info .max_time );
164172 else {
165- const char * units = env .nanoseconds ? "nsecs" : "usecs" ;
166-
173+ if ( env .cpu )
174+ printf ( "cpu = %u " , next_key . cpu );
167175 printf ("hardirq = %s\n" , next_key .name );
168176 print_log2_hist (info .slots , MAX_SLOTS , units );
169177 }
@@ -203,11 +211,6 @@ int main(int argc, char **argv)
203211 if (err )
204212 return err ;
205213
206- if (env .count && env .distributed ) {
207- fprintf (stderr , "count, distributed cann't be used together.\n" );
208- return 1 ;
209- }
210-
211214 libbpf_set_print (libbpf_print_fn );
212215
213216 obj = hardirqs_bpf__open ();
@@ -219,24 +222,17 @@ int main(int argc, char **argv)
219222 if (probe_tp_btf ("irq_handler_entry" )) {
220223 bpf_program__set_autoload (obj -> progs .irq_handler_entry , false);
221224 bpf_program__set_autoload (obj -> progs .irq_handler_exit , false);
222- if (env .count )
223- bpf_program__set_autoload (obj -> progs .irq_handler_exit_btf , false);
224225 } else {
225226 bpf_program__set_autoload (obj -> progs .irq_handler_entry_btf , false);
226227 bpf_program__set_autoload (obj -> progs .irq_handler_exit_btf , false);
227- if (env .count )
228- bpf_program__set_autoload (obj -> progs .irq_handler_exit , false);
229228 }
230229
230+ /* initialize global data (filtering options) */
231231 obj -> rodata -> filter_cg = env .cg ;
232- obj -> rodata -> do_count = env .count ;
232+ obj -> rodata -> cpu = env .cpu ;
233233 obj -> rodata -> targ_cpu = env .targ_cpu ;
234-
235- /* initialize global data (filtering options) */
236- if (!env .count ) {
237- obj -> rodata -> targ_dist = env .distributed ;
238- obj -> rodata -> targ_ns = env .nanoseconds ;
239- }
234+ obj -> rodata -> targ_dist = env .distributed ;
235+ obj -> rodata -> targ_ns = env .nanoseconds ;
240236
241237 err = hardirqs_bpf__load (obj );
242238 if (err ) {
@@ -267,10 +263,7 @@ int main(int argc, char **argv)
267263
268264 signal (SIGINT , sig_handler );
269265
270- if (env .count )
271- printf ("Tracing hard irq events... Hit Ctrl-C to end.\n" );
272- else
273- printf ("Tracing hard irq event time... Hit Ctrl-C to end.\n" );
266+ printf ("Tracing hard irq event time... Hit Ctrl-C to end.\n" );
274267
275268 /* main: poll */
276269 while (1 ) {
0 commit comments