Belle II Software  release-05-02-19
ProcessStatisticsPython Class Reference

Python interface for ProcessStatistics. More...

#include <ProcessStatisticsPython.h>

Public Member Functions

ProcessStatisticsgetWrapped ()
 Get wrapped ProcessStatistics object.
 
std::string getStatisticsString (ModuleStatistics::EStatisticCounters type=ModuleStatistics::c_Event, const std::vector< ModuleStatistics > *modules=nullptr)
 Return string with statistics for all modules. More...
 
std::string getModuleStatistics (const boost::python::list &modulesPyList, ModuleStatistics::EStatisticCounters type=ModuleStatistics::c_Event)
 Return string with statistics for selected modules. More...
 
void setModuleName (Module *module, const std::string &name)
 Set name for module in statistics. More...
 
const ModuleStatisticsget (const std::shared_ptr< Module > &module)
 Get statistics for given module.
 
const ModuleStatisticsgetGlobal ()
 Get statistics for the framework itself.
 
boost::python::list getAll ()
 Get statistics for all modules as python list.
 
void clear ()
 Clear collected statistics but keep names of modules.
 

Static Public Member Functions

static ProcessStatisticsPythongetInstance ()
 Return singleton instance of the statistics.
 
static void exposePythonAPI ()
 Define python wrappers to make functionality avaiable in python.
 

Private Member Functions

 ProcessStatisticsPython ()=default
 Private constructor due to singleton pattern.
 
 ProcessStatisticsPython (const ProcessStatisticsPython &)=delete
 Prohibit copy constructor.
 
ProcessStatisticsPythonoperator= (ProcessStatisticsPython &)=delete
 Prohibit assignment operator.
 

Detailed Description

Python interface for ProcessStatistics.

Since ProcessStatistics itself resides in the data store, this wraps around it to export some functionality to python.

Definition at line 33 of file ProcessStatisticsPython.h.

Member Function Documentation

โ—† getModuleStatistics()

string getModuleStatistics ( const boost::python::list &  modulesPyList,
ModuleStatistics::EStatisticCounters  type = ModuleStatistics::c_Event 
)

Return string with statistics for selected modules.

Parameters
modulesPyListpython list of modules to show
typecounter type to use for statistics

Definition at line 49 of file ProcessStatisticsPython.cc.

51 {
52  if (!getWrapped())
53  return "";
54 
55  std::vector<ModuleStatistics> moduleStats;
56  auto modules = PyObjConvUtils::convertPythonObject(modulesPyList, std::vector<ModulePtr>());
57  for (const ModulePtr& ptr : modules) {
58  ModuleStatistics& stats = getWrapped()->getStatistics(ptr.get());
59  //Name could be empty if module has never been called
60  if (stats.getName().empty()) stats.setName(ptr->getName());
61  moduleStats.push_back(stats);
62  }
63  return getStatisticsString(mode, &moduleStats);
64 }

โ—† getStatisticsString()

string getStatisticsString ( ModuleStatistics::EStatisticCounters  type = ModuleStatistics::c_Event,
const std::vector< ModuleStatistics > *  modules = nullptr 
)

Return string with statistics for all modules.

Can be used in steering file with 'print statistics'.

Parameters
typecounter type to use for statistics
modulesmap of modules to use. If NULL, default map will be used

Definition at line 41 of file ProcessStatisticsPython.cc.

โ—† setModuleName()

void setModuleName ( Module module,
const std::string &  name 
)
inline

Set name for module in statistics.

Normally, all modules get assigned their default name which is used to register them. If multiple instances of the same module are present at the same time, this can be used to distuingish between them

Parameters
moduleShared pointer to the Module for which a name is to be defined
nameName to show in statistics

Definition at line 74 of file ProcessStatisticsPython.h.

75  {
76  getWrapped()->getStatistics(module).setName(name);
77  }

The documentation for this class was generated from the following files:
Belle2::ModuleStatistics::setName
void setName(const std::string &name)
Set the name of the module for display.
Definition: ModuleStatistics.h:81
Belle2::ProcessStatisticsPython::getStatisticsString
std::string getStatisticsString(ModuleStatistics::EStatisticCounters type=ModuleStatistics::c_Event, const std::vector< ModuleStatistics > *modules=nullptr)
Return string with statistics for all modules.
Definition: ProcessStatisticsPython.cc:41
Belle2::ModulePtr
std::shared_ptr< Module > ModulePtr
Defines a pointer to a module object as a boost shared pointer.
Definition: Module.h:42
Belle2::ProcessStatistics::getStatistics
ModuleStatistics & getStatistics(const Module *module)
Get statistics for single module.
Definition: ProcessStatistics.h:172
Belle2::ProcessStatisticsPython::getWrapped
ProcessStatistics * getWrapped()
Get wrapped ProcessStatistics object.
Definition: ProcessStatisticsPython.cc:29
Belle2::PyObjConvUtils::convertPythonObject
Scalar convertPythonObject(const boost::python::object &pyObject, Scalar)
Convert from Python to given type.
Definition: PyObjConvUtils.h:510
Belle2::ModuleStatistics
Keep track of time and memory consumption during processing.
Definition: ModuleStatistics.h:36