Belle II Software light-2406-ragdoll
StatisticsSummaryModule.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <framework/modules/profile/StatisticsSummaryModule.h>
10
11#include <framework/core/ModuleStatistics.h>
12#include <framework/core/ModuleManager.h>
13
14
15using namespace Belle2;
16
17// Register the Module
18REG_MODULE(StatisticsSummary);
19
20
21StatisticsSummaryModule::StatisticsSummaryModule() : Module(), m_processStatistics("", DataStore::c_Persistent)
22{
23 // Set module description
24 setDescription("Sums up the statistics of preceeding modules. All modules until the first module or another StatisticsSummary module in the module statistics are included.");
26}
27
29{
31}
32
34{
36}
37
39{
41}
42
44{
46}
47
49{
50 // get module statistics and list of modules
51 auto allStatistics = m_processStatistics->getAll();
53
54 // initialize sums
57
58 // loop over module statistics
59 for (int index = m_processStatistics->getIndex(this) - 1; index >= 0; index--) {
60 const ModuleStatistics& statistics = allStatistics[index];
61
62 // check if we have another StatisticsSummary module
63 const std::string& name = statistics.getName();
64 const Module* module = nullptr;
65 for (const auto& aModule : modules) {
66 if (aModule->getName() == name) {
67 module = aModule.get();
68 break;
69 }
70 }
71 if (module && (module->getType() == "StatisticsSummary")) {
72 break;
73 }
74
75 // sum up
76 time += statistics.getTimeSum(type);
77 memory += statistics.getMemorySum(type);
78 }
79
80 // update statistics of this module
81 ModuleStatistics& thisStatistics = m_processStatistics->getStatistics(this);
82 time -= thisStatistics.getTimeSum(type);
83 memory -= thisStatistics.getMemorySum(type);
84 thisStatistics.add(type, time, memory);
85}
86
In the store you can park objects that have to be accessed by various modules.
Definition: DataStore.h:51
const std::list< std::shared_ptr< Module > > & getCreatedModules() const
Returns a reference to the list of created modules.
static ModuleManager & Instance()
Exception is thrown if the requested module could not be created by the ModuleManager.
Keep track of time and memory consumption during processing.
const std::string & getName() const
Return the previously set name.
void add(EStatisticCounters type, value_type time, value_type memory)
Add a time and memory measurment to the counter of a given type.
EStatisticCounters
Enum to define all counter types.
@ c_Init
Counting time/calls in initialize()
@ c_EndRun
Counting time/calls in endRun()
@ c_BeginRun
Counting time/calls in beginRun()
@ c_Event
Counting time/calls in event()
value_type getMemorySum(EStatisticCounters type=c_Total) const
return the total used memory for a given counter
value_type getTimeSum(EStatisticCounters type=c_Total) const
return the sum of all execution times for a given counter
double value_type
type of float variable to use for calculations and storage
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:208
@ c_DontCollectStatistics
No statistics is collected for this module.
Definition: Module.h:84
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition: Module.h:80
virtual void initialize() override
Record initialize statistics sum.
StoreObjPtr< ProcessStatistics > m_processStatistics
process statistics pointer
virtual void event() override
Record event statistics sum.
virtual void endRun() override
Record end run statistics sum.
virtual void beginRun() override
Record begin run statistics sum.
void record(ModuleStatistics::EStatisticCounters type)
Record the statistics of given type.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Abstract base class for different kinds of events.
Definition: ClusterUtils.h:24