ATLAS Offline Software
print_auditor_callgraph.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
4 
5 # @file: print_auditor_callgraph.py
6 # @purpose: print the callgraph sequence of a job stage (ini/exe/fin), parsing
7 # the logfile of a job run with NameAuditor enabled.
8 # @author: Sebastien Binet <binet@cern.ch>
9 # @date: May 2008
10 #
11 # @example:
12 # @code
13 # print_auditor_callgraph recexcommon.log
14 # @endcode
15 #
16 
17 __author__ = "Sebastien Binet <binet@cern.ch>"
18 
19 import os
20 import re
21 import sys
22 
23 class Steps:
24  ini = 'Initialization'
25  exe = 'Execute'
26  fin = 'Finalization'
27  ALLOWED = ('ini', 'exe', 'fin')
28 
29 def parse_log_file(fname, step=Steps.ini):
30  beg_pat = re.compile(r"NameAuditor.*?About to Enter "
31  r"(?P<CompName>.*?) "
32  r"%s Method"%step)
33  end_pat = re.compile(r"NameAuditor.*?Just Exited "
34  r"(?P<CompName>.*?) "
35  r"%s Method"%step)
36 
37  stack = 0
38  graph = []
39 
40  for l in open(fname, 'r'):
41  l = l.strip()
42  beg = re.match(beg_pat, l)
43  end = re.match(end_pat, l)
44  if not (beg or end):
45  continue
46 
47  if beg:
48  component = beg.group('CompName')
49  #print (" "*stack,component)
50  stack += 1
51  graph += [ (stack, component) ]
52 
53  if end:
54  component = end.group('CompName')
55  #print (" "*stack,component)
56  stack -= 1
57 
58  return graph
59 
60 
61 if __name__ == '__main__':
62  if len(sys.argv) < 2:
63  raise SystemExit(1, "You have to provide a path to a logfile to parse")
64 
65  fname = os.path.expandvars(os.path.expanduser(sys.argv[1]))
66  if not os.path.exists(fname):
67  raise SystemExit(
68  1, "You have to provide a VALID path to a logfile to parse")
69 
70  step = Steps.ini
71  if len(sys.argv) > 2:
72  step = sys.argv[2].lower()
73  if step not in Steps.ALLOWED:
74  raise SystemExit(
75  2, "Invalid step name [%s] allowed=%r"%(step, Steps.ALLOWED))
76 
77  step = getattr(Steps,step)
78 
79  gr = parse_log_file(fname,step)
80  #print (gr)
81  for i in gr:
82  print (".."*(i[0]+1),i[1])
83 
Trk::open
@ open
Definition: BinningType.h:40
print_auditor_callgraph.Steps
Definition: print_auditor_callgraph.py:23
print_auditor_callgraph.parse_log_file
def parse_log_file(fname, step=Steps.ini)
Definition: print_auditor_callgraph.py:29