[PATCH 2/3] perf: allow processing single op args

From: Hidetoshi Seto
Date: Tue Dec 06 2011 - 20:37:31 EST


I got following error from record with btrfs tracepoints:

$ perf script
Fatal: unknown op '-'

It seems that perf failed to handle '-' in the following format:

print fmt: "%s", ((REC->id >= -9) || (REC->id <= 7)) ? "x" : "y"
~
process_arg() have code to parse '-9' as a "single op" arg, which is
PRINT_OP as type, '-' as op and have '9' as right arg but no left arg.
However arg_num_eval() have no code to handle this "single op" arg
even it is parsed successfully.

This patch allow perf to process such "single op" args.

Signed-off-by: Hidetoshi Seto <seto.hidetoshi@xxxxxxxxxxxxxx>
---
tools/perf/util/trace-event-parse.c | 18 ++++++++++++++++++
1 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/tools/perf/util/trace-event-parse.c b/tools/perf/util/trace-event-parse.c
index c2adc76..b709f78 100644
--- a/tools/perf/util/trace-event-parse.c
+++ b/tools/perf/util/trace-event-parse.c
@@ -1355,6 +1355,24 @@ static long long arg_num_eval(struct print_arg *arg)
val = arg_num_eval(arg->typecast.item);
break;
case PRINT_OP:
+ if (!arg->op.left || arg->op.left->type == PRINT_NULL) {
+ /* handle single op */
+ right = arg_num_eval(arg->op.right);
+ switch (arg->op.op[0]) {
+ case '!':
+ val = !right;
+ break;
+ case '+':
+ val = right;
+ break;
+ case '-':
+ val = -right;
+ break;
+ default:
+ die("unknown single op %s", arg->op.op);
+ }
+ break;
+ }
switch (arg->op.op[0]) {
case '|':
left = arg_num_eval(arg->op.left);
--
1.7.7.3


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/