Skip to content

Commit

Permalink
Keep dictionary of edges with counts. also created quick script to di…
Browse files Browse the repository at this point in the history
…vide scaled flame graphs by 1000
  • Loading branch information
ayakayorihiro committed Nov 20, 2024
1 parent 6232f2a commit a0cccd4
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
32 changes: 32 additions & 0 deletions tools/profiler/finagle-with-svg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import os
import sys

# Takes in a flame graph svg that is scaled by 1000 and prints a version with fixed cycles.

def main(svg_in):
oin = open(svg_in, "r")

for line in oin:
if line.startswith("<title>"):
line_split = line.strip().split(" ")
target_idx = 0
for i in range(len(line_split)):
if line_split[i] == "cycles,":
target_idx = i-1
new_number = int(line_split[target_idx].split("(")[1].replace(",", "")) / 1000
print(" ".join(line_split[0:target_idx]) + " (" + str(new_number) + " " + " ".join(line_split[target_idx+1:]))
else:
print(line.strip())


if __name__ == "__main__":
if len(sys.argv) > 1:
svg_filename = sys.argv[1]
main(svg_filename)
else:
args_desc = [
"INPUT_SVG"
]
print(f"Usage: {sys.argv[0]} {' '.join(args_desc)}")
print("CELLS_JSON: Run the `component_cells` tool")
sys.exit(-1)
7 changes: 6 additions & 1 deletion tools/profiler/new-profiler-approach.sh
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,10 @@ done
for folded in $( ls ${FLAME_OUT_DIR}/*.folded ); do
echo "Writing flame graph for ${folded}"
base_name=$( echo ${folded} | rev | cut -d. -f2- | rev )
${FLAMEGRAPH_DIR}/flamegraph.pl --countname="cycles" ${folded} > ${base_name}.svg
if [[ "${base_name}" == *"scaled"* ]]; then
${FLAMEGRAPH_DIR}/flamegraph.pl --countname="cycles" ${folded} > ${base_name}-original.svg
python3 ${SCRIPT_DIR}/finagle-with-svg.py ${base_name}-original.svg > ${base_name}.svg
else
${FLAMEGRAPH_DIR}/flamegraph.pl --countname="cycles" ${folded} > ${base_name}.svg
fi
done
11 changes: 7 additions & 4 deletions tools/profiler/profiler-process.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ def create_output(timeline_map, dot_out_dir, flame_out_file, flames_out_dir):
flame_out.write(f"{stack} {stacks[stack]}\n")

divided_stacks = div_flame_helper(timeline_map)
with open(os.path.join(flames_out_dir, "divided-flame.folded"), "w") as div_flame_out:
with open(os.path.join(flames_out_dir, "scaled-flame.folded"), "w") as div_flame_out:
for stack in divided_stacks:
div_flame_out.write(f"{stack} {divided_stacks[stack]}\n")

Expand All @@ -490,7 +490,7 @@ def create_output(timeline_map, dot_out_dir, flame_out_file, flames_out_dir):

all_paths_ordered = sorted(path_dict.keys())
for i in timeline_map:
used_edges = set()
used_edges = {}
used_paths = set()
used_nodes = set()
all_nodes = set(tree_dict.keys())
Expand All @@ -501,7 +501,10 @@ def create_output(timeline_map, dot_out_dir, flame_out_file, flames_out_dir):
for node_id in path_dict[stack_id]:
used_nodes.add(node_id)
for edge in path_to_edges[stack_id]:
used_edges.add(edge)
if edge not in used_edges:
used_edges[edge] = 1
else:
used_edges[edge] += 1

fpath = os.path.join(dot_out_dir, f"cycle{i}.dot")
with open(fpath, "w") as f:
Expand All @@ -514,7 +517,7 @@ def create_output(timeline_map, dot_out_dir, flame_out_file, flames_out_dir):
f.write(f'\t{node} [label="{tree_dict[node]}",color="{INVISIBLE}",fontcolor="{INVISIBLE}"];\n')
# write all edges.
for edge in all_edges:
if edge in used_edges:
if edge in used_edges.keys():
f.write(f'\t{edge} ; \n')
else:
f.write(f'\t{edge} [color="{INVISIBLE}"]; \n')
Expand Down

0 comments on commit a0cccd4

Please sign in to comment.