[tip:perf/core] perf tools: Handle arrays in print fields for trace parsing

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: tip-bot for Steven Rostedt
Date: Thursday, October 15, 2009 - 1:48 am

Commit-ID:  0959b8d65ce26131c2d5ccfa518a7b76529280fa
Gitweb:     http://git.kernel.org/tip/0959b8d65ce26131c2d5ccfa518a7b76529280fa
Author:     Steven Rostedt <srostedt@redhat.com>
AuthorDate: Wed, 14 Oct 2009 15:43:35 -0400
Committer:  Ingo Molnar <mingo@elte.hu>
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.

Signed-off-by: Steven Rostedt <srostedt@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
LKML-Reference: <20091014194358.124833639@goodmis.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
 tools/perf/util/trace-event-parse.c |   62 +++++++++++++++++++++++++++++++++++
 1 files changed, 62 insertions(+), 0 deletions(-)

diff --git a/tools/perf/util/trace-event-parse.c b/tools/perf/util/trace-event-parse.c
index 3e643f5..7aeedb0 100644
--- a/tools/perf/util/trace-event-parse.c
+++ b/tools/perf/util/trace-event-parse.c
@@ -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]) {
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Re: [PATCH 13/13] [PATCH 13/13] perf tools: remove all cha ..., Frederic Weisbecker, (Wed Oct 14, 1:26 pm)
[tip:perf/core] perf tools: Handle print concatenations in ..., tip-bot for Steven R ..., (Thu Oct 15, 1:48 am)
[tip:perf/core] perf tools: Fix backslash processing on tr ..., tip-bot for Steven R ..., (Thu Oct 15, 1:48 am)
[tip:perf/core] perf tools: Handle trace parsing of &lt; and &gt;, tip-bot for Steven R ..., (Thu Oct 15, 1:48 am)
[tip:perf/core] perf tools: Handle arrays in print fields ..., tip-bot for Steven R ..., (Thu Oct 15, 1:48 am)
[tip:perf/core] perf tools: Handle * as typecast in trace ..., tip-bot for Steven R ..., (Thu Oct 15, 1:49 am)
[tip:perf/core] perf tools: Handle newlines in trace parsi ..., tip-bot for Steven R ..., (Thu Oct 15, 1:49 am)
[tip:perf/core] perf tools: Handle the case with and witho ..., tip-bot for Steven R ..., (Thu Oct 15, 1:49 am)
[tip:perf/core] perf tools: Still continue on failed parsi ..., tip-bot for Steven R ..., (Thu Oct 15, 1:49 am)
[tip:perf/core] perf tools: Fix bprintk reading in trace o ..., tip-bot for Steven R ..., (Thu Oct 15, 1:50 am)
[tip:perf/core] perf tools: Handle both versions of ftrace ..., tip-bot for Steven R ..., (Thu Oct 15, 1:50 am)
[tip:perf/core] perf tools: Add latency format to trace output, tip-bot for Steven R ..., (Thu Oct 15, 1:50 am)
[tip:perf/core] perf tools: Handle - and + in parsing trac ..., tip-bot for Steven R ..., (Thu Oct 15, 1:50 am)
[tip:perf/core] perf tools: Remove all char * typecasts an ..., tip-bot for Steven R ..., (Thu Oct 15, 1:51 am)