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