From 23c58ab13d93e59e8394e575182b1fbef9d8f410 Mon Sep 17 00:00:00 2001 From: asodeur Date: Fri, 28 Aug 2020 09:53:19 +0200 Subject: [PATCH] restricting counts/timings on the callee tab to calls by caller --- runsnakerun/pstatsloader.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/runsnakerun/pstatsloader.py b/runsnakerun/pstatsloader.py index bb5d644..166d2e6 100644 --- a/runsnakerun/pstatsloader.py +++ b/runsnakerun/pstatsloader.py @@ -100,6 +100,8 @@ def load(self, stats): log.info('Null row: %s', func) for row in six.itervalues(rows): row.weave(rows) + for row in six.itervalues(rows): + row.fix_children() return self.find_root(rows) def load_functions(self): @@ -269,6 +271,29 @@ def weave(self, rows): self.parents.append(parent) parent.children.append(self) + def fix_children(self, seen=None): + """make sure rows in .children only contain call count/timings when called by self""" + seen = set() if seen is None else seen + if self in seen: + return self + + seen.add(self) + + children = [] + for c in self.children: + call_timings = c.callers.get(self.key) + if call_timings is None: + children.append(c) + else: + child_node = PStatRow(c.key, (*call_timings, c.callers)) + seen.add(child_node) + child_node.parents = c.parents + child_node.children = [cc.fix_children(seen) for cc in c.children] + children.append(child_node) + + self.children = children + return self + def child_cumulative_time(self, child): total = self.cumulative if total: