summaryrefslogtreecommitdiff
path: root/tools/perf/tests/parse-metric.c
diff options
context:
space:
mode:
authorJiri Olsa <jolsa@kernel.org>2020-07-19 21:13:16 +0300
committerArnaldo Carvalho de Melo <acme@redhat.com>2020-07-30 13:01:49 +0300
commitf6fb0960f920e3040088992f32bbceded7a74322 (patch)
tree3a3827acaa67f85cde9d495fe18613eeb3e4907c /tools/perf/tests/parse-metric.c
parent5a606f3b9c85ea024a8071765a523c85df93c454 (diff)
downloadlinux-f6fb0960f920e3040088992f32bbceded7a74322.tar.xz
perf metric: Add recursion check when processing nested metrics
Keeping the stack of nested metrics via 'struct expr_id' objects and checking if we are in recursion via already processed metric. The stack is implemented as static array within the struct egroup with 100 entries, which should be enough nesting depth for any metric we have or plan to have at the moment. Adding test that simulates the recursion and checks we can detect it. Committer notes: Bumped RECURSION_ID_MAX to 1000 as per Jiri's reply to Paul Clark on the patch series e-mail discussion. Fixed these: tests/parse-metric.c:308:7: error: missing field 'val' initializer [-Werror,-Wmissing-field-initializers] { 0 }, ^ util/metricgroup.c:924:28: error: missing field 'parent' initializer [-Werror,-Wmissing-field-initializers] struct expr_ids ids = { 0 }; ^ util/metricgroup.c:924:26: error: suggest braces around initialization of subobject [-Werror,-Wmissing-braces] struct expr_ids ids = { 0 }; ^ {} util/metricgroup.c:924:26: error: suggest braces around initialization of subobject [-Werror,-Wmissing-braces] struct expr_ids ids = { 0 }; ^ {} util/metricgroup.c:924:28: error: missing field 'cnt' initializer [-Werror,-Wmissing-field-initializers] struct expr_ids ids = { 0 }; ^ Signed-off-by: Jiri Olsa <jolsa@kernel.org> Reviewed-by: Kajol Jain <kjain@linux.ibm.com> Acked-by: Ian Rogers <irogers@google.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: John Garry <john.garry@huawei.com> Cc: Michael Petlan <mpetlan@redhat.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Paul Clarke <pc@us.ibm.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Link: http://lore.kernel.org/lkml/20200719181320.785305-16-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/tests/parse-metric.c')
-rw-r--r--tools/perf/tests/parse-metric.c34
1 files changed, 32 insertions, 2 deletions
diff --git a/tools/perf/tests/parse-metric.c b/tools/perf/tests/parse-metric.c
index 7a7dea833a6e..d7cc3bf64854 100644
--- a/tools/perf/tests/parse-metric.c
+++ b/tools/perf/tests/parse-metric.c
@@ -57,6 +57,18 @@ static struct pmu_event pme_test[] = {
.metric_expr = "d_ratio(dcache_l2_all_miss, dcache_l2_all)",
.metric_name = "DCache_L2_Misses",
},
+{
+ .metric_expr = "ipc + m2",
+ .metric_name = "M1",
+},
+{
+ .metric_expr = "ipc + m1",
+ .metric_name = "M2",
+},
+{
+ .metric_expr = "1/m3",
+ .metric_name = "M3",
+}
};
static struct pmu_events_map map = {
@@ -139,8 +151,8 @@ static int compute_metric(const char *name, struct value *vals, double *ratio)
err = metricgroup__parse_groups_test(evlist, &map, name,
false, false,
&metric_events);
-
- TEST_ASSERT_VAL("failed to parse metric", err == 0);
+ if (err)
+ return err;
if (perf_evlist__alloc_stats(evlist, false))
return -1;
@@ -264,11 +276,29 @@ static int test_dcache_l2(void)
return 0;
}
+static int test_recursion_fail(void)
+{
+ double ratio;
+ struct value vals[] = {
+ { .event = "inst_retired.any", .val = 300 },
+ { .event = "cpu_clk_unhalted.thread", .val = 200 },
+ { .event = NULL, },
+ };
+
+ TEST_ASSERT_VAL("failed to find recursion",
+ compute_metric("M1", vals, &ratio) == -1);
+
+ TEST_ASSERT_VAL("failed to find recursion",
+ compute_metric("M3", vals, &ratio) == -1);
+ return 0;
+}
+
int test__parse_metric(struct test *test __maybe_unused, int subtest __maybe_unused)
{
TEST_ASSERT_VAL("IPC failed", test_ipc() == 0);
TEST_ASSERT_VAL("frontend failed", test_frontend() == 0);
TEST_ASSERT_VAL("cache_miss_cycles failed", test_cache_miss_cycles() == 0);
TEST_ASSERT_VAL("DCache_L2 failed", test_dcache_l2() == 0);
+ TEST_ASSERT_VAL("recursion fail failed", test_recursion_fail() == 0);
return 0;
}