1 // SPDX-License-Identifier: LGPL-2.1
2 /*
3 * Copyright (C) 2009 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
4 */
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8
9 #include "event-parse.h"
10 #include "trace-seq.h"
11
call_site_handler(struct trace_seq * s,struct tep_record * record,struct tep_event * event,void * context)12 static int call_site_handler(struct trace_seq *s, struct tep_record *record,
13 struct tep_event *event, void *context)
14 {
15 struct tep_format_field *field;
16 unsigned long long val, addr;
17 void *data = record->data;
18 const char *func;
19
20 field = tep_find_field(event, "call_site");
21 if (!field)
22 return 1;
23
24 if (tep_read_number_field(field, data, &val))
25 return 1;
26
27 func = tep_find_function(event->tep, val);
28 if (!func)
29 return 1;
30
31 addr = tep_find_function_address(event->tep, val);
32
33 trace_seq_printf(s, "(%s+0x%x) ", func, (int)(val - addr));
34 return 1;
35 }
36
TEP_PLUGIN_LOADER(struct tep_handle * tep)37 int TEP_PLUGIN_LOADER(struct tep_handle *tep)
38 {
39 tep_register_event_handler(tep, -1, "kmem", "kfree",
40 call_site_handler, NULL);
41
42 tep_register_event_handler(tep, -1, "kmem", "kmalloc",
43 call_site_handler, NULL);
44
45 tep_register_event_handler(tep, -1, "kmem", "kmalloc_node",
46 call_site_handler, NULL);
47
48 tep_register_event_handler(tep, -1, "kmem", "kmem_cache_alloc",
49 call_site_handler, NULL);
50
51 tep_register_event_handler(tep, -1, "kmem",
52 "kmem_cache_alloc_node",
53 call_site_handler, NULL);
54
55 tep_register_event_handler(tep, -1, "kmem", "kmem_cache_free",
56 call_site_handler, NULL);
57 return 0;
58 }
59
TEP_PLUGIN_UNLOADER(struct tep_handle * tep)60 void TEP_PLUGIN_UNLOADER(struct tep_handle *tep)
61 {
62 tep_unregister_event_handler(tep, -1, "kmem", "kfree",
63 call_site_handler, NULL);
64
65 tep_unregister_event_handler(tep, -1, "kmem", "kmalloc",
66 call_site_handler, NULL);
67
68 tep_unregister_event_handler(tep, -1, "kmem", "kmalloc_node",
69 call_site_handler, NULL);
70
71 tep_unregister_event_handler(tep, -1, "kmem", "kmem_cache_alloc",
72 call_site_handler, NULL);
73
74 tep_unregister_event_handler(tep, -1, "kmem",
75 "kmem_cache_alloc_node",
76 call_site_handler, NULL);
77
78 tep_unregister_event_handler(tep, -1, "kmem", "kmem_cache_free",
79 call_site_handler, NULL);
80 }
81