From e31c5b09e674f7e34c5c159372d8e83fcae5b7ed Mon Sep 17 00:00:00 2001 From: asodeur Date: Thu, 27 Aug 2020 09:23:03 +0200 Subject: [PATCH] only use longest running function as a root when there are no functions w/o parents --- runsnakerun/pstatsloader.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/runsnakerun/pstatsloader.py b/runsnakerun/pstatsloader.py index bb5d644..94adef6 100644 --- a/runsnakerun/pstatsloader.py +++ b/runsnakerun/pstatsloader.py @@ -18,7 +18,7 @@ def load_pstats(filenames): """Given list of filenames, load pstats, potentially using a different python version - + Internally will create a python2 subprocess to convert python2 pstats dumps for loading in python3, that will create a cPickle/pickle dump and load it locally. @@ -116,16 +116,21 @@ def find_root(self, rows): cycles by sorting on cumulative time, and then collecting the traced roots (or, if they are all on the same root, use that). """ - maxes = sorted(list(rows.values()), key=lambda x: x.cumulative) - if not maxes: - raise RuntimeError("""Null results!""") - root = maxes[-1] - roots = [root] + roots = [] for key, value in rows.items(): if not value.parents: log.debug('Found node root: %s', value) if value not in roots: roots.append(value) + + if len(roots) == 0: + # use longest running function as root when we have not found a root, yet + maxes = sorted(list(rows.values()), key=lambda x: x.cumulative) + if not maxes: + raise RuntimeError("""Null results!""") + root = maxes[-1] + roots.append(root) + if len(roots) > 1: root = PStatGroup( directory='*', filename='*', name=_(""), children=roots,