From d1a6c2030ca6585cb02aa67e01de093e960686e3 Mon Sep 17 00:00:00 2001 From: Xinding Wei Date: Mon, 11 Nov 2024 17:45:50 -0800 Subject: [PATCH] Fix flamegraph computing (#809) --- ci/scripts/metric_unify/flamegraph.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/ci/scripts/metric_unify/flamegraph.py b/ci/scripts/metric_unify/flamegraph.py index 0a8c7f476..d89fc9e00 100644 --- a/ci/scripts/metric_unify/flamegraph.py +++ b/ci/scripts/metric_unify/flamegraph.py @@ -18,6 +18,8 @@ def get_stack_lines(metrics_dict, group_by_kvs, stack_keys, metric_name): # Process counters for counter in metrics_dict.get('counter', []): + if counter['metric'] != metric_name: + continue # list of pairs -> dict labels = dict(counter['labels']) filter = False @@ -30,12 +32,11 @@ def get_stack_lines(metrics_dict, group_by_kvs, stack_keys, metric_name): stack_values = [] for key in stack_keys: - if key in labels: - stack_values.append(labels[key]) - if len(stack_values) == 0: - continue - - if counter['metric'] != metric_name: + if key not in labels: + filter = True + break + stack_values.append(labels[key]) + if filter: continue stack = ';'.join(stack_values) @@ -46,6 +47,7 @@ def get_stack_lines(metrics_dict, group_by_kvs, stack_keys, metric_name): # Currently cycle tracker does not use gauge return lines + def create_flamegraph(fname, metrics_dict, group_by_kvs, stack_keys, metric_name, reverse=False): lines = get_stack_lines(metrics_dict, group_by_kvs, stack_keys, metric_name) @@ -69,7 +71,7 @@ def create_flamegraph(fname, metrics_dict, group_by_kvs, stack_keys, metric_name command.append("--reverse") subprocess.run(command, stdout=f, check=False) - print (f"Created flamegraph at {flamegraph_path}") + print(f"Created flamegraph at {flamegraph_path}") def create_flamegraphs(metrics_file, group_by, stack_keys, metric_name, reverse=False): @@ -95,8 +97,10 @@ def create_flamegraphs(metrics_file, group_by, stack_keys, metric_name, reverse= def create_custom_flamegraphs(metrics_file, group_by=["group"]): for reverse in [False, True]: - create_flamegraphs(metrics_file, group_by, ["cycle_tracker_span", "dsl_ir", "opcode"], "frequency", reverse=reverse) - create_flamegraphs(metrics_file, group_by, ["cycle_tracker_span", "dsl_ir", "opcode", "air_name"], "cells_used", reverse=reverse) + create_flamegraphs(metrics_file, group_by, ["cycle_tracker_span", "dsl_ir", "opcode"], "frequency", + reverse=reverse) + create_flamegraphs(metrics_file, group_by, ["cycle_tracker_span", "dsl_ir", "opcode", "air_name"], "cells_used", + reverse=reverse) def main():