Belle II Software development
processstatistics.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#include <framework/core/ProcessStatistics.h>
9#include <framework/core/Module.h>
10
11#include <gtest/gtest.h>
12
13using namespace std;
14using namespace Belle2;
15
16namespace {
17 class DummyModule : public Module {
18 public:
19 DummyModule()
20 {
21 setName("Dummy");
22 setType("Dummy");
23 }
24 };
25
26 TEST(ProcessStatisticsTest, Clear)
27 {
29 EXPECT_EQ(0, a.getGlobal().getCalls());
30 EXPECT_EQ(0, a.getStatistics(nullptr).getCalls());
31 EXPECT_EQ(0, a.getGlobal().getTimeMean());
32
33 a.startGlobal();
34 a.startModule();
35 a.stopModule(nullptr, ModuleStatistics::c_Event);
36 a.stopGlobal(ModuleStatistics::c_Init);
37
38 EXPECT_EQ(1, a.getGlobal().getCalls());
39 EXPECT_EQ(1, a.getStatistics(nullptr).getCalls());
40 EXPECT_TRUE(a.getGlobal().getTimeMean() > 0);
41
42 a.clear();
43
44 EXPECT_EQ(0, a.getGlobal().getCalls());
45 EXPECT_EQ(0, a.getStatistics(nullptr).getCalls());
46 EXPECT_EQ(0, a.getGlobal().getTimeMean());
47 }
48
49 TEST(ProcessStatisticsTest, Merge)
50 {
53
54 a.startGlobal();
55 a.stopGlobal(ModuleStatistics::c_Init);
56 a.startModule();
57 a.stopModule(nullptr, ModuleStatistics::c_Event);
58
59 b.startGlobal();
60 b.stopGlobal(ModuleStatistics::c_Init);
61 b.startModule();
62 b.stopModule(nullptr, ModuleStatistics::c_Event);
63
64 EXPECT_EQ(1, a.getGlobal().getCalls());
65 EXPECT_EQ(1, a.getStatistics(nullptr).getCalls());
66 float sum = a.getGlobal().getTimeSum();
67 EXPECT_TRUE(sum > 0);
68
69 a.merge(&b); //all modules are there
70
71
72 EXPECT_EQ(1, a.getGlobal().getCalls());
73 EXPECT_EQ(2, a.getStatistics(nullptr).getCalls());
74 EXPECT_FLOAT_EQ(sum, a.getGlobal().getTimeSum());
75
76
77 //Add another module
79 DummyModule dummyMod;
80 c.startGlobal();
81 c.stopGlobal(ModuleStatistics::c_Init);
82 c.startModule();
83 c.stopModule(&dummyMod, ModuleStatistics::c_Event);
84
85 sum += c.getGlobal().getTimeSum();
86 a.merge(&c); //different merge process used, global time should also increase
87
88 EXPECT_EQ(2, a.getGlobal().getCalls());
89 EXPECT_EQ(2, a.getStatistics(nullptr).getCalls());
90 EXPECT_EQ(1, a.getStatistics(&dummyMod).getCalls());
91 EXPECT_FLOAT_EQ(sum, a.getGlobal().getTimeSum());
92 }
93} // namespace
@ c_Init
Counting time/calls in initialize()
@ c_Event
Counting time/calls in event()
Base class for Modules.
Definition: Module.h:72
void setName(const std::string &name)
Set the name of the module.
Definition: Module.h:214
void setType(const std::string &type)
Set the module type.
Definition: Module.cc:48
Class to collect call statistics for all modules.
Abstract base class for different kinds of events.
STL namespace.