diff options
author | Karl Berry <karl@freefriends.org> | 2021-02-25 19:22:25 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2021-02-25 19:22:25 +0000 |
commit | ad547a6b5986815fda458221149728d9d9ab1d87 (patch) | |
tree | 16296910eb3eca724371474ea9aea3994dc69614 /Build/source/utils/asymptote/profile.py | |
parent | 947b43de3dd21d58ccc2ffadefc4441ea1c2a813 (diff) |
restore Build,TODO from r57911
git-svn-id: svn://tug.org/texlive/trunk@57915 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/utils/asymptote/profile.py')
-rw-r--r-- | Build/source/utils/asymptote/profile.py | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/Build/source/utils/asymptote/profile.py b/Build/source/utils/asymptote/profile.py new file mode 100644 index 00000000000..bfdd52015bc --- /dev/null +++ b/Build/source/utils/asymptote/profile.py @@ -0,0 +1,98 @@ +#!/usr/bin/env python3 + +import sys +from pprint import pprint + +# Unused line numbers required by kcachegrind. +POS = '1' + +def nameFromNode(tree): + name = tree['name'] + pos = tree['pos'] + if pos.endswith(": "): + pos = pos[:-2] + return (name, pos) + +def addFuncNames(tree, s): + s.add(nameFromNode(tree)) + for child in tree['children']: + addFuncNames(child, s) + +def funcNames(tree): + s = set() + addFuncNames(tree, s) + return s + +def computeTotals(tree): + for child in tree['children']: + computeTotals(child) + tree['instTotal'] = (tree['instructions'] + + sum(child['instTotal'] for child in tree['children'])) + tree['nsecsTotal'] = (tree['nsecs'] + + sum(child['nsecsTotal'] for child in tree['children'])) + +def printName(name, prefix=''): + print (prefix+"fl=", name[1]) + print (prefix+"fn=", name[0]) + +class Arc: + def __init__(self): + self.calls = 0 + self.instTotal = 0 + self.nsecsTotal = 0 + + def add(self, tree): + self.calls += tree['calls'] + self.instTotal += tree['instTotal'] + self.nsecsTotal += tree['nsecsTotal'] + +class Func: + def __init__(self): + self.instructions = 0 + self.nsecs = 0 + self.arcs = {} + + def addChildTime(self, tree): + arc = self.arcs.setdefault(nameFromNode(tree), Arc()) + arc.add(tree) + + def analyse(self, tree): + self.instructions += tree['instructions'] + self.nsecs += tree['nsecs'] + for child in tree['children']: + self.addChildTime(child) + + def dump(self): + print (POS, self.instructions, self.nsecs) + for name in self.arcs: + printName(name, prefix='c') + arc = self.arcs[name] + print ("calls="+str(arc.calls), POS) + print (POS, arc.instTotal, arc.nsecsTotal) + print () + +def analyse(funcs, tree): + funcs[nameFromNode(tree)].analyse(tree) + for child in tree['children']: + analyse(funcs, child) + +def dump(funcs): + print ("events: Instructions Nanoseconds") + for name in funcs: + printName(name) + funcs[name].dump() + +rawdata = __import__("asyprof") +profile = rawdata.profile + +computeTotals(profile) +names = funcNames(profile) + +funcs = {} +for name in names: + funcs[name] = Func() + +analyse(funcs, profile) +dump(funcs) + +#pprint(names) |