18
18
#include "trace_helpers.h"
19
19
20
20
struct env {
21
- bool count ;
21
+ bool cpu ;
22
22
bool distributed ;
23
23
bool nanoseconds ;
24
24
time_t interval ;
@@ -42,18 +42,19 @@ const char *argp_program_bug_address =
42
42
const char argp_program_doc [] =
43
43
"Summarize hard irq event time as histograms.\n"
44
44
"\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"
46
46
"\n"
47
47
"EXAMPLES:\n"
48
48
" hardirqs # sum hard irq event time\n"
49
49
" hardirqs -d # show hard irq event time as histograms\n"
50
50
" hardirqs 1 10 # print 1 second summaries, 10 times\n"
51
51
" hardirqs -c CG # Trace process under cgroupsPath CG\n"
52
52
" hardirqs --cpu 1 # only stat irq on cpu 1\n"
53
+ " hardirqs -C # display separately by CPU\n"
53
54
" hardirqs -NT 1 # 1s summaries, nanoseconds, and timestamps\n" ;
54
55
55
56
static 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 },
57
58
{ "distributed" , 'd' , NULL , 0 , "Show distributions as histograms" , 0 },
58
59
{ "cgroup" , 'c' , "/sys/fs/cgroup/unified" , 0 , "Trace process in cgroup path" , 0 },
59
60
{ "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)
79
80
env .distributed = true;
80
81
break ;
81
82
case 'C' :
82
- env .count = true;
83
+ env .cpu = true;
83
84
break ;
84
85
case 's' :
85
86
errno = 0 ;
@@ -142,14 +143,16 @@ static int print_map(struct bpf_map *map)
142
143
{
143
144
struct irq_key lookup_key = {}, next_key ;
144
145
struct info info ;
146
+ const char * units = env .nanoseconds ? "nsecs" : "usecs" ;
145
147
int fd , err ;
146
148
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" );
153
156
}
154
157
155
158
fd = bpf_map__fd (map );
@@ -160,10 +163,15 @@ static int print_map(struct bpf_map *map)
160
163
return -1 ;
161
164
}
162
165
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 );
164
172
else {
165
- const char * units = env .nanoseconds ? "nsecs" : "usecs" ;
166
-
173
+ if ( env .cpu )
174
+ printf ( "cpu = %u " , next_key . cpu );
167
175
printf ("hardirq = %s\n" , next_key .name );
168
176
print_log2_hist (info .slots , MAX_SLOTS , units );
169
177
}
@@ -203,11 +211,6 @@ int main(int argc, char **argv)
203
211
if (err )
204
212
return err ;
205
213
206
- if (env .count && env .distributed ) {
207
- fprintf (stderr , "count, distributed cann't be used together.\n" );
208
- return 1 ;
209
- }
210
-
211
214
libbpf_set_print (libbpf_print_fn );
212
215
213
216
obj = hardirqs_bpf__open ();
@@ -219,24 +222,17 @@ int main(int argc, char **argv)
219
222
if (probe_tp_btf ("irq_handler_entry" )) {
220
223
bpf_program__set_autoload (obj -> progs .irq_handler_entry , false);
221
224
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);
224
225
} else {
225
226
bpf_program__set_autoload (obj -> progs .irq_handler_entry_btf , false);
226
227
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);
229
228
}
230
229
230
+ /* initialize global data (filtering options) */
231
231
obj -> rodata -> filter_cg = env .cg ;
232
- obj -> rodata -> do_count = env .count ;
232
+ obj -> rodata -> cpu = env .cpu ;
233
233
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 ;
240
236
241
237
err = hardirqs_bpf__load (obj );
242
238
if (err ) {
@@ -267,10 +263,7 @@ int main(int argc, char **argv)
267
263
268
264
signal (SIGINT , sig_handler );
269
265
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" );
274
267
275
268
/* main: poll */
276
269
while (1 ) {
0 commit comments