rtla/trace: Add trace event filter helpers
Add a set of helper functions to allow rtla tools to filter events in the trace instance. Link: https://lkml.kernel.org/r/12623b1684684549d53b90f4bf66fae44584fd14.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:
committed by
Steven Rostedt (Google)
parent
1a75489365
commit
5487b6ce26
@@ -204,6 +204,8 @@ static void trace_events_free(struct trace_events *events)
|
|||||||
|
|
||||||
tevent = tevent->next;
|
tevent = tevent->next;
|
||||||
|
|
||||||
|
if (free_event->filter)
|
||||||
|
free(free_event->filter);
|
||||||
if (free_event->trigger)
|
if (free_event->trigger)
|
||||||
free(free_event->trigger);
|
free(free_event->trigger);
|
||||||
free(free_event->system);
|
free(free_event->system);
|
||||||
@@ -237,6 +239,21 @@ struct trace_events *trace_event_alloc(const char *event_string)
|
|||||||
return tevent;
|
return tevent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* trace_event_add_filter - record an event filter
|
||||||
|
*/
|
||||||
|
int trace_event_add_filter(struct trace_events *event, char *filter)
|
||||||
|
{
|
||||||
|
if (event->filter)
|
||||||
|
free(event->filter);
|
||||||
|
|
||||||
|
event->filter = strdup(filter);
|
||||||
|
if (!event->filter)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* trace_event_add_trigger - record an event trigger action
|
* trace_event_add_trigger - record an event trigger action
|
||||||
*/
|
*/
|
||||||
@@ -252,6 +269,33 @@ int trace_event_add_trigger(struct trace_events *event, char *trigger)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* trace_event_disable_filter - disable an event filter
|
||||||
|
*/
|
||||||
|
static void trace_event_disable_filter(struct trace_instance *instance,
|
||||||
|
struct trace_events *tevent)
|
||||||
|
{
|
||||||
|
char filter[1024];
|
||||||
|
int retval;
|
||||||
|
|
||||||
|
if (!tevent->filter)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!tevent->filter_enabled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
debug_msg("Disabling %s:%s filter %s\n", tevent->system,
|
||||||
|
tevent->event ? : "*", tevent->filter);
|
||||||
|
|
||||||
|
snprintf(filter, 1024, "!%s\n", tevent->filter);
|
||||||
|
|
||||||
|
retval = tracefs_event_file_write(instance->inst, tevent->system,
|
||||||
|
tevent->event, "filter", filter);
|
||||||
|
if (retval < 0)
|
||||||
|
err_msg("Error disabling %s:%s filter %s\n", tevent->system,
|
||||||
|
tevent->event ? : "*", tevent->filter);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* trace_event_disable_trigger - disable an event trigger
|
* trace_event_disable_trigger - disable an event trigger
|
||||||
*/
|
*/
|
||||||
@@ -293,6 +337,7 @@ void trace_events_disable(struct trace_instance *instance,
|
|||||||
while (tevent) {
|
while (tevent) {
|
||||||
debug_msg("Disabling event %s:%s\n", tevent->system, tevent->event ? : "*");
|
debug_msg("Disabling event %s:%s\n", tevent->system, tevent->event ? : "*");
|
||||||
if (tevent->enabled) {
|
if (tevent->enabled) {
|
||||||
|
trace_event_disable_filter(instance, tevent);
|
||||||
trace_event_disable_trigger(instance, tevent);
|
trace_event_disable_trigger(instance, tevent);
|
||||||
tracefs_event_disable(instance->inst, tevent->system, tevent->event);
|
tracefs_event_disable(instance->inst, tevent->system, tevent->event);
|
||||||
}
|
}
|
||||||
@@ -302,6 +347,41 @@ void trace_events_disable(struct trace_instance *instance,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* trace_event_enable_filter - enable an event filter associated with an event
|
||||||
|
*/
|
||||||
|
static int trace_event_enable_filter(struct trace_instance *instance,
|
||||||
|
struct trace_events *tevent)
|
||||||
|
{
|
||||||
|
char filter[1024];
|
||||||
|
int retval;
|
||||||
|
|
||||||
|
if (!tevent->filter)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (!tevent->event) {
|
||||||
|
err_msg("Filter %s applies only for single events, not for all %s:* events\n",
|
||||||
|
tevent->filter, tevent->system);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
snprintf(filter, 1024, "%s\n", tevent->filter);
|
||||||
|
|
||||||
|
debug_msg("Enabling %s:%s filter %s\n", tevent->system,
|
||||||
|
tevent->event ? : "*", tevent->filter);
|
||||||
|
|
||||||
|
retval = tracefs_event_file_write(instance->inst, tevent->system,
|
||||||
|
tevent->event, "filter", filter);
|
||||||
|
if (retval < 0) {
|
||||||
|
err_msg("Error enabling %s:%s filter %s\n", tevent->system,
|
||||||
|
tevent->event ? : "*", tevent->filter);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
tevent->filter_enabled = 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* trace_event_enable_trigger - enable an event trigger associated with an event
|
* trace_event_enable_trigger - enable an event trigger associated with an event
|
||||||
*/
|
*/
|
||||||
@@ -356,6 +436,9 @@ int trace_events_enable(struct trace_instance *instance,
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
retval = trace_event_enable_filter(instance, tevent);
|
||||||
|
if (retval)
|
||||||
|
return 1;
|
||||||
|
|
||||||
retval = trace_event_enable_trigger(instance, tevent);
|
retval = trace_event_enable_trigger(instance, tevent);
|
||||||
if (retval)
|
if (retval)
|
||||||
|
|||||||
@@ -6,8 +6,10 @@ struct trace_events {
|
|||||||
struct trace_events *next;
|
struct trace_events *next;
|
||||||
char *system;
|
char *system;
|
||||||
char *event;
|
char *event;
|
||||||
|
char *filter;
|
||||||
char *trigger;
|
char *trigger;
|
||||||
char enabled;
|
char enabled;
|
||||||
|
char filter_enabled;
|
||||||
char trigger_enabled;
|
char trigger_enabled;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -43,4 +45,5 @@ void trace_events_destroy(struct trace_instance *instance,
|
|||||||
int trace_events_enable(struct trace_instance *instance,
|
int trace_events_enable(struct trace_instance *instance,
|
||||||
struct trace_events *events);
|
struct trace_events *events);
|
||||||
|
|
||||||
|
int trace_event_add_filter(struct trace_events *event, char *filter);
|
||||||
int trace_event_add_trigger(struct trace_events *event, char *trigger);
|
int trace_event_add_trigger(struct trace_events *event, char *trigger);
|
||||||
|
|||||||
Reference in New Issue
Block a user