ATLAS Offline Software
lsprofcalltree.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
2 
3 from six import print_
4 
5 def label(code):
6  if isinstance(code, str):
7  return ('~', 0, code) # built-in functions ('~' sorts at the end)
8  else:
9  return '%s %s:%d' % (code.co_name, code.co_filename, code.co_firstlineno)
10 
11 
12 
14  def __init__(self, profiler):
15  self.data = profiler.getstats()
16  self.out_file = None
17 
18  def output(self, out_file):
19  self.out_file = out_file
20  print_('events: Ticks', file=out_file)
21  self._print_summary()
22  for entry in self.data:
23  self._entry(entry)
24 
25  def _print_summary(self):
26  max_cost = 0
27  for entry in self.data:
28  totaltime = int(entry.totaltime * 1000)
29  max_cost = max(max_cost, totaltime)
30  print_('summary: %d' % (max_cost,), file=self.out_file)
31 
32  def _entry(self, entry):
33  out_file = self.out_file
34  code = entry.code
35  inlinetime = int(entry.inlinetime * 1000)
36  #print >> out_file, 'ob=%s' % (code.co_filename,)
37  if isinstance(code, str):
38  print_('fi=~', file=out_file)
39  else:
40  print_('fi=%s' % (code.co_filename,), file=out_file)
41  print_('fn=%s' % (label(code),), file=out_file)
42  if isinstance(code, str):
43  print_('0 ', inlinetime, file=out_file)
44  else:
45  print_('%d %d' % (code.co_firstlineno, inlinetime), file=out_file)
46  # recursive calls are counted in entry.calls
47  if entry.calls:
48  calls = entry.calls
49  else:
50  calls = []
51  if isinstance(code, str):
52  lineno = 0
53  else:
54  lineno = code.co_firstlineno
55  for subentry in calls:
56  self._subentry(lineno, subentry)
57  print_(file=out_file)
58 
59  def _subentry(self, lineno, subentry):
60  out_file = self.out_file
61  code = subentry.code
62  totaltime = int(subentry.totaltime * 1000)
63  #print >> out_file, 'cob=%s' % (code.co_filename,)
64  print_('cfn=%s' % (label(code),), file=out_file)
65  if isinstance(code, str):
66  print_('cfi=~', file=out_file)
67  print_('calls=%d 0' % (subentry.callcount,), file=out_file)
68  else:
69  print_('cfi=%s' % (code.co_filename,), file=out_file)
70  print_('calls=%d %d' % (
71  subentry.callcount, code.co_firstlineno), file=out_file)
72  print_('%d %d' % (lineno, totaltime), file=out_file)
max
#define max(a, b)
Definition: cfImp.cxx:41
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
python.ext.lsprofcalltree.KCacheGrind.__init__
def __init__(self, profiler)
Definition: lsprofcalltree.py:14
python.ext.lsprofcalltree.KCacheGrind.output
def output(self, out_file)
Definition: lsprofcalltree.py:18
python.ext.lsprofcalltree.KCacheGrind._subentry
def _subentry(self, lineno, subentry)
Definition: lsprofcalltree.py:59
python.ext.lsprofcalltree.KCacheGrind._print_summary
def _print_summary(self)
Definition: lsprofcalltree.py:25
python.ext.lsprofcalltree.label
def label(code)
Definition: lsprofcalltree.py:5
python.ext.lsprofcalltree.KCacheGrind._entry
def _entry(self, entry)
Definition: lsprofcalltree.py:32
pickleTool.object
object
Definition: pickleTool.py:30
python.ext.lsprofcalltree.KCacheGrind.out_file
out_file
Definition: lsprofcalltree.py:16
python.ext.lsprofcalltree.KCacheGrind
Definition: lsprofcalltree.py:13
python.ext.lsprofcalltree.KCacheGrind.data
data
Definition: lsprofcalltree.py:15