1 // SPDX-License-Identifier: GPL-2.0
8 #include <sys/sendfile.h>
20 * create_instance - create a trace instance with *instance_name
22 static struct tracefs_instance *create_instance(char *instance_name)
24 return tracefs_instance_create(instance_name);
28 * destroy_instance - remove a trace instance and free the data
30 static void destroy_instance(struct tracefs_instance *inst)
32 tracefs_instance_destroy(inst);
33 tracefs_instance_free(inst);
37 * collect_registered_events - call the existing callback function for the event
39 * If an event has a registered callback function, call it.
40 * Otherwise, ignore the event.
42 * Returns 0 if the event was collected, 1 if the tool should stop collecting trace.
45 collect_registered_events(struct tep_event *event, struct tep_record *record,
46 int cpu, void *context)
48 struct trace_instance *trace = context;
49 struct trace_seq *s = trace->seq;
57 event->handler(s, record, event, context);
63 * trace_instance_destroy - destroy and free a rv trace instance
65 void trace_instance_destroy(struct trace_instance *trace)
68 destroy_instance(trace->inst);
84 * trace_instance_init - create a trace instance
86 * It is more than the tracefs instance, as it contains other
87 * things required for the tracing, such as the local events and
90 * Note that the trace instance is returned disabled. This allows
91 * the tool to apply some other configs, like setting priority
92 * to the kernel threads, before starting generating trace entries.
94 * Returns 0 on success, non-zero otherwise.
96 int trace_instance_init(struct trace_instance *trace, char *name)
98 trace->seq = calloc(1, sizeof(*trace->seq));
102 trace_seq_init(trace->seq);
104 trace->inst = create_instance(name);
108 trace->tep = tracefs_local_events(NULL);
113 * Let the main enable the record after setting some other
114 * things such as the priority of the tracer's threads.
116 tracefs_trace_off(trace->inst);
121 trace_instance_destroy(trace);
126 * trace_instance_start - start tracing a given rv instance
128 * Returns 0 on success, -1 otherwise.
130 int trace_instance_start(struct trace_instance *trace)
132 return tracefs_trace_on(trace->inst);