Skip to content

Commit b5aa0be

Browse files
Daniel Bristot de Oliveirarostedt
authored andcommitted
rtla/trace: Add trace events helpers
Add a set of helper functions to allow the rtla tools to enable additional tracepoints in the trace instance. Link: https://lkml.kernel.org/r/932398b36c1bbaa22c7810d7a40ca9b8c5595b94.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 173a3b0 commit b5aa0be

2 files changed

Lines changed: 119 additions & 0 deletions

File tree

tools/tracing/rtla/src/trace.c

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,107 @@ int trace_instance_start(struct trace_instance *trace)
190190
{
191191
return tracefs_trace_on(trace->inst);
192192
}
193+
194+
/*
195+
* trace_events_free - free a list of trace events
196+
*/
197+
static void trace_events_free(struct trace_events *events)
198+
{
199+
struct trace_events *tevent = events;
200+
struct trace_events *free_event;
201+
202+
while (tevent) {
203+
free_event = tevent;
204+
205+
tevent = tevent->next;
206+
207+
free(free_event->system);
208+
free(free_event);
209+
}
210+
}
211+
212+
/*
213+
* trace_event_alloc - alloc and parse a single trace event
214+
*/
215+
struct trace_events *trace_event_alloc(const char *event_string)
216+
{
217+
struct trace_events *tevent;
218+
219+
tevent = calloc(1, sizeof(*tevent));
220+
if (!tevent)
221+
return NULL;
222+
223+
tevent->system = strdup(event_string);
224+
if (!tevent->system) {
225+
free(tevent);
226+
return NULL;
227+
}
228+
229+
tevent->event = strstr(tevent->system, ":");
230+
if (tevent->event) {
231+
*tevent->event = '\0';
232+
tevent->event = &tevent->event[1];
233+
}
234+
235+
return tevent;
236+
}
237+
238+
/*
239+
* trace_events_disable - disable all trace events
240+
*/
241+
void trace_events_disable(struct trace_instance *instance,
242+
struct trace_events *events)
243+
{
244+
struct trace_events *tevent = events;
245+
246+
if (!events)
247+
return;
248+
249+
while (tevent) {
250+
debug_msg("Disabling event %s:%s\n", tevent->system, tevent->event ? : "*");
251+
if (tevent->enabled)
252+
tracefs_event_disable(instance->inst, tevent->system, tevent->event);
253+
254+
tevent->enabled = 0;
255+
tevent = tevent->next;
256+
}
257+
}
258+
259+
/*
260+
* trace_events_enable - enable all events
261+
*/
262+
int trace_events_enable(struct trace_instance *instance,
263+
struct trace_events *events)
264+
{
265+
struct trace_events *tevent = events;
266+
int retval;
267+
268+
while (tevent) {
269+
debug_msg("Enabling event %s:%s\n", tevent->system, tevent->event ? : "*");
270+
retval = tracefs_event_enable(instance->inst, tevent->system, tevent->event);
271+
if (retval < 0) {
272+
err_msg("Error enabling event %s:%s\n", tevent->system,
273+
tevent->event ? : "*");
274+
return 1;
275+
}
276+
277+
278+
tevent->enabled = 1;
279+
tevent = tevent->next;
280+
}
281+
282+
return 0;
283+
}
284+
285+
/*
286+
* trace_events_destroy - disable and free all trace events
287+
*/
288+
void trace_events_destroy(struct trace_instance *instance,
289+
struct trace_events *events)
290+
{
291+
if (!events)
292+
return;
293+
294+
trace_events_disable(instance, events);
295+
trace_events_free(events);
296+
}

tools/tracing/rtla/src/trace.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
#include <tracefs.h>
33
#include <stddef.h>
44

5+
struct trace_events {
6+
struct trace_events *next;
7+
char *system;
8+
char *event;
9+
char enabled;
10+
};
11+
512
struct trace_instance {
613
struct tracefs_instance *inst;
714
struct tep_handle *tep;
@@ -25,3 +32,11 @@ void destroy_instance(struct tracefs_instance *inst);
2532
int save_trace_to_file(struct tracefs_instance *inst, const char *filename);
2633
int collect_registered_events(struct tep_event *tep, struct tep_record *record,
2734
int cpu, void *context);
35+
36+
struct trace_events *trace_event_alloc(const char *event_string);
37+
void trace_events_disable(struct trace_instance *instance,
38+
struct trace_events *events);
39+
void trace_events_destroy(struct trace_instance *instance,
40+
struct trace_events *events);
41+
int trace_events_enable(struct trace_instance *instance,
42+
struct trace_events *events);

0 commit comments

Comments
 (0)