perf metric: Use NAN for missing event IDs.
authorIan Rogers <irogers@google.com>
Thu, 23 Sep 2021 07:46:05 +0000 (00:46 -0700)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 29 Sep 2021 16:25:56 +0000 (13:25 -0300)
If during computing a metric an event (id) is missing the parsing
aborts. A later patch will make it so that events that aren't used in
the output are deliberately omitted, in which case we don't want the
abort. Modify the missing ID case to report NAN for these cases.

Reviewed-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: John Garry <john.garry@huawei.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Sandeep Dasgupta <sdasgup@google.com>
Cc: Stephane Eranian <eranian@google.com>
Link: https://lore.kernel.org/r/20210923074616.674826-3-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/expr.y

index b2ada8f..41c9cd4 100644 (file)
@@ -1,6 +1,7 @@
 /* Simple expression parser */
 %{
 #define YYDEBUG 1
+#include <math.h>
 #include <stdio.h>
 #include "util.h"
 #include "util/debug.h"
@@ -88,12 +89,10 @@ expr:         NUMBER
        | ID                    {
                                        struct expr_id_data *data;
 
-                                       if (expr__resolve_id(ctx, $1, &data)) {
-                                               free($1);
-                                               YYABORT;
-                                       }
+                                       $$ = NAN;
+                                       if (expr__resolve_id(ctx, $1, &data) == 0)
+                                               $$ = expr_id_data__value(data);
 
-                                       $$ = expr_id_data__value(data);
                                        free($1);
                                }
        | expr '|' expr         { $$ = (long)$1 | (long)$3; }