perf tools: updates to parsing events
Ingo,
Please pull the latest perf/core tree, which can be found at:
git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-2.6-trace.git
perf/core
Steven Rostedt (13):
perf tools: handle print concatinations in event format file perf tools: fix backslash processing on trace print formats perf tools: handle trace parsing of '<' and '>'
perf tools: handle arrays in print fields for trace parsing perf tools: handle '*' as typecast in trace parsing
perf tools: handle newlines in trace parsing better
perf tools: handle the case with and without the "signed" trace field perf tools: still continue on failed parsing of an event perf tools: fix bprintk reading in trace output
perf tools: handle both versions of ftrace output
perf tools: add latency format to trace output
perf tools: handle '-' and '+' in parsing trace print format perf tools: remove all char * typecasts and use const in prototype
----
tools/perf/Makefile | 2 +- tools/perf/builtin-trace.c | 2 + tools/perf/util/trace-event-parse.c | 533 +++++++++++++++++++++++++---------- tools/perf/util/trace-event.h | 25 ++- 4 files changed, 405 insertions(+), 157 deletions(-)
PATCH 1/13 perf tools: handle print concatinations in event format file
From: Steven Rostedt <[email protected]>
kmem_alloc ftrace event format had a string that was broken up by two tokens. "string 1" "string 2". This patch lets the parser be able to handle the concatination.
--- tools/perf/util/trace-event-parse.c | 16 ++++++++++++++++ 1 files changed, 16 insertions(+), 0 deletions(-)
tools/perf/util/trace-event-parse.c +16 -0
@@ -1734,6 +1734,7 @@ static int event_read_print(struct event *event)if (read_expect_type (EVENT_DQUOTE , &token) <0 ) goto fail; + concat: event->print_fmt.format = token; event->print_fmt.args =NULL ;
@@ -1743,6 +1744,21 @@ static int event_read_print(struct event *event)if (type ==EVENT_NONE )return 0 ; +/* Handle concatination of print lines */ +if (type ==EVENT_DQUOTE ) { +char *cat; + + cat =malloc_or_die (strlen (event->print_fmt.format) + +strlen (token) +1 ); +strcpy (cat, event->print_fmt.format); +strcat (cat, token); +free_token (token); +free_token (event->print_fmt.format); + event->print_fmt.format =NULL ; + token = cat; + goto concat; + } +if (test_type_token (type, token,EVENT_DELIM , (char *)"," )) goto fail;
Signature · 1 line
1.6.3.3
[tip:perf/core] perf tools: Handle print concatenations in event format file
Commit-ID: 924a79af2cdee26a034b9bdce8c9c76995b5c901 Gitweb: http://git.kernel.org/tip/924a79af2cdee26a034b9bdce8c9c76995b5c901 Author: Steven Rostedt <[email protected]> AuthorDate: Wed, 14 Oct 2009 15:43:32 -0400 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 15 Oct 2009 10:42:34 +0200
perf tools: Handle print concatenations in event format file
kmem_alloc ftrace event format had a string that was broken up by two tokens. "string 1" "string 2". This patch lets the parser be able to handle the concatenation.
LKML-Reference: <[email protected]>
--- tools/perf/util/trace-event-parse.c | 16 ++++++++++++++++ 1 files changed, 16 insertions(+), 0 deletions(-)
tools/perf/util/trace-event-parse.c +16 -0
@@ -1734,6 +1734,7 @@ static int event_read_print(struct event *event)if (read_expect_type (EVENT_DQUOTE , &token) <0 ) goto fail; + concat: event->print_fmt.format = token; event->print_fmt.args =NULL ;
@@ -1743,6 +1744,21 @@ static int event_read_print(struct event *event)if (type ==EVENT_NONE )return 0 ; +/* Handle concatination of print lines */ +if (type ==EVENT_DQUOTE ) { +char *cat; + + cat =malloc_or_die (strlen (event->print_fmt.format) + +strlen (token) +1 ); +strcpy (cat, event->print_fmt.format); +strcat (cat, token); +free_token (token); +free_token (event->print_fmt.format); + event->print_fmt.format =NULL ; + token = cat; + goto concat; + } +if (test_type_token (type, token,EVENT_DELIM , (char *)"," )) goto fail;
PATCH 2/13 perf tools: fix backslash processing on trace print formats
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
The handling of backslashes was broken. It would stop parsing when accountering one. Also, '\n', '\t', '\r' and '\\' were not converted.
--- tools/perf/util/trace-event-parse.c | 27 +++++++++++++++++++++++++-- 1 files changed, 25 insertions(+), 2 deletions(-)
tools/perf/util/trace-event-parse.c +25 -2
@@ -522,7 +522,10 @@ static enum event_type __read_token(char **tok) last_ch = ch; ch =__read_char (); buf[i++] = ch; - }while (ch != quote_ch && last_ch !='\\' ); +/* the '\' '\' will cancel itself */ +if (ch =='\\' && last_ch =='\\' ) + last_ch =0 ; + }while (ch != quote_ch || last_ch =='\\' );/* remove the last quote */ i--; goto out;
@@ -2325,7 +2328,27 @@ static void pretty_print(void *data, int size, struct event *event)for (; *ptr; ptr++) { ls =0 ; -if (*ptr =='%' ) { +if (*ptr =='\\' ) { + ptr++; +switch (*ptr) { +case 'n' : +printf ("\n" ); +break ; +case 't' : +printf ("\t" ); +break ; +case 'r' : +printf ("\r" ); +break ; +case '\\' : +printf ("\\" ); +break ; +default : +printf ("%c" , *ptr); +break ; + } + + }else if (*ptr =='%' ) { saveptr = ptr; show_func =0 ; cont_process:
Signature · 1 line
1.6.3.3
[tip:perf/core] perf tools: Fix backslash processing on trace print formats
Commit-ID: 91ff2bc191827f0d3f5ad0a433ff7df7d2dd9aee Gitweb: http://git.kernel.org/tip/91ff2bc191827f0d3f5ad0a433ff7df7d2dd9aee Author: Steven Rostedt <[email protected]> AuthorDate: Wed, 14 Oct 2009 15:43:33 -0400 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 15 Oct 2009 10:42:35 +0200
perf tools: Fix backslash processing on trace print formats
The handling of backslashes was broken. It would stop parsing when encountering one. Also, '\n', '\t', '\r' and '\\' were not converted.
LKML-Reference: <[email protected]>
--- tools/perf/util/trace-event-parse.c | 27 +++++++++++++++++++++++++-- 1 files changed, 25 insertions(+), 2 deletions(-)
tools/perf/util/trace-event-parse.c +25 -2
@@ -522,7 +522,10 @@ static enum event_type __read_token(char **tok) last_ch = ch; ch =__read_char (); buf[i++] = ch; - }while (ch != quote_ch && last_ch !='\\' ); +/* the '\' '\' will cancel itself */ +if (ch =='\\' && last_ch =='\\' ) + last_ch =0 ; + }while (ch != quote_ch || last_ch =='\\' );/* remove the last quote */ i--; goto out;
@@ -2325,7 +2328,27 @@ static void pretty_print(void *data, int size, struct event *event)for (; *ptr; ptr++) { ls =0 ; -if (*ptr =='%' ) { +if (*ptr =='\\' ) { + ptr++; +switch (*ptr) { +case 'n' : +printf ("\n" ); +break ; +case 't' : +printf ("\t" ); +break ; +case 'r' : +printf ("\r" ); +break ; +case '\\' : +printf ("\\" ); +break ; +default : +printf ("%c" , *ptr); +break ; + } + + }else if (*ptr =='%' ) { saveptr = ptr; show_func =0 ; cont_process:
PATCH 3/13 perf tools: handle trace parsing of < and >
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
The code to handle the '<' and '>' ops was all in place, but they were not in the switch statement to consider them as valid ops.
--- tools/perf/util/trace-event-parse.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
tools/perf/util/trace-event-parse.c +2 -0
@@ -1170,6 +1170,8 @@ process_op(struct event *event, struct print_arg *arg, char **tok)strcmp (token,"*" ) ==0 ||strcmp (token,"^" ) ==0 ||strcmp (token,"/" ) ==0 || +strcmp (token,"<" ) ==0 || +strcmp (token,">" ) ==0 ||strcmp (token,"==" ) ==0 || strcmp(token, "!=") == 0) {
Signature · 1 line
1.6.3.3
[tip:perf/core] perf tools: Handle trace parsing of < and >
Commit-ID: 298ebc3ef2a6c569b3eb51651f04e26aecbf8a1d Gitweb: http://git.kernel.org/tip/298ebc3ef2a6c569b3eb51651f04e26aecbf8a1d Author: Steven Rostedt <[email protected]> AuthorDate: Wed, 14 Oct 2009 15:43:34 -0400 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 15 Oct 2009 10:42:35 +0200
perf tools: Handle trace parsing of < and >
The code to handle the '<' and '>' ops was all in place, but they were not in the switch statement to consider them as valid ops.
LKML-Reference: <[email protected]>
--- tools/perf/util/trace-event-parse.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
tools/perf/util/trace-event-parse.c +2 -0
@@ -1170,6 +1170,8 @@ process_op(struct event *event, struct print_arg *arg, char **tok)strcmp (token,"*" ) ==0 ||strcmp (token,"^" ) ==0 ||strcmp (token,"/" ) ==0 || +strcmp (token,"<" ) ==0 || +strcmp (token,">" ) ==0 ||strcmp (token,"==" ) ==0 || strcmp(token, "!=") == 0) {
PATCH 4/13 perf tools: handle arrays in print fields for trace parsing
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
The array used by the ftrace stack events (caller[x]) causes issues with the parser. This adds code to handle the case, but it also assumes that the array is of type long.
Note, this is a special case used (currently) only by the ftrace user and kernel stack records.
--- tools/perf/util/trace-event-parse.c | 62 +++++++++++++++++++++++++++++++++++ 1 files changed, 62 insertions(+), 0 deletions(-)
tools/perf/util/trace-event-parse.c +62 -0
@@ -1046,6 +1046,35 @@ out_free:return EVENT_ERROR ; } +static enum event_type +process_array (struct event *event,struct print_arg *top,char **tok) +{ +struct print_arg *arg; +enum event_type type; +char *token =NULL ; + + arg =malloc_or_die (sizeof (*arg)); +memset (arg,0 ,sizeof (*arg)); + + *tok =NULL ; + type =process_arg (event, arg, &token); +if (test_type_token (type, token,EVENT_OP , (char *)"]" )) + goto out_free; + + top->op.right = arg; + +free_token (token); + type =read_token_item (&token); + *tok = token; + +return type; + +out_free: +free_token (*tok); +free_arg (arg); +return EVENT_ERROR ; +} +static int get_op_prio (char *op) {if (!op[1 ]) {
@@ -1192,6 +1221,18 @@ process_op(struct event *event, struct print_arg *arg, char **tok) arg->op.right = right; + }else if (strcmp (token,"[" ) ==0 ) { + + left =malloc_or_die (sizeof (*left)); + *left = *arg; + + arg->type =PRINT_OP ; + arg->op.op = token; + arg->op.left = left; + + arg->op.prio =0 ; + type =process_array (event, arg, tok); + }else {die ("unknown op '%s'" , token);/* the arg is now the left side */
@@ -1931,6 +1972,7 @@ static unsigned long long eval_num_arg(void *data, int size, {unsigned long long val =0 ;unsigned long long left, right; +struct print_arg *larg;switch (arg->type) {case PRINT_NULL :
@@ -1957,6 +1999,26 @@ static unsigned long long eval_num_arg(void *data, int size,return 0 ;break ;case PRINT_OP : +if (strcmp (arg->op.op,"[" ) ==0 ) { +/* +* Arrays are special, since we don't want +* to read the arg as is. +*/ +if (arg->op.left->type !=PRINT_FIELD ) + goto default_op;/* oops, all bets off */ + larg = arg->op.left; +if (!larg->field.field) { + larg->field.field = +find_any_field (event, larg->field.name); +if (!larg->field.field) +die ("field %s not found" , larg->field.name); + } + right =eval_num_arg (data, size, event, arg->op.right); + val =read_size (data + larg->field.field->offset + + right * long_size, long_size); +break ; + } + default_op: left =eval_num_arg (data, size, event, arg->op.left); right =eval_num_arg (data, size, event, arg->op.right);switch (arg->op.op[0 ]) {
Signature · 1 line
1.6.3.3
[tip:perf/core] perf tools: Handle arrays in print fields for trace parsing
Commit-ID: 0959b8d65ce26131c2d5ccfa518a7b76529280fa Gitweb: http://git.kernel.org/tip/0959b8d65ce26131c2d5ccfa518a7b76529280fa Author: Steven Rostedt <[email protected]> AuthorDate: Wed, 14 Oct 2009 15:43:35 -0400 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 15 Oct 2009 10:42:36 +0200
perf tools: Handle arrays in print fields for trace parsing
The array used by the ftrace stack events (caller[x]) causes issues with the parser. This adds code to handle the case, but it also assumes that the array is of type long.
Note, this is a special case used (currently) only by the ftrace user and kernel stack records.
LKML-Reference: <[email protected]>
--- tools/perf/util/trace-event-parse.c | 62 +++++++++++++++++++++++++++++++++++ 1 files changed, 62 insertions(+), 0 deletions(-)
tools/perf/util/trace-event-parse.c +62 -0
@@ -1046,6 +1046,35 @@ out_free:return EVENT_ERROR ; } +static enum event_type +process_array (struct event *event,struct print_arg *top,char **tok) +{ +struct print_arg *arg; +enum event_type type; +char *token =NULL ; + + arg =malloc_or_die (sizeof (*arg)); +memset (arg,0 ,sizeof (*arg)); + + *tok =NULL ; + type =process_arg (event, arg, &token); +if (test_type_token (type, token,EVENT_OP , (char *)"]" )) + goto out_free; + + top->op.right = arg; + +free_token (token); + type =read_token_item (&token); + *tok = token; + +return type; + +out_free: +free_token (*tok); +free_arg (arg); +return EVENT_ERROR ; +} +static int get_op_prio (char *op) {if (!op[1 ]) {
@@ -1192,6 +1221,18 @@ process_op(struct event *event, struct print_arg *arg, char **tok) arg->op.right = right; + }else if (strcmp (token,"[" ) ==0 ) { + + left =malloc_or_die (sizeof (*left)); + *left = *arg; + + arg->type =PRINT_OP ; + arg->op.op = token; + arg->op.left = left; + + arg->op.prio =0 ; + type =process_array (event, arg, tok); + }else {die ("unknown op '%s'" , token);/* the arg is now the left side */
@@ -1931,6 +1972,7 @@ static unsigned long long eval_num_arg(void *data, int size, {unsigned long long val =0 ;unsigned long long left, right; +struct print_arg *larg;switch (arg->type) {case PRINT_NULL :
@@ -1957,6 +1999,26 @@ static unsigned long long eval_num_arg(void *data, int size,return 0 ;break ;case PRINT_OP : +if (strcmp (arg->op.op,"[" ) ==0 ) { +/* +* Arrays are special, since we don't want +* to read the arg as is. +*/ +if (arg->op.left->type !=PRINT_FIELD ) + goto default_op;/* oops, all bets off */ + larg = arg->op.left; +if (!larg->field.field) { + larg->field.field = +find_any_field (event, larg->field.name); +if (!larg->field.field) +die ("field %s not found" , larg->field.name); + } + right =eval_num_arg (data, size, event, arg->op.right); + val =read_size (data + larg->field.field->offset + + right * long_size, long_size); +break ; + } + default_op: left =eval_num_arg (data, size, event, arg->op.left); right =eval_num_arg (data, size, event, arg->op.right);switch (arg->op.op[0 ]) {
PATCH 5/13 perf tools: handle * as typecast in trace parsing
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
The '*' is currently only treated as a multiplication, and it needs to be handled as a typecast pointer.
This is the version used by trace-cmd.
--- tools/perf/util/trace-event-parse.c | 50 +++++++++++++++------------------- 1 files changed, 22 insertions(+), 28 deletions(-)
tools/perf/util/trace-event-parse.c +22 -28
@@ -1217,7 +1217,24 @@ process_op(struct event *event, struct print_arg *arg, char **tok) right =malloc_or_die (sizeof (*right)); - type =process_arg (event, right, tok); + type =read_token_item (&token); + *tok = token; + +/* could just be a type pointer */ +if ((strcmp (arg->op.op,"*" ) ==0 ) && + type ==EVENT_DELIM && (strcmp (token,")" ) ==0 )) { +if (left->type !=PRINT_ATOM ) +die ("bad pointer type" ); + left->atom.atom =realloc (left->atom.atom, +sizeof (left->atom.atom) +3 ); +strcat (left->atom.atom," *" ); + *arg = *left; +free (arg); + +return type; + } + + type =process_arg_token (event, right, tok, type); arg->op.right = right;
@@ -1548,7 +1565,6 @@ process_paren(struct event *event, struct print_arg *arg, char **tok) {struct print_arg *item_arg;enum event_type type; -int ptr_cast =0 ;char *token; type =process_arg (event, arg, &token);
@@ -1556,26 +1572,11 @@ process_paren(struct event *event, struct print_arg *arg, char **tok)if (type ==EVENT_ERROR )return EVENT_ERROR ; -if (type ==EVENT_OP ) { -/* handle the ptr casts */ -if (!strcmp (token,"*" )) { -/* -* FIXME: should we zapp whitespaces before ')' ? -* (may require a peek_token_item()) -*/ -if (__peek_char () ==')' ) { - ptr_cast =1 ; -free_token (token); - type =read_token_item (&token); - } - } -if (!ptr_cast) { - type =process_op (event, arg, &token); +if (type ==EVENT_OP ) + type =process_op (event, arg, &token); -if (type ==EVENT_ERROR ) -return EVENT_ERROR ; - } - } +if (type ==EVENT_ERROR ) +return EVENT_ERROR ;if (test_type_token (type, token,EVENT_DELIM , (char *)")" )) {free_token (token);
@@ -1601,13 +1602,6 @@ process_paren(struct event *event, struct print_arg *arg, char **tok) item_arg =malloc_or_die (sizeof (*item_arg)); arg->type =PRINT_TYPE ; -if (ptr_cast) { -char *old = arg->atom.atom; - - arg->atom.atom =malloc_or_die (strlen (old +3 )); -sprintf (arg->atom.atom,"%s *" , old); -free (old); - } arg->typecast.type = arg->atom.atom; arg->typecast.item = item_arg; type =process_arg_token (event, item_arg, &token, type);
Signature · 1 line
1.6.3.3
[tip:perf/core] perf tools: Handle * as typecast in trace parsing
Commit-ID: b99af874829cba2b30d212bc6fd31b56275ee4d2 Gitweb: http://git.kernel.org/tip/b99af874829cba2b30d212bc6fd31b56275ee4d2 Author: Steven Rostedt <[email protected]> AuthorDate: Wed, 14 Oct 2009 15:43:36 -0400 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 15 Oct 2009 10:42:36 +0200
perf tools: Handle * as typecast in trace parsing
The '*' is currently only treated as a multiplication, and it needs to be handled as a typecast pointer.
This is the version used by trace-cmd.
LKML-Reference: <[email protected]>
--- tools/perf/util/trace-event-parse.c | 50 +++++++++++++++------------------- 1 files changed, 22 insertions(+), 28 deletions(-)
tools/perf/util/trace-event-parse.c +22 -28
@@ -1217,7 +1217,24 @@ process_op(struct event *event, struct print_arg *arg, char **tok) right =malloc_or_die (sizeof (*right)); - type =process_arg (event, right, tok); + type =read_token_item (&token); + *tok = token; + +/* could just be a type pointer */ +if ((strcmp (arg->op.op,"*" ) ==0 ) && + type ==EVENT_DELIM && (strcmp (token,")" ) ==0 )) { +if (left->type !=PRINT_ATOM ) +die ("bad pointer type" ); + left->atom.atom =realloc (left->atom.atom, +sizeof (left->atom.atom) +3 ); +strcat (left->atom.atom," *" ); + *arg = *left; +free (arg); + +return type; + } + + type =process_arg_token (event, right, tok, type); arg->op.right = right;
@@ -1548,7 +1565,6 @@ process_paren(struct event *event, struct print_arg *arg, char **tok) {struct print_arg *item_arg;enum event_type type; -int ptr_cast =0 ;char *token; type =process_arg (event, arg, &token);
@@ -1556,26 +1572,11 @@ process_paren(struct event *event, struct print_arg *arg, char **tok)if (type ==EVENT_ERROR )return EVENT_ERROR ; -if (type ==EVENT_OP ) { -/* handle the ptr casts */ -if (!strcmp (token,"*" )) { -/* -* FIXME: should we zapp whitespaces before ')' ? -* (may require a peek_token_item()) -*/ -if (__peek_char () ==')' ) { - ptr_cast =1 ; -free_token (token); - type =read_token_item (&token); - } - } -if (!ptr_cast) { - type =process_op (event, arg, &token); +if (type ==EVENT_OP ) + type =process_op (event, arg, &token); -if (type ==EVENT_ERROR ) -return EVENT_ERROR ; - } - } +if (type ==EVENT_ERROR ) +return EVENT_ERROR ;if (test_type_token (type, token,EVENT_DELIM , (char *)")" )) {free_token (token);
@@ -1601,13 +1602,6 @@ process_paren(struct event *event, struct print_arg *arg, char **tok) item_arg =malloc_or_die (sizeof (*item_arg)); arg->type =PRINT_TYPE ; -if (ptr_cast) { -char *old = arg->atom.atom; - - arg->atom.atom =malloc_or_die (strlen (old +3 )); -sprintf (arg->atom.atom,"%s *" , old); -free (old); - } arg->typecast.type = arg->atom.atom; arg->typecast.item = item_arg; type =process_arg_token (event, item_arg, &token, type);
PATCH 6/13 perf tools: handle newlines in trace parsing better
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
New lines between args in the trace format can break the parsing. This should not be the case.
--- tools/perf/util/trace-event-parse.c | 8 +++++++- 1 files changed, 7 insertions(+), 1 deletions(-)
tools/perf/util/trace-event-parse.c +7 -1
@@ -1716,12 +1716,18 @@ process_arg_token(struct event *event, struct print_arg *arg,static int event_read_print_args (struct event *event,struct print_arg **list) { -enum event_type type; +enum event_type type =EVENT_ERROR ;struct print_arg *arg;char *token;int args =0 ; do { + if (type == EVENT_NEWLINE) { + free_token(token); + type = read_token_item(&token); + continue; + } + arg = malloc_or_die(sizeof(*arg)); memset(arg, 0, sizeof(*arg));
Signature · 1 line
1.6.3.3
[tip:perf/core] perf tools: Handle newlines in trace parsing better
Commit-ID: f1d1feecf07261d083859ecfef0d4399036f9683 Gitweb: http://git.kernel.org/tip/f1d1feecf07261d083859ecfef0d4399036f9683 Author: Steven Rostedt <[email protected]> AuthorDate: Wed, 14 Oct 2009 15:43:37 -0400 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 15 Oct 2009 10:42:37 +0200
perf tools: Handle newlines in trace parsing better
New lines between args in the trace format can break the parsing. This should not be the case.
LKML-Reference: <[email protected]>
--- tools/perf/util/trace-event-parse.c | 8 +++++++- 1 files changed, 7 insertions(+), 1 deletions(-)
tools/perf/util/trace-event-parse.c +7 -1
@@ -1716,12 +1716,18 @@ process_arg_token(struct event *event, struct print_arg *arg,static int event_read_print_args (struct event *event,struct print_arg **list) { -enum event_type type; +enum event_type type =EVENT_ERROR ;struct print_arg *arg;char *token;int args =0 ; do { + if (type == EVENT_NEWLINE) { + free_token(token); + type = read_token_item(&token); + continue; + } + arg = malloc_or_die(sizeof(*arg)); memset(arg, 0, sizeof(*arg));
PATCH 7/13 perf tools: handle the case with and without the "signed" trace field
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
The trace format files now have a "signed" field. But we should still be able to handle the kernels that do not have this field.
--- tools/perf/util/trace-event-parse.c | 81 ++++++++++++++++++++++------------ 1 files changed, 52 insertions(+), 29 deletions(-)
tools/perf/util/trace-event-parse.c +52 -29
@@ -924,23 +924,30 @@ static int event_read_fields(struct event *event, struct format_field **fields)if (read_expected (EVENT_OP , (char *)";" ) <0 ) goto fail_expect; -if (read_expected (EVENT_ITEM , (char *)"signed" ) <0 ) - goto fail_expect; + type =read_token (&token); +if (type !=EVENT_NEWLINE ) { +/* newer versions of the kernel have a "signed" type */ +if (test_type_token (type, token,EVENT_ITEM , (char *)"signed" )) + goto fail; -if (read_expected (EVENT_OP , (char *)":" ) <0 ) - goto fail_expect; +free_token (token); -if (read_expect_type (EVENT_ITEM , &token)) - goto fail; -if (strtoul (token,NULL ,0 )) - field->flags |=FIELD_IS_SIGNED ; -free_token (token); +if (read_expected (EVENT_OP , (char *)":" ) <0 ) + goto fail_expect; -if (read_expected (EVENT_OP , (char *)";" ) <0 ) - goto fail_expect; +if (read_expect_type (EVENT_ITEM , &token)) + goto fail; + +/* add signed type */ + +free_token (token); +if (read_expected (EVENT_OP , (char *)";" ) <0 ) + goto fail_expect; + +if (read_expect_type (EVENT_NEWLINE , &token)) + goto fail; + } -if (read_expect_type (EVENT_NEWLINE , &token) <0 ) - goto fail;free_token (token); *fields = field;
@@ -2949,21 +2956,23 @@ static void print_args(struct print_arg *args) } } -static void parse_header_field (char *type, +static void parse_header_field (char *field,int *offset,int *size) {char *token; +int type;if (read_expected (EVENT_ITEM , (char *)"field" ) <0 )return ;if (read_expected (EVENT_OP , (char *)":" ) <0 )return ; +/* type */ if (read_expect_type (EVENT_ITEM , &token) <0 ) -return ; + goto fail;free_token (token); -if (read_expected (EVENT_ITEM , type) <0 ) +if (read_expected (EVENT_ITEM , field) <0 )return ;if (read_expected (EVENT_OP , (char *)";" ) <0 )return ;
@@ -2972,7 +2981,7 @@ static void parse_header_field(char *type,if (read_expected (EVENT_OP , (char *)":" ) <0 )return ;if (read_expect_type (EVENT_ITEM , &token) <0 ) -return ; + goto fail; *offset =atoi (token);free_token (token);if (read_expected (EVENT_OP , (char *)";" ) <0 )
@@ -2982,22 +2991,36 @@ static void parse_header_field(char *type,if (read_expected (EVENT_OP , (char *)":" ) <0 )return ;if (read_expect_type (EVENT_ITEM , &token) <0 ) -return ; + goto fail; *size =atoi (token);free_token (token);if (read_expected (EVENT_OP , (char *)";" ) <0 )return ; -if (read_expected (EVENT_ITEM , (char *)"signed" ) <0 ) -return ; -if (read_expected (EVENT_OP , (char *)":" ) <0 ) -return ; -if (read_expect_type (EVENT_ITEM , &token) <0 ) -return ; -free_token (token); -if (read_expected (EVENT_OP , (char *)";" ) <0 ) -return ; -if (read_expect_type (EVENT_NEWLINE , &token) <0 ) -return ; + type =read_token (&token); +if (type !=EVENT_NEWLINE ) { +/* newer versions of the kernel have a "signed" type */ +if (type !=EVENT_ITEM ) + goto fail; + +if (strcmp (token, (char *)"signed" ) !=0 ) + goto fail; + +free_token (token); + +if (read_expected (EVENT_OP , (char *)":" ) <0 ) +return ; + +if (read_expect_type (EVENT_ITEM , &token)) + goto fail; + +free_token (token); +if (read_expected (EVENT_OP , (char *)";" ) <0 ) +return ; + +if (read_expect_type (EVENT_NEWLINE , &token)) + goto fail; + } + fail:free_token (token); }
Signature · 1 line
1.6.3.3
[tip:perf/core] perf tools: Handle the case with and without the "signed" trace field
Commit-ID: 13999e59343b042b0807be2df6ae5895d29782a0 Gitweb: http://git.kernel.org/tip/13999e59343b042b0807be2df6ae5895d29782a0 Author: Steven Rostedt <[email protected]> AuthorDate: Wed, 14 Oct 2009 15:43:38 -0400 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 15 Oct 2009 10:42:37 +0200
perf tools: Handle the case with and without the "signed" trace field
The trace format files now have a "signed" field. But we should still be able to handle the kernels that do not have this field.
LKML-Reference: <[email protected]>
--- tools/perf/util/trace-event-parse.c | 81 ++++++++++++++++++++++------------ 1 files changed, 52 insertions(+), 29 deletions(-)
tools/perf/util/trace-event-parse.c +52 -29
@@ -924,23 +924,30 @@ static int event_read_fields(struct event *event, struct format_field **fields)if (read_expected (EVENT_OP , (char *)";" ) <0 ) goto fail_expect; -if (read_expected (EVENT_ITEM , (char *)"signed" ) <0 ) - goto fail_expect; + type =read_token (&token); +if (type !=EVENT_NEWLINE ) { +/* newer versions of the kernel have a "signed" type */ +if (test_type_token (type, token,EVENT_ITEM , (char *)"signed" )) + goto fail; -if (read_expected (EVENT_OP , (char *)":" ) <0 ) - goto fail_expect; +free_token (token); -if (read_expect_type (EVENT_ITEM , &token)) - goto fail; -if (strtoul (token,NULL ,0 )) - field->flags |=FIELD_IS_SIGNED ; -free_token (token); +if (read_expected (EVENT_OP , (char *)":" ) <0 ) + goto fail_expect; -if (read_expected (EVENT_OP , (char *)";" ) <0 ) - goto fail_expect; +if (read_expect_type (EVENT_ITEM , &token)) + goto fail; + +/* add signed type */ + +free_token (token); +if (read_expected (EVENT_OP , (char *)";" ) <0 ) + goto fail_expect; + +if (read_expect_type (EVENT_NEWLINE , &token)) + goto fail; + } -if (read_expect_type (EVENT_NEWLINE , &token) <0 ) - goto fail;free_token (token); *fields = field;
@@ -2949,21 +2956,23 @@ static void print_args(struct print_arg *args) } } -static void parse_header_field (char *type, +static void parse_header_field (char *field,int *offset,int *size) {char *token; +int type;if (read_expected (EVENT_ITEM , (char *)"field" ) <0 )return ;if (read_expected (EVENT_OP , (char *)":" ) <0 )return ; +/* type */ if (read_expect_type (EVENT_ITEM , &token) <0 ) -return ; + goto fail;free_token (token); -if (read_expected (EVENT_ITEM , type) <0 ) +if (read_expected (EVENT_ITEM , field) <0 )return ;if (read_expected (EVENT_OP , (char *)";" ) <0 )return ;
@@ -2972,7 +2981,7 @@ static void parse_header_field(char *type,if (read_expected (EVENT_OP , (char *)":" ) <0 )return ;if (read_expect_type (EVENT_ITEM , &token) <0 ) -return ; + goto fail; *offset =atoi (token);free_token (token);if (read_expected (EVENT_OP , (char *)";" ) <0 )
@@ -2982,22 +2991,36 @@ static void parse_header_field(char *type,if (read_expected (EVENT_OP , (char *)":" ) <0 )return ;if (read_expect_type (EVENT_ITEM , &token) <0 ) -return ; + goto fail; *size =atoi (token);free_token (token);if (read_expected (EVENT_OP , (char *)";" ) <0 )return ; -if (read_expected (EVENT_ITEM , (char *)"signed" ) <0 ) -return ; -if (read_expected (EVENT_OP , (char *)":" ) <0 ) -return ; -if (read_expect_type (EVENT_ITEM , &token) <0 ) -return ; -free_token (token); -if (read_expected (EVENT_OP , (char *)";" ) <0 ) -return ; -if (read_expect_type (EVENT_NEWLINE , &token) <0 ) -return ; + type =read_token (&token); +if (type !=EVENT_NEWLINE ) { +/* newer versions of the kernel have a "signed" type */ +if (type !=EVENT_ITEM ) + goto fail; + +if (strcmp (token, (char *)"signed" ) !=0 ) + goto fail; + +free_token (token); + +if (read_expected (EVENT_OP , (char *)":" ) <0 ) +return ; + +if (read_expect_type (EVENT_ITEM , &token)) + goto fail; + +free_token (token); +if (read_expected (EVENT_OP , (char *)";" ) <0 ) +return ; + +if (read_expect_type (EVENT_NEWLINE , &token)) + goto fail; + } + fail:free_token (token); }
PATCH 8/13 perf tools: still continue on failed parsing of an event
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
Even though an event may fail to parse, we should not kill the entire report. The trace should still be able to show what it can.
If an event fails to parse, a warning is printed, and the output continues.
--- tools/perf/util/trace-event-parse.c | 38 ++++++++++++++++++++++++---------- tools/perf/util/trace-event.h | 14 +++++++----- 2 files changed, 35 insertions(+), 17 deletions(-)
tools/perf/util/trace-event-parse.c +27 -11
@@ -613,7 +613,7 @@ static enum event_type read_token_item(char **tok)static int test_type (enum event_type type,enum event_type expect) {if (type != expect) { -die ("Error: expected type %d but read %d" , +warning ("Error: expected type %d but read %d" , expect, type);return -1 ; }
@@ -624,13 +624,13 @@ static int test_type_token(enum event_type type, char *token, enum event_type expect, char *expect_tok) {if (type != expect) { -die ("Error: expected type %d but read %d" , +warning ("Error: expected type %d but read %d" , expect, type);return -1 ; }if (strcmp (token, expect_tok) !=0 ) { -die ("Error: expected '%s' but read '%s'" , +warning ("Error: expected '%s' but read '%s'" , expect_tok, token);return -1 ; }
@@ -668,7 +668,7 @@ static int __read_expected(enum event_type expect, char *str, int newline_ok)free_token (token); -return 0 ; +return ret; }static int read_expected (enum event_type expect,char *str)
@@ -1258,12 +1258,12 @@ process_op(struct event *event, struct print_arg *arg, char **tok) type =process_array (event, arg, tok); }else { -die ("unknown op '%s'" , token); +warning ("unknown op '%s'" , token); + event->flags |=EVENT_FL_FAILED ;/* the arg is now the left side */ return EVENT_NONE ; } -if (type ==EVENT_OP ) {int prio;
@@ -2873,7 +2873,7 @@ void print_event(int cpu, void *data, int size, unsigned long long nsecs, event =trace_find_event (type);if (!event) { -printf ("ug! no event found for type %d\n" , type); +warning ("ug! no event found for type %d" , type);return ; }
@@ -2887,6 +2887,12 @@ void print_event(int cpu, void *data, int size, unsigned long long nsecs, comm, pid, cpu, secs, nsecs, event->name); +if (event->flags &EVENT_FL_FAILED ) { +printf ("EVENT '%s' FAILED TO PARSE\n" , + event->name); +return ; + } +pretty_print (data, size, event);printf ("\n" ); }
@@ -3120,12 +3126,16 @@ int parse_event_file(char *buf, unsigned long size, char *sys)die ("failed to read event id" ); ret =event_read_format (event); -if (ret <0 ) -die ("failed to read event format" ); +if (ret <0 ) { +warning ("failed to read event format for %s" , event->name); + goto event_failed; + } ret =event_read_print (event); -if (ret <0 ) -die ("failed to read event print fmt" ); +if (ret <0 ) { +warning ("failed to read event print fmt for %s" , event->name); + goto event_failed; + } event->system =strdup (sys);
@@ -3135,6 +3145,12 @@ int parse_event_file(char *buf, unsigned long size, char *sys)add_event (event);return 0 ; + + event_failed: + event->flags |=EVENT_FL_FAILED ; +/* still add it even if it failed */ +add_event (event); +return -1 ; }void parse_set_info (int nr_cpus,int long_sz)
tools/perf/util/trace-event.h +8 -6
@@ -139,12 +139,14 @@ struct event { };enum { -EVENT_FL_ISFTRACE =1 , -EVENT_FL_ISPRINT =2 , -EVENT_FL_ISBPRINT =4 , -EVENT_FL_ISFUNC =8 , -EVENT_FL_ISFUNCENT =16 , -EVENT_FL_ISFUNCRET =32 , +EVENT_FL_ISFTRACE =0x01 , +EVENT_FL_ISPRINT =0x02 , +EVENT_FL_ISBPRINT =0x04 , +EVENT_FL_ISFUNC =0x08 , +EVENT_FL_ISFUNCENT =0x10 , +EVENT_FL_ISFUNCRET =0x20 , + +EVENT_FL_FAILED =0x80000000 };struct record {
Signature · 1 line
1.6.3.3
[tip:perf/core] perf tools: Still continue on failed parsing of an event
Commit-ID: 07a4bdddcf2546ccfbfb3c782deab636c371edeb Gitweb: http://git.kernel.org/tip/07a4bdddcf2546ccfbfb3c782deab636c371edeb Author: Steven Rostedt <[email protected]> AuthorDate: Wed, 14 Oct 2009 15:43:39 -0400 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 15 Oct 2009 10:42:38 +0200
perf tools: Still continue on failed parsing of an event
Even though an event may fail to parse, we should not kill the entire report. The trace should still be able to show what it can.
If an event fails to parse, a warning is printed, and the output continues.
LKML-Reference: <[email protected]>
--- tools/perf/util/trace-event-parse.c | 38 ++++++++++++++++++++++++---------- tools/perf/util/trace-event.h | 14 +++++++----- 2 files changed, 35 insertions(+), 17 deletions(-)
tools/perf/util/trace-event-parse.c +27 -11
@@ -613,7 +613,7 @@ static enum event_type read_token_item(char **tok)static int test_type (enum event_type type,enum event_type expect) {if (type != expect) { -die ("Error: expected type %d but read %d" , +warning ("Error: expected type %d but read %d" , expect, type);return -1 ; }
@@ -624,13 +624,13 @@ static int test_type_token(enum event_type type, char *token, enum event_type expect, const char *expect_tok) {if (type != expect) { -die ("Error: expected type %d but read %d" , +warning ("Error: expected type %d but read %d" , expect, type);return -1 ; }if (strcmp (token, expect_tok) !=0 ) { -die ("Error: expected '%s' but read '%s'" , +warning ("Error: expected '%s' but read '%s'" , expect_tok, token);return -1 ; }
@@ -668,7 +668,7 @@ static int __read_expected(enum event_type expect, const char *str, int newline_free_token (token); -return 0 ; +return ret; }static int read_expected (enum event_type expect,const char *str)
@@ -1258,12 +1258,12 @@ process_op(struct event *event, struct print_arg *arg, char **tok) type =process_array (event, arg, tok); }else { -die ("unknown op '%s'" , token); +warning ("unknown op '%s'" , token); + event->flags |=EVENT_FL_FAILED ;/* the arg is now the left side */ return EVENT_NONE ; } -if (type ==EVENT_OP ) {int prio;
@@ -2873,7 +2873,7 @@ void print_event(int cpu, void *data, int size, unsigned long long nsecs, event =trace_find_event (type);if (!event) { -printf ("ug! no event found for type %d\n" , type); +warning ("ug! no event found for type %d" , type);return ; }
@@ -2887,6 +2887,12 @@ void print_event(int cpu, void *data, int size, unsigned long long nsecs, comm, pid, cpu, secs, nsecs, event->name); +if (event->flags &EVENT_FL_FAILED ) { +printf ("EVENT '%s' FAILED TO PARSE\n" , + event->name); +return ; + } +pretty_print (data, size, event);printf ("\n" ); }
@@ -3120,12 +3126,16 @@ int parse_event_file(char *buf, unsigned long size, char *sys)die ("failed to read event id" ); ret =event_read_format (event); -if (ret <0 ) -die ("failed to read event format" ); +if (ret <0 ) { +warning ("failed to read event format for %s" , event->name); + goto event_failed; + } ret =event_read_print (event); -if (ret <0 ) -die ("failed to read event print fmt" ); +if (ret <0 ) { +warning ("failed to read event print fmt for %s" , event->name); + goto event_failed; + } event->system =strdup (sys);
@@ -3135,6 +3145,12 @@ int parse_event_file(char *buf, unsigned long size, char *sys)add_event (event);return 0 ; + + event_failed: + event->flags |=EVENT_FL_FAILED ; +/* still add it even if it failed */ +add_event (event); +return -1 ; }void parse_set_info (int nr_cpus,int long_sz)
tools/perf/util/trace-event.h +8 -6
@@ -139,12 +139,14 @@ struct event { };enum { -EVENT_FL_ISFTRACE =1 , -EVENT_FL_ISPRINT =2 , -EVENT_FL_ISBPRINT =4 , -EVENT_FL_ISFUNC =8 , -EVENT_FL_ISFUNCENT =16 , -EVENT_FL_ISFUNCRET =32 , +EVENT_FL_ISFTRACE =0x01 , +EVENT_FL_ISPRINT =0x02 , +EVENT_FL_ISBPRINT =0x04 , +EVENT_FL_ISFUNC =0x08 , +EVENT_FL_ISFUNCENT =0x10 , +EVENT_FL_ISFUNCRET =0x20 , + +EVENT_FL_FAILED =0x80000000 };struct record {
PATCH 9/13 perf tools: fix bprintk reading in trace output
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
The bprintk parsing was broken in more ways than one.
The file parsing was incorrect, and the words used by the arguments are always 4 bytes aligned, even on 64bit machines.
--- tools/perf/util/trace-event-parse.c | 15 +++++++-------- 1 files changed, 7 insertions(+), 8 deletions(-)
tools/perf/util/trace-event-parse.c +7 -8
@@ -284,18 +284,16 @@ void parse_ftrace_printk(char *file, unsigned int size __unused)char *line;char *next =NULL ;char *addr_str; -int ret; +char *fmt;int i; line =strtok_r (file,"\n" , &next);while (line) { item =malloc_or_die (sizeof (*item)); - ret =sscanf (line,"%as : %as" , - (float *)(void *)&addr_str,/* workaround gcc warning */ - (float *)(void *)&item->printk); + addr_str =strtok_r (line,":" , &fmt); item->addr =strtoull (addr_str,NULL ,16 ); -free (addr_str); - +/* fmt still has a space, skip it */ + item->printk =strdup (fmt+1 ); item->next = list; list = item; line =strtok_r (NULL ,"\n" , &next);
@@ -2274,8 +2272,9 @@ static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struccase 'u' :case 'x' :case 'i' : - bptr = (void *)(((unsigned long )bptr + (long_size -1 )) & - ~(long_size -1 )); +/* the pointers are always 4 bytes aligned */ + bptr = (void *)(((unsigned long )bptr +3 ) & + ~3 );switch (ls) {case 0 :case 1 :
Signature · 1 line
1.6.3.3
[tip:perf/core] perf tools: Fix bprintk reading in trace output
Commit-ID: ffa1895561645103d8f8059b35d9c06e6eeead2e Gitweb: http://git.kernel.org/tip/ffa1895561645103d8f8059b35d9c06e6eeead2e Author: Steven Rostedt <[email protected]> AuthorDate: Wed, 14 Oct 2009 15:43:40 -0400 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 15 Oct 2009 10:42:38 +0200
perf tools: Fix bprintk reading in trace output
The bprintk parsing was broken in more ways than one.
The file parsing was incorrect, and the words used by the arguments are always 4 bytes aligned, even on 64-bit machines.
LKML-Reference: <[email protected]>
--- tools/perf/util/trace-event-parse.c | 15 +++++++-------- 1 files changed, 7 insertions(+), 8 deletions(-)
tools/perf/util/trace-event-parse.c +7 -8
@@ -284,18 +284,16 @@ void parse_ftrace_printk(char *file, unsigned int size __unused)char *line;char *next =NULL ;char *addr_str; -int ret; +char *fmt;int i; line =strtok_r (file,"\n" , &next);while (line) { item =malloc_or_die (sizeof (*item)); - ret =sscanf (line,"%as : %as" , - (float *)(void *)&addr_str,/* workaround gcc warning */ - (float *)(void *)&item->printk); + addr_str =strtok_r (line,":" , &fmt); item->addr =strtoull (addr_str,NULL ,16 ); -free (addr_str); - +/* fmt still has a space, skip it */ + item->printk =strdup (fmt+1 ); item->next = list; list = item; line =strtok_r (NULL ,"\n" , &next);
@@ -2274,8 +2272,9 @@ static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struccase 'u' :case 'x' :case 'i' : - bptr = (void *)(((unsigned long )bptr + (long_size -1 )) & - ~(long_size -1 )); +/* the pointers are always 4 bytes aligned */ + bptr = (void *)(((unsigned long )bptr +3 ) & + ~3 );switch (ls) {case 0 :case 1 :
PATCH 10/13 perf tools: handle both versions of ftrace output
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
The ftrace output events can have either arguments or no arguments. The parser needs to be able to handle both.
--- tools/perf/util/trace-event-parse.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)
tools/perf/util/trace-event-parse.c +4 -1
@@ -1819,7 +1819,7 @@ static int event_read_print(struct event *event)if (ret <0 )return -1 ; -return 0 ; +return ret; fail:free_token (token);
@@ -3088,6 +3088,9 @@ int parse_ftrace_file(char *buf, unsigned long size)if (ret <0 )die ("failed to read ftrace event print fmt" ); +/* New ftrace handles args */ +if (ret >0 ) +return 0 ;/* * The arguments for ftrace files are parsed by the fields. * Set up the fields as their arguments.
Signature · 1 line
1.6.3.3
[tip:perf/core] perf tools: Handle both versions of ftrace output
Commit-ID: 0d1da915c76838c9ee7af7cdefbcb2bae9424161 Gitweb: http://git.kernel.org/tip/0d1da915c76838c9ee7af7cdefbcb2bae9424161 Author: Steven Rostedt <[email protected]> AuthorDate: Wed, 14 Oct 2009 15:43:41 -0400 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 15 Oct 2009 10:42:39 +0200
perf tools: Handle both versions of ftrace output
The ftrace output events can have either arguments or no arguments. The parser needs to be able to handle both.
LKML-Reference: <[email protected]>
--- tools/perf/util/trace-event-parse.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)
tools/perf/util/trace-event-parse.c +4 -1
@@ -1819,7 +1819,7 @@ static int event_read_print(struct event *event)if (ret <0 )return -1 ; -return 0 ; +return ret; fail:free_token (token);
@@ -3088,6 +3088,9 @@ int parse_ftrace_file(char *buf, unsigned long size)if (ret <0 )die ("failed to read ftrace event print fmt" ); +/* New ftrace handles args */ +if (ret >0 ) +return 0 ;/* * The arguments for ftrace files are parsed by the fields. * Set up the fields as their arguments.
PATCH 11/13 perf tools: add latency format to trace output
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
Add the irqs disabled, preemption count, need resched, and other info that is shown in the latency format of ftrace.
# perf trace -l
perf-16457 2..s2. 53636.260344: kmem_cache_free: call_site=ffffffff811198f
perf-16457 2..s2. 53636.264330: kmem_cache_free: call_site=ffffffff811198f
perf-16457 2d.s4. 53636.300006: kmem_cache_free: call_site=ffffffff810d889--- tools/perf/builtin-trace.c | 2 + tools/perf/util/trace-event-parse.c | 120 +++++++++++++++++++++++++++++------ tools/perf/util/trace-event.h | 11 +++ 3 files changed, 114 insertions(+), 19 deletions(-)
tools/perf/builtin-trace.c +2 -0
@@ -144,6 +144,8 @@ static const struct option options[] = { "dump raw trace in ASCII"),OPT_BOOLEAN ('v' ,"verbose" , &verbose,"be more verbose (show symbol address, etc)" ), +OPT_BOOLEAN ('l' ,"latency" , &latency_format, +"show latency attributes (irqs/preemption disabled, etc)" ), OPT_END() };
tools/perf/util/trace-event-parse.c +101 -19
171 lines not on this page · raw message
tools/perf/util/trace-event.h +11 -0
@@ -239,6 +239,8 @@ extern int header_page_size_size;extern int header_page_data_offset;extern int header_page_data_size; +extern int latency_format; +int parse_header_page (char *buf,unsigned long size);int trace_parse_common_type (void *data);struct event *trace_find_event (int id);
@@ -248,4 +250,13 @@ void *raw_field_ptr(struct event *event, const char *name, void *data);void read_tracing_data (int fd,struct perf_event_attr *pattrs,int nb_events); +/* taken from kernel/trace/trace.h */ +enum trace_flag_type { +TRACE_FLAG_IRQS_OFF =0x01 , +TRACE_FLAG_IRQS_NOSUPPORT =0x02 , +TRACE_FLAG_NEED_RESCHED =0x04 , +TRACE_FLAG_HARDIRQ =0x08 , +TRACE_FLAG_SOFTIRQ =0x10 , +}; +#endif /* __PERF_TRACE_EVENTS_H */
Signature · 1 line
1.6.3.3
[tip:perf/core] perf tools: Add latency format to trace output
Commit-ID: cda48461c7fb8431a99b7960480f5f42cc1a5324 Gitweb: http://git.kernel.org/tip/cda48461c7fb8431a99b7960480f5f42cc1a5324 Author: Steven Rostedt <[email protected]> AuthorDate: Wed, 14 Oct 2009 15:43:42 -0400 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 15 Oct 2009 10:42:39 +0200
perf tools: Add latency format to trace output
Add the irqs disabled, preemption count, need resched, and other info that is shown in the latency format of ftrace.
# perf trace -l
perf-16457 2..s2. 53636.260344: kmem_cache_free: call_site=ffffffff811198f
perf-16457 2..s2. 53636.264330: kmem_cache_free: call_site=ffffffff811198f
perf-16457 2d.s4. 53636.300006: kmem_cache_free: call_site=ffffffff810d889LKML-Reference: <[email protected]>
--- tools/perf/builtin-trace.c | 2 + tools/perf/util/trace-event-parse.c | 120 +++++++++++++++++++++++++++++------ tools/perf/util/trace-event.h | 11 +++ 3 files changed, 114 insertions(+), 19 deletions(-)
tools/perf/builtin-trace.c +2 -0
@@ -144,6 +144,8 @@ static const struct option options[] = { "dump raw trace in ASCII"),OPT_BOOLEAN ('v' ,"verbose" , &verbose,"be more verbose (show symbol address, etc)" ), +OPT_BOOLEAN ('l' ,"latency" , &latency_format, +"show latency attributes (irqs/preemption disabled, etc)" ), OPT_END() };
tools/perf/util/trace-event-parse.c +101 -19
171 lines not on this page · raw message
tools/perf/util/trace-event.h +11 -0
@@ -239,6 +239,8 @@ extern int header_page_size_size;extern int header_page_data_offset;extern int header_page_data_size; +extern int latency_format; +int parse_header_page (char *buf,unsigned long size);int trace_parse_common_type (void *data);struct event *trace_find_event (int id);
@@ -248,4 +250,13 @@ void *raw_field_ptr(struct event *event, const char *name, void *data);void read_tracing_data (int fd,struct perf_event_attr *pattrs,int nb_events); +/* taken from kernel/trace/trace.h */ +enum trace_flag_type { +TRACE_FLAG_IRQS_OFF =0x01 , +TRACE_FLAG_IRQS_NOSUPPORT =0x02 , +TRACE_FLAG_NEED_RESCHED =0x04 , +TRACE_FLAG_HARDIRQ =0x08 , +TRACE_FLAG_SOFTIRQ =0x10 , +}; +#endif /* __PERF_TRACE_EVENTS_H */
PATCH 12/13 perf tools: handle - and + in parsing trace print format
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
The opterators '-' and '+' are not handled in the trace print format.
To do: '++' and '--'.
--- tools/perf/Makefile | 2 +- tools/perf/util/trace-event-parse.c | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletions(-)
tools/perf/Makefile +1 -1
@@ -194,7 +194,7 @@ EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wold-style-definition EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wstrict-prototypes EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wdeclaration-after-statement -CFLAGS = $(M64) -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -fstack-protector-all -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) +CFLAGS = $(M64) -ggdb3 -Wall -Wextra -std=gnu99 -Werror -fstack-protector-all -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) LDFLAGS = -lpthread -lrt -lelf -lm ALL_CFLAGS = $(CFLAGS) ALL_LDFLAGS = $(LDFLAGS)
tools/perf/util/trace-event-parse.c +6 -0
@@ -2106,6 +2106,12 @@ static unsigned long long eval_num_arg(void *data, int size,die ("unknown op '%s'" , arg->op.op); val = left == right;break ; +case '-' : + val = left - right; +break ; +case '+' : + val = left + right; +break ;default :die ("unknown op '%s'" , arg->op.op); }
Signature · 1 line
1.6.3.3
Re: [PATCH 12/13] [PATCH 12/13] perf tools: handle - and + in parsing trace print format
Quoted 17 lines · Steven Rostedt
From: Steven Rostedt <[email protected]>
The opterators '-' and '+' are not handled in the trace print format.
To do: '++' and '--'.
Signed-off-by Steven Rostedt <[email protected]>--- tools/perf/Makefile | 2 +- tools/perf/util/trace-event-parse.c | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletions(-)tools/perf/Makefile +0
-0
tools/perf/Makefile EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wold-style-definition · line 197
Quoted 5 lines
tools/perf/Makefile +1
-1@@ -194,7 +194,7 @@ EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wold-style-definition EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wstrict-prototypes EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wdeclaration-after-statement -CFLAGS = $(M64) -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -fstack-protector-all -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) +CFLAGS = $(M64) -ggdb3 -Wall -Wextra -std=gnu99 -Werror -fstack-protector-all -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS)
hm, why does this patch change the Makefile?
i've skipped this hunk, it does not appear to be connected to the commit.
Ingo
Peter Zijlstra
maintainerRe: [PATCH 12/13] [PATCH 12/13] perf tools: handle - and + in parsing trace print format
Quoted 7 lines · Ingo Molnar
tools/perf/Makefile EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wold-style-definition · line 197
Quoted 2 lines
tools/perf/Makefile +1
-1-CFLAGS = $(M64) -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -fstack-protector-all -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) +CFLAGS = $(M64) -ggdb3 -Wall -Wextra -std=gnu99 -Werror -fstack-protector-all -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS)hm, why does this patch change the
Makefile?i've skipped this hunk, it does not appear to be connected to the commit.
Probably because he wanted to debug things and O6 generates crappy gdb experience.. and then it slipped into the diff
Re: [PATCH 12/13] [PATCH 12/13] perf tools: handle - and + in parsing trace print format
Quoted 7 lines · Peter Zijlstra
Quoted 5 lines · Ingo Molnar
tools/perf/Makefile EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wold-style-definition · line 197
Quoted 2 lines
tools/perf/Makefile +1
-1-CFLAGS = $(M64) -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -fstack-protector-all -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) +CFLAGS = $(M64) -ggdb3 -Wall -Wextra -std=gnu99 -Werror -fstack-protector-all -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS)hm, why does this patch change the
Makefile?
Quoted 5 lines
Quoted 2 lines
i've skipped this hunk, it does not appear to be connected to the commit.
Probably because he wanted to debug things and O6 generates crappy gdb experience.. and then it slipped into the diff
Yeah, that's exactly what happened. Damn, I thought I put the -O6 back. This patch, I originally just did the '-', and thought. Hmm, it is trivial to do the '+'. So I added it and did a "git commit -a --amend", forgetting that I modified the Makefile.
This hunk can be ignored.
Thanks!
-- Steve
[tip:perf/core] perf tools: Handle - and + in parsing trace print format
In reply to Steven RostedtCommit-ID: afdf1a404eed236d6f762ee44cc0f1dcc97206e0 Gitweb: http://git.kernel.org/tip/afdf1a404eed236d6f762ee44cc0f1dcc97206e0 Author: Steven Rostedt <[email protected]> AuthorDate: Wed, 14 Oct 2009 15:43:43 -0400 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 15 Oct 2009 10:42:40 +0200
perf tools: Handle - and + in parsing trace print format
The opterators '-' and '+' are not handled in the trace print format.
To do: '++' and '--'.
LKML-Reference: <[email protected]>
--- tools/perf/util/trace-event-parse.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
tools/perf/util/trace-event-parse.c +6 -0
@@ -2106,6 +2106,12 @@ static unsigned long long eval_num_arg(void *data, int size,die ("unknown op '%s'" , arg->op.op); val = left == right;break ; +case '-' : + val = left - right; +break ; +case '+' : + val = left + right; +break ;default :die ("unknown op '%s'" , arg->op.op); }
PATCH 13/13 perf tools: remove all char * typecasts and use const in prototype
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
The (char *) for all the static strings was a fix for the symptom and not the disease. The real issue was that the function prototypes needed to be declared "const char *".
--- tools/perf/util/trace-event-parse.c | 131 ++++++++++++++++++----------------- 1 files changed, 66 insertions(+), 65 deletions(-)
tools/perf/util/trace-event-parse.c +66 -65
@@ -620,8 +620,8 @@ static int test_type(enum event_type type, enum event_type expect)return 0 ; } -static int test_type_token (enum event_type type,char *token, -enum event_type expect,char *expect_tok) +static int test_type_token (enum event_type type,const char *token, +enum event_type expect,const char *expect_tok) {if (type != expect) { warning("Error: expected type %d but read %d",
@@ -653,7 +653,8 @@ static int read_expect_type(enum event_type expect, char **tok)return __read_expect_type (expect, tok,1 ); } -static int __read_expected (enum event_type expect,char *str,int newline_ok) +static int __read_expected (enum event_type expect,const char *str, +int newline_ok) {enum event_type type;char *token;
@@ -671,12 +672,12 @@ static int __read_expected(enum event_type expect, char *str, int newline_ok)return ret; } -static int read_expected (enum event_type expect,char *str) +static int read_expected (enum event_type expect,const char *str) {return __read_expected (expect, str,1 ); } -static int read_expected_item (enum event_type expect,char *str) +static int read_expected_item (enum event_type expect,const char *str) {return __read_expected (expect, str,0 ); }
@@ -685,10 +686,10 @@ static char *event_read_name(void) {char *token; -if (read_expected (EVENT_ITEM , (char *)"name" ) <0 ) +if (read_expected (EVENT_ITEM ,"name" ) <0 )return NULL ; -if (read_expected (EVENT_OP , (char *)":" ) <0 ) +if (read_expected (EVENT_OP ,":" ) <0 )return NULL ;if (read_expect_type (EVENT_ITEM , &token) <0 )
@@ -706,10 +707,10 @@ static int event_read_id(void)char *token;int id; -if (read_expected_item (EVENT_ITEM , (char *)"ID" ) <0 ) +if (read_expected_item (EVENT_ITEM ,"ID" ) <0 )return -1 ; -if (read_expected (EVENT_OP , (char *)":" ) <0 ) +if (read_expected (EVENT_OP ,":" ) <0 )return -1 ;if (read_expect_type (EVENT_ITEM , &token) <0 )
@@ -759,7 +760,7 @@ static int event_read_fields(struct event *event, struct format_field **fields) count++; -if (test_type_token (type, token,EVENT_ITEM , (char *)"field" )) +if (test_type_token (type, token,EVENT_ITEM ,"field" )) goto fail;free_token (token);
@@ -774,7 +775,7 @@ static int event_read_fields(struct event *event, struct format_field **fields) type =read_token (&token); } -if (test_type_token (type, token,EVENT_OP , (char *)":" ) <0 ) +if (test_type_token (type, token,EVENT_OP ,":" ) <0 )return -1 ;if (read_expect_type (EVENT_ITEM , &token) <0 )
@@ -892,14 +893,14 @@ static int event_read_fields(struct event *event, struct format_field **fields) field->flags |=FIELD_IS_DYNAMIC ; } -if (test_type_token (type, token,EVENT_OP , (char *)";" )) +if (test_type_token (type, token,EVENT_OP ,";" )) goto fail;free_token (token); -if (read_expected (EVENT_ITEM , (char *)"offset" ) <0 ) +if (read_expected (EVENT_ITEM ,"offset" ) <0 ) goto fail_expect; -if (read_expected (EVENT_OP , (char *)":" ) <0 ) +if (read_expected (EVENT_OP ,":" ) <0 ) goto fail_expect;if (read_expect_type (EVENT_ITEM , &token))
@@ -907,13 +908,13 @@ static int event_read_fields(struct event *event, struct format_field **fields) field->offset =strtoul (token,NULL ,0 );free_token (token); -if (read_expected (EVENT_OP , (char *)";" ) <0 ) +if (read_expected (EVENT_OP ,";" ) <0 ) goto fail_expect; -if (read_expected (EVENT_ITEM , (char *)"size" ) <0 ) +if (read_expected (EVENT_ITEM ,"size" ) <0 ) goto fail_expect; -if (read_expected (EVENT_OP , (char *)":" ) <0 ) +if (read_expected (EVENT_OP ,":" ) <0 ) goto fail_expect;if (read_expect_type (EVENT_ITEM , &token))
@@ -921,18 +922,18 @@ static int event_read_fields(struct event *event, struct format_field **fields) field->size =strtoul (token,NULL ,0 );free_token (token); -if (read_expected (EVENT_OP , (char *)";" ) <0 ) +if (read_expected (EVENT_OP ,";" ) <0 ) goto fail_expect; type =read_token (&token);if (type !=EVENT_NEWLINE ) {/* newer versions of the kernel have a "signed" type */ -if (test_type_token (type, token,EVENT_ITEM , (char *)"signed" )) +if (test_type_token (type, token,EVENT_ITEM ,"signed" )) goto fail;free_token (token); -if (read_expected (EVENT_OP , (char *)":" ) <0 ) +if (read_expected (EVENT_OP ,":" ) <0 ) goto fail_expect;if (read_expect_type (EVENT_ITEM , &token))
@@ -941,7 +942,7 @@ static int event_read_fields(struct event *event, struct format_field **fields)/* add signed type */ free_token (token); -if (read_expected (EVENT_OP , (char *)";" ) <0 ) +if (read_expected (EVENT_OP ,";" ) <0 ) goto fail_expect;if (read_expect_type (EVENT_NEWLINE , &token))
@@ -970,10 +971,10 @@ static int event_read_format(struct event *event)char *token;int ret; -if (read_expected_item (EVENT_ITEM , (char *)"format" ) <0 ) +if (read_expected_item (EVENT_ITEM ,"format" ) <0 )return -1 ; -if (read_expected (EVENT_OP , (char *)":" ) <0 ) +if (read_expected (EVENT_OP ,":" ) <0 )return -1 ;if (read_expect_type (EVENT_NEWLINE , &token))
@@ -1033,7 +1034,7 @@ process_cond(struct event *event, struct print_arg *top, char **tok) *tok =NULL ; type =process_arg (event, left, &token); -if (test_type_token (type, token,EVENT_OP , (char *)":" )) +if (test_type_token (type, token,EVENT_OP ,":" )) goto out_free; arg->op.op = token;
@@ -1065,7 +1066,7 @@ process_array(struct event *event, struct print_arg *top, char **tok) *tok =NULL ; type =process_arg (event, arg, &token); -if (test_type_token (type, token,EVENT_OP , (char *)"]" )) +if (test_type_token (type, token,EVENT_OP ,"]" )) goto out_free; top->op.right = arg;
@@ -1287,7 +1288,7 @@ process_entry(struct event *event __unused, struct print_arg *arg,char *field;char *token; -if (read_expected (EVENT_OP , (char *)"->" ) <0 ) +if (read_expected (EVENT_OP ,"->" ) <0 )return EVENT_ERROR ;if (read_expect_type (EVENT_ITEM , &token) <0 )
@@ -1447,14 +1448,14 @@ process_fields(struct event *event, struct print_flag_sym **list, char **tok) do { free_token(token); type = read_token_item(&token); - if (test_type_token(type, token, EVENT_OP, (char *)"{")) + if (test_type_token(type, token, EVENT_OP, "{")) break; arg = malloc_or_die(sizeof(*arg)); free_token(token); type = process_arg(event, arg, &token); - if (test_type_token(type, token, EVENT_DELIM, (char *)",")) + if (test_type_token(type, token, EVENT_DELIM, ",")) goto out_free; field = malloc_or_die(sizeof(*field));
@@ -1465,7 +1466,7 @@ process_fields(struct event *event, struct print_flag_sym **list, char **tok)free_token (token); type =process_arg (event, arg, &token); -if (test_type_token (type, token,EVENT_OP , (char *)"}" )) +if (test_type_token (type, token,EVENT_OP ,"}" )) goto out_free; value =arg_eval (arg);
@@ -1500,13 +1501,13 @@ process_flags(struct event *event, struct print_arg *arg, char **tok)memset (arg,0 ,sizeof (*arg)); arg->type =PRINT_FLAGS ; -if (read_expected_item (EVENT_DELIM , (char *)"(" ) <0 ) +if (read_expected_item (EVENT_DELIM ,"(" ) <0 )return EVENT_ERROR ; field =malloc_or_die (sizeof (*field)); type =process_arg (event, field, &token); -if (test_type_token (type, token,EVENT_DELIM , (char *)"," )) +if (test_type_token (type, token,EVENT_DELIM ,"," )) goto out_free; arg->flags.field = field;
@@ -1517,11 +1518,11 @@ process_flags(struct event *event, struct print_arg *arg, char **tok) type =read_token_item (&token); } -if (test_type_token (type, token,EVENT_DELIM , (char *)"," )) +if (test_type_token (type, token,EVENT_DELIM ,"," )) goto out_free; type =process_fields (event, &arg->flags.flags, &token); -if (test_type_token (type, token,EVENT_DELIM , (char *)")" )) +if (test_type_token (type, token,EVENT_DELIM ,")" )) goto out_free;free_token (token);
@@ -1543,19 +1544,19 @@ process_symbols(struct event *event, struct print_arg *arg, char **tok)memset (arg,0 ,sizeof (*arg)); arg->type =PRINT_SYMBOL ; -if (read_expected_item (EVENT_DELIM , (char *)"(" ) <0 ) +if (read_expected_item (EVENT_DELIM ,"(" ) <0 )return EVENT_ERROR ; field =malloc_or_die (sizeof (*field)); type =process_arg (event, field, &token); -if (test_type_token (type, token,EVENT_DELIM , (char *)"," )) +if (test_type_token (type, token,EVENT_DELIM ,"," )) goto out_free; arg->symbol.field = field; type =process_fields (event, &arg->symbol.symbols, &token); -if (test_type_token (type, token,EVENT_DELIM , (char *)")" )) +if (test_type_token (type, token,EVENT_DELIM ,")" )) goto out_free;free_token (token);
@@ -1585,7 +1586,7 @@ process_paren(struct event *event, struct print_arg *arg, char **tok)if (type ==EVENT_ERROR )return EVENT_ERROR ; -if (test_type_token (type, token,EVENT_DELIM , (char *)")" )) { +if (test_type_token (type, token,EVENT_DELIM ,")" )) {free_token (token);return EVENT_ERROR ; }
@@ -1626,7 +1627,7 @@ process_str(struct event *event __unused, struct print_arg *arg, char **tok)enum event_type type;char *token; -if (read_expected (EVENT_DELIM , (char *)"(" ) <0 ) +if (read_expected (EVENT_DELIM ,"(" ) <0 )return EVENT_ERROR ;if (read_expect_type (EVENT_ITEM , &token) <0 )
@@ -1636,7 +1637,7 @@ process_str(struct event *event __unused, struct print_arg *arg, char **tok) arg->string.string = token; arg->string.offset =-1 ; -if (read_expected (EVENT_DELIM , (char *)")" ) <0 ) +if (read_expected (EVENT_DELIM ,")" ) <0 )return EVENT_ERROR ; type =read_token (&token);
@@ -1775,13 +1776,13 @@ static int event_read_print(struct event *event)char *token;int ret; -if (read_expected_item (EVENT_ITEM , (char *)"print" ) <0 ) +if (read_expected_item (EVENT_ITEM ,"print" ) <0 )return -1 ; -if (read_expected (EVENT_ITEM , (char *)"fmt" ) <0 ) +if (read_expected (EVENT_ITEM ,"fmt" ) <0 )return -1 ; -if (read_expected (EVENT_OP , (char *)":" ) <0 ) +if (read_expected (EVENT_OP ,":" ) <0 )return -1 ;if (read_expect_type (EVENT_DQUOTE , &token) <0 )
@@ -1812,7 +1813,7 @@ static int event_read_print(struct event *event) goto concat; } -if (test_type_token (type, token,EVENT_DELIM , (char *)"," )) +if (test_type_token (type, token,EVENT_DELIM ,"," )) goto fail;free_token (token);
@@ -1931,7 +1932,7 @@ static int get_common_info(const char *type, int *offset, int *size) }static int __parse_common (void *data,int *size,int *offset, -char *name) +const char *name) {int ret;
@@ -1949,7 +1950,7 @@ int trace_parse_common_type(void *data)static int type_size;return __parse_common (data, &type_size, &type_offset, - (char *)"common_type" ); +"common_type" ); }static int parse_common_pid (void *data)
@@ -1958,7 +1959,7 @@ static int parse_common_pid(void *data)static int pid_size;return __parse_common (data, &pid_size, &pid_offset, - (char *)"common_pid" ); +"common_pid" ); }static int parse_common_pc (void *data)
@@ -1967,7 +1968,7 @@ static int parse_common_pc(void *data)static int pc_size;return __parse_common (data, &pc_size, &pc_offset, - (char *)"common_preempt_count" ); +"common_preempt_count" ); }static int parse_common_flags (void *data)
@@ -1976,7 +1977,7 @@ static int parse_common_flags(void *data)static int flags_size;return __parse_common (data, &flags_size, &flags_offset, - (char *)"common_flags" ); +"common_flags" ); }static int parse_common_lock_depth (void *data)
@@ -1986,7 +1987,7 @@ static int parse_common_lock_depth(void *data)int ret; ret =__parse_common (data, &ld_size, &ld_offset, - (char *)"common_lock_depth" ); +"common_lock_depth" );if (ret <0 )return -1 ;
@@ -3049,15 +3050,15 @@ static void print_args(struct print_arg *args) } } -static void parse_header_field (char *field, +static void parse_header_field (const char *field,int *offset,int *size) {char *token;int type; -if (read_expected (EVENT_ITEM , (char *)"field" ) <0 ) +if (read_expected (EVENT_ITEM ,"field" ) <0 )return ; -if (read_expected (EVENT_OP , (char *)":" ) <0 ) +if (read_expected (EVENT_OP ,":" ) <0 )return ;/* type */
@@ -3067,27 +3068,27 @@ static void parse_header_field(char *field,if (read_expected (EVENT_ITEM , field) <0 )return ; -if (read_expected (EVENT_OP , (char *)";" ) <0 ) +if (read_expected (EVENT_OP ,";" ) <0 )return ; -if (read_expected (EVENT_ITEM , (char *)"offset" ) <0 ) +if (read_expected (EVENT_ITEM ,"offset" ) <0 )return ; -if (read_expected (EVENT_OP , (char *)":" ) <0 ) +if (read_expected (EVENT_OP ,":" ) <0 )return ;if (read_expect_type (EVENT_ITEM , &token) <0 ) goto fail; *offset =atoi (token);free_token (token); -if (read_expected (EVENT_OP , (char *)";" ) <0 ) +if (read_expected (EVENT_OP ,";" ) <0 )return ; -if (read_expected (EVENT_ITEM , (char *)"size" ) <0 ) +if (read_expected (EVENT_ITEM ,"size" ) <0 )return ; -if (read_expected (EVENT_OP , (char *)":" ) <0 ) +if (read_expected (EVENT_OP ,":" ) <0 )return ;if (read_expect_type (EVENT_ITEM , &token) <0 ) goto fail; *size =atoi (token);free_token (token); -if (read_expected (EVENT_OP , (char *)";" ) <0 ) +if (read_expected (EVENT_OP ,";" ) <0 )return ; type =read_token (&token);if (type !=EVENT_NEWLINE ) {
@@ -3095,19 +3096,19 @@ static void parse_header_field(char *field,if (type !=EVENT_ITEM ) goto fail; -if (strcmp (token, (char *)"signed" ) !=0 ) +if (strcmp (token,"signed" ) !=0 ) goto fail;free_token (token); -if (read_expected (EVENT_OP , (char *)":" ) <0 ) +if (read_expected (EVENT_OP ,":" ) <0 )return ;if (read_expect_type (EVENT_ITEM , &token)) goto fail;free_token (token); -if (read_expected (EVENT_OP , (char *)";" ) <0 ) +if (read_expected (EVENT_OP ,";" ) <0 )return ;if (read_expect_type (EVENT_NEWLINE , &token))
@@ -3121,11 +3122,11 @@ int parse_header_page(char *buf, unsigned long size) {init_input_buf (buf, size); -parse_header_field ((char *)"timestamp" , &header_page_ts_offset, +parse_header_field ("timestamp" , &header_page_ts_offset, &header_page_ts_size); -parse_header_field ((char *)"commit" , &header_page_size_offset, +parse_header_field ("commit" , &header_page_size_offset, &header_page_size_size); -parse_header_field ((char *)"data" , &header_page_data_offset, +parse_header_field ("data" , &header_page_data_offset, &header_page_data_size);return 0 ;
Signature · 1 line
1.6.3.3
Re: [PATCH 13/13] [PATCH 13/13] perf tools: remove all char * typecasts and use const in prototype
Quoted 8 lines · Steven Rostedt
From: Steven Rostedt <[email protected]>
The (char *) for all the static strings was a fix for the symptom and not the disease. The real issue was that the function prototypes needed to be declared "const char *".
Signed-off-by Steven Rostedt <[email protected]>---
Yep.
I know it's a shame what I did. I was just harassed by tons of warnings when I integrated trace-cmd into perf (because of its gcc flags) and then I was too impatient and did the wrong thing :)
Thanks.
[tip:perf/core] perf tools: Remove all char * typecasts and use const in prototype
In reply to Steven RostedtCommit-ID: c4dc775f53136cd6af8f88bce67cce9b42751768 Gitweb: http://git.kernel.org/tip/c4dc775f53136cd6af8f88bce67cce9b42751768 Author: Steven Rostedt <[email protected]> AuthorDate: Wed, 14 Oct 2009 15:43:44 -0400 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 15 Oct 2009 10:43:17 +0200
perf tools: Remove all char * typecasts and use const in prototype
The (char *) for all the static strings was a fix for the symptom and not the disease. The real issue was that the function prototypes needed to be declared "const char *".
LKML-Reference: <[email protected]>
--- tools/perf/util/trace-event-parse.c | 122 +++++++++++++++++----------------- 1 files changed, 61 insertions(+), 61 deletions(-)
tools/perf/util/trace-event-parse.c +61 -61
@@ -685,10 +685,10 @@ static char *event_read_name(void) {char *token; -if (read_expected (EVENT_ITEM , (char *)"name" ) <0 ) +if (read_expected (EVENT_ITEM ,"name" ) <0 )return NULL ; -if (read_expected (EVENT_OP , (char *)":" ) <0 ) +if (read_expected (EVENT_OP ,":" ) <0 )return NULL ;if (read_expect_type (EVENT_ITEM , &token) <0 )
@@ -706,10 +706,10 @@ static int event_read_id(void)char *token;int id; -if (read_expected_item (EVENT_ITEM , (char *)"ID" ) <0 ) +if (read_expected_item (EVENT_ITEM ,"ID" ) <0 )return -1 ; -if (read_expected (EVENT_OP , (char *)":" ) <0 ) +if (read_expected (EVENT_OP ,":" ) <0 )return -1 ;if (read_expect_type (EVENT_ITEM , &token) <0 )
@@ -759,7 +759,7 @@ static int event_read_fields(struct event *event, struct format_field **fields) count++; -if (test_type_token (type, token,EVENT_ITEM , (char *)"field" )) +if (test_type_token (type, token,EVENT_ITEM ,"field" )) goto fail;free_token (token);
@@ -774,7 +774,7 @@ static int event_read_fields(struct event *event, struct format_field **fields) type =read_token (&token); } -if (test_type_token (type, token,EVENT_OP , (char *)":" ) <0 ) +if (test_type_token (type, token,EVENT_OP ,":" ) <0 )return -1 ;if (read_expect_type (EVENT_ITEM , &token) <0 )
@@ -892,14 +892,14 @@ static int event_read_fields(struct event *event, struct format_field **fields) field->flags |=FIELD_IS_DYNAMIC ; } -if (test_type_token (type, token,EVENT_OP , (char *)";" )) +if (test_type_token (type, token,EVENT_OP ,";" )) goto fail;free_token (token); -if (read_expected (EVENT_ITEM , (char *)"offset" ) <0 ) +if (read_expected (EVENT_ITEM ,"offset" ) <0 ) goto fail_expect; -if (read_expected (EVENT_OP , (char *)":" ) <0 ) +if (read_expected (EVENT_OP ,":" ) <0 ) goto fail_expect;if (read_expect_type (EVENT_ITEM , &token))
@@ -907,13 +907,13 @@ static int event_read_fields(struct event *event, struct format_field **fields) field->offset =strtoul (token,NULL ,0 );free_token (token); -if (read_expected (EVENT_OP , (char *)";" ) <0 ) +if (read_expected (EVENT_OP ,";" ) <0 ) goto fail_expect; -if (read_expected (EVENT_ITEM , (char *)"size" ) <0 ) +if (read_expected (EVENT_ITEM ,"size" ) <0 ) goto fail_expect; -if (read_expected (EVENT_OP , (char *)":" ) <0 ) +if (read_expected (EVENT_OP ,":" ) <0 ) goto fail_expect;if (read_expect_type (EVENT_ITEM , &token))
@@ -921,18 +921,18 @@ static int event_read_fields(struct event *event, struct format_field **fields) field->size =strtoul (token,NULL ,0 );free_token (token); -if (read_expected (EVENT_OP , (char *)";" ) <0 ) +if (read_expected (EVENT_OP ,";" ) <0 ) goto fail_expect; type =read_token (&token);if (type !=EVENT_NEWLINE ) {/* newer versions of the kernel have a "signed" type */ -if (test_type_token (type, token,EVENT_ITEM , (char *)"signed" )) +if (test_type_token (type, token,EVENT_ITEM ,"signed" )) goto fail;free_token (token); -if (read_expected (EVENT_OP , (char *)":" ) <0 ) +if (read_expected (EVENT_OP ,":" ) <0 ) goto fail_expect;if (read_expect_type (EVENT_ITEM , &token))
@@ -941,7 +941,7 @@ static int event_read_fields(struct event *event, struct format_field **fields)/* add signed type */ free_token (token); -if (read_expected (EVENT_OP , (char *)";" ) <0 ) +if (read_expected (EVENT_OP ,";" ) <0 ) goto fail_expect;if (read_expect_type (EVENT_NEWLINE , &token))
@@ -970,10 +970,10 @@ static int event_read_format(struct event *event)char *token;int ret; -if (read_expected_item (EVENT_ITEM , (char *)"format" ) <0 ) +if (read_expected_item (EVENT_ITEM ,"format" ) <0 )return -1 ; -if (read_expected (EVENT_OP , (char *)":" ) <0 ) +if (read_expected (EVENT_OP ,":" ) <0 )return -1 ;if (read_expect_type (EVENT_NEWLINE , &token))
@@ -1033,7 +1033,7 @@ process_cond(struct event *event, struct print_arg *top, char **tok) *tok =NULL ; type =process_arg (event, left, &token); -if (test_type_token (type, token,EVENT_OP , (char *)":" )) +if (test_type_token (type, token,EVENT_OP ,":" )) goto out_free; arg->op.op = token;
@@ -1065,7 +1065,7 @@ process_array(struct event *event, struct print_arg *top, char **tok) *tok =NULL ; type =process_arg (event, arg, &token); -if (test_type_token (type, token,EVENT_OP , (char *)"]" )) +if (test_type_token (type, token,EVENT_OP ,"]" )) goto out_free; top->op.right = arg;
@@ -1287,7 +1287,7 @@ process_entry(struct event *event __unused, struct print_arg *arg,char *field;char *token; -if (read_expected (EVENT_OP , (char *)"->" ) <0 ) +if (read_expected (EVENT_OP ,"->" ) <0 )return EVENT_ERROR ;if (read_expect_type (EVENT_ITEM , &token) <0 )
@@ -1447,14 +1447,14 @@ process_fields(struct event *event, struct print_flag_sym **list, char **tok) do { free_token(token); type = read_token_item(&token); - if (test_type_token(type, token, EVENT_OP, (char *)"{")) + if (test_type_token(type, token, EVENT_OP, "{")) break; arg = malloc_or_die(sizeof(*arg)); free_token(token); type = process_arg(event, arg, &token); - if (test_type_token(type, token, EVENT_DELIM, (char *)",")) + if (test_type_token(type, token, EVENT_DELIM, ",")) goto out_free; field = malloc_or_die(sizeof(*field));
@@ -1465,7 +1465,7 @@ process_fields(struct event *event, struct print_flag_sym **list, char **tok)free_token (token); type =process_arg (event, arg, &token); -if (test_type_token (type, token,EVENT_OP , (char *)"}" )) +if (test_type_token (type, token,EVENT_OP ,"}" )) goto out_free; value =arg_eval (arg);
@@ -1500,13 +1500,13 @@ process_flags(struct event *event, struct print_arg *arg, char **tok)memset (arg,0 ,sizeof (*arg)); arg->type =PRINT_FLAGS ; -if (read_expected_item (EVENT_DELIM , (char *)"(" ) <0 ) +if (read_expected_item (EVENT_DELIM ,"(" ) <0 )return EVENT_ERROR ; field =malloc_or_die (sizeof (*field)); type =process_arg (event, field, &token); -if (test_type_token (type, token,EVENT_DELIM , (char *)"," )) +if (test_type_token (type, token,EVENT_DELIM ,"," )) goto out_free; arg->flags.field = field;
@@ -1517,11 +1517,11 @@ process_flags(struct event *event, struct print_arg *arg, char **tok) type =read_token_item (&token); } -if (test_type_token (type, token,EVENT_DELIM , (char *)"," )) +if (test_type_token (type, token,EVENT_DELIM ,"," )) goto out_free; type =process_fields (event, &arg->flags.flags, &token); -if (test_type_token (type, token,EVENT_DELIM , (char *)")" )) +if (test_type_token (type, token,EVENT_DELIM ,")" )) goto out_free;free_token (token);
@@ -1543,19 +1543,19 @@ process_symbols(struct event *event, struct print_arg *arg, char **tok)memset (arg,0 ,sizeof (*arg)); arg->type =PRINT_SYMBOL ; -if (read_expected_item (EVENT_DELIM , (char *)"(" ) <0 ) +if (read_expected_item (EVENT_DELIM ,"(" ) <0 )return EVENT_ERROR ; field =malloc_or_die (sizeof (*field)); type =process_arg (event, field, &token); -if (test_type_token (type, token,EVENT_DELIM , (char *)"," )) +if (test_type_token (type, token,EVENT_DELIM ,"," )) goto out_free; arg->symbol.field = field; type =process_fields (event, &arg->symbol.symbols, &token); -if (test_type_token (type, token,EVENT_DELIM , (char *)")" )) +if (test_type_token (type, token,EVENT_DELIM ,")" )) goto out_free;free_token (token);
@@ -1585,7 +1585,7 @@ process_paren(struct event *event, struct print_arg *arg, char **tok)if (type ==EVENT_ERROR )return EVENT_ERROR ; -if (test_type_token (type, token,EVENT_DELIM , (char *)")" )) { +if (test_type_token (type, token,EVENT_DELIM ,")" )) {free_token (token);return EVENT_ERROR ; }
@@ -1626,7 +1626,7 @@ process_str(struct event *event __unused, struct print_arg *arg, char **tok)enum event_type type;char *token; -if (read_expected (EVENT_DELIM , (char *)"(" ) <0 ) +if (read_expected (EVENT_DELIM ,"(" ) <0 )return EVENT_ERROR ;if (read_expect_type (EVENT_ITEM , &token) <0 )
@@ -1636,7 +1636,7 @@ process_str(struct event *event __unused, struct print_arg *arg, char **tok) arg->string.string = token; arg->string.offset =-1 ; -if (read_expected (EVENT_DELIM , (char *)")" ) <0 ) +if (read_expected (EVENT_DELIM ,")" ) <0 )return EVENT_ERROR ; type =read_token (&token);
@@ -1775,13 +1775,13 @@ static int event_read_print(struct event *event)char *token;int ret; -if (read_expected_item (EVENT_ITEM , (char *)"print" ) <0 ) +if (read_expected_item (EVENT_ITEM ,"print" ) <0 )return -1 ; -if (read_expected (EVENT_ITEM , (char *)"fmt" ) <0 ) +if (read_expected (EVENT_ITEM ,"fmt" ) <0 )return -1 ; -if (read_expected (EVENT_OP , (char *)":" ) <0 ) +if (read_expected (EVENT_OP ,":" ) <0 )return -1 ;if (read_expect_type (EVENT_DQUOTE , &token) <0 )
@@ -1811,8 +1811,8 @@ static int event_read_print(struct event *event) token = cat; goto concat; } - -if (test_type_token (type, token,EVENT_DELIM , (char *)"," )) + +if (test_type_token (type, token,EVENT_DELIM ,"," )) goto fail;free_token (token);
@@ -1931,7 +1931,7 @@ static int get_common_info(const char *type, int *offset, int *size) }static int __parse_common (void *data,int *size,int *offset, -char *name) +const char *name) {int ret;
@@ -1949,7 +1949,7 @@ int trace_parse_common_type(void *data)static int type_size;return __parse_common (data, &type_size, &type_offset, - (char *)"common_type" ); +"common_type" ); }static int parse_common_pid (void *data)
@@ -1958,7 +1958,7 @@ static int parse_common_pid(void *data)static int pid_size;return __parse_common (data, &pid_size, &pid_offset, - (char *)"common_pid" ); +"common_pid" ); }static int parse_common_pc (void *data)
@@ -1967,7 +1967,7 @@ static int parse_common_pc(void *data)static int pc_size;return __parse_common (data, &pc_size, &pc_offset, - (char *)"common_preempt_count" ); +"common_preempt_count" ); }static int parse_common_flags (void *data)
@@ -1976,7 +1976,7 @@ static int parse_common_flags(void *data)static int flags_size;return __parse_common (data, &flags_size, &flags_offset, - (char *)"common_flags" ); +"common_flags" ); }static int parse_common_lock_depth (void *data)
@@ -1986,7 +1986,7 @@ static int parse_common_lock_depth(void *data)int ret; ret =__parse_common (data, &ld_size, &ld_offset, - (char *)"common_lock_depth" ); +"common_lock_depth" );if (ret <0 )return -1 ;
@@ -3049,15 +3049,15 @@ static void print_args(struct print_arg *args) } } -static void parse_header_field (char *field, +static void parse_header_field (const char *field,int *offset,int *size) {char *token;int type; -if (read_expected (EVENT_ITEM , (char *)"field" ) <0 ) +if (read_expected (EVENT_ITEM ,"field" ) <0 )return ; -if (read_expected (EVENT_OP , (char *)":" ) <0 ) +if (read_expected (EVENT_OP ,":" ) <0 )return ;/* type */
@@ -3067,27 +3067,27 @@ static void parse_header_field(char *field,if (read_expected (EVENT_ITEM , field) <0 )return ; -if (read_expected (EVENT_OP , (char *)";" ) <0 ) +if (read_expected (EVENT_OP ,";" ) <0 )return ; -if (read_expected (EVENT_ITEM , (char *)"offset" ) <0 ) +if (read_expected (EVENT_ITEM ,"offset" ) <0 )return ; -if (read_expected (EVENT_OP , (char *)":" ) <0 ) +if (read_expected (EVENT_OP ,":" ) <0 )return ;if (read_expect_type (EVENT_ITEM , &token) <0 ) goto fail; *offset =atoi (token);free_token (token); -if (read_expected (EVENT_OP , (char *)";" ) <0 ) +if (read_expected (EVENT_OP ,";" ) <0 )return ; -if (read_expected (EVENT_ITEM , (char *)"size" ) <0 ) +if (read_expected (EVENT_ITEM ,"size" ) <0 )return ; -if (read_expected (EVENT_OP , (char *)":" ) <0 ) +if (read_expected (EVENT_OP ,":" ) <0 )return ;if (read_expect_type (EVENT_ITEM , &token) <0 ) goto fail; *size =atoi (token);free_token (token); -if (read_expected (EVENT_OP , (char *)";" ) <0 ) +if (read_expected (EVENT_OP ,";" ) <0 )return ; type =read_token (&token);if (type !=EVENT_NEWLINE ) {
@@ -3095,19 +3095,19 @@ static void parse_header_field(char *field,if (type !=EVENT_ITEM ) goto fail; -if (strcmp (token, (char *)"signed" ) !=0 ) +if (strcmp (token,"signed" ) !=0 ) goto fail;free_token (token); -if (read_expected (EVENT_OP , (char *)":" ) <0 ) +if (read_expected (EVENT_OP ,":" ) <0 )return ;if (read_expect_type (EVENT_ITEM , &token)) goto fail;free_token (token); -if (read_expected (EVENT_OP , (char *)";" ) <0 ) +if (read_expected (EVENT_OP ,";" ) <0 )return ;if (read_expect_type (EVENT_NEWLINE , &token))
@@ -3121,11 +3121,11 @@ int parse_header_page(char *buf, unsigned long size) {init_input_buf (buf, size); -parse_header_field ((char *)"timestamp" , &header_page_ts_offset, +parse_header_field ("timestamp" , &header_page_ts_offset, &header_page_ts_size); -parse_header_field ((char *)"commit" , &header_page_size_offset, +parse_header_field ("commit" , &header_page_size_offset, &header_page_size_size); -parse_header_field ((char *)"data" , &header_page_data_offset, +parse_header_field ("data" , &header_page_data_offset, &header_page_data_size);return 0 ;
Ingo Molnar
AppliedQuoted 23 lines · Steven Rostedt
Ingo,
Please pull the latest perf/core tree, which can be found at:
git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-2.6-trace.git
perf/coreSteven Rostedt (13):
perf tools: handle print concatinations in event format file perf tools: fix backslash processing on trace print formats perf tools: handle trace parsing of '<' and '>'
perf tools: handle arrays in print fields for trace parsing perf tools: handle '*' as typecast in trace parsing
perf tools: handle newlines in trace parsing better
perf tools: handle the case with and without the "signed" trace field perf tools: still continue on failed parsing of an event perf tools: fix bprintk reading in trace output
perf tools: handle both versions of ftrace output
perf tools: add latency format to trace output
perf tools: handle '-' and '+' in parsing trace print format perf tools: remove all char * typecasts and use const in prototype
Quoted 6 lines
----
tools/perf/Makefile | 2 +- tools/perf/builtin-trace.c | 2 + tools/perf/util/trace-event-parse.c | 533 +++++++++++++++++++++++++---------- tools/perf/util/trace-event.h | 25 ++- 4 files changed, 405 insertions(+), 157 deletions(-)
Applied, thanks Steve! Very nice changes/fixes!
Ingo
[PATCH 0/2] [GIT PULL] perf tools: trace parse fix and debug compiling
Ingo,
Please pull the latest perf/core tree, which can be found at:
git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-2.6-trace.git
perf/core
Steven Rostedt (2):
perf tools: add make DEBUG=1 to remove the -O6 cflag perf tools: use strsep over strtok_r for parsing single line
----
tools/perf/Makefile | 9 ++++++++- tools/perf/util/trace-event-parse.c | 9 ++++++--- 2 files changed, 14 insertions(+), 4 deletions(-)
PATCH 1/2 perf tools: add make DEBUG=1 to remove the -O6 cflag
From: Steven Rostedt <[email protected]>
When using gdb to debug perf, it is practically impossible to use when perf is compiled with -O6. For developers, this patch adds the DEBUG feature to the make command line so that a developer can easily remove the optimization flag.
Cc: Peter Zijlstra <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Arnaldo Carvalho de Melo <[email protected]>
Cc: Ingo Molnar <[email protected]>
LKML-Reference: <1255590330.8392.446.camel@twins>
--- tools/perf/Makefile | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-)
tools/perf/Makefile +8 -1
@@ -201,7 +201,14 @@ EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wold-style-definition EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wstrict-prototypes EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wdeclaration-after-statement -CFLAGS = $(MBITS) -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -fstack-protector-all -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) +ifeq ("$(origin DEBUG)", "command line") + PERF_DEBUG = $(DEBUG) +endif +ifndef PERF_DEBUG + CFLAGS_OPTIMIZE = -O6 +endif + +CFLAGS = $(MBITS) -ggdb3 -Wall -Wextra -std=gnu99 -Werror $(CFLAGS_OPTIMIZE) -fstack-protector-all -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) LDFLAGS = -lpthread -lrt -lelf -lm ALL_CFLAGS = $(CFLAGS) ALL_LDFLAGS = $(LDFLAGS)
Signature · 1 line
1.6.3.3
[tip:branch?] perf tools: Add 'make DEBUG=1' to remove the -O6 cflag
Commit-ID: 60d526f7fa6246b8e32d5b45610d625a5608d988 Gitweb: http://git.kernel.org/tip/60d526f7fa6246b8e32d5b45610d625a5608d988 Author: Steven Rostedt <[email protected]> AuthorDate: Tue, 20 Oct 2009 19:19:34 -0400 Committer: Ingo Molnar <[email protected]> CommitDate: Wed, 21 Oct 2009 13:39:57 +0200
perf tools: Add 'make DEBUG=1' to remove the -O6 cflag
When using gdb to debug perf, it is practically impossible to use when perf is compiled with -O6. For developers, this patch adds the DEBUG feature to the make command line so that a developer can easily remove the optimization flag.
LKML-Reference: <1255590330.8392.446.camel@twins>
LKML-Reference: <[email protected]>
--- tools/perf/Makefile | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-)
tools/perf/Makefile +8 -1
@@ -201,7 +201,14 @@ EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wold-style-definition EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wstrict-prototypes EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wdeclaration-after-statement -CFLAGS = $(MBITS) -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -fstack-protector-all -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) +ifeq ("$(origin DEBUG)", "command line") + PERF_DEBUG = $(DEBUG) +endif +ifndef PERF_DEBUG + CFLAGS_OPTIMIZE = -O6 +endif + +CFLAGS = $(MBITS) -ggdb3 -Wall -Wextra -std=gnu99 -Werror $(CFLAGS_OPTIMIZE) -fstack-protector-all -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) LDFLAGS = -lpthread -lrt -lelf -lm ALL_CFLAGS = $(CFLAGS) ALL_LDFLAGS = $(LDFLAGS)
PATCH 2/2 perf tools: use strsep over strtok_r for parsing single line
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
The second argument in the strtok_r is not to be used generically and can have different implementations. Currently the function parsing of the perf trace code uses the second argument to copy data from. This can crash the tool or just have unpredictable results.
The correct solution is to use strsep which has a defined result.
I also added a check to see if the result was correct, and will break out of the loop in case it fails to parse as expected.
LKML-Reference: <[email protected]>
--- tools/perf/util/trace-event-parse.c | 9 ++++++--- 1 files changed, 6 insertions(+), 3 deletions(-)
tools/perf/util/trace-event-parse.c +6 -3
@@ -286,16 +286,19 @@ void parse_ftrace_printk(char *file, unsigned int size __unused)char *line;char *next =NULL ;char *addr_str; -char *fmt;int i; line =strtok_r (file,"\n" , &next);while (line) { + addr_str =strsep (&line,":" ); +if (!line) { +warning ("error parsing print strings" ); +break ; + } item =malloc_or_die (sizeof (*item)); - addr_str =strtok_r (line,":" , &fmt); item->addr =strtoull (addr_str,NULL ,16 );/* fmt still has a space, skip it */ - item->printk =strdup (fmt+1 ); + item->printk =strdup (line+1 ); item->next = list; list = item; line =strtok_r (NULL ,"\n" , &next);
Signature · 1 line
1.6.3.3
[tip:branch?] perf tools: Use strsep() over strtok_r() for parsing single line
Commit-ID: 4e3b799d7dbb2a12ca8dca8d3594d32095772973 Gitweb: http://git.kernel.org/tip/4e3b799d7dbb2a12ca8dca8d3594d32095772973 Author: Steven Rostedt <[email protected]> AuthorDate: Tue, 20 Oct 2009 19:19:35 -0400 Committer: Ingo Molnar <[email protected]> CommitDate: Wed, 21 Oct 2009 13:39:57 +0200
perf tools: Use strsep() over strtok_r() for parsing single line
The second argument in the strtok_r() function is not to be used generically and can have different implementations. Currently the function parsing of the perf trace code uses the second argument to copy data from. This can crash the tool or just have unpredictable results.
The correct solution is to use strsep() which has a defined result.
I also added a check to see if the result was correct, and will break out of the loop in case it fails to parse as expected.
LKML-Reference: <[email protected]>
--- tools/perf/util/trace-event-parse.c | 9 ++++++--- 1 files changed, 6 insertions(+), 3 deletions(-)
tools/perf/util/trace-event-parse.c +6 -3
@@ -286,16 +286,19 @@ void parse_ftrace_printk(char *file, unsigned int size __unused)char *line;char *next =NULL ;char *addr_str; -char *fmt;int i; line =strtok_r (file,"\n" , &next);while (line) { + addr_str =strsep (&line,":" ); +if (!line) { +warning ("error parsing print strings" ); +break ; + } item =malloc_or_die (sizeof (*item)); - addr_str =strtok_r (line,":" , &fmt); item->addr =strtoull (addr_str,NULL ,16 );/* fmt still has a space, skip it */ - item->printk =strdup (fmt+1 ); + item->printk =strdup (line+1 ); item->next = list; list = item; line =strtok_r (NULL ,"\n" , &next);