Belle II Software
development
entities.py
1
8
import
numpy
as
np
9
10
from
hep_ipython_tools.entities
import
Statistics, StatisticsColumn
11
12
13
class
ModuleStatistics
:
14
15
"""
16
Dictionary list holding the module statistics (like the C++ class ModuleStatistics)
17
"""
18
19
def
__init__
(self, stats, categories):
20
"""Create a new module statistics entity."""
21
22
self.
name
= stats.name
23
24
self.
time_sum
= self.
get_dict
(stats.time_sum, categories)
25
26
self.
time_mean
= self.
get_dict
(stats.time_mean, categories)
27
28
self.
time_stddev
= self.
get_dict
(stats.time_stddev, categories)
29
30
self.
memory_sum
= self.
get_dict
(stats.memory_sum, categories)
31
32
self.
memory_mean
= self.
get_dict
(stats.memory_mean, categories)
33
34
self.
memory_stddev
= self.
get_dict
(stats.memory_stddev, categories)
35
36
self.
calls
= self.
get_dict
(stats.calls, categories)
37
38
@staticmethod
39
def
get_dict
(function, categories):
40
"""
41
Call the function on each information in the categories and return a dict
42
name -> function(value)
43
"""
44
return
{name: function(category)
for
name, category
in
categories}
45
46
def
__getitem__
(self, item):
47
"""Convenience function for the display."""
48
if
item ==
"name"
:
49
return
self.
name
50
elif
item ==
"calls"
:
51
return
self.
calls
[
"EVENT"
]
52
elif
item ==
"mem"
:
53
return
self.
memory_mean
[
"EVENT"
] * 1E-3
54
elif
item ==
"time"
:
55
return
np.round(self.
time_sum
[
"EVENT"
] * 1E-9, 2)
56
elif
item ==
"eventtime"
:
57
return
np.round(self.
time_mean
[
"EVENT"
] * 1E-6, 2),
"±"
, np.round(self.
time_stddev
[
"EVENT"
] * 1E-6, 2)
58
59
60
class
Basf2CalculationQueueStatistics
(
Statistics
):
61
62
"""
63
As the ipython_handler_basf2 statistics is not pickable, we can not store it into the queue.
64
So we write a wrapper which unpacks the needed properties.
65
"""
66
67
def
__str__
(self):
68
""" Make the str behave like before """
69
return
self.
str
70
71
def
__repr__
(self):
72
""" Make the repr behave like before """
73
return
self.
str
74
75
def
__init__
(self, statistics):
76
""" Initialize with the C++ statistics """
77
modules = []
78
79
columns = [
StatisticsColumn
(
"name"
,
"Name"
),
80
StatisticsColumn
(
"calls"
,
"Calls"
),
StatisticsColumn
(
"mem"
,
"VMemory (MB)"
),
81
StatisticsColumn
(
"time"
,
"Time (s)"
),
StatisticsColumn
(
"eventtime"
,
"Time (ms)/Call"
,
True
)]
82
83
categories = [(
"INIT"
, statistics.INIT),
84
(
"BEGIN_RUN"
, statistics.BEGIN_RUN),
85
(
"EVENT"
, statistics.EVENT),
86
(
"END_RUN"
, statistics.END_RUN),
87
(
"TERM"
, statistics.TERM),
88
(
"TOTAL"
, statistics.TOTAL)]
89
90
for
stats
in
statistics.modules:
91
modules.append(
ModuleStatistics
(stats, categories))
92
93
modules.append(
ModuleStatistics
(statistics.get_global(), categories))
94
95
96
self.
str
= statistics()
97
98
super().
__init__
(columns, modules)
hep_ipython_tools.entities.StatisticsColumn
Definition
entities.py:46
hep_ipython_tools.entities.Statistics
Definition
entities.py:73
hep_ipython_tools.ipython_handler_basf2.entities.Basf2CalculationQueueStatistics
Definition
entities.py:60
hep_ipython_tools.ipython_handler_basf2.entities.Basf2CalculationQueueStatistics.__str__
__str__(self)
Definition
entities.py:67
hep_ipython_tools.ipython_handler_basf2.entities.Basf2CalculationQueueStatistics.str
str
The str representation.
Definition
entities.py:96
hep_ipython_tools.ipython_handler_basf2.entities.Basf2CalculationQueueStatistics.__repr__
__repr__(self)
Definition
entities.py:71
hep_ipython_tools.ipython_handler_basf2.entities.Basf2CalculationQueueStatistics.__init__
__init__(self, statistics)
Definition
entities.py:75
hep_ipython_tools.ipython_handler_basf2.entities.ModuleStatistics
Definition
entities.py:13
hep_ipython_tools.ipython_handler_basf2.entities.ModuleStatistics.__getitem__
__getitem__(self, item)
Definition
entities.py:46
hep_ipython_tools.ipython_handler_basf2.entities.ModuleStatistics.memory_stddev
memory_stddev
Memory std property.
Definition
entities.py:34
hep_ipython_tools.ipython_handler_basf2.entities.ModuleStatistics.time_mean
time_mean
Time mean property.
Definition
entities.py:26
hep_ipython_tools.ipython_handler_basf2.entities.ModuleStatistics.time_sum
time_sum
Time sum property.
Definition
entities.py:24
hep_ipython_tools.ipython_handler_basf2.entities.ModuleStatistics.__init__
__init__(self, stats, categories)
Definition
entities.py:19
hep_ipython_tools.ipython_handler_basf2.entities.ModuleStatistics.memory_sum
memory_sum
Memory sum property.
Definition
entities.py:30
hep_ipython_tools.ipython_handler_basf2.entities.ModuleStatistics.name
name
Name property.
Definition
entities.py:22
hep_ipython_tools.ipython_handler_basf2.entities.ModuleStatistics.time_stddev
time_stddev
Time std property.
Definition
entities.py:28
hep_ipython_tools.ipython_handler_basf2.entities.ModuleStatistics.memory_mean
memory_mean
Memory mean property.
Definition
entities.py:32
hep_ipython_tools.ipython_handler_basf2.entities.ModuleStatistics.calls
calls
Calls property.
Definition
entities.py:36
hep_ipython_tools.ipython_handler_basf2.entities.ModuleStatistics.get_dict
get_dict(function, categories)
Definition
entities.py:39
hep_ipython_tools.entities
Definition
entities.py:1
framework
scripts
hep_ipython_tools
ipython_handler_basf2
entities.py
Generated on Mon Sep 1 2025 02:51:52 for Belle II Software by
1.13.2