9 #include <linux/kernel.h>
10 #include <traceevent/event-parse.h>
11 #include "trace-event.h"
16 * global trace_event object used by trace_event__tp_format
18 * TODO There's no cleanup call for this. Add some sort of
19 * __exit function support and call trace_event__cleanup
22 static struct trace_event tevent
;
23 static bool tevent_initialized
;
25 int trace_event__init(struct trace_event
*t
)
27 struct pevent
*pevent
= pevent_alloc();
30 t
->plugin_list
= traceevent_load_plugins(pevent
);
34 return pevent
? 0 : -1;
37 static int trace_event__init2(void)
39 int be
= traceevent_host_bigendian();
40 struct pevent
*pevent
;
42 if (trace_event__init(&tevent
))
45 pevent
= tevent
.pevent
;
46 pevent_set_flag(pevent
, PEVENT_NSEC_OUTPUT
);
47 pevent_set_file_bigendian(pevent
, be
);
48 pevent_set_host_bigendian(pevent
, be
);
49 tevent_initialized
= true;
53 int trace_event__register_resolver(struct machine
*machine
,
54 pevent_func_resolver_t
*func
)
56 if (!tevent_initialized
&& trace_event__init2())
59 return pevent_set_function_resolver(tevent
.pevent
, func
, machine
);
62 void trace_event__cleanup(struct trace_event
*t
)
64 traceevent_unload_plugins(t
->plugin_list
, t
->pevent
);
65 pevent_free(t
->pevent
);
68 static struct event_format
*
69 tp_format(const char *sys
, const char *name
)
71 struct pevent
*pevent
= tevent
.pevent
;
72 struct event_format
*event
= NULL
;
77 scnprintf(path
, PATH_MAX
, "%s/%s/%s/format",
78 tracing_events_path
, sys
, name
);
80 if (filename__read_str(path
, &data
, &size
))
83 pevent_parse_format(pevent
, &event
, data
, size
, sys
);
90 trace_event__tp_format(const char *sys
, const char *name
)
92 if (!tevent_initialized
&& trace_event__init2())
95 return tp_format(sys
, name
);