Belle II Software  release-05-01-25
processstatistics.cc
1 #include <framework/core/ProcessStatistics.h>
2 #include <framework/core/Module.h>
3 
4 #include <gtest/gtest.h>
5 
6 using namespace std;
7 using namespace Belle2;
8 
9 namespace {
10  class DummyModule : public Module {
11  public:
12  DummyModule()
13  {
14  setName("Dummy");
15  setType("Dummy");
16  }
17  };
18 
19  TEST(ProcessStatisticsTest, Clear)
20  {
22  EXPECT_EQ(0, a.getGlobal().getCalls());
23  EXPECT_EQ(0, a.getStatistics(nullptr).getCalls());
24  EXPECT_EQ(0, a.getGlobal().getTimeMean());
25 
26  a.startGlobal();
27  a.startModule();
28  a.stopModule(nullptr, ModuleStatistics::c_Event);
29  a.stopGlobal(ModuleStatistics::c_Init);
30 
31  EXPECT_EQ(1, a.getGlobal().getCalls());
32  EXPECT_EQ(1, a.getStatistics(nullptr).getCalls());
33  EXPECT_TRUE(a.getGlobal().getTimeMean() > 0);
34 
35  a.clear();
36 
37  EXPECT_EQ(0, a.getGlobal().getCalls());
38  EXPECT_EQ(0, a.getStatistics(nullptr).getCalls());
39  EXPECT_EQ(0, a.getGlobal().getTimeMean());
40  }
41 
42  TEST(ProcessStatisticsTest, Merge)
43  {
46 
47  a.startGlobal();
48  a.stopGlobal(ModuleStatistics::c_Init);
49  a.startModule();
50  a.stopModule(nullptr, ModuleStatistics::c_Event);
51 
52  b.startGlobal();
53  b.stopGlobal(ModuleStatistics::c_Init);
54  b.startModule();
55  b.stopModule(nullptr, ModuleStatistics::c_Event);
56 
57  EXPECT_EQ(1, a.getGlobal().getCalls());
58  EXPECT_EQ(1, a.getStatistics(nullptr).getCalls());
59  float sum = a.getGlobal().getTimeSum();
60  EXPECT_TRUE(sum > 0);
61 
62  a.merge(&b); //all modules are there
63 
64 
65  EXPECT_EQ(1, a.getGlobal().getCalls());
66  EXPECT_EQ(2, a.getStatistics(nullptr).getCalls());
67  EXPECT_FLOAT_EQ(sum, a.getGlobal().getTimeSum());
68 
69 
70  //Add another module
72  DummyModule dummyMod;
73  c.startGlobal();
74  c.stopGlobal(ModuleStatistics::c_Init);
75  c.startModule();
76  c.stopModule(&dummyMod, ModuleStatistics::c_Event);
77 
78  sum += c.getGlobal().getTimeSum();
79  a.merge(&c); //different merge process used, global time should also increase
80 
81  EXPECT_EQ(2, a.getGlobal().getCalls());
82  EXPECT_EQ(2, a.getStatistics(nullptr).getCalls());
83  EXPECT_EQ(1, a.getStatistics(&dummyMod).getCalls());
84  EXPECT_FLOAT_EQ(sum, a.getGlobal().getTimeSum());
85  }
86 } // namespace
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TEST
TEST(TestgetDetectorRegion, TestgetDetectorRegion)
Test Constructors.
Definition: utilityFunctions.cc:18
Belle2::ProcessStatistics
Class to collect call statistics for all modules.
Definition: ProcessStatistics.h:94