aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--parse-events.c45
-rw-r--r--parse-events.h6
-rw-r--r--test_plugin.c13
-rw-r--r--trace-util.c7
5 files changed, 68 insertions, 5 deletions
diff --git a/Makefile b/Makefile
index c895ba7..213f196 100644
--- a/Makefile
+++ b/Makefile
@@ -19,7 +19,7 @@ trace-read.o:: parse-events.h
19trace-cmd.o:: parse-events.h $(LIB_FILE) 19trace-cmd.o:: parse-events.h $(LIB_FILE)
20 20
21trace-cmd:: trace-cmd.o trace-read.o trace-util.o 21trace-cmd:: trace-cmd.o trace-read.o trace-util.o
22 $(CC) $^ $(LIBS) -o $@ 22 $(CC) $^ $(LIBS) -rdynamic -o $@
23 23
24parse-events.o: parse-events.c parse-events.h 24parse-events.o: parse-events.c parse-events.h
25 $(CC) -c $(CFLAGS) $(EXT) $(INCLUDES) -fPIC $< -o $@ 25 $(CC) -c $(CFLAGS) $(EXT) $(INCLUDES) -fPIC $< -o $@
diff --git a/parse-events.c b/parse-events.c
index 5f02519..15cd0e4 100644
--- a/parse-events.c
+++ b/parse-events.c
@@ -2180,6 +2180,22 @@ static struct event *trace_find_event(int id)
2180 return event; 2180 return event;
2181} 2181}
2182 2182
2183static struct event *
2184trace_find_event_by_name(const char *sys, const char *name)
2185{
2186 struct event *event;
2187
2188 for (event = event_list; event; event = event->next) {
2189 if (strcmp(event->name, name) == 0) {
2190 if (!sys)
2191 break;
2192 if (strcmp(event->system, sys) == 0)
2193 break;
2194 }
2195 }
2196 return event;
2197}
2198
2183static unsigned long long eval_num_arg(void *data, int size, 2199static unsigned long long eval_num_arg(void *data, int size,
2184 struct event *event, struct print_arg *arg) 2200 struct event *event, struct print_arg *arg)
2185{ 2201{
@@ -3236,7 +3252,10 @@ void pevent_print_event(struct trace_seq *s,
3236 return; 3252 return;
3237 } 3253 }
3238 3254
3239 pretty_print(s, data, size, event); 3255 if (event->handler)
3256 event->handler(s, data, size);
3257 else
3258 pretty_print(s, data, size, event);
3240 trace_seq_putc(s, '\n'); 3259 trace_seq_putc(s, '\n');
3241} 3260}
3242 3261
@@ -3488,6 +3507,30 @@ int pevent_parse_event(char *buf, unsigned long size, char *sys)
3488 return -1; 3507 return -1;
3489} 3508}
3490 3509
3510int pevent_register_event_handler(int id, char *sys_name, char *event_name,
3511 pevent_event_handler_func func)
3512{
3513 struct event *event;
3514
3515 if (id >= 0) {
3516 /* search by id */
3517 event = trace_find_event(id);
3518 if (!event)
3519 return -1;
3520 if (event_name && (strcmp(event_name, event->name) != 0))
3521 return -1;
3522 if (sys_name && (strcmp(sys_name, event->system) != 0))
3523 return -1;
3524 } else {
3525 event = trace_find_event_by_name(sys_name, event_name);
3526 if (!event)
3527 return -1;
3528 }
3529
3530 event->handler = func;
3531 return 0;
3532}
3533
3491void parse_set_info(int nr_cpus, int long_sz) 3534void parse_set_info(int nr_cpus, int long_sz)
3492{ 3535{
3493 cpus = nr_cpus; 3536 cpus = nr_cpus;
diff --git a/parse-events.h b/parse-events.h
index ceffef2..b4e7fdf 100644
--- a/parse-events.h
+++ b/parse-events.h
@@ -46,6 +46,8 @@ extern int trace_seq_do_printf(struct trace_seq *s);
46/* ----------------------- pevent ----------------------- */ 46/* ----------------------- pevent ----------------------- */
47 47
48typedef int (*pevent_plugin_load_func)(void); 48typedef int (*pevent_plugin_load_func)(void);
49typedef int (*pevent_event_handler_func)(struct trace_seq *s, void *data, int size);
50
49#define PEVENT_PLUGIN_LOADER pevent_plugin_loader 51#define PEVENT_PLUGIN_LOADER pevent_plugin_loader
50#define MAKE_STR(x) #x 52#define MAKE_STR(x) #x
51#define PEVENT_PLUGIN_LOADER_NAME MAKE_STR(pevent_plugin_loader) 53#define PEVENT_PLUGIN_LOADER_NAME MAKE_STR(pevent_plugin_loader)
@@ -173,6 +175,7 @@ struct event {
173 struct format format; 175 struct format format;
174 struct print_fmt print_fmt; 176 struct print_fmt print_fmt;
175 char *system; 177 char *system;
178 pevent_event_handler_func handler;
176}; 179};
177 180
178enum { 181enum {
@@ -288,6 +291,9 @@ int pevent_parse_header_page(char *buf, unsigned long size);
288 291
289int pevent_parse_event(char *buf, unsigned long size, char *sys); 292int pevent_parse_event(char *buf, unsigned long size, char *sys);
290 293
294int pevent_register_event_handler(int id, char *sys_name, char *event_name,
295 pevent_event_handler_func func);
296
291/* for debugging */ 297/* for debugging */
292void pevent_print_funcs(void); 298void pevent_print_funcs(void);
293void pevent_print_printk(void); 299void pevent_print_printk(void);
diff --git a/test_plugin.c b/test_plugin.c
index fd62c27..26edbad 100644
--- a/test_plugin.c
+++ b/test_plugin.c
@@ -4,8 +4,21 @@
4 4
5#include "parse-events.h" 5#include "parse-events.h"
6 6
7static int handler(struct trace_seq *s, void *data, int size)
8{
9 int ret;
10
11 ret = trace_seq_printf(s, "COMM: %s state is %d next is %s",
12 (char *)(data+12), *(int *)(data + 40),
13 (char *)(data+48));
14 return ret;
15}
16
7int PEVENT_PLUGIN_LOADER(void) 17int PEVENT_PLUGIN_LOADER(void)
8{ 18{
9 printf("HELLO WORLD!!!\n"); 19 printf("HELLO WORLD!!!\n");
20
21 pevent_register_event_handler(-1, "sched", "sched_switch",
22 handler);
10 return 0; 23 return 0;
11} 24}
diff --git a/trace-util.c b/trace-util.c
index b60b680..4780f26 100644
--- a/trace-util.c
+++ b/trace-util.c
@@ -96,14 +96,15 @@ static int load_plugin(const char *path, const char *file)
96 96
97 handle = dlopen(plugin, RTLD_NOW); 97 handle = dlopen(plugin, RTLD_NOW);
98 if (!handle) { 98 if (!handle) {
99 warning("cound not load plugin '%s'", plugin); 99 warning("cound not load plugin '%s'\n%s\n",
100 plugin, dlerror());
100 return -1; 101 return -1;
101 } 102 }
102 103
103 func = dlsym(handle, PEVENT_PLUGIN_LOADER_NAME); 104 func = dlsym(handle, PEVENT_PLUGIN_LOADER_NAME);
104 if (!func) { 105 if (!func) {
105 warning("cound not find func '%s' in plugin '%s'", 106 warning("cound not find func '%s' in plugin '%s'\n%s\n",
106 PEVENT_PLUGIN_LOADER_NAME, plugin); 107 PEVENT_PLUGIN_LOADER_NAME, plugin, dlerror());
107 return -1; 108 return -1;
108 } 109 }
109 110