10 from generators
import add_kkmc_generator
11 from simulation
import add_simulation
12 from L1trigger
import add_tsim
13 from reconstruction
import add_reconstruction
14 from ROOT
import TFile
15 from argparse
import ArgumentParser
21 parser = ArgumentParser(description=
'Measure the execution time.')
22 parser.add_argument(
'-m',
'--multiplicity', default=
'high', choices=[
'high',
'low'], help=
'Multiplicity of events')
23 parser.add_argument(
'-l',
'--limits', help=
'Name of file containing limits')
24 parser.add_argument(
'-f',
'--file', help=
'Name of benchmark output file')
25 args = parser.parse_args()
29 set_log_level(LogLevel.ERROR)
32 main.add_module(
'EventInfoSetter', evtNumList=[1000])
33 main.add_module(
'EventInfoPrinter').set_log_level(LogLevel.INFO)
35 if args.multiplicity ==
'high':
37 main.add_module(
'EvtGenInput')
38 elif args.multiplicity ==
'low':
40 add_kkmc_generator(main,
'mu+mu-')
43 add_simulation(main, bkgfiles=glob.glob(os.environ.get(
'BELLE2_BACKGROUND_DIR',
'/sw/belle2/bkg') +
'/*.root'))
49 add_reconstruction(main)
57 limits_file = args.limits
58 default_limits_file = args.multiplicity +
'.limits'
59 if limits_file
is None and os.path.isfile(default_limits_file):
60 limits_file = default_limits_file
61 if limits_file
is not None:
62 for line
in open(limits_file).readlines():
63 entries = line.split()
64 limits[entries[0]] = float(entries[1])
66 limits[entries[0]] /= float(entries[2])
69 categories = [
'Simulation',
'TriggerSimulation',
'Tracking',
'PID',
'Clustering']
71 for module
in statistics.modules:
72 if module.name
not in [
'Sum_' + category
for category
in categories]:
74 category = module.name[4:]
75 if category
not in times.keys():
77 times[category] += module.time_mean(statistics.EVENT) * 1e-6
81 if args.file
is not None:
82 output = open(args.file,
'wt')
85 set_log_level(LogLevel.INFO)
87 for category
in categories:
88 if category
not in times.keys():
90 time = times[category]
91 message =
'Execution time per event for %s is %.f ms' % (category, time)
93 if category
in limits.keys():
94 fraction = time / limits[category]
95 if fraction > max_fraction:
96 max_fraction = fraction
97 message +=
' = %.f%% of the limit.' % (100 * fraction)
107 if output
is not None:
108 output.write(
'%s %.2f' % (category, time))
110 output.write(
' %.4f' % fraction)
114 sys.exit(0
if max_fraction <= 1
else 1)