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