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>
This commit is contained in:
Родитель
44f3a37d1d
Коммит
761916fd02
|
@ -23,7 +23,15 @@
|
|||
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.
|
||||
|
||||
**--trigger** *<trigger>*
|
||||
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.
|
||||
Enable a trace event trigger to the previous **-e** *sys:event*.
|
||||
If the *hist:* trigger is activated, the output histogram will be automatically saved to a file named *system_event_hist.txt*.
|
||||
For example, the command:
|
||||
|
||||
rtla <command> <mode> -t -e osnoise:irq_noise --trigger="hist:key=desc,duration/1000:sort=desc,duration/1000:vals=hitcount"
|
||||
|
||||
Will automatically save the content of the histogram associated to *osnoise:irq_noise* event in *osnoise_irq_noise_hist.txt*.
|
||||
|
||||
For further information about event trigger see https://www.kernel.org/doc/html/latest/trace/events.html#event-triggers.
|
||||
|
||||
**-P**, **--priority** *o:prio|r:prio|f:prio|d:runtime:period*
|
||||
|
||||
|
|
|
@ -296,6 +296,57 @@ static void trace_event_disable_filter(struct trace_instance *instance,
|
|||
tevent->event ? : "*", tevent->filter);
|
||||
}
|
||||
|
||||
/*
|
||||
* trace_event_save_hist - save the content of an event hist
|
||||
*
|
||||
* If the trigger is a hist: one, save the content of the hist file.
|
||||
*/
|
||||
static void trace_event_save_hist(struct trace_instance *instance,
|
||||
struct trace_events *tevent)
|
||||
{
|
||||
int retval, index, out_fd;
|
||||
mode_t mode = 0644;
|
||||
char path[1024];
|
||||
char *hist;
|
||||
|
||||
if (!tevent)
|
||||
return;
|
||||
|
||||
/* trigger enables hist */
|
||||
if (!tevent->trigger)
|
||||
return;
|
||||
|
||||
/* is this a hist: trigger? */
|
||||
retval = strncmp(tevent->trigger, "hist:", strlen("hist:"));
|
||||
if (retval)
|
||||
return;
|
||||
|
||||
snprintf(path, 1024, "%s_%s_hist.txt", tevent->system, tevent->event);
|
||||
|
||||
printf(" Saving event %s:%s hist to %s\n", tevent->system, tevent->event, path);
|
||||
|
||||
out_fd = creat(path, mode);
|
||||
if (out_fd < 0) {
|
||||
err_msg(" Failed to create %s output file\n", path);
|
||||
return;
|
||||
}
|
||||
|
||||
hist = tracefs_event_file_read(instance->inst, tevent->system, tevent->event, "hist", 0);
|
||||
if (!hist) {
|
||||
err_msg(" Failed to read %s:%s hist file\n", tevent->system, tevent->event);
|
||||
goto out_close;
|
||||
}
|
||||
|
||||
index = 0;
|
||||
do {
|
||||
index += write(out_fd, &hist[index], strlen(hist) - index);
|
||||
} while (index < strlen(hist));
|
||||
|
||||
free(hist);
|
||||
out_close:
|
||||
close(out_fd);
|
||||
}
|
||||
|
||||
/*
|
||||
* trace_event_disable_trigger - disable an event trigger
|
||||
*/
|
||||
|
@ -314,6 +365,8 @@ static void trace_event_disable_trigger(struct trace_instance *instance,
|
|||
debug_msg("Disabling %s:%s trigger %s\n", tevent->system,
|
||||
tevent->event ? : "*", tevent->trigger);
|
||||
|
||||
trace_event_save_hist(instance, tevent);
|
||||
|
||||
snprintf(trigger, 1024, "!%s\n", tevent->trigger);
|
||||
|
||||
retval = tracefs_event_file_write(instance->inst, tevent->system,
|
||||
|
|
Загрузка…
Ссылка в новой задаче