diff options
| author | Steven Rostedt <rostedt@goodmis.org> | 2016-02-29 09:01:28 -0500 |
|---|---|---|
| committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2016-02-29 09:35:21 -0500 |
| commit | a6745330789f25103e67011bcfeec908fcc3b341 (patch) | |
| tree | 983529a632216cf142edf440373e0681d1f03e1e /tools/lib/traceevent | |
| parent | 026842d148b920dc28f0499ede4950dcb098d4d5 (diff) | |
tools lib traceevent: Split pevent_print_event() into specific functionality functions
Currently there's a single function that is used to display a record's
data in human readable format. That's pevent_print_event().
Unfortunately, this gives little room for adding other output within the
line without updating that function call.
I've decided to split that function into 3 parts.
pevent_print_event_task() which prints the task comm, pid and the CPU
pevent_print_event_time() which outputs the record's timestamp
pevent_print_event_data() which outputs the rest of the event data.
pevent_print_event() now simply calls these three functions.
To save time from doing the search for event from the record's type, I
created a new helper function called pevent_find_event_by_record(),
which returns the record's event, and this event has to be passed to the
above functions.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: http://lkml.kernel.org/r/20160229090128.43a56704@gandalf.local.home
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/lib/traceevent')
| -rw-r--r-- | tools/lib/traceevent/event-parse.c | 136 | ||||
| -rw-r--r-- | tools/lib/traceevent/event-parse.h | 13 |
2 files changed, 117 insertions, 32 deletions
diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c index 575e75174087..9a1e48afcf89 100644 --- a/tools/lib/traceevent/event-parse.c +++ b/tools/lib/traceevent/event-parse.c | |||
| @@ -5339,41 +5339,45 @@ static bool is_timestamp_in_us(char *trace_clock, bool use_trace_clock) | |||
| 5339 | return false; | 5339 | return false; |
| 5340 | } | 5340 | } |
| 5341 | 5341 | ||
| 5342 | void pevent_print_event(struct pevent *pevent, struct trace_seq *s, | 5342 | /** |
| 5343 | struct pevent_record *record, bool use_trace_clock) | 5343 | * pevent_find_event_by_record - return the event from a given record |
| 5344 | * @pevent: a handle to the pevent | ||
| 5345 | * @record: The record to get the event from | ||
| 5346 | * | ||
| 5347 | * Returns the associated event for a given record, or NULL if non is | ||
| 5348 | * is found. | ||
| 5349 | */ | ||
| 5350 | struct event_format * | ||
| 5351 | pevent_find_event_by_record(struct pevent *pevent, struct pevent_record *record) | ||
| 5344 | { | 5352 | { |
| 5345 | static const char *spaces = " "; /* 20 spaces */ | ||
| 5346 | struct event_format *event; | ||
| 5347 | unsigned long secs; | ||
| 5348 | unsigned long usecs; | ||
| 5349 | unsigned long nsecs; | ||
| 5350 | const char *comm; | ||
| 5351 | void *data = record->data; | ||
| 5352 | int type; | 5353 | int type; |
| 5353 | int pid; | ||
| 5354 | int len; | ||
| 5355 | int p; | ||
| 5356 | bool use_usec_format; | ||
| 5357 | |||
| 5358 | use_usec_format = is_timestamp_in_us(pevent->trace_clock, | ||
| 5359 | use_trace_clock); | ||
| 5360 | if (use_usec_format) { | ||
| 5361 | secs = record->ts / NSECS_PER_SEC; | ||
| 5362 | nsecs = record->ts - secs * NSECS_PER_SEC; | ||
| 5363 | } | ||
| 5364 | 5354 | ||
| 5365 | if (record->size < 0) { | 5355 | if (record->size < 0) { |
| 5366 | do_warning("ug! negative record size %d", record->size); | 5356 | do_warning("ug! negative record size %d", record->size); |
| 5367 | return; | 5357 | return NULL; |
| 5368 | } | 5358 | } |
| 5369 | 5359 | ||
| 5370 | type = trace_parse_common_type(pevent, data); | 5360 | type = trace_parse_common_type(pevent, record->data); |
| 5371 | 5361 | ||
| 5372 | event = pevent_find_event(pevent, type); | 5362 | return pevent_find_event(pevent, type); |
| 5373 | if (!event) { | 5363 | } |
| 5374 | do_warning("ug! no event found for type %d", type); | 5364 | |
| 5375 | return; | 5365 | /** |
| 5376 | } | 5366 | * pevent_print_event_task - Write the event task comm, pid and CPU |
| 5367 | * @pevent: a handle to the pevent | ||
| 5368 | * @s: the trace_seq to write to | ||
| 5369 | * @event: the handle to the record's event | ||
| 5370 | * @record: The record to get the event from | ||
| 5371 | * | ||
| 5372 | * Writes the tasks comm, pid and CPU to @s. | ||
| 5373 | */ | ||
| 5374 | void pevent_print_event_task(struct pevent *pevent, struct trace_seq *s, | ||
| 5375 | struct event_format *event, | ||
| 5376 | struct pevent_record *record) | ||
| 5377 | { | ||
| 5378 | void *data = record->data; | ||
| 5379 | const char *comm; | ||
| 5380 | int pid; | ||
| 5377 | 5381 | ||
| 5378 | pid = parse_common_pid(pevent, data); | 5382 | pid = parse_common_pid(pevent, data); |
| 5379 | comm = find_cmdline(pevent, pid); | 5383 | comm = find_cmdline(pevent, pid); |
| @@ -5381,9 +5385,43 @@ void pevent_print_event(struct pevent *pevent, struct trace_seq *s, | |||
| 5381 | if (pevent->latency_format) { | 5385 | if (pevent->latency_format) { |
| 5382 | trace_seq_printf(s, "%8.8s-%-5d %3d", | 5386 | trace_seq_printf(s, "%8.8s-%-5d %3d", |
| 5383 | comm, pid, record->cpu); | 5387 | comm, pid, record->cpu); |
| 5384 | pevent_data_lat_fmt(pevent, s, record); | ||
| 5385 | } else | 5388 | } else |
| 5386 | trace_seq_printf(s, "%16s-%-5d [%03d]", comm, pid, record->cpu); | 5389 | trace_seq_printf(s, "%16s-%-5d [%03d]", comm, pid, record->cpu); |
| 5390 | } | ||
| 5391 | |||
| 5392 | /** | ||
| 5393 | * pevent_print_event_time - Write the event timestamp | ||
| 5394 | * @pevent: a handle to the pevent | ||
| 5395 | * @s: the trace_seq to write to | ||
| 5396 | * @event: the handle to the record's event | ||
| 5397 | * @record: The record to get the event from | ||
| 5398 | * @use_trace_clock: Set to parse according to the @pevent->trace_clock | ||
| 5399 | * | ||
| 5400 | * Writes the timestamp of the record into @s. | ||
| 5401 | */ | ||
| 5402 | void pevent_print_event_time(struct pevent *pevent, struct trace_seq *s, | ||
| 5403 | struct event_format *event, | ||
| 5404 | struct pevent_record *record, | ||
| 5405 | bool use_trace_clock) | ||
| 5406 | { | ||
| 5407 | unsigned long secs; | ||
| 5408 | unsigned long usecs; | ||
| 5409 | unsigned long nsecs; | ||
| 5410 | int p; | ||
| 5411 | bool use_usec_format; | ||
| 5412 | |||
| 5413 | use_usec_format = is_timestamp_in_us(pevent->trace_clock, | ||
| 5414 | use_trace_clock); | ||
| 5415 | if (use_usec_format) { | ||
| 5416 | secs = record->ts / NSECS_PER_SEC; | ||
| 5417 | nsecs = record->ts - secs * NSECS_PER_SEC; | ||
| 5418 | } | ||
| 5419 | |||
| 5420 | if (pevent->latency_format) { | ||
| 5421 | trace_seq_printf(s, " %3d", record->cpu); | ||
| 5422 | pevent_data_lat_fmt(pevent, s, record); | ||
| 5423 | } else | ||
| 5424 | trace_seq_printf(s, " [%03d]", record->cpu); | ||
| 5387 | 5425 | ||
| 5388 | if (use_usec_format) { | 5426 | if (use_usec_format) { |
| 5389 | if (pevent->flags & PEVENT_NSEC_OUTPUT) { | 5427 | if (pevent->flags & PEVENT_NSEC_OUTPUT) { |
| @@ -5394,11 +5432,28 @@ void pevent_print_event(struct pevent *pevent, struct trace_seq *s, | |||
| 5394 | p = 6; | 5432 | p = 6; |
| 5395 | } | 5433 | } |
| 5396 | 5434 | ||
| 5397 | trace_seq_printf(s, " %5lu.%0*lu: %s: ", | 5435 | trace_seq_printf(s, " %5lu.%0*lu:", secs, p, usecs); |
| 5398 | secs, p, usecs, event->name); | ||
| 5399 | } else | 5436 | } else |
| 5400 | trace_seq_printf(s, " %12llu: %s: ", | 5437 | trace_seq_printf(s, " %12llu:", record->ts); |
| 5401 | record->ts, event->name); | 5438 | } |
| 5439 | |||
| 5440 | /** | ||
| 5441 | * pevent_print_event_data - Write the event data section | ||
| 5442 | * @pevent: a handle to the pevent | ||
| 5443 | * @s: the trace_seq to write to | ||
| 5444 | * @event: the handle to the record's event | ||
| 5445 | * @record: The record to get the event from | ||
| 5446 | * | ||
| 5447 | * Writes the parsing of the record's data to @s. | ||
| 5448 | */ | ||
| 5449 | void pevent_print_event_data(struct pevent *pevent, struct trace_seq *s, | ||
| 5450 | struct event_format *event, | ||
| 5451 | struct pevent_record *record) | ||
| 5452 | { | ||
| 5453 | static const char *spaces = " "; /* 20 spaces */ | ||
| 5454 | int len; | ||
| 5455 | |||
| 5456 | trace_seq_printf(s, " %s: ", event->name); | ||
| 5402 | 5457 | ||
| 5403 | /* Space out the event names evenly. */ | 5458 | /* Space out the event names evenly. */ |
| 5404 | len = strlen(event->name); | 5459 | len = strlen(event->name); |
| @@ -5408,6 +5463,23 @@ void pevent_print_event(struct pevent *pevent, struct trace_seq *s, | |||
| 5408 | pevent_event_info(s, event, record); | 5463 | pevent_event_info(s, event, record); |
| 5409 | } | 5464 | } |
| 5410 | 5465 | ||
| 5466 | void pevent_print_event(struct pevent *pevent, struct trace_seq *s, | ||
| 5467 | struct pevent_record *record, bool use_trace_clock) | ||
| 5468 | { | ||
| 5469 | struct event_format *event; | ||
| 5470 | |||
| 5471 | event = pevent_find_event_by_record(pevent, record); | ||
| 5472 | if (!event) { | ||
| 5473 | do_warning("ug! no event found for type %d", | ||
| 5474 | trace_parse_common_type(pevent, record->data)); | ||
| 5475 | return; | ||
| 5476 | } | ||
| 5477 | |||
| 5478 | pevent_print_event_task(pevent, s, event, record); | ||
| 5479 | pevent_print_event_time(pevent, s, event, record, use_trace_clock); | ||
| 5480 | pevent_print_event_data(pevent, s, event, record); | ||
| 5481 | } | ||
| 5482 | |||
| 5411 | static int events_id_cmp(const void *a, const void *b) | 5483 | static int events_id_cmp(const void *a, const void *b) |
| 5412 | { | 5484 | { |
| 5413 | struct event_format * const * ea = a; | 5485 | struct event_format * const * ea = a; |
diff --git a/tools/lib/traceevent/event-parse.h b/tools/lib/traceevent/event-parse.h index 706d9bc24066..9ffde377e89d 100644 --- a/tools/lib/traceevent/event-parse.h +++ b/tools/lib/traceevent/event-parse.h | |||
| @@ -628,6 +628,16 @@ int pevent_register_print_string(struct pevent *pevent, const char *fmt, | |||
| 628 | unsigned long long addr); | 628 | unsigned long long addr); |
| 629 | int pevent_pid_is_registered(struct pevent *pevent, int pid); | 629 | int pevent_pid_is_registered(struct pevent *pevent, int pid); |
| 630 | 630 | ||
| 631 | void pevent_print_event_task(struct pevent *pevent, struct trace_seq *s, | ||
| 632 | struct event_format *event, | ||
| 633 | struct pevent_record *record); | ||
| 634 | void pevent_print_event_time(struct pevent *pevent, struct trace_seq *s, | ||
| 635 | struct event_format *event, | ||
| 636 | struct pevent_record *record, | ||
| 637 | bool use_trace_clock); | ||
| 638 | void pevent_print_event_data(struct pevent *pevent, struct trace_seq *s, | ||
| 639 | struct event_format *event, | ||
| 640 | struct pevent_record *record); | ||
| 631 | void pevent_print_event(struct pevent *pevent, struct trace_seq *s, | 641 | void pevent_print_event(struct pevent *pevent, struct trace_seq *s, |
| 632 | struct pevent_record *record, bool use_trace_clock); | 642 | struct pevent_record *record, bool use_trace_clock); |
| 633 | 643 | ||
| @@ -694,6 +704,9 @@ struct event_format *pevent_find_event(struct pevent *pevent, int id); | |||
| 694 | struct event_format * | 704 | struct event_format * |
| 695 | pevent_find_event_by_name(struct pevent *pevent, const char *sys, const char *name); | 705 | pevent_find_event_by_name(struct pevent *pevent, const char *sys, const char *name); |
| 696 | 706 | ||
| 707 | struct event_format * | ||
| 708 | pevent_find_event_by_record(struct pevent *pevent, struct pevent_record *record); | ||
| 709 | |||
| 697 | void pevent_data_lat_fmt(struct pevent *pevent, | 710 | void pevent_data_lat_fmt(struct pevent *pevent, |
| 698 | struct trace_seq *s, struct pevent_record *record); | 711 | struct trace_seq *s, struct pevent_record *record); |
| 699 | int pevent_data_type(struct pevent *pevent, struct pevent_record *rec); | 712 | int pevent_data_type(struct pevent *pevent, struct pevent_record *rec); |
