ATLAS Offline Software
vtune_athena.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 
3 # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
4 
5 import logging
6 import subprocess
7 import sys
8 
9 # Setting logging options
10 fmt = '%(asctime)s :: %(levelname)-8s :: %(message)s'
11 datefmt = '%m/%d/%Y %H:%M'
12 logger = logging.getLogger(__name__)
13 logging.basicConfig(level=logging.DEBUG,
14  format=fmt,
15  datefmt=datefmt,
16  filename='./vtune_athena.log',
17  filemode='w')
18 console = logging.StreamHandler()
19 formatter = logging.Formatter(fmt,datefmt=datefmt)
20 console.setFormatter(formatter)
21 logger.addHandler(console)
22 
23 
27  try:
28  a = subprocess.check_output(['athena','--version'])
29  logger.debug('Athena version information \n %s',a)
30  except Exception:
31  logger.fatal('Athena is not setup!')
32  sys.exit(-1)
33 
34 
38  try:
39  a = subprocess.check_output(['vtune','--version'])
40  logger.debug('VTune version information \n %s',a)
41  except Exception:
42  logger.fatal('VTune is not setup!')
43  sys.exit(-1)
44 
45 
48 def generateJOFragment(fileName,firstEvent,lastEvent):
49  logger.info('Creating jOptions fragment %s', fileName)
50  with open('{}'.format(fileName),'w') as f:
51  f.write('# Auto generated jobOptions fragment to setup Athena VTune profiler')
52  f.write('\ninclude(\'PerfMonVTune/VTuneProfileEventLoop_preInclude.py\')')
53  f.write('\n\nfrom AthenaCommon.AppMgr import ServiceMgr')
54  f.write('\nServiceMgr.VTuneProfilerService.ResumeEvent = {}'.format(firstEvent))
55  f.write('\nServiceMgr.VTuneProfilerService.PauseEvent = {}'.format(lastEvent))
56 
57 
60 def main():
61  ''' Main function that parses user inputs, prepares and runs the tests '''
62 
63  from optparse import OptionParser
64  parser=OptionParser(usage='%prog [options]',
65  version='%prog 0.1.0')
66 
67  parser.add_option('--log-level',
68  type='choice',
69  action='store',
70  dest='logLevel',
71  choices=['critical','error','warning','info','debug'],
72  default='info',
73  help='Logging level (default: info)')
74 
75  parser.add_option('--collect',
76  type='choice',
77  action='store',
78  dest='collect',
79  choices=['hotspots','threading','memory-consumption',
80  'hpc-performance','memory-access','cpugpu-concurrency',
81  'gpu-hotspots','gpu-profiling','graphics-rendering',
82  'fpga-interaction','io','system-overview'],
83  default='hotspots',
84  help='Run the specified analysis type and collect data into a result (default: hotspots)')
85 
86  parser.add_option('--strategy',
87  type='string',
88  dest='strategy',
89  default=':trace:trace',
90  help='Run the specified strategy and collect data into a result. (default: :trace:trace)')
91 
92  parser.add_option('--tf',
93  type='string',
94  dest='tf',
95  default='',
96  help='Run the specified transformation command and collect data into a result.')
97 
98  parser.add_option('--resumeEvent',
99  type='int',
100  dest='start',
101  default=0,
102  help='Start the profiling from the specified event (default: 0).')
103 
104  parser.add_option('--pauseEvent',
105  type='int',
106  dest='stop',
107  default=-1,
108  help='Start the profiling at the specified event (default: -1).')
109 
110  (options,args) = parser.parse_args()
111 
112  logger.info(76*'-')
113 
114  # Set logging level
115  logger.setLevel(options.logLevel.upper())
116 
117  # Check the Athena and VTune setups
120 
121  # Perpare the JO fragment
122  joFragment = 'PerfMonVTune_autoSetup.py'
123  generateJOFragment(joFragment, options.start, options.stop)
124 
125  # Prepare the transformation command to execute
126  if not options.tf:
127  logger.fatal('The transformation command is empty, quitting...')
128  sys.exit(-1)
129 
130  args = options.tf.split()
131  if 'preInclude' in args:
132  index = args.index('--preInclude')
133  args.insert(index+1,joFragment)
134  else:
135  args.extend(['--preInclude',joFragment])
136 
137  # Run the command
138  cmd = ( 'vtune' +
139  ' -collect ' + options.collect +
140  ' -strategy ' + options.strategy +
141  ' -start-paused -- ' )
142  cmd += ' '.join(args)
143 
144  logger.info('Running the full command "{}"'.format(cmd))
145  subprocess.call(cmd,shell=True)
146 
147  logger.info('All done...')
148  logger.info(76*'-')
149 
150 if __name__ == '__main__':
151  main()
vtune_athena.format
format
Definition: vtune_athena.py:14
vtune_athena.checkVTuneSetup
def checkVTuneSetup()
Check VTune Setup.
Definition: vtune_athena.py:37
vtune_athena.main
def main()
Main Function.
Definition: vtune_athena.py:60
vtune_athena.generateJOFragment
def generateJOFragment(fileName, firstEvent, lastEvent)
AutoGen a jobOptions fragment.
Definition: vtune_athena.py:48
vtune_athena.checkAthenaSetup
def checkAthenaSetup()
Check Athena Setup.
Definition: vtune_athena.py:26
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
Trk::open
@ open
Definition: BinningType.h:40