diff options
author | Steven Rostedt <srostedt@redhat.com> | 2009-12-09 21:59:37 -0500 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2009-12-09 21:59:37 -0500 |
commit | 0c5d394f1fc8d965e1dfb2973499ef280d65d125 (patch) | |
tree | 0a5b12cb779078ef80e89c255a2d0905e4875860 | |
parent | 96de171c7597161a3da63dc078d1f94d695bce34 (diff) |
Add command to show event formats from the data file
Sometimes we need to see the event formats that are stored in a data
file. This patch adds the options "--events" that prints out these
formats.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r-- | trace-cmd.h | 2 | ||||
-rw-r--r-- | trace-input.c | 69 | ||||
-rw-r--r-- | trace-read.c | 13 |
3 files changed, 66 insertions, 18 deletions
diff --git a/trace-cmd.h b/trace-cmd.h index afd7d6b..39dff16 100644 --- a/trace-cmd.h +++ b/trace-cmd.h | |||
@@ -42,6 +42,8 @@ int tracecmd_long_size(struct tracecmd_input *handle); | |||
42 | int tracecmd_page_size(struct tracecmd_input *handle); | 42 | int tracecmd_page_size(struct tracecmd_input *handle); |
43 | int tracecmd_cpus(struct tracecmd_input *handle); | 43 | int tracecmd_cpus(struct tracecmd_input *handle); |
44 | 44 | ||
45 | void tracecmd_print_events(struct tracecmd_input *handle); | ||
46 | |||
45 | int tracecmd_init_data(struct tracecmd_input *handle); | 47 | int tracecmd_init_data(struct tracecmd_input *handle); |
46 | 48 | ||
47 | struct record * | 49 | struct record * |
diff --git a/trace-input.c b/trace-input.c index 23d4986..46c5e05 100644 --- a/trace-input.c +++ b/trace-input.c | |||
@@ -38,10 +38,15 @@ struct tracecmd_input { | |||
38 | int fd; | 38 | int fd; |
39 | int long_size; | 39 | int long_size; |
40 | int page_size; | 40 | int page_size; |
41 | int print_events; | ||
42 | int read_page; | 41 | int read_page; |
43 | int cpus; | 42 | int cpus; |
44 | struct cpu_data *cpu_data; | 43 | struct cpu_data *cpu_data; |
44 | |||
45 | /* file information */ | ||
46 | size_t header_files_start; | ||
47 | size_t ftrace_files_start; | ||
48 | size_t event_files_start; | ||
49 | |||
45 | }; | 50 | }; |
46 | 51 | ||
47 | __thread struct tracecmd_input *tracecmd_curr_thread_handle; | 52 | __thread struct tracecmd_input *tracecmd_curr_thread_handle; |
@@ -220,6 +225,9 @@ static int read_header_files(struct tracecmd_input *handle) | |||
220 | 225 | ||
221 | free(header); | 226 | free(header); |
222 | 227 | ||
228 | handle->ftrace_files_start = | ||
229 | lseek64(handle->fd, 0, SEEK_CUR); | ||
230 | |||
223 | return 0; | 231 | return 0; |
224 | 232 | ||
225 | failed_read: | 233 | failed_read: |
@@ -228,7 +236,7 @@ static int read_header_files(struct tracecmd_input *handle) | |||
228 | } | 236 | } |
229 | 237 | ||
230 | static int read_ftrace_file(struct tracecmd_input *handle, | 238 | static int read_ftrace_file(struct tracecmd_input *handle, |
231 | unsigned long long size) | 239 | unsigned long long size, int print) |
232 | { | 240 | { |
233 | struct pevent *pevent = handle->pevent; | 241 | struct pevent *pevent = handle->pevent; |
234 | char *buf; | 242 | char *buf; |
@@ -241,37 +249,41 @@ static int read_ftrace_file(struct tracecmd_input *handle, | |||
241 | return -1; | 249 | return -1; |
242 | } | 250 | } |
243 | 251 | ||
244 | pevent_parse_event(pevent, buf, size, "ftrace"); | 252 | if (print) |
253 | printf("%.*s\n", (int)size, buf); | ||
254 | else | ||
255 | pevent_parse_event(pevent, buf, size, "ftrace"); | ||
245 | free(buf); | 256 | free(buf); |
246 | 257 | ||
247 | return 0; | 258 | return 0; |
248 | } | 259 | } |
249 | 260 | ||
250 | static int read_event_file(struct tracecmd_input *handle, | 261 | static int read_event_file(struct tracecmd_input *handle, |
251 | char *system, unsigned long long size) | 262 | char *system, unsigned long long size, |
263 | int print) | ||
252 | { | 264 | { |
253 | struct pevent *pevent = handle->pevent; | 265 | struct pevent *pevent = handle->pevent; |
254 | char *buf; | 266 | char *buf; |
255 | 267 | ||
256 | buf = malloc(size+1); | 268 | buf = malloc(size); |
257 | if (!buf) | 269 | if (!buf) |
258 | return -1; | 270 | return -1; |
259 | 271 | ||
260 | if (do_read_check(handle,buf, size)) { | 272 | if (do_read_check(handle, buf, size)) { |
261 | free(buf); | 273 | free(buf); |
262 | return -1; | 274 | return -1; |
263 | } | 275 | } |
264 | 276 | ||
265 | buf[size] = 0; | 277 | if (print) |
266 | if (handle->print_events) | 278 | printf("%.*s\n", (int)size, buf); |
267 | printf("%s\n", buf); | 279 | else |
268 | pevent_parse_event(pevent, buf, size, system); | 280 | pevent_parse_event(pevent, buf, size, system); |
269 | free(buf); | 281 | free(buf); |
270 | 282 | ||
271 | return 0; | 283 | return 0; |
272 | } | 284 | } |
273 | 285 | ||
274 | static int read_ftrace_files(struct tracecmd_input *handle) | 286 | static int read_ftrace_files(struct tracecmd_input *handle, int print) |
275 | { | 287 | { |
276 | unsigned long long size; | 288 | unsigned long long size; |
277 | int count; | 289 | int count; |
@@ -286,15 +298,18 @@ static int read_ftrace_files(struct tracecmd_input *handle) | |||
286 | size = read8(handle); | 298 | size = read8(handle); |
287 | if (size < 0) | 299 | if (size < 0) |
288 | return -1; | 300 | return -1; |
289 | ret = read_ftrace_file(handle, size); | 301 | ret = read_ftrace_file(handle, size, print); |
290 | if (ret < 0) | 302 | if (ret < 0) |
291 | return -1; | 303 | return -1; |
292 | } | 304 | } |
293 | 305 | ||
306 | handle->event_files_start = | ||
307 | lseek64(handle->fd, 0, SEEK_CUR); | ||
308 | |||
294 | return 0; | 309 | return 0; |
295 | } | 310 | } |
296 | 311 | ||
297 | static int read_event_files(struct tracecmd_input *handle) | 312 | static int read_event_files(struct tracecmd_input *handle, int print) |
298 | { | 313 | { |
299 | unsigned long long size; | 314 | unsigned long long size; |
300 | char *system; | 315 | char *system; |
@@ -312,6 +327,9 @@ static int read_event_files(struct tracecmd_input *handle) | |||
312 | if (!system) | 327 | if (!system) |
313 | return -1; | 328 | return -1; |
314 | 329 | ||
330 | if (print) | ||
331 | printf("\nsystem: %s\n", system); | ||
332 | |||
315 | count = read4(handle); | 333 | count = read4(handle); |
316 | if (count < 0) | 334 | if (count < 0) |
317 | goto failed; | 335 | goto failed; |
@@ -321,7 +339,7 @@ static int read_event_files(struct tracecmd_input *handle) | |||
321 | if (size < 0) | 339 | if (size < 0) |
322 | goto failed; | 340 | goto failed; |
323 | 341 | ||
324 | ret = read_event_file(handle, system, size); | 342 | ret = read_event_file(handle, system, size, print); |
325 | if (ret < 0) | 343 | if (ret < 0) |
326 | goto failed; | 344 | goto failed; |
327 | } | 345 | } |
@@ -398,11 +416,11 @@ int tracecmd_read_headers(struct tracecmd_input *handle) | |||
398 | if (ret < 0) | 416 | if (ret < 0) |
399 | return -1; | 417 | return -1; |
400 | 418 | ||
401 | ret = read_ftrace_files(handle); | 419 | ret = read_ftrace_files(handle, 0); |
402 | if (ret < 0) | 420 | if (ret < 0) |
403 | return -1; | 421 | return -1; |
404 | 422 | ||
405 | ret = read_event_files(handle); | 423 | ret = read_event_files(handle, 0); |
406 | if (ret < 0) | 424 | if (ret < 0) |
407 | return -1; | 425 | return -1; |
408 | 426 | ||
@@ -1032,6 +1050,22 @@ int tracecmd_init_data(struct tracecmd_input *handle) | |||
1032 | return 0; | 1050 | return 0; |
1033 | } | 1051 | } |
1034 | 1052 | ||
1053 | void tracecmd_print_events(struct tracecmd_input *handle) | ||
1054 | { | ||
1055 | int ret; | ||
1056 | |||
1057 | if (!handle->ftrace_files_start) { | ||
1058 | lseek64(handle->fd, handle->header_files_start, SEEK_SET); | ||
1059 | read_header_files(handle); | ||
1060 | } | ||
1061 | ret = read_ftrace_files(handle, 1); | ||
1062 | if (ret < 0) | ||
1063 | return; | ||
1064 | |||
1065 | read_event_files(handle, 1); | ||
1066 | return; | ||
1067 | } | ||
1068 | |||
1035 | struct tracecmd_input *tracecmd_open(int fd) | 1069 | struct tracecmd_input *tracecmd_open(int fd) |
1036 | { | 1070 | { |
1037 | struct tracecmd_input *handle; | 1071 | struct tracecmd_input *handle; |
@@ -1078,6 +1112,9 @@ struct tracecmd_input *tracecmd_open(int fd) | |||
1078 | 1112 | ||
1079 | handle->page_size = read4(handle); | 1113 | handle->page_size = read4(handle); |
1080 | 1114 | ||
1115 | handle->header_files_start = | ||
1116 | lseek64(handle->fd, 0, SEEK_CUR); | ||
1117 | |||
1081 | return handle; | 1118 | return handle; |
1082 | 1119 | ||
1083 | failed_read: | 1120 | failed_read: |
diff --git a/trace-read.c b/trace-read.c index 9bc7f60..3baa9d8 100644 --- a/trace-read.c +++ b/trace-read.c | |||
@@ -42,8 +42,6 @@ unsigned int page_size; | |||
42 | int input_fd; | 42 | int input_fd; |
43 | const char *input_file = "trace.dat"; | 43 | const char *input_file = "trace.dat"; |
44 | 44 | ||
45 | int show_events = 0; | ||
46 | |||
47 | static int filter_cpu = -1; | 45 | static int filter_cpu = -1; |
48 | 46 | ||
49 | static void show_data(struct tracecmd_input *handle, int cpu) | 47 | static void show_data(struct tracecmd_input *handle, int cpu) |
@@ -141,6 +139,8 @@ void trace_report (int argc, char **argv) | |||
141 | int show_page_size = 0; | 139 | int show_page_size = 0; |
142 | int show_printk = 0; | 140 | int show_printk = 0; |
143 | int latency_format; | 141 | int latency_format; |
142 | int show_events = 0; | ||
143 | int print_events = 0; | ||
144 | int c; | 144 | int c; |
145 | 145 | ||
146 | if (argc < 2) | 146 | if (argc < 2) |
@@ -153,6 +153,7 @@ void trace_report (int argc, char **argv) | |||
153 | int option_index = 0; | 153 | int option_index = 0; |
154 | static struct option long_options[] = { | 154 | static struct option long_options[] = { |
155 | {"cpu", required_argument, NULL, 0}, | 155 | {"cpu", required_argument, NULL, 0}, |
156 | {"events", no_argument, NULL, 0}, | ||
156 | {"help", no_argument, NULL, '?'}, | 157 | {"help", no_argument, NULL, '?'}, |
157 | {NULL, 0, NULL, 0} | 158 | {NULL, 0, NULL, 0} |
158 | }; | 159 | }; |
@@ -191,6 +192,9 @@ void trace_report (int argc, char **argv) | |||
191 | case 0: | 192 | case 0: |
192 | filter_cpu = atoi(optarg); | 193 | filter_cpu = atoi(optarg); |
193 | break; | 194 | break; |
195 | case 1: | ||
196 | print_events = 1; | ||
197 | break; | ||
194 | default: | 198 | default: |
195 | usage(argv); | 199 | usage(argv); |
196 | } | 200 | } |
@@ -222,6 +226,11 @@ void trace_report (int argc, char **argv) | |||
222 | return; | 226 | return; |
223 | } | 227 | } |
224 | 228 | ||
229 | if (print_events) { | ||
230 | tracecmd_print_events(handle); | ||
231 | return; | ||
232 | } | ||
233 | |||
225 | if (tracecmd_read_headers(handle) < 0) | 234 | if (tracecmd_read_headers(handle) < 0) |
226 | return; | 235 | return; |
227 | 236 | ||