38TEST(StatisticsTests, TestStatisticsMeasurements)
47 statistics.
Start(10, 6.0);
49 std::atomic_signal_fence(std::memory_order::memory_order_seq_cst);
50 statistics.
Stop(-400,
"poor");
53 EXPECT_EQ(statistics.
GetId(), Statistics::Id::Aggregation);
58 EXPECT_TRUE(statistics.
HasTimer(
"Timer"));
59 EXPECT_FALSE(statistics.
HasTimer(
"SpinLockTimer"));
69 auto it = measurements.begin();
70 EXPECT_EQ(it->first,
"count");
72 EXPECT_EQ(it->first,
"weight");
74 EXPECT_EQ(it->first,
"bankAccount");
76 EXPECT_EQ(it->first,
"state");
78 EXPECT_EQ(it, measurements.end());
81 EXPECT_EQ(timers.begin()->first,
"Timer");
84TEST(StatisticsTests, TestStatisticsCollection)
93 std::unique_ptr<Statistics> testStatistics1(
95 std::unique_ptr<Statistics> testStatistics2(
99 collector.CollectDemandedStatistics(std::move(testStatistics1));
100 collector.CollectDemandedStatistics(std::move(testStatistics2));
103 auto numCollectedStatistics =
104 std::distance(collector.CollectedStatistics().begin(), collector.CollectedStatistics().end());
106 EXPECT_EQ(numCollectedStatistics, 1u);
107 for (
auto & statistic : collector.CollectedStatistics())
109 EXPECT_EQ(statistic.GetId(), Statistics::Id::Aggregation);
113TEST(StatisticsTests, TestStatisticsPrinting)
118 auto testOutputDir = FilePath::TempDirectoryPath().Join(
"jlm-test-statistics");
121 std::filesystem::remove(testOutputDir.to_str());
122 EXPECT_FALSE(testOutputDir.Exists());
125 { Statistics::Id::Aggregation },
132 std::unique_ptr<MyTestStatistics> statistics(
134 statistics->Start(10, 6.0);
135 statistics->Stop(-400,
"poor");
137 collector.CollectDemandedStatistics(std::move(statistics));
140 collector.PrintStatistics();
143 EXPECT_TRUE(testOutputDir.IsDirectory());
145 const auto outputFileName =
"test-module-" + settings.GetUniqueString() +
"-statistics.log";
146 std::ifstream file(testOutputDir.Join(outputFileName).to_str());
147 std::string name, fileName, measurement;
148 file >> name >> fileName >> measurement;
150 EXPECT_EQ(name,
"Aggregation");
151 EXPECT_EQ(fileName, path.
to_str());
152 EXPECT_EQ(measurement,
"count:10");
155 std::filesystem::remove_all(testOutputDir.to_str());