Belle II Software  release-05-02-19
StatisticsSummaryModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2017 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Thomas Kuhr *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <framework/modules/profile/StatisticsSummaryModule.h>
12 
13 #include <framework/core/ModuleStatistics.h>
14 #include <framework/core/ModuleManager.h>
15 
16 
17 using namespace Belle2;
18 
19 // Register the Module
20 REG_MODULE(StatisticsSummary)
21 
22 
23 StatisticsSummaryModule::StatisticsSummaryModule() : Module(), m_processStatistics("", DataStore::c_Persistent)
24 {
25  // Set module description
26  setDescription("Sums up the statistics of preceeding modules. All modules until the first module or another StatisticsSummary module in the module statistics are included.");
27  setPropertyFlags(c_ParallelProcessingCertified | c_DontCollectStatistics);
28 }
29 
31 {
33 }
34 
36 {
38 }
39 
41 {
43 }
44 
46 {
48 }
49 
51 {
52  // get module statistics and list of modules
53  auto allStatistics = m_processStatistics->getAll();
54  auto modules = ModuleManager::Instance().getCreatedModules();
55 
56  // initialize sums
59 
60  // loop over module statistics
61  for (int index = m_processStatistics->getIndex(this) - 1; index >= 0; index--) {
62  const ModuleStatistics& statistics = allStatistics[index];
63 
64  // check if we have another StatisticsSummary module
65  const std::string& name = statistics.getName();
66  const Module* module = nullptr;
67  for (const auto& aModule : modules) {
68  if (aModule->getName() == name) {
69  module = aModule.get();
70  break;
71  }
72  }
73  if (module && (module->getType() == "StatisticsSummary")) {
74  break;
75  }
76 
77  // sum up
78  time += statistics.getTimeSum(type);
79  memory += statistics.getMemorySum(type);
80  }
81 
82  // update statistics of this module
83  ModuleStatistics& thisStatistics = m_processStatistics->getStatistics(this);
84  time -= thisStatistics.getTimeSum(type);
85  memory -= thisStatistics.getMemorySum(type);
86  thisStatistics.add(type, time, memory);
87 }
88 
Belle2::ModuleStatistics::c_Event
@ c_Event
Counting time/calls in event()
Definition: ModuleStatistics.h:45
Belle2::StatisticsSummaryModule::endRun
virtual void endRun() override
Record end run statistics sum.
Definition: StatisticsSummaryModule.cc:45
Belle2::ModuleManager::Instance
static ModuleManager & Instance()
Exception is thrown if the requested module could not be created by the ModuleManager.
Definition: ModuleManager.cc:28
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::ModuleStatistics::c_EndRun
@ c_EndRun
Counting time/calls in endRun()
Definition: ModuleStatistics.h:47
Belle2::ModuleStatistics::EStatisticCounters
EStatisticCounters
Enum to define all counter types.
Definition: ModuleStatistics.h:39
Belle2::ModuleStatistics::getMemorySum
value_type getMemorySum(EStatisticCounters type=c_Total) const
return the total used memory for a given counter
Definition: ModuleStatistics.h:112
Belle2::StatisticsSummaryModule::initialize
virtual void initialize() override
Record initialize statistics sum.
Definition: StatisticsSummaryModule.cc:30
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::ModuleStatistics::getName
const std::string & getName() const
Return the previously set name.
Definition: ModuleStatistics.h:86
Belle2::ModuleManager::getCreatedModules
const std::list< std::shared_ptr< Module > > & getCreatedModules() const
Returns a reference to the list of created modules.
Definition: ModuleManager.cc:128
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::StatisticsSummaryModule
A module that displays the sum of multiple modules in the module statistics.
Definition: StatisticsSummaryModule.h:39
Belle2::ModuleStatistics::add
void add(EStatisticCounters type, value_type time, value_type memory)
Add a time and memory measurment to the counter of a given type.
Definition: ModuleStatistics.h:65
Belle2::StatisticsSummaryModule::event
virtual void event() override
Record event statistics sum.
Definition: StatisticsSummaryModule.cc:40
Belle2::ModuleStatistics::value_type
double value_type
type of float variable to use for calculations and storage
Definition: ModuleStatistics.h:55
Belle2::ModuleStatistics::c_BeginRun
@ c_BeginRun
Counting time/calls in beginRun()
Definition: ModuleStatistics.h:43
Belle2::StatisticsSummaryModule::record
void record(ModuleStatistics::EStatisticCounters type)
Record the statistics of given type.
Definition: StatisticsSummaryModule.cc:50
Belle2::StatisticsSummaryModule::beginRun
virtual void beginRun() override
Record begin run statistics sum.
Definition: StatisticsSummaryModule.cc:35
Belle2::StatisticsSummaryModule::m_processStatistics
StoreObjPtr< ProcessStatistics > m_processStatistics
process statistics pointer
Definition: StatisticsSummaryModule.h:66
Belle2::ModuleStatistics::getTimeSum
value_type getTimeSum(EStatisticCounters type=c_Total) const
return the sum of all execution times for a given counter
Definition: ModuleStatistics.h:97
Belle2::DataStore
In the store you can park objects that have to be accessed by various modules.
Definition: DataStore.h:53
Belle2::ModuleStatistics
Keep track of time and memory consumption during processing.
Definition: ModuleStatistics.h:36
Belle2::ModuleStatistics::c_Init
@ c_Init
Counting time/calls in initialize()
Definition: ModuleStatistics.h:41