aboutsummaryrefslogtreecommitdiffstats
path: root/tools/lib/traceevent
diff options
context:
space:
mode:
Diffstat (limited to 'tools/lib/traceevent')
-rw-r--r--tools/lib/traceevent/Makefile18
-rw-r--r--tools/lib/traceevent/event-parse.c178
-rw-r--r--tools/lib/traceevent/event-parse.h14
3 files changed, 158 insertions, 52 deletions
diff --git a/tools/lib/traceevent/Makefile b/tools/lib/traceevent/Makefile
index ca6cb779876a..fc1502098595 100644
--- a/tools/lib/traceevent/Makefile
+++ b/tools/lib/traceevent/Makefile
@@ -134,14 +134,14 @@ ifeq ($(VERBOSE),1)
134 print_install = 134 print_install =
135else 135else
136 Q = @ 136 Q = @
137 print_compile = echo ' CC '$(OBJ); 137 print_compile = echo ' CC '$(OBJ);
138 print_app_build = echo ' BUILD '$(OBJ); 138 print_app_build = echo ' BUILD '$(OBJ);
139 print_fpic_compile = echo ' CC FPIC '$(OBJ); 139 print_fpic_compile = echo ' CC FPIC '$(OBJ);
140 print_shared_lib_compile = echo ' BUILD SHARED LIB '$(OBJ); 140 print_shared_lib_compile = echo ' BUILD SHARED LIB '$(OBJ);
141 print_plugin_obj_compile = echo ' CC PLUGIN OBJ '$(OBJ); 141 print_plugin_obj_compile = echo ' BUILD PLUGIN OBJ '$(OBJ);
142 print_plugin_build = echo ' CC PLUGI '$(OBJ); 142 print_plugin_build = echo ' BUILD PLUGIN '$(OBJ);
143 print_static_lib_build = echo ' BUILD STATIC LIB '$(OBJ); 143 print_static_lib_build = echo ' BUILD STATIC LIB '$(OBJ);
144 print_install = echo ' INSTALL '$1' to $(DESTDIR_SQ)$2'; 144 print_install = echo ' INSTALL '$1' to $(DESTDIR_SQ)$2';
145endif 145endif
146 146
147do_fpic_compile = \ 147do_fpic_compile = \
@@ -268,7 +268,7 @@ TRACK_CFLAGS = $(subst ','\'',$(CFLAGS)):$(ARCH):$(CROSS_COMPILE)
268TRACEEVENT-CFLAGS: force 268TRACEEVENT-CFLAGS: force
269 @FLAGS='$(TRACK_CFLAGS)'; \ 269 @FLAGS='$(TRACK_CFLAGS)'; \
270 if test x"$$FLAGS" != x"`cat TRACEEVENT-CFLAGS 2>/dev/null`" ; then \ 270 if test x"$$FLAGS" != x"`cat TRACEEVENT-CFLAGS 2>/dev/null`" ; then \
271 echo 1>&2 " * new build flags or cross compiler"; \ 271 echo 1>&2 " FLAGS: * new build flags or cross compiler"; \
272 echo "$$FLAGS" >TRACEEVENT-CFLAGS; \ 272 echo "$$FLAGS" >TRACEEVENT-CFLAGS; \
273 fi 273 fi
274 274
diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
index d1c2a6a4cd32..0362d575de7d 100644
--- a/tools/lib/traceevent/event-parse.c
+++ b/tools/lib/traceevent/event-parse.c
@@ -305,6 +305,11 @@ int pevent_register_comm(struct pevent *pevent, const char *comm, int pid)
305 return 0; 305 return 0;
306} 306}
307 307
308void pevent_register_trace_clock(struct pevent *pevent, char *trace_clock)
309{
310 pevent->trace_clock = trace_clock;
311}
312
308struct func_map { 313struct func_map {
309 unsigned long long addr; 314 unsigned long long addr;
310 char *func; 315 char *func;
@@ -599,10 +604,11 @@ find_printk(struct pevent *pevent, unsigned long long addr)
599 * This registers a string by the address it was stored in the kernel. 604 * This registers a string by the address it was stored in the kernel.
600 * The @fmt passed in is duplicated. 605 * The @fmt passed in is duplicated.
601 */ 606 */
602int pevent_register_print_string(struct pevent *pevent, char *fmt, 607int pevent_register_print_string(struct pevent *pevent, const char *fmt,
603 unsigned long long addr) 608 unsigned long long addr)
604{ 609{
605 struct printk_list *item = malloc(sizeof(*item)); 610 struct printk_list *item = malloc(sizeof(*item));
611 char *p;
606 612
607 if (!item) 613 if (!item)
608 return -1; 614 return -1;
@@ -610,10 +616,21 @@ int pevent_register_print_string(struct pevent *pevent, char *fmt,
610 item->next = pevent->printklist; 616 item->next = pevent->printklist;
611 item->addr = addr; 617 item->addr = addr;
612 618
619 /* Strip off quotes and '\n' from the end */
620 if (fmt[0] == '"')
621 fmt++;
613 item->printk = strdup(fmt); 622 item->printk = strdup(fmt);
614 if (!item->printk) 623 if (!item->printk)
615 goto out_free; 624 goto out_free;
616 625
626 p = item->printk + strlen(item->printk) - 1;
627 if (*p == '"')
628 *p = 0;
629
630 p -= 2;
631 if (strcmp(p, "\\n") == 0)
632 *p = 0;
633
617 pevent->printklist = item; 634 pevent->printklist = item;
618 pevent->printk_count++; 635 pevent->printk_count++;
619 636
@@ -3418,6 +3435,19 @@ eval_num_arg(void *data, int size, struct event_format *event, struct print_arg
3418 goto out_warning_op; 3435 goto out_warning_op;
3419 } 3436 }
3420 break; 3437 break;
3438 case PRINT_DYNAMIC_ARRAY:
3439 /* Without [], we pass the address to the dynamic data */
3440 offset = pevent_read_number(pevent,
3441 data + arg->dynarray.field->offset,
3442 arg->dynarray.field->size);
3443 /*
3444 * The actual length of the dynamic array is stored
3445 * in the top half of the field, and the offset
3446 * is in the bottom half of the 32 bit field.
3447 */
3448 offset &= 0xffff;
3449 val = (unsigned long long)(data + offset);
3450 break;
3421 default: /* not sure what to do there */ 3451 default: /* not sure what to do there */
3422 return 0; 3452 return 0;
3423 } 3453 }
@@ -3488,6 +3518,7 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,
3488 struct pevent *pevent = event->pevent; 3518 struct pevent *pevent = event->pevent;
3489 struct print_flag_sym *flag; 3519 struct print_flag_sym *flag;
3490 struct format_field *field; 3520 struct format_field *field;
3521 struct printk_map *printk;
3491 unsigned long long val, fval; 3522 unsigned long long val, fval;
3492 unsigned long addr; 3523 unsigned long addr;
3493 char *str; 3524 char *str;
@@ -3523,7 +3554,12 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,
3523 if (!(field->flags & FIELD_IS_ARRAY) && 3554 if (!(field->flags & FIELD_IS_ARRAY) &&
3524 field->size == pevent->long_size) { 3555 field->size == pevent->long_size) {
3525 addr = *(unsigned long *)(data + field->offset); 3556 addr = *(unsigned long *)(data + field->offset);
3526 trace_seq_printf(s, "%lx", addr); 3557 /* Check if it matches a print format */
3558 printk = find_printk(pevent, addr);
3559 if (printk)
3560 trace_seq_puts(s, printk->printk);
3561 else
3562 trace_seq_printf(s, "%lx", addr);
3527 break; 3563 break;
3528 } 3564 }
3529 str = malloc(len + 1); 3565 str = malloc(len + 1);
@@ -3565,15 +3601,23 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,
3565 } 3601 }
3566 break; 3602 break;
3567 case PRINT_HEX: 3603 case PRINT_HEX:
3568 field = arg->hex.field->field.field; 3604 if (arg->hex.field->type == PRINT_DYNAMIC_ARRAY) {
3569 if (!field) { 3605 unsigned long offset;
3570 str = arg->hex.field->field.name; 3606 offset = pevent_read_number(pevent,
3571 field = pevent_find_any_field(event, str); 3607 data + arg->hex.field->dynarray.field->offset,
3572 if (!field) 3608 arg->hex.field->dynarray.field->size);
3573 goto out_warning_field; 3609 hex = data + (offset & 0xffff);
3574 arg->hex.field->field.field = field; 3610 } else {
3611 field = arg->hex.field->field.field;
3612 if (!field) {
3613 str = arg->hex.field->field.name;
3614 field = pevent_find_any_field(event, str);
3615 if (!field)
3616 goto out_warning_field;
3617 arg->hex.field->field.field = field;
3618 }
3619 hex = data + field->offset;
3575 } 3620 }
3576 hex = data + field->offset;
3577 len = eval_num_arg(data, size, event, arg->hex.size); 3621 len = eval_num_arg(data, size, event, arg->hex.size);
3578 for (i = 0; i < len; i++) { 3622 for (i = 0; i < len; i++) {
3579 if (i) 3623 if (i)
@@ -3771,8 +3815,8 @@ static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struc
3771 if (asprintf(&arg->atom.atom, "%lld", ip) < 0) 3815 if (asprintf(&arg->atom.atom, "%lld", ip) < 0)
3772 goto out_free; 3816 goto out_free;
3773 3817
3774 /* skip the first "%pf : " */ 3818 /* skip the first "%pf: " */
3775 for (ptr = fmt + 6, bptr = data + field->offset; 3819 for (ptr = fmt + 5, bptr = data + field->offset;
3776 bptr < data + size && *ptr; ptr++) { 3820 bptr < data + size && *ptr; ptr++) {
3777 int ls = 0; 3821 int ls = 0;
3778 3822
@@ -3882,7 +3926,6 @@ get_bprint_format(void *data, int size __maybe_unused,
3882 struct format_field *field; 3926 struct format_field *field;
3883 struct printk_map *printk; 3927 struct printk_map *printk;
3884 char *format; 3928 char *format;
3885 char *p;
3886 3929
3887 field = pevent->bprint_fmt_field; 3930 field = pevent->bprint_fmt_field;
3888 3931
@@ -3899,25 +3942,13 @@ get_bprint_format(void *data, int size __maybe_unused,
3899 3942
3900 printk = find_printk(pevent, addr); 3943 printk = find_printk(pevent, addr);
3901 if (!printk) { 3944 if (!printk) {
3902 if (asprintf(&format, "%%pf : (NO FORMAT FOUND at %llx)\n", addr) < 0) 3945 if (asprintf(&format, "%%pf: (NO FORMAT FOUND at %llx)\n", addr) < 0)
3903 return NULL; 3946 return NULL;
3904 return format; 3947 return format;
3905 } 3948 }
3906 3949
3907 p = printk->printk; 3950 if (asprintf(&format, "%s: %s", "%pf", printk->printk) < 0)
3908 /* Remove any quotes. */
3909 if (*p == '"')
3910 p++;
3911 if (asprintf(&format, "%s : %s", "%pf", p) < 0)
3912 return NULL; 3951 return NULL;
3913 /* remove ending quotes and new line since we will add one too */
3914 p = format + strlen(format) - 1;
3915 if (*p == '"')
3916 *p = 0;
3917
3918 p -= 2;
3919 if (strcmp(p, "\\n") == 0)
3920 *p = 0;
3921 3952
3922 return format; 3953 return format;
3923} 3954}
@@ -3963,7 +3994,7 @@ static int is_printable_array(char *p, unsigned int len)
3963 unsigned int i; 3994 unsigned int i;
3964 3995
3965 for (i = 0; i < len && p[i]; i++) 3996 for (i = 0; i < len && p[i]; i++)
3966 if (!isprint(p[i])) 3997 if (!isprint(p[i]) && !isspace(p[i]))
3967 return 0; 3998 return 0;
3968 return 1; 3999 return 1;
3969} 4000}
@@ -4428,11 +4459,11 @@ void pevent_event_info(struct trace_seq *s, struct event_format *event,
4428{ 4459{
4429 int print_pretty = 1; 4460 int print_pretty = 1;
4430 4461
4431 if (event->pevent->print_raw) 4462 if (event->pevent->print_raw || (event->flags & EVENT_FL_PRINTRAW))
4432 print_event_fields(s, record->data, record->size, event); 4463 print_event_fields(s, record->data, record->size, event);
4433 else { 4464 else {
4434 4465
4435 if (event->handler) 4466 if (event->handler && !(event->flags & EVENT_FL_NOHANDLE))
4436 print_pretty = event->handler(s, record, event, 4467 print_pretty = event->handler(s, record, event,
4437 event->context); 4468 event->context);
4438 4469
@@ -4443,8 +4474,21 @@ void pevent_event_info(struct trace_seq *s, struct event_format *event,
4443 trace_seq_terminate(s); 4474 trace_seq_terminate(s);
4444} 4475}
4445 4476
4477static bool is_timestamp_in_us(char *trace_clock, bool use_trace_clock)
4478{
4479 if (!use_trace_clock)
4480 return true;
4481
4482 if (!strcmp(trace_clock, "local") || !strcmp(trace_clock, "global")
4483 || !strcmp(trace_clock, "uptime") || !strcmp(trace_clock, "perf"))
4484 return true;
4485
4486 /* trace_clock is setting in tsc or counter mode */
4487 return false;
4488}
4489
4446void pevent_print_event(struct pevent *pevent, struct trace_seq *s, 4490void pevent_print_event(struct pevent *pevent, struct trace_seq *s,
4447 struct pevent_record *record) 4491 struct pevent_record *record, bool use_trace_clock)
4448{ 4492{
4449 static const char *spaces = " "; /* 20 spaces */ 4493 static const char *spaces = " "; /* 20 spaces */
4450 struct event_format *event; 4494 struct event_format *event;
@@ -4457,9 +4501,14 @@ void pevent_print_event(struct pevent *pevent, struct trace_seq *s,
4457 int pid; 4501 int pid;
4458 int len; 4502 int len;
4459 int p; 4503 int p;
4504 bool use_usec_format;
4460 4505
4461 secs = record->ts / NSECS_PER_SEC; 4506 use_usec_format = is_timestamp_in_us(pevent->trace_clock,
4462 nsecs = record->ts - secs * NSECS_PER_SEC; 4507 use_trace_clock);
4508 if (use_usec_format) {
4509 secs = record->ts / NSECS_PER_SEC;
4510 nsecs = record->ts - secs * NSECS_PER_SEC;
4511 }
4463 4512
4464 if (record->size < 0) { 4513 if (record->size < 0) {
4465 do_warning("ug! negative record size %d", record->size); 4514 do_warning("ug! negative record size %d", record->size);
@@ -4484,15 +4533,20 @@ void pevent_print_event(struct pevent *pevent, struct trace_seq *s,
4484 } else 4533 } else
4485 trace_seq_printf(s, "%16s-%-5d [%03d]", comm, pid, record->cpu); 4534 trace_seq_printf(s, "%16s-%-5d [%03d]", comm, pid, record->cpu);
4486 4535
4487 if (pevent->flags & PEVENT_NSEC_OUTPUT) { 4536 if (use_usec_format) {
4488 usecs = nsecs; 4537 if (pevent->flags & PEVENT_NSEC_OUTPUT) {
4489 p = 9; 4538 usecs = nsecs;
4490 } else { 4539 p = 9;
4491 usecs = (nsecs + 500) / NSECS_PER_USEC; 4540 } else {
4492 p = 6; 4541 usecs = (nsecs + 500) / NSECS_PER_USEC;
4493 } 4542 p = 6;
4543 }
4494 4544
4495 trace_seq_printf(s, " %5lu.%0*lu: %s: ", secs, p, usecs, event->name); 4545 trace_seq_printf(s, " %5lu.%0*lu: %s: ",
4546 secs, p, usecs, event->name);
4547 } else
4548 trace_seq_printf(s, " %12llu: %s: ",
4549 record->ts, event->name);
4496 4550
4497 /* Space out the event names evenly. */ 4551 /* Space out the event names evenly. */
4498 len = strlen(event->name); 4552 len = strlen(event->name);
@@ -5326,6 +5380,48 @@ int pevent_print_num_field(struct trace_seq *s, const char *fmt,
5326 return -1; 5380 return -1;
5327} 5381}
5328 5382
5383/**
5384 * pevent_print_func_field - print a field and a format for function pointers
5385 * @s: The seq to print to
5386 * @fmt: The printf format to print the field with.
5387 * @event: the event that the field is for
5388 * @name: The name of the field
5389 * @record: The record with the field name.
5390 * @err: print default error if failed.
5391 *
5392 * Returns: 0 on success, -1 field not found, or 1 if buffer is full.
5393 */
5394int pevent_print_func_field(struct trace_seq *s, const char *fmt,
5395 struct event_format *event, const char *name,
5396 struct pevent_record *record, int err)
5397{
5398 struct format_field *field = pevent_find_field(event, name);
5399 struct pevent *pevent = event->pevent;
5400 unsigned long long val;
5401 struct func_map *func;
5402 char tmp[128];
5403
5404 if (!field)
5405 goto failed;
5406
5407 if (pevent_read_number_field(field, record->data, &val))
5408 goto failed;
5409
5410 func = find_func(pevent, val);
5411
5412 if (func)
5413 snprintf(tmp, 128, "%s/0x%llx", func->func, func->addr - val);
5414 else
5415 sprintf(tmp, "0x%08llx", val);
5416
5417 return trace_seq_printf(s, fmt, tmp);
5418
5419 failed:
5420 if (err)
5421 trace_seq_printf(s, "CAN'T FIND FIELD \"%s\"", name);
5422 return -1;
5423}
5424
5329static void free_func_handle(struct pevent_function_handler *func) 5425static void free_func_handle(struct pevent_function_handler *func)
5330{ 5426{
5331 struct pevent_func_params *params; 5427 struct pevent_func_params *params;
diff --git a/tools/lib/traceevent/event-parse.h b/tools/lib/traceevent/event-parse.h
index c37b2026d04a..8d73d2594f65 100644
--- a/tools/lib/traceevent/event-parse.h
+++ b/tools/lib/traceevent/event-parse.h
@@ -20,6 +20,7 @@
20#ifndef _PARSE_EVENTS_H 20#ifndef _PARSE_EVENTS_H
21#define _PARSE_EVENTS_H 21#define _PARSE_EVENTS_H
22 22
23#include <stdbool.h>
23#include <stdarg.h> 24#include <stdarg.h>
24#include <regex.h> 25#include <regex.h>
25 26
@@ -307,6 +308,8 @@ enum {
307 EVENT_FL_ISBPRINT = 0x04, 308 EVENT_FL_ISBPRINT = 0x04,
308 EVENT_FL_ISFUNCENT = 0x10, 309 EVENT_FL_ISFUNCENT = 0x10,
309 EVENT_FL_ISFUNCRET = 0x20, 310 EVENT_FL_ISFUNCRET = 0x20,
311 EVENT_FL_NOHANDLE = 0x40,
312 EVENT_FL_PRINTRAW = 0x80,
310 313
311 EVENT_FL_FAILED = 0x80000000 314 EVENT_FL_FAILED = 0x80000000
312}; 315};
@@ -450,6 +453,8 @@ struct pevent {
450 453
451 /* cache */ 454 /* cache */
452 struct event_format *last_event; 455 struct event_format *last_event;
456
457 char *trace_clock;
453}; 458};
454 459
455static inline void pevent_set_flag(struct pevent *pevent, int flag) 460static inline void pevent_set_flag(struct pevent *pevent, int flag)
@@ -527,14 +532,15 @@ enum trace_flag_type {
527}; 532};
528 533
529int pevent_register_comm(struct pevent *pevent, const char *comm, int pid); 534int pevent_register_comm(struct pevent *pevent, const char *comm, int pid);
535void pevent_register_trace_clock(struct pevent *pevent, char *trace_clock);
530int pevent_register_function(struct pevent *pevent, char *name, 536int pevent_register_function(struct pevent *pevent, char *name,
531 unsigned long long addr, char *mod); 537 unsigned long long addr, char *mod);
532int pevent_register_print_string(struct pevent *pevent, char *fmt, 538int pevent_register_print_string(struct pevent *pevent, const char *fmt,
533 unsigned long long addr); 539 unsigned long long addr);
534int pevent_pid_is_registered(struct pevent *pevent, int pid); 540int pevent_pid_is_registered(struct pevent *pevent, int pid);
535 541
536void pevent_print_event(struct pevent *pevent, struct trace_seq *s, 542void pevent_print_event(struct pevent *pevent, struct trace_seq *s,
537 struct pevent_record *record); 543 struct pevent_record *record, bool use_trace_clock);
538 544
539int pevent_parse_header_page(struct pevent *pevent, char *buf, unsigned long size, 545int pevent_parse_header_page(struct pevent *pevent, char *buf, unsigned long size,
540 int long_size); 546 int long_size);
@@ -563,6 +569,10 @@ int pevent_print_num_field(struct trace_seq *s, const char *fmt,
563 struct event_format *event, const char *name, 569 struct event_format *event, const char *name,
564 struct pevent_record *record, int err); 570 struct pevent_record *record, int err);
565 571
572int pevent_print_func_field(struct trace_seq *s, const char *fmt,
573 struct event_format *event, const char *name,
574 struct pevent_record *record, int err);
575
566int pevent_register_event_handler(struct pevent *pevent, int id, 576int pevent_register_event_handler(struct pevent *pevent, int id,
567 const char *sys_name, const char *event_name, 577 const char *sys_name, const char *event_name,
568 pevent_event_handler_func func, void *context); 578 pevent_event_handler_func func, void *context);