1LIBTRACEEVENT(3) libtraceevent Manual LIBTRACEEVENT(3)
2
3
4
6 tep_parse_saved_cmdlines, tep_parse_printk_formats, tep_parse_kallsyms
7 - Parsing functions to load mappings
8
10 #include <event-parse.h>
11
12 int tep_parse_saved_cmdlines(struct tep_handle *tep, const char *buf);
13 int tep_parse_printk_formats(struct tep_handle *tep, const char *buf);
14 int tep_parse_kallsyms(struct tep_handle *tep, const char *buf);
15
17 tep_parse_saved_cmdlines() is a helper function to parse content in the
18 tracefs file system of the "saved_cmdlines" file (stored in a string
19 buffer passed in by buf) and loads the mapping of the process IDs (pid)
20 to the comm names in the tep handler. The events store the pid and this
21 is used to be able to show the process names associated to those
22 process ids. It parses the string buf that holds the content of
23 saved_cmdlines and ends with a nul character (\0).
24
25 tep_parse_printk_formats() is a helper function to parse content in the
26 tracefs file system of the "printk_formats" file (stored in a string
27 buffer passed in by buf) and loads the mapping of addresses of strings
28 that may be referenced by events. Events only store the address of
29 constant strings in the kernel, and the mapping of their address to the
30 string is exported to user space in the printk_formats file. It parses
31 the string buf that holds the content of printk_formats and ends with a
32 nul character (\0).
33
34 tep_parse_kallsyms() is a helper function to parse the Linux kernel
35 /proc/kallsyms format (stored in a string buffer passed in by buf) and
36 load the functions into the tep handler such that function IP addresses
37 can be mapped to their name when parsing events with %pS in the print
38 format field. It parses the string buf that holds the content of
39 /proc/kallsyms and ends with a nul character (\0).
40
42 The tep_parse_saved_cmdlines() function returns 0 in case of success,
43 or -1 in case of an error.
44
45 The tep_parse_printk_formats() function returns 0 in case of success,
46 or -1 in case of an error.
47
48 The tep_parse_kallsyms() function returns 0 in case of success, or -1
49 in case of an error.
50
52 ...
53 #include <event-parse.h>
54 #include <tracefs.h>
55 #include <stdlib.h>
56
57 int load_cmdlines(struct tep_handle *tep)
58 {
59 char *buf = NULL;
60 int r;
61
62 buf = tracefs_instance_file_read(NULL, "saved_cmdlines", NULL);
63 if (!buf)
64 return -1;
65 r = tep_parse_saved_cmdlines(tep, buf);
66 free(buf);
67 return r;
68 }
69
70 int load_print_strings(struct tep_handle *tep)
71 {
72 char *buf = NULL;
73 int r;
74
75 buf = tracefs_instance_file_read(NULL, "printk_formats", NULL);
76 if (!buf)
77 return -1;
78 r = tep_parse_printk_formats(tep, buf);
79 free(buf);
80 return r;
81 }
82
83 int load_kallsyms(struct tep_handle *tep)
84 {
85 char *line = NULL;
86 char *buf = NULL;
87 size_t sz = 0;
88 FILE *fp;
89 int len = 0;
90 int r;
91
92 fp = fopen("/proc/kallsyms", "r");
93 while ((r = getline(&line, &sz, fp)) >= 0) {
94 buf = realloc(buf, len + r + 1);
95 memcpy(buf + len, line, r);
96 len += r;
97 }
98 free(line);
99 fclose(fp);
100 if (!buf)
101 return -1;
102 buf[len] = 0;
103
104 r = tep_parse_kallsyms(tep, buf);
105 free(buf);
106 return r;
107 }
108 ...
109
111 event-parse.h
112 Header file to include in order to have access to the library APIs.
113 -ltraceevent
114 Linker switch to add when building a program that uses the library.
115
117 libtraceevent(3), trace-cmd(1), tep_register_comm(3),
118 tep_register_function(3), tep_register_print_string(3)
119
121 Steven Rostedt <rostedt@goodmis.org[1]>, author of libtraceevent.
122 Tzvetomir Stoyanov <tz.stoyanov@gmail.com[2]>, coauthor of libtraceevent.
123
125 Report bugs to <linux-trace-devel@vger.kernel.org[3]>
126
128 libtraceevent is Free Software licensed under the GNU LGPL 2.1
129
131 https://git.kernel.org/pub/scm/libs/libtrace/libtraceevent.git/
132
134 1. rostedt@goodmis.org
135 mailto:rostedt@goodmis.org
136
137 2. tz.stoyanov@gmail.com
138 mailto:tz.stoyanov@gmail.com
139
140 3. linux-trace-devel@vger.kernel.org
141 mailto:linux-trace-devel@vger.kernel.org
142
143
144
145libtraceevent 1.7.2 07/20/2023 LIBTRACEEVENT(3)