Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf expr: Fix "has_event" function for metric style events

Events in metrics cannot use '/' as a separator, it would be
recognized as a divide, so they use '@'. The '@' is recognized in the
metricgroups code and changed to '/', do the same in the has_event
function so that the parsing is only tried without the @s.

Fixes: 4a4a9bf9075f ("perf expr: Add has_event function")
Signed-off-by: Ian Rogers <irogers@google.com>
Reviewed-by: Kan Liang <kan.liang@linux.intel.com>
Cc: K Prateek Nayak <kprateek.nayak@amd.com>
Cc: James Clark <james.clark@arm.com>
Cc: Kaige Ye <ye@kaige.org>
Cc: John Garry <john.g.garry@oracle.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/20240209204947.3873294-3-irogers@google.com

authored by

Ian Rogers and committed by
Namhyung Kim
6dd76680 4ea7d944

+19 -1
+19 -1
tools/perf/util/expr.c
··· 500 500 tmp = evlist__new(); 501 501 if (!tmp) 502 502 return NAN; 503 - ret = parse_event(tmp, id) ? 0 : 1; 503 + 504 + if (strchr(id, '@')) { 505 + char *tmp_id, *p; 506 + 507 + tmp_id = strdup(id); 508 + if (!tmp_id) { 509 + ret = NAN; 510 + goto out; 511 + } 512 + p = strchr(tmp_id, '@'); 513 + *p = '/'; 514 + p = strrchr(tmp_id, '@'); 515 + *p = '/'; 516 + ret = parse_event(tmp, tmp_id) ? 0 : 1; 517 + free(tmp_id); 518 + } else { 519 + ret = parse_event(tmp, id) ? 0 : 1; 520 + } 521 + out: 504 522 evlist__delete(tmp); 505 523 return ret; 506 524 }