Skip to content

Commit 761916f

Browse files
Daniel Bristot de Oliveirarostedt
authored andcommitted
rtla/trace: Save event histogram output to a file
The hist: trigger generates a histogram in the file sys/event/hist. If the hist: trigger is used, automatically save the histogram output of the event sys:event in the sys_event_hist.txt file. Link: https://lkml.kernel.org/r/b5c906af31d4e022ffe87fb0848fac5c089087c8.1646247211.git.bristot@kernel.org Cc: Daniel Bristot de Oliveira <bristot@kernel.org> Cc: Clark Williams <williams@redhat.com> Cc: Juri Lelli <juri.lelli@redhat.com> Cc: Jonathan Corbet <corbet@lwn.net> Signed-off-by: Daniel Bristot de Oliveira <bristot@kernel.org> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent 44f3a37 commit 761916f

2 files changed

Lines changed: 62 additions & 1 deletion

File tree

Documentation/tools/rtla/common_options.rst

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,15 @@
2323
Filter the previous **-e** *sys:event* event with *<filter>*. For further information about event filtering see https://www.kernel.org/doc/html/latest/trace/events.html#event-filtering.
2424

2525
**--trigger** *<trigger>*
26-
Enable a trace event trigger to the previous **-e** *sys:event*. For further information about event trigger see https://www.kernel.org/doc/html/latest/trace/events.html#event-triggers.
26+
Enable a trace event trigger to the previous **-e** *sys:event*.
27+
If the *hist:* trigger is activated, the output histogram will be automatically saved to a file named *system_event_hist.txt*.
28+
For example, the command:
29+
30+
rtla <command> <mode> -t -e osnoise:irq_noise --trigger="hist:key=desc,duration/1000:sort=desc,duration/1000:vals=hitcount"
31+
32+
Will automatically save the content of the histogram associated to *osnoise:irq_noise* event in *osnoise_irq_noise_hist.txt*.
33+
34+
For further information about event trigger see https://www.kernel.org/doc/html/latest/trace/events.html#event-triggers.
2735

2836
**-P**, **--priority** *o:prio|r:prio|f:prio|d:runtime:period*
2937

tools/tracing/rtla/src/trace.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,57 @@ static void trace_event_disable_filter(struct trace_instance *instance,
296296
tevent->event ? : "*", tevent->filter);
297297
}
298298

299+
/*
300+
* trace_event_save_hist - save the content of an event hist
301+
*
302+
* If the trigger is a hist: one, save the content of the hist file.
303+
*/
304+
static void trace_event_save_hist(struct trace_instance *instance,
305+
struct trace_events *tevent)
306+
{
307+
int retval, index, out_fd;
308+
mode_t mode = 0644;
309+
char path[1024];
310+
char *hist;
311+
312+
if (!tevent)
313+
return;
314+
315+
/* trigger enables hist */
316+
if (!tevent->trigger)
317+
return;
318+
319+
/* is this a hist: trigger? */
320+
retval = strncmp(tevent->trigger, "hist:", strlen("hist:"));
321+
if (retval)
322+
return;
323+
324+
snprintf(path, 1024, "%s_%s_hist.txt", tevent->system, tevent->event);
325+
326+
printf(" Saving event %s:%s hist to %s\n", tevent->system, tevent->event, path);
327+
328+
out_fd = creat(path, mode);
329+
if (out_fd < 0) {
330+
err_msg(" Failed to create %s output file\n", path);
331+
return;
332+
}
333+
334+
hist = tracefs_event_file_read(instance->inst, tevent->system, tevent->event, "hist", 0);
335+
if (!hist) {
336+
err_msg(" Failed to read %s:%s hist file\n", tevent->system, tevent->event);
337+
goto out_close;
338+
}
339+
340+
index = 0;
341+
do {
342+
index += write(out_fd, &hist[index], strlen(hist) - index);
343+
} while (index < strlen(hist));
344+
345+
free(hist);
346+
out_close:
347+
close(out_fd);
348+
}
349+
299350
/*
300351
* trace_event_disable_trigger - disable an event trigger
301352
*/
@@ -314,6 +365,8 @@ static void trace_event_disable_trigger(struct trace_instance *instance,
314365
debug_msg("Disabling %s:%s trigger %s\n", tevent->system,
315366
tevent->event ? : "*", tevent->trigger);
316367

368+
trace_event_save_hist(instance, tevent);
369+
317370
snprintf(trigger, 1024, "!%s\n", tevent->trigger);
318371

319372
retval = tracefs_event_file_write(instance->inst, tevent->system,

0 commit comments

Comments
 (0)