From 27dbac97b9572435dabf59e2831ff4677e185274 Mon Sep 17 00:00:00 2001 From: KasiaS999 Date: Tue, 2 Jul 2024 16:44:28 +0200 Subject: [PATCH] fix showing comparison on the edges --- README.md | 4 ++-- gprof2dot.py | 13 +++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 548a6a0..f2d1d23 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ It can: * use an heuristic to propagate time inside mutually recursive functions; * use color efficiently to draw attention to hot-spots; * work on any platform where Python and Graphviz is available, i.e, virtually anywhere; - * compare two graphs with identical structures for the analysis of performance metrics such as time or function calls. + * compare two graphs with almost identical structures for the analysis of performance metrics such as time or function calls. **If you want an interactive viewer for the graphs generated by _gprof2dot_, check [xdot.py](https://github.com/jrfonseca/xdot.py).** @@ -131,7 +131,7 @@ Options: variety to lower percentages -p FILTER_PATHS, --path=FILTER_PATHS Filter all modules not in a specified path - --compare Compare two graphs with identical structure. With this + --compare Compare two graphs with almost identical structure. With this option two files should be provided.gprof2dot.py [options] --compare [file1] [file2] ... --compare-tolerance=TOLERANCE diff --git a/gprof2dot.py b/gprof2dot.py index 54009b9..1fec633 100755 --- a/gprof2dot.py +++ b/gprof2dot.py @@ -3288,8 +3288,7 @@ def graphs_compare(self, profile1, profile2, theme, options): self.attr('node', fontname=fontname, style=nodestyle, fontcolor=fontcolor, width=0, height=0) self.attr('edge', fontname=fontname) - functions2 = {function.name: function - for _, function in sorted_iteritems(profile2.functions)} + functions2 = {function.name: function for _, function in sorted_iteritems(profile2.functions)} for _, function1 in sorted_iteritems(profile1.functions): labels = [] @@ -3403,10 +3402,16 @@ def graphs_compare(self, profile1, profile2, theme, options): ) calls2 = {call.callee_id: call for _, call in sorted_iteritems(function2.calls)} + functions_by_id1 = {function.id: function for _, function in sorted_iteritems(profile1.functions)} + for _, call1 in sorted_iteritems(function1.calls): labels = [] try: - call2 = calls2[call1.callee_id] + # if profiles do not have identical setups, callee_id will not be identical either + call_id1 = call1.callee_id + call_name = functions_by_id1[call_id1].name + call_id2 = functions2[call_name].id + call2 = calls2[call_id2] for event in self.show_edge_events: if event in call1.events: label = f'{event.format(call1[event])} / {event.format(call2[event])}' @@ -3725,7 +3730,7 @@ def main(argv=sys.argv[1:]): '--compare', action="store_true", dest="compare", default=False, - help="Compare two graphs with identical structure. With this option two files should be provided." + help="Compare two graphs with almost identical structure. With this option two files should be provided." "gprof2dot.py [options] --compare [file1] [file2] ...") optparser.add_option( '--compare-tolerance',