perf expr: Make the evaluation of & and | logical and lazy
Ian Rogers
reviewerPATCH v2 1/2 perf expr: Make the evaluation of & and | logical and lazy
Currently the & and | operators are only used in metric thresholds like (from the tma_retiring metric):tma_retiring > 0.7 | tma_heavy_operations > 0.1
Thresholds are always computed when present, but a lack events may mean the threshold can't be computed. This happens with the option --metric-no-threshold for say the metric tma_retiring on Tigerlake model CPUs. To fully compute the threshold tma_heavy_operations is needed and it needs the extra events of IDQ.MS_UOPS, UOPS_DECODED.DEC0, cpu/UOPS_DECODED.DEC0,cmask=1/ and IDQ.MITE_UOPS. So --metric-no-threshold is a useful option to reduce the number of events needed and potentially multiplexing of events.
Rather than just fail threshold computations like this, we may know a result from just the left or right-hand side. So, for tma_retiring if its value is "> 0.7" we know it is over the threshold. This allows the metric to have the threshold coloring, when possible, without all the counters being programmed.
--- tools/perf/tests/expr.c | 40 +++++++++++++++++++ tools/perf/util/expr.y | 86 +++++++++++++++++++++++++++++++++-------- 2 files changed, 109 insertions(+), 17 deletions(-)
tools/perf/tests/expr.c +40 -0
@@ -185,6 +185,46 @@ static int test__expr(struct test_suite *t __maybe_unused, int subtest __maybe_u NULL, ctx) == 0);TEST_ASSERT_VAL ("find ids" ,hashmap__size (ctx->ids) ==0 ); +/* The expression is a constant 0.0 without needing to evaluate EVENT1. */ +expr__ctx_clear (ctx); +TEST_ASSERT_VAL ("find ids" , +expr__find_ids ("0 & EVENT1 > 0" ,NULL , ctx) ==0 ); +TEST_ASSERT_VAL ("find ids" ,hashmap__size (ctx->ids) ==0 ); +expr__ctx_clear (ctx); +TEST_ASSERT_VAL ("find ids" , +expr__find_ids ("EVENT1 > 0 & 0" ,NULL , ctx) ==0 ); +TEST_ASSERT_VAL ("find ids" ,hashmap__size (ctx->ids) ==0 ); +expr__ctx_clear (ctx); +TEST_ASSERT_VAL ("find ids" , +expr__find_ids ("1 & EVENT1 > 0" ,NULL , ctx) ==0 ); +TEST_ASSERT_VAL ("find ids" ,hashmap__size (ctx->ids) ==1 ); +TEST_ASSERT_VAL ("find ids" ,hashmap__find (ctx->ids,"EVENT1" , &val_ptr)); +expr__ctx_clear (ctx); +TEST_ASSERT_VAL ("find ids" , +expr__find_ids ("EVENT1 > 0 & 1" ,NULL , ctx) ==0 ); +TEST_ASSERT_VAL ("find ids" ,hashmap__size (ctx->ids) ==1 ); +TEST_ASSERT_VAL ("find ids" ,hashmap__find (ctx->ids,"EVENT1" , &val_ptr)); + +/* The expression is a constant 1.0 without needing to evaluate EVENT1. */ +expr__ctx_clear (ctx); +TEST_ASSERT_VAL ("find ids" , +expr__find_ids ("1 | EVENT1 > 0" ,NULL , ctx) ==0 ); +TEST_ASSERT_VAL ("find ids" ,hashmap__size (ctx->ids) ==0 ); +expr__ctx_clear (ctx); +TEST_ASSERT_VAL ("find ids" , +expr__find_ids ("EVENT1 > 0 | 1" ,NULL , ctx) ==0 ); +TEST_ASSERT_VAL ("find ids" ,hashmap__size (ctx->ids) ==0 ); +expr__ctx_clear (ctx); +TEST_ASSERT_VAL ("find ids" , +expr__find_ids ("0 | EVENT1 > 0" ,NULL , ctx) ==0 ); +TEST_ASSERT_VAL ("find ids" ,hashmap__size (ctx->ids) ==1 ); +TEST_ASSERT_VAL ("find ids" ,hashmap__find (ctx->ids,"EVENT1" , &val_ptr)); +expr__ctx_clear (ctx); +TEST_ASSERT_VAL ("find ids" , +expr__find_ids ("EVENT1 > 0 | 0" ,NULL , ctx) ==0 ); +TEST_ASSERT_VAL ("find ids" ,hashmap__size (ctx->ids) ==1 ); +TEST_ASSERT_VAL ("find ids" ,hashmap__find (ctx->ids,"EVENT1" , &val_ptr)); +/* Test toplogy constants appear well ordered. */ expr__ctx_clear (ctx);TEST_ASSERT_VAL ("#num_cpus" ,expr__parse (&num_cpus, ctx,"#num_cpus" ) ==0 );
tools/perf/util/expr.y +69 -17
98 lines not on this page · raw message
Signature · 1 line
2.40.1.698.g37aff9b760-goog
Ian Rogers
reviewerPATCH v2 2/2 perf stat: Document --metric-no-threshold and threshold colors
Document the threshold behavior for -M/--metrics.
--- tools/perf/Documentation/perf-stat.txt | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
tools/perf/Documentation/perf-stat.txt +15 -0
@@ -353,6 +353,15 @@ small group that need not have multiplexing is lowered. This option forbids the event merging logic from sharing events between groups and may be used to increase accuracy in this case. +--metric-no-threshold:: +Metric thresholds may increase the number of events necessary to +compute whether a metric has exceeded its threshold expression. This +may not be desirable, for example, as the events can introduce +multiplexing. This option disables the adding of threshold expression +events for a metric. However, if there are sufficient events to +compute the threshold then the threshold is still computed and used to +color the metric's computed value. + --quiet:: Don't print output, warnings or messages. This is useful with perf stat record below to only write data to the perf.data file.
@@ -389,6 +398,12 @@ For a group all metrics from the group are added. The events from the metrics are automatically measured. See perf list output for the possible metrics and metricgroups. + When threshold information is available for a metric, the + color red is used to signify a metric has exceeded a threshold + while green shows it hasn't. The default color means that + no threshold information was available or the threshold + couldn't be computed. + -A:: --no-aggr:: Do not aggregate counts across all monitored CPUs.
Signature · 1 line
2.40.1.698.g37aff9b760-goog