aboutsummaryrefslogtreecommitdiffstats
path: root/tools/lib
diff options
context:
space:
mode:
Diffstat (limited to 'tools/lib')
-rw-r--r--tools/lib/lk/debugfs.c1
-rw-r--r--tools/lib/traceevent/Makefile18
-rw-r--r--tools/lib/traceevent/event-parse.c201
-rw-r--r--tools/lib/traceevent/event-parse.h14
4 files changed, 179 insertions, 55 deletions
diff --git a/tools/lib/lk/debugfs.c b/tools/lib/lk/debugfs.c
index 099e7cd022e4..7c4347962353 100644
--- a/tools/lib/lk/debugfs.c
+++ b/tools/lib/lk/debugfs.c
@@ -5,7 +5,6 @@
5#include <stdbool.h> 5#include <stdbool.h>
6#include <sys/vfs.h> 6#include <sys/vfs.h>
7#include <sys/mount.h> 7#include <sys/mount.h>
8#include <linux/magic.h>
9#include <linux/kernel.h> 8#include <linux/kernel.h>
10 9
11#include "debugfs.h" 10#include "debugfs.h"
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..217c82ee3665 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
@@ -1589,6 +1606,24 @@ process_arg(struct event_format *event, struct print_arg *arg, char **tok)
1589static enum event_type 1606static enum event_type
1590process_op(struct event_format *event, struct print_arg *arg, char **tok); 1607process_op(struct event_format *event, struct print_arg *arg, char **tok);
1591 1608
1609/*
1610 * For __print_symbolic() and __print_flags, we need to completely
1611 * evaluate the first argument, which defines what to print next.
1612 */
1613static enum event_type
1614process_field_arg(struct event_format *event, struct print_arg *arg, char **tok)
1615{
1616 enum event_type type;
1617
1618 type = process_arg(event, arg, tok);
1619
1620 while (type == EVENT_OP) {
1621 type = process_op(event, arg, tok);
1622 }
1623
1624 return type;
1625}
1626
1592static enum event_type 1627static enum event_type
1593process_cond(struct event_format *event, struct print_arg *top, char **tok) 1628process_cond(struct event_format *event, struct print_arg *top, char **tok)
1594{ 1629{
@@ -2354,7 +2389,7 @@ process_flags(struct event_format *event, struct print_arg *arg, char **tok)
2354 goto out_free; 2389 goto out_free;
2355 } 2390 }
2356 2391
2357 type = process_arg(event, field, &token); 2392 type = process_field_arg(event, field, &token);
2358 2393
2359 /* Handle operations in the first argument */ 2394 /* Handle operations in the first argument */
2360 while (type == EVENT_OP) 2395 while (type == EVENT_OP)
@@ -2407,7 +2442,8 @@ process_symbols(struct event_format *event, struct print_arg *arg, char **tok)
2407 goto out_free; 2442 goto out_free;
2408 } 2443 }
2409 2444
2410 type = process_arg(event, field, &token); 2445 type = process_field_arg(event, field, &token);
2446
2411 if (test_type_token(type, token, EVENT_DELIM, ",")) 2447 if (test_type_token(type, token, EVENT_DELIM, ","))
2412 goto out_free_field; 2448 goto out_free_field;
2413 2449
@@ -3418,6 +3454,19 @@ eval_num_arg(void *data, int size, struct event_format *event, struct print_arg
3418 goto out_warning_op; 3454 goto out_warning_op;
3419 } 3455 }
3420 break; 3456 break;
3457 case PRINT_DYNAMIC_ARRAY:
3458 /* Without [], we pass the address to the dynamic data */
3459 offset = pevent_read_number(pevent,
3460 data + arg->dynarray.field->offset,
3461 arg->dynarray.field->size);
3462 /*
3463 * The actual length of the dynamic array is stored
3464 * in the top half of the field, and the offset
3465 * is in the bottom half of the 32 bit field.
3466 */
3467 offset &= 0xffff;
3468 val = (unsigned long long)((unsigned long)data + offset);
3469 break;
3421 default: /* not sure what to do there */ 3470 default: /* not sure what to do there */
3422 return 0; 3471 return 0;
3423 } 3472 }
@@ -3488,6 +3537,7 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,
3488 struct pevent *pevent = event->pevent; 3537 struct pevent *pevent = event->pevent;
3489 struct print_flag_sym *flag; 3538 struct print_flag_sym *flag;
3490 struct format_field *field; 3539 struct format_field *field;
3540 struct printk_map *printk;
3491 unsigned long long val, fval; 3541 unsigned long long val, fval;
3492 unsigned long addr; 3542 unsigned long addr;
3493 char *str; 3543 char *str;
@@ -3523,7 +3573,12 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,
3523 if (!(field->flags & FIELD_IS_ARRAY) && 3573 if (!(field->flags & FIELD_IS_ARRAY) &&
3524 field->size == pevent->long_size) { 3574 field->size == pevent->long_size) {
3525 addr = *(unsigned long *)(data + field->offset); 3575 addr = *(unsigned long *)(data + field->offset);
3526 trace_seq_printf(s, "%lx", addr); 3576 /* Check if it matches a print format */
3577 printk = find_printk(pevent, addr);
3578 if (printk)
3579 trace_seq_puts(s, printk->printk);
3580 else
3581 trace_seq_printf(s, "%lx", addr);
3527 break; 3582 break;
3528 } 3583 }
3529 str = malloc(len + 1); 3584 str = malloc(len + 1);
@@ -3565,15 +3620,23 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,
3565 } 3620 }
3566 break; 3621 break;
3567 case PRINT_HEX: 3622 case PRINT_HEX:
3568 field = arg->hex.field->field.field; 3623 if (arg->hex.field->type == PRINT_DYNAMIC_ARRAY) {
3569 if (!field) { 3624 unsigned long offset;
3570 str = arg->hex.field->field.name; 3625 offset = pevent_read_number(pevent,
3571 field = pevent_find_any_field(event, str); 3626 data + arg->hex.field->dynarray.field->offset,
3572 if (!field) 3627 arg->hex.field->dynarray.field->size);
3573 goto out_warning_field; 3628 hex = data + (offset & 0xffff);
3574 arg->hex.field->field.field = field; 3629 } else {
3630 field = arg->hex.field->field.field;
3631 if (!field) {
3632 str = arg->hex.field->field.name;
3633 field = pevent_find_any_field(event, str);
3634 if (!field)
3635 goto out_warning_field;
3636 arg->hex.field->field.field = field;
3637 }
3638 hex = data + field->offset;
3575 } 3639 }
3576 hex = data + field->offset;
3577 len = eval_num_arg(data, size, event, arg->hex.size); 3640 len = eval_num_arg(data, size, event, arg->hex.size);
3578 for (i = 0; i < len; i++) { 3641 for (i = 0; i < len; i++) {
3579 if (i) 3642 if (i)
@@ -3771,8 +3834,8 @@ static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struc
3771 if (asprintf(&arg->atom.atom, "%lld", ip) < 0) 3834 if (asprintf(&arg->atom.atom, "%lld", ip) < 0)
3772 goto out_free; 3835 goto out_free;
3773 3836
3774 /* skip the first "%pf : " */ 3837 /* skip the first "%pf: " */
3775 for (ptr = fmt + 6, bptr = data + field->offset; 3838 for (ptr = fmt + 5, bptr = data + field->offset;
3776 bptr < data + size && *ptr; ptr++) { 3839 bptr < data + size && *ptr; ptr++) {
3777 int ls = 0; 3840 int ls = 0;
3778 3841
@@ -3882,7 +3945,6 @@ get_bprint_format(void *data, int size __maybe_unused,
3882 struct format_field *field; 3945 struct format_field *field;
3883 struct printk_map *printk; 3946 struct printk_map *printk;
3884 char *format; 3947 char *format;
3885 char *p;
3886 3948
3887 field = pevent->bprint_fmt_field; 3949 field = pevent->bprint_fmt_field;
3888 3950
@@ -3899,25 +3961,13 @@ get_bprint_format(void *data, int size __maybe_unused,
3899 3961
3900 printk = find_printk(pevent, addr); 3962 printk = find_printk(pevent, addr);
3901 if (!printk) { 3963 if (!printk) {
3902 if (asprintf(&format, "%%pf : (NO FORMAT FOUND at %llx)\n", addr) < 0) 3964 if (asprintf(&format, "%%pf: (NO FORMAT FOUND at %llx)\n", addr) < 0)
3903 return NULL; 3965 return NULL;
3904 return format; 3966 return format;
3905 } 3967 }
3906 3968
3907 p = printk->printk; 3969 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; 3970 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 3971
3922 return format; 3972 return format;
3923} 3973}
@@ -3963,7 +4013,7 @@ static int is_printable_array(char *p, unsigned int len)
3963 unsigned int i; 4013 unsigned int i;
3964 4014
3965 for (i = 0; i < len && p[i]; i++) 4015 for (i = 0; i < len && p[i]; i++)
3966 if (!isprint(p[i])) 4016 if (!isprint(p[i]) && !isspace(p[i]))
3967 return 0; 4017 return 0;
3968 return 1; 4018 return 1;
3969} 4019}
@@ -4428,11 +4478,11 @@ void pevent_event_info(struct trace_seq *s, struct event_format *event,
4428{ 4478{
4429 int print_pretty = 1; 4479 int print_pretty = 1;
4430 4480
4431 if (event->pevent->print_raw) 4481 if (event->pevent->print_raw || (event->flags & EVENT_FL_PRINTRAW))
4432 print_event_fields(s, record->data, record->size, event); 4482 print_event_fields(s, record->data, record->size, event);
4433 else { 4483 else {
4434 4484
4435 if (event->handler) 4485 if (event->handler && !(event->flags & EVENT_FL_NOHANDLE))
4436 print_pretty = event->handler(s, record, event, 4486 print_pretty = event->handler(s, record, event,
4437 event->context); 4487 event->context);
4438 4488
@@ -4443,8 +4493,21 @@ void pevent_event_info(struct trace_seq *s, struct event_format *event,
4443 trace_seq_terminate(s); 4493 trace_seq_terminate(s);
4444} 4494}
4445 4495
4496static bool is_timestamp_in_us(char *trace_clock, bool use_trace_clock)
4497{
4498 if (!use_trace_clock)
4499 return true;
4500
4501 if (!strcmp(trace_clock, "local") || !strcmp(trace_clock, "global")
4502 || !strcmp(trace_clock, "uptime") || !strcmp(trace_clock, "perf"))
4503 return true;
4504
4505 /* trace_clock is setting in tsc or counter mode */
4506 return false;
4507}
4508
4446void pevent_print_event(struct pevent *pevent, struct trace_seq *s, 4509void pevent_print_event(struct pevent *pevent, struct trace_seq *s,
4447 struct pevent_record *record) 4510 struct pevent_record *record, bool use_trace_clock)
4448{ 4511{
4449 static const char *spaces = " "; /* 20 spaces */ 4512 static const char *spaces = " "; /* 20 spaces */
4450 struct event_format *event; 4513 struct event_format *event;
@@ -4457,9 +4520,14 @@ void pevent_print_event(struct pevent *pevent, struct trace_seq *s,
4457 int pid; 4520 int pid;
4458 int len; 4521 int len;
4459 int p; 4522 int p;
4523 bool use_usec_format;
4460 4524
4461 secs = record->ts / NSECS_PER_SEC; 4525 use_usec_format = is_timestamp_in_us(pevent->trace_clock,
4462 nsecs = record->ts - secs * NSECS_PER_SEC; 4526 use_trace_clock);
4527 if (use_usec_format) {
4528 secs = record->ts / NSECS_PER_SEC;
4529 nsecs = record->ts - secs * NSECS_PER_SEC;
4530 }
4463 4531
4464 if (record->size < 0) { 4532 if (record->size < 0) {
4465 do_warning("ug! negative record size %d", record->size); 4533 do_warning("ug! negative record size %d", record->size);
@@ -4484,15 +4552,20 @@ void pevent_print_event(struct pevent *pevent, struct trace_seq *s,
4484 } else 4552 } else
4485 trace_seq_printf(s, "%16s-%-5d [%03d]", comm, pid, record->cpu); 4553 trace_seq_printf(s, "%16s-%-5d [%03d]", comm, pid, record->cpu);
4486 4554
4487 if (pevent->flags & PEVENT_NSEC_OUTPUT) { 4555 if (use_usec_format) {
4488 usecs = nsecs; 4556 if (pevent->flags & PEVENT_NSEC_OUTPUT) {
4489 p = 9; 4557 usecs = nsecs;
4490 } else { 4558 p = 9;
4491 usecs = (nsecs + 500) / NSECS_PER_USEC; 4559 } else {
4492 p = 6; 4560 usecs = (nsecs + 500) / NSECS_PER_USEC;
4493 } 4561 p = 6;
4562 }
4494 4563
4495 trace_seq_printf(s, " %5lu.%0*lu: %s: ", secs, p, usecs, event->name); 4564 trace_seq_printf(s, " %5lu.%0*lu: %s: ",
4565 secs, p, usecs, event->name);
4566 } else
4567 trace_seq_printf(s, " %12llu: %s: ",
4568 record->ts, event->name);
4496 4569
4497 /* Space out the event names evenly. */ 4570 /* Space out the event names evenly. */
4498 len = strlen(event->name); 4571 len = strlen(event->name);
@@ -5326,6 +5399,48 @@ int pevent_print_num_field(struct trace_seq *s, const char *fmt,
5326 return -1; 5399 return -1;
5327} 5400}
5328 5401
5402/**
5403 * pevent_print_func_field - print a field and a format for function pointers
5404 * @s: The seq to print to
5405 * @fmt: The printf format to print the field with.
5406 * @event: the event that the field is for
5407 * @name: The name of the field
5408 * @record: The record with the field name.
5409 * @err: print default error if failed.
5410 *
5411 * Returns: 0 on success, -1 field not found, or 1 if buffer is full.
5412 */
5413int pevent_print_func_field(struct trace_seq *s, const char *fmt,
5414 struct event_format *event, const char *name,
5415 struct pevent_record *record, int err)
5416{
5417 struct format_field *field = pevent_find_field(event, name);
5418 struct pevent *pevent = event->pevent;
5419 unsigned long long val;
5420 struct func_map *func;
5421 char tmp[128];
5422
5423 if (!field)
5424 goto failed;
5425
5426 if (pevent_read_number_field(field, record->data, &val))
5427 goto failed;
5428
5429 func = find_func(pevent, val);
5430
5431 if (func)
5432 snprintf(tmp, 128, "%s/0x%llx", func->func, func->addr - val);
5433 else
5434 sprintf(tmp, "0x%08llx", val);
5435
5436 return trace_seq_printf(s, fmt, tmp);
5437
5438 failed:
5439 if (err)
5440 trace_seq_printf(s, "CAN'T FIND FIELD \"%s\"", name);
5441 return -1;
5442}
5443
5329static void free_func_handle(struct pevent_function_handler *func) 5444static void free_func_handle(struct pevent_function_handler *func)
5330{ 5445{
5331 struct pevent_func_params *params; 5446 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);