Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Steven Rostedt and committed by
Arnaldo Carvalho de Melo
a6745330 026842d1

+117 -32
+104 -32
tools/lib/traceevent/event-parse.c
··· 5339 5339 return false; 5340 5340 } 5341 5341 5342 - void pevent_print_event(struct pevent *pevent, struct trace_seq *s, 5343 - struct pevent_record *record, bool use_trace_clock) 5342 + /** 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; 5353 + int type; 5354 + 5355 + if (record->size < 0) { 5356 + do_warning("ug! negative record size %d", record->size); 5357 + return NULL; 5358 + } 5359 + 5360 + type = trace_parse_common_type(pevent, record->data); 5361 + 5362 + return pevent_find_event(pevent, type); 5363 + } 5364 + 5365 + /** 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; 5381 + 5382 + pid = parse_common_pid(pevent, data); 5383 + comm = find_cmdline(pevent, pid); 5384 + 5385 + if (pevent->latency_format) { 5386 + trace_seq_printf(s, "%8.8s-%-5d %3d", 5387 + comm, pid, record->cpu); 5388 + } else 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 + { 5347 5407 unsigned long secs; 5348 5408 unsigned long usecs; 5349 5409 unsigned long nsecs; 5350 - const char *comm; 5351 - void *data = record->data; 5352 - int type; 5353 - int pid; 5354 - int len; 5355 5410 int p; 5356 5411 bool use_usec_format; 5357 5412 ··· 5417 5362 nsecs = record->ts - secs * NSECS_PER_SEC; 5418 5363 } 5419 5364 5420 - if (record->size < 0) { 5421 - do_warning("ug! negative record size %d", record->size); 5422 - return; 5423 - } 5424 - 5425 - type = trace_parse_common_type(pevent, data); 5426 - 5427 - event = pevent_find_event(pevent, type); 5428 - if (!event) { 5429 - do_warning("ug! no event found for type %d", type); 5430 - return; 5431 - } 5432 - 5433 - pid = parse_common_pid(pevent, data); 5434 - comm = find_cmdline(pevent, pid); 5435 - 5436 5365 if (pevent->latency_format) { 5437 - trace_seq_printf(s, "%8.8s-%-5d %3d", 5438 - comm, pid, record->cpu); 5366 + trace_seq_printf(s, " %3d", record->cpu); 5439 5367 pevent_data_lat_fmt(pevent, s, record); 5440 5368 } else 5441 - trace_seq_printf(s, "%16s-%-5d [%03d]", comm, pid, record->cpu); 5369 + trace_seq_printf(s, " [%03d]", record->cpu); 5442 5370 5443 5371 if (use_usec_format) { 5444 5372 if (pevent->flags & PEVENT_NSEC_OUTPUT) { ··· 5432 5394 p = 6; 5433 5395 } 5434 5396 5435 - trace_seq_printf(s, " %5lu.%0*lu: %s: ", 5436 - secs, p, usecs, event->name); 5397 + trace_seq_printf(s, " %5lu.%0*lu:", secs, p, usecs); 5437 5398 } else 5438 - trace_seq_printf(s, " %12llu: %s: ", 5439 - record->ts, event->name); 5399 + trace_seq_printf(s, " %12llu:", record->ts); 5400 + } 5401 + 5402 + /** 5403 + * pevent_print_event_data - Write the event data section 5404 + * @pevent: a handle to the pevent 5405 + * @s: the trace_seq to write to 5406 + * @event: the handle to the record's event 5407 + * @record: The record to get the event from 5408 + * 5409 + * Writes the parsing of the record's data to @s. 5410 + */ 5411 + void pevent_print_event_data(struct pevent *pevent, struct trace_seq *s, 5412 + struct event_format *event, 5413 + struct pevent_record *record) 5414 + { 5415 + static const char *spaces = " "; /* 20 spaces */ 5416 + int len; 5417 + 5418 + trace_seq_printf(s, " %s: ", event->name); 5440 5419 5441 5420 /* Space out the event names evenly. */ 5442 5421 len = strlen(event->name); ··· 5461 5406 trace_seq_printf(s, "%.*s", 20 - len, spaces); 5462 5407 5463 5408 pevent_event_info(s, event, record); 5409 + } 5410 + 5411 + void pevent_print_event(struct pevent *pevent, struct trace_seq *s, 5412 + struct pevent_record *record, bool use_trace_clock) 5413 + { 5414 + struct event_format *event; 5415 + 5416 + event = pevent_find_event_by_record(pevent, record); 5417 + if (!event) { 5418 + do_warning("ug! no event found for type %d", 5419 + trace_parse_common_type(pevent, record->data)); 5420 + return; 5421 + } 5422 + 5423 + pevent_print_event_task(pevent, s, event, record); 5424 + pevent_print_event_time(pevent, s, event, record, use_trace_clock); 5425 + pevent_print_event_data(pevent, s, event, record); 5464 5426 } 5465 5427 5466 5428 static int events_id_cmp(const void *a, const void *b)
+13
tools/lib/traceevent/event-parse.h
··· 628 628 unsigned long long addr); 629 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 641 void pevent_print_event(struct pevent *pevent, struct trace_seq *s, 632 642 struct pevent_record *record, bool use_trace_clock); 633 643 ··· 703 693 704 694 struct event_format * 705 695 pevent_find_event_by_name(struct pevent *pevent, const char *sys, const char *name); 696 + 697 + struct event_format * 698 + pevent_find_event_by_record(struct pevent *pevent, struct pevent_record *record); 706 699 707 700 void pevent_data_lat_fmt(struct pevent *pevent, 708 701 struct trace_seq *s, struct pevent_record *record);