Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[PATCH 2/8] tools lib traceevent: Update printk formats when entered

1 view
Skip to first unread message

Steven Rostedt

unread,
Nov 1, 2013, 6:00:02 PM11/1/13
to
0002-tools-lib-traceevent-Update-printk-formats-when-ente.patch

Steven Rostedt

unread,
Nov 1, 2013, 6:00:03 PM11/1/13
to
0001-tools-lib-traceevent-Add-support-for-extracting-trac.patch

Steven Rostedt

unread,
Nov 1, 2013, 6:00:03 PM11/1/13
to
0004-tools-lib-traceevent-Handle-__print_hex-__get_dynami.patch

Steven Rostedt

unread,
Nov 1, 2013, 6:00:03 PM11/1/13
to
0007-tools-lib-traceevent-Add-flags-NOHANDLE-and-PRINTRAW.patch

Steven Rostedt

unread,
Nov 1, 2013, 6:00:04 PM11/1/13
to
0005-tools-lib-traceevent-Have-bprintk-output-the-same-as.patch

Steven Rostedt

unread,
Nov 1, 2013, 6:00:02 PM11/1/13
to
0008-tools-lib-traceevent-Add-pevent_print_func_field-hel.patch

Steven Rostedt

unread,
Nov 1, 2013, 6:00:02 PM11/1/13
to

Arnaldo,

I was looking at the differences between the event-parse.c file in
trace-cmd compared to what's in tools/lib/traceevent, and discovered
that they have diverged a little. I pulled in several patches from
upstream and realized I had some clean ups that I would like to be
added too.

Maybe someday we can get a nice package that puts libtraceevent into
its own .so that can be used by all.

Anyway you can pull this or you can take the patches straight in.
I based off of Linus's 3.12-rc7.

-- Steve


Please pull the latest traceevent/updates tree, which can be found at:

git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git
traceevent/updates

Head SHA1: 29ad23b00474c34e3b5040dda508c78d33a1a3eb
9ab76c2620680c767771f307e2dc5b152a153350


Howard Cochran (1):
tools lib traceevent: Handle __print_hex(__get_dynamic_array(fieldname), len)

Steven Rostedt (2):
tools lib traceevent: Add flags NOHANDLE and PRINTRAW to individual events
tools lib traceevent: Add pevent_print_func_field() helper function

Steven Rostedt (Red Hat) (4):
tools lib traceevent: Update printk formats when entered
tools lib traceevent: If %s is a pointer, check printk formats
tools lib traceevent: Have bprintk output the same as the kernel does
tools lib traceevent: Check for spaces in character array

Yoshihiro YUNOMAE (1):
tools lib traceevent: Add support for extracting trace_clock in report

----
tools/lib/traceevent/event-parse.c | 165 ++++++++++++++++++++++++++++---------
tools/lib/traceevent/event-parse.h | 14 +++-
2 files changed, 136 insertions(+), 43 deletions(-)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majo...@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Steven Rostedt

unread,
Nov 1, 2013, 6:00:02 PM11/1/13
to
0003-tools-lib-traceevent-If-s-is-a-pointer-check-printk-.patch

Steven Rostedt

unread,
Nov 1, 2013, 6:00:02 PM11/1/13
to
0006-tools-lib-traceevent-Check-for-spaces-in-character-a.patch

tip-bot for Steven Rostedt

unread,
Nov 4, 2013, 3:30:01 PM11/4/13
to
Commit-ID: 6d862b8c14ba539c7c87ffc77f2e1d6dc9630c4d
Gitweb: http://git.kernel.org/tip/6d862b8c14ba539c7c87ffc77f2e1d6dc9630c4d
Author: Steven Rostedt <sros...@redhat.com>
AuthorDate: Fri, 1 Nov 2013 17:54:00 -0400
Committer: Arnaldo Carvalho de Melo <ac...@redhat.com>
CommitDate: Mon, 4 Nov 2013 14:36:49 -0300

tools lib traceevent: Add pevent_print_func_field() helper function

Add the pevent_print_func_field() that will look up a field that is
expected to be a function pointer, and it will print the function name
and offset of the address given by the field.

Signed-off-by: Steven Rostedt <ros...@goodmis.org>
Cc: Andrew Morton <ak...@linux-foundation.org>
Cc: Frederic Weisbecker <fwei...@gmail.com>
Cc: Ingo Molnar <mi...@kernel.org>
Cc: Namhyung Kim <namh...@kernel.org>
Link: http://lkml.kernel.org/r/201311012155...@goodmis.org
Signed-off-by: Arnaldo Carvalho de Melo <ac...@redhat.com>
---
tools/lib/traceevent/event-parse.c | 42 ++++++++++++++++++++++++++++++++++++++
tools/lib/traceevent/event-parse.h | 4 ++++
2 files changed, 46 insertions(+)

diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
index fc6f35f..8f450ad 100644
--- a/tools/lib/traceevent/event-parse.c
+++ b/tools/lib/traceevent/event-parse.c
@@ -5367,6 +5367,48 @@ int pevent_print_num_field(struct trace_seq *s, const char *fmt,
return -1;
}

+/**
+ * pevent_print_func_field - print a field and a format for function pointers
+ * @s: The seq to print to
+ * @fmt: The printf format to print the field with.
+ * @event: the event that the field is for
+ * @name: The name of the field
+ * @record: The record with the field name.
+ * @err: print default error if failed.
+ *
+ * Returns: 0 on success, -1 field not found, or 1 if buffer is full.
+ */
+int pevent_print_func_field(struct trace_seq *s, const char *fmt,
+ struct event_format *event, const char *name,
+ struct pevent_record *record, int err)
+{
+ struct format_field *field = pevent_find_field(event, name);
+ struct pevent *pevent = event->pevent;
+ unsigned long long val;
+ struct func_map *func;
+ char tmp[128];
+
+ if (!field)
+ goto failed;
+
+ if (pevent_read_number_field(field, record->data, &val))
+ goto failed;
+
+ func = find_func(pevent, val);
+
+ if (func)
+ snprintf(tmp, 128, "%s/0x%llx", func->func, func->addr - val);
+ else
+ sprintf(tmp, "0x%08llx", val);
+
+ return trace_seq_printf(s, fmt, tmp);
+
+ failed:
+ if (err)
+ trace_seq_printf(s, "CAN'T FIND FIELD \"%s\"", name);
+ return -1;
+}
+
static void free_func_handle(struct pevent_function_handler *func)
{
struct pevent_func_params *params;
diff --git a/tools/lib/traceevent/event-parse.h b/tools/lib/traceevent/event-parse.h
index dc8539e..8d73d25 100644
--- a/tools/lib/traceevent/event-parse.h
+++ b/tools/lib/traceevent/event-parse.h
@@ -569,6 +569,10 @@ int pevent_print_num_field(struct trace_seq *s, const char *fmt,
struct event_format *event, const char *name,
struct pevent_record *record, int err);

+int pevent_print_func_field(struct trace_seq *s, const char *fmt,
+ struct event_format *event, const char *name,
+ struct pevent_record *record, int err);
+
int pevent_register_event_handler(struct pevent *pevent, int id,
const char *sys_name, const char *event_name,
pevent_event_handler_func func, void *context);

tip-bot for Steven Rostedt

unread,
Nov 4, 2013, 3:30:02 PM11/4/13
to
Commit-ID: c6c2b960b7a4105f096499fba3df65d6c0272a20
Gitweb: http://git.kernel.org/tip/c6c2b960b7a4105f096499fba3df65d6c0272a20
Author: Steven Rostedt <sros...@redhat.com>
AuthorDate: Fri, 1 Nov 2013 17:53:59 -0400
Committer: Arnaldo Carvalho de Melo <ac...@redhat.com>
CommitDate: Mon, 4 Nov 2013 14:36:27 -0300

tools lib traceevent: Add flags NOHANDLE and PRINTRAW to individual events

Add the flags EVENT_FL_NOHANDLE and EVENT_FL_PRINTRAW to the event flags
to have the event either ignore the register handler or to ignore the
handler and also print the raw format respectively.

This allows a tool to force a raw format or non handle for an event.

Signed-off-by: Steven Rostedt <ros...@goodmis.org>
Cc: Andrew Morton <ak...@linux-foundation.org>
Cc: Frederic Weisbecker <fwei...@gmail.com>
Cc: Ingo Molnar <mi...@kernel.org>
Cc: Namhyung Kim <namh...@kernel.org>
Link: http://lkml.kernel.org/r/201311012155...@goodmis.org
Signed-off-by: Arnaldo Carvalho de Melo <ac...@redhat.com>
---
tools/lib/traceevent/event-parse.c | 4 ++--
tools/lib/traceevent/event-parse.h | 2 ++
2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
index 85cbbdd..fc6f35f 100644
--- a/tools/lib/traceevent/event-parse.c
+++ b/tools/lib/traceevent/event-parse.c
@@ -4446,11 +4446,11 @@ void pevent_event_info(struct trace_seq *s, struct event_format *event,
{
int print_pretty = 1;

- if (event->pevent->print_raw)
+ if (event->pevent->print_raw || (event->flags & EVENT_FL_PRINTRAW))
print_event_fields(s, record->data, record->size, event);
else {

- if (event->handler)
+ if (event->handler && !(event->flags & EVENT_FL_NOHANDLE))
print_pretty = event->handler(s, record, event,
event->context);

diff --git a/tools/lib/traceevent/event-parse.h b/tools/lib/traceevent/event-parse.h
index 9ab6367..dc8539e 100644
--- a/tools/lib/traceevent/event-parse.h
+++ b/tools/lib/traceevent/event-parse.h
@@ -308,6 +308,8 @@ enum {
EVENT_FL_ISBPRINT = 0x04,
EVENT_FL_ISFUNCENT = 0x10,
EVENT_FL_ISFUNCRET = 0x20,
+ EVENT_FL_NOHANDLE = 0x40,
+ EVENT_FL_PRINTRAW = 0x80,

EVENT_FL_FAILED = 0x80000000

tip-bot for Steven Rostedt (Red Hat)

unread,
Nov 4, 2013, 3:30:03 PM11/4/13
to
Commit-ID: 0970b5f438261216afcd0ccaa2fcfffc83df7ca2
Gitweb: http://git.kernel.org/tip/0970b5f438261216afcd0ccaa2fcfffc83df7ca2
Author: Steven Rostedt (Red Hat) <ros...@goodmis.org>
AuthorDate: Fri, 1 Nov 2013 17:53:55 -0400
Committer: Arnaldo Carvalho de Melo <ac...@redhat.com>
CommitDate: Mon, 4 Nov 2013 14:34:26 -0300

tools lib traceevent: If %s is a pointer, check printk formats

If the format string of TP_printk() contains a %s, and the argument is
not a string, check if the argument is a pointer that might match the
printk_formats that were stored.

Signed-off-by: Steven Rostedt <ros...@goodmis.org>
Cc: Andrew Morton <ak...@linux-foundation.org>
Cc: Frederic Weisbecker <fwei...@gmail.com>
Cc: Ingo Molnar <mi...@kernel.org>
Cc: Namhyung Kim <namh...@kernel.org>
Link: http://lkml.kernel.org/r/201311012155...@goodmis.org
Signed-off-by: Arnaldo Carvalho de Melo <ac...@redhat.com>
---
tools/lib/traceevent/event-parse.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
index 856b791..013c8d3 100644
--- a/tools/lib/traceevent/event-parse.c
+++ b/tools/lib/traceevent/event-parse.c
@@ -3505,6 +3505,7 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,
struct pevent *pevent = event->pevent;
struct print_flag_sym *flag;
struct format_field *field;
+ struct printk_map *printk;
unsigned long long val, fval;
unsigned long addr;
char *str;
@@ -3540,7 +3541,12 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,
if (!(field->flags & FIELD_IS_ARRAY) &&
field->size == pevent->long_size) {
addr = *(unsigned long *)(data + field->offset);
- trace_seq_printf(s, "%lx", addr);
+ /* Check if it matches a print format */
+ printk = find_printk(pevent, addr);
+ if (printk)
+ trace_seq_puts(s, printk->printk);
+ else
+ trace_seq_printf(s, "%lx", addr);
break;
}
str = malloc(len + 1);

tip-bot for Steven Rostedt (Red Hat)

unread,
Nov 4, 2013, 3:30:03 PM11/4/13
to
Commit-ID: 18900af8292180151c82f0762506fa0740aa54a5
Gitweb: http://git.kernel.org/tip/18900af8292180151c82f0762506fa0740aa54a5
Author: Steven Rostedt (Red Hat) <ros...@goodmis.org>
AuthorDate: Fri, 1 Nov 2013 17:53:54 -0400
Committer: Arnaldo Carvalho de Melo <ac...@redhat.com>
CommitDate: Mon, 4 Nov 2013 14:33:59 -0300

tools lib traceevent: Update printk formats when entered

Instead of cropping off the '"' and '\n"' from a printk format every
time it is referenced, do it when it's added. This makes it easier to
reference a printk_map and should speed things up a little.

Signed-off-by: Steven Rostedt <ros...@goodmis.org>
Cc: Andrew Morton <ak...@linux-foundation.org>
Cc: Frederic Weisbecker <fwei...@gmail.com>
Cc: Ingo Molnar <mi...@kernel.org>
Cc: Namhyung Kim <namh...@kernel.org>
Link: http://lkml.kernel.org/r/201311012155...@goodmis.org
Signed-off-by: Arnaldo Carvalho de Melo <ac...@redhat.com>
---
tools/lib/traceevent/event-parse.c | 29 ++++++++++++++---------------
tools/lib/traceevent/event-parse.h | 2 +-
2 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
index deedff9..856b791 100644
--- a/tools/lib/traceevent/event-parse.c
+++ b/tools/lib/traceevent/event-parse.c
@@ -604,10 +604,11 @@ find_printk(struct pevent *pevent, unsigned long long addr)
* This registers a string by the address it was stored in the kernel.
* The @fmt passed in is duplicated.
*/
-int pevent_register_print_string(struct pevent *pevent, char *fmt,
+int pevent_register_print_string(struct pevent *pevent, const char *fmt,
unsigned long long addr)
{
struct printk_list *item = malloc(sizeof(*item));
+ char *p;

if (!item)
return -1;
@@ -615,10 +616,21 @@ int pevent_register_print_string(struct pevent *pevent, char *fmt,
item->next = pevent->printklist;
item->addr = addr;

+ /* Strip off quotes and '\n' from the end */
+ if (fmt[0] == '"')
+ fmt++;
item->printk = strdup(fmt);
if (!item->printk)
goto out_free;

+ p = item->printk + strlen(item->printk) - 1;
+ if (*p == '"')
+ *p = 0;
+
+ p -= 2;
+ if (strcmp(p, "\\n") == 0)
+ *p = 0;
+
pevent->printklist = item;
pevent->printk_count++;

@@ -3887,7 +3899,6 @@ get_bprint_format(void *data, int size __maybe_unused,
struct format_field *field;
struct printk_map *printk;
char *format;
- char *p;

field = pevent->bprint_fmt_field;

@@ -3909,20 +3920,8 @@ get_bprint_format(void *data, int size __maybe_unused,
return format;
}

- p = printk->printk;
- /* Remove any quotes. */
- if (*p == '"')
- p++;
- if (asprintf(&format, "%s : %s", "%pf", p) < 0)
+ if (asprintf(&format, "%s : %s", "%pf", printk->printk) < 0)
return NULL;
- /* remove ending quotes and new line since we will add one too */
- p = format + strlen(format) - 1;
- if (*p == '"')
- *p = 0;
-
- p -= 2;
- if (strcmp(p, "\\n") == 0)
- *p = 0;

return format;
}
diff --git a/tools/lib/traceevent/event-parse.h b/tools/lib/traceevent/event-parse.h
index 7503edf..9ab6367 100644
--- a/tools/lib/traceevent/event-parse.h
+++ b/tools/lib/traceevent/event-parse.h
@@ -533,7 +533,7 @@ int pevent_register_comm(struct pevent *pevent, const char *comm, int pid);
void pevent_register_trace_clock(struct pevent *pevent, char *trace_clock);
int pevent_register_function(struct pevent *pevent, char *name,
unsigned long long addr, char *mod);
-int pevent_register_print_string(struct pevent *pevent, char *fmt,
+int pevent_register_print_string(struct pevent *pevent, const char *fmt,
unsigned long long addr);
int pevent_pid_is_registered(struct pevent *pevent, int pid);

tip-bot for Steven Rostedt (Red Hat)

unread,
Nov 4, 2013, 3:30:03 PM11/4/13
to
Commit-ID: 0883d9d730fc294c3d90ebd190b94e5782ead316
Gitweb: http://git.kernel.org/tip/0883d9d730fc294c3d90ebd190b94e5782ead316
Author: Steven Rostedt (Red Hat) <ros...@goodmis.org>
AuthorDate: Fri, 1 Nov 2013 17:53:57 -0400
Committer: Arnaldo Carvalho de Melo <ac...@redhat.com>
CommitDate: Mon, 4 Nov 2013 14:35:35 -0300

tools lib traceevent: Have bprintk output the same as the kernel does

The trace_bprintk() in the kernel looks like:

ring_buffer_producer_thread: Missed: 0
ring_buffer_producer_thread: Hit: 62174350
ring_buffer_producer_thread: Entries per millisec: 6296
ring_buffer_producer_thread: 158 ns per entry
ring_buffer_producer_thread: Sleeping for 10 secs
ring_buffer_producer_thread: Starting ring buffer hammer
ring_buffer_producer_thread: End ring buffer hammer

But the current output looks like this:

ring_buffer_producer_thread : Time: 9407018 (usecs)
ring_buffer_producer_thread : Overruns: 43285485
ring_buffer_producer_thread : Read: 4405365 (by events)
ring_buffer_producer_thread : Entries: 0
ring_buffer_producer_thread : Total: 47690850
ring_buffer_producer_thread : Missed: 0
ring_buffer_producer_thread : Hit: 47690850

Remove the space between the function and the colon.

Signed-off-by: Steven Rostedt <ros...@goodmis.org>
Cc: Andrew Morton <ak...@linux-foundation.org>
Cc: Frederic Weisbecker <fwei...@gmail.com>
Cc: Ingo Molnar <mi...@kernel.org>
Cc: Namhyung Kim <namh...@kernel.org>
Link: http://lkml.kernel.org/r/201311012155...@goodmis.org
Signed-off-by: Arnaldo Carvalho de Melo <ac...@redhat.com>
---
tools/lib/traceevent/event-parse.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
index 0a1ffe0..e1c743c 100644
--- a/tools/lib/traceevent/event-parse.c
+++ b/tools/lib/traceevent/event-parse.c
@@ -3802,8 +3802,8 @@ static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struc
if (asprintf(&arg->atom.atom, "%lld", ip) < 0)
goto out_free;

- /* skip the first "%pf : " */
- for (ptr = fmt + 6, bptr = data + field->offset;
+ /* skip the first "%pf: " */
+ for (ptr = fmt + 5, bptr = data + field->offset;
bptr < data + size && *ptr; ptr++) {
int ls = 0;

@@ -3929,12 +3929,12 @@ get_bprint_format(void *data, int size __maybe_unused,

printk = find_printk(pevent, addr);
if (!printk) {
- if (asprintf(&format, "%%pf : (NO FORMAT FOUND at %llx)\n", addr) < 0)
+ if (asprintf(&format, "%%pf: (NO FORMAT FOUND at %llx)\n", addr) < 0)
return NULL;
return format;
}

- if (asprintf(&format, "%s : %s", "%pf", printk->printk) < 0)
+ if (asprintf(&format, "%s: %s", "%pf", printk->printk) < 0)
return NULL;

return format;

tip-bot for Steven Rostedt (Red Hat)

unread,
Nov 4, 2013, 3:30:04 PM11/4/13
to
Commit-ID: 5efb9fbd5f1bfe4435bd0a3ea5f0e187875509c2
Gitweb: http://git.kernel.org/tip/5efb9fbd5f1bfe4435bd0a3ea5f0e187875509c2
Author: Steven Rostedt (Red Hat) <ros...@goodmis.org>
AuthorDate: Fri, 1 Nov 2013 17:53:58 -0400
Committer: Arnaldo Carvalho de Melo <ac...@redhat.com>
CommitDate: Mon, 4 Nov 2013 14:35:54 -0300

tools lib traceevent: Check for spaces in character array

Currently when using the raw format for fields, when looking at a
character array, to determine if it is a string or not, we make sure all
characters are "isprint()". If not, then we consider it a numeric array,
and print the hex numbers of the characters instead.

But it seems that '\n' fails the isprint() check! Add isspace() to the
check as well, such that if all characters pass isprint() or isspace()
it will assume the character array is a string.

Reported-by: Xenia Ragiadakou <burza...@gmail.com>
Signed-off-by: Steven Rostedt <ros...@goodmis.org>
Cc: Andrew Morton <ak...@linux-foundation.org>
Cc: Frederic Weisbecker <fwei...@gmail.com>
Cc: Ingo Molnar <mi...@kernel.org>
Cc: Namhyung Kim <namh...@kernel.org>
Cc: Xenia Ragiadakou <burza...@gmail.com>
Link: http://lkml.kernel.org/r/201311012155...@goodmis.org
Signed-off-by: Arnaldo Carvalho de Melo <ac...@redhat.com>
---
tools/lib/traceevent/event-parse.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
index e1c743c..85cbbdd 100644
--- a/tools/lib/traceevent/event-parse.c
+++ b/tools/lib/traceevent/event-parse.c
@@ -3981,7 +3981,7 @@ static int is_printable_array(char *p, unsigned int len)
unsigned int i;

for (i = 0; i < len && p[i]; i++)
- if (!isprint(p[i]))
+ if (!isprint(p[i]) && !isspace(p[i]))
return 0;
return 1;
0 new messages