From 87ffb3c5eecc30c62c20750f9b5e2a762acae077 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Schl=C3=B6mer?= Date: Sun, 20 Dec 2020 23:00:00 +0100 Subject: [PATCH 1/2] handle loops in profiles --- tuna/_runtime_profile.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tuna/_runtime_profile.py b/tuna/_runtime_profile.py index d6ae72b..ef64a35 100644 --- a/tuna/_runtime_profile.py +++ b/tuna/_runtime_profile.py @@ -45,7 +45,7 @@ def read_runtime_profile(prof_filename): for parent in parents: children[parent].append(key) - def populate(key, parent): + def populate(key, parent, all_ancestors): # stats.stats[key] returns a tuple of length 5 with the following data: # [0]: total calls # [1]: prim calls @@ -61,10 +61,14 @@ def populate(key, parent): # Convert the tuple key into a string name = "{}::{}::{}".format(*key) + + if key in all_ancestors: + # avoid loops + return {} + if len(parent_times) <= 1: # Handle children - # merge dictionaries - c = [populate(child, key) for child in children[key]] + c = [populate(child, key, all_ancestors + [key]) for child in children[key]] c.append( { "text": [name + "::self", f"{selftime:.3} s"], @@ -94,7 +98,7 @@ def populate(key, parent): return {"text": [name, f"{selftime:.3f}"], "color": 0, "value": selftime} if len(roots) == 1: - data = populate(roots[0], None) + data = populate(roots[0], None, []) else: # If there is more than one root, add an artificial "master root" item that is # parent to all roots. @@ -102,6 +106,6 @@ def populate(key, parent): data = { "text": ["root"], "color": 0, - "children": [populate(root, None) for root in roots], + "children": [populate(root, None, []) for root in roots], } return data From 9548fa494eb875549a5479c0b8782a513587ad16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Schl=C3=B6mer?= Date: Sun, 20 Dec 2020 23:00:14 +0100 Subject: [PATCH 2/2] version bump --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index b016137..ad876fc 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = tuna -version = 0.5.2 +version = 0.5.3 author = Nico Schlömer author_email = nico.schloemer@gmail.com description = Visualize Python performance profiles