Belle II Software  release-08-01-10
module_statistics.py
1 #!/usr/bin/env python3
2 
3 
10 
11 
15 
16 from basf2 import Path, process, statistics
17 
18 # Create main path
19 main = Path()
20 
21 # EventInfoSetter - generate event meta data
22 eventinfosetter = main.add_module('EventInfoSetter',
23  expList=[71, 71, 73, 73, 73],
24  runList=[3, 4, 10, 20, 30],
25  evtNumList=[40, 600, 20, 500, 301])
26 # eventinfo - show event meta info
27 eventinfo = main.add_module('EventInfoPrinter')
28 
29 # Process all events
30 process(main)
31 
32 # Print basic event statistics to stdout
33 print('Event Statistics:')
34 print(statistics)
35 
36 # Print basic event statistics for specific modules
37 print('Event Statistics for selected modules:')
38 print(statistics(modules=[eventinfosetter]))
39 
40 # Print statistics adding all counters
41 print('Total processing times:')
42 print(statistics(statistics.TOTAL))
43 
44 # Make a list of all available statistic counters
45 statistic_counters = [
46  (statistics.INIT, "initialize()"),
47  (statistics.BEGIN_RUN, "beginRun()"),
48  (statistics.EVENT, "event()"),
49  (statistics.END_RUN, "endRun()"),
50  (statistics.TERM, "terminate()"),
51  (statistics.TOTAL, "*total*"),
52 ]
53 
54 # Print detailed statistics for each module
55 for stats in statistics.modules:
56  print('Module %s:' % stats.name)
57  for stat_counter, stat_name in statistic_counters:
58  print(' -> %12s: %10.3f ms, %4d calls, %10.3f +-%10.3f ms/call' % (
59  stat_name,
60  # Time is in the default time unit which happens to be ns
61  stats.time_sum(stat_counter) / 1e6,
62  stats.calls(stat_counter),
63  stats.time_mean(stat_counter) / 1e6,
64  stats.time_stddev(stat_counter) / 1e6,
65  ))
66  print()
67 
68 print('Memory statistics')
69 for stats in statistics.modules:
70  print('Module %s:' % stats.name)
71  for stat_counter, stat_name in statistic_counters:
72  print(' -> %12s: %10d KB, %4d calls, %10d +-%10.3f KB/call' % (
73  stat_name,
74  stats.memory_sum(stat_counter),
75  stats.calls(stat_counter),
76  stats.memory_mean(stat_counter),
77  stats.memory_stddev(stat_counter),
78  ))
79 
80 # Get Statistics for single module
81 stats = statistics.get(eventinfosetter)
82 eventinfo_total = stats.time_sum(statistics.TOTAL)
83 print('EventInfoSetter needed %.3f ms in total' % (eventinfo_total / 1e6))
84 
85 # Print total processing time
86 framework_total = statistics.get_global().time_sum(statistics.TOTAL)
87 print('Total processing time: %.3f ms' % (framework_total / 1e6))
88 
89 # Calculate estimate for framework overhead
90 modules_total = sum(e.time_sum(statistics.TOTAL) for e in statistics.modules)
91 overhead = framework_total - modules_total
92 print('Framework overhead: {:.3f} ms ({:.2f} %)'.format(
93  overhead / 1e6,
94  100 * overhead / framework_total,
95 ))
96 print()
97 
98 # Clear statistics
99 statistics.clear()
100 print('Empty statistics')
101 print(statistics)