6 #include <gtest/gtest.h>
22 Start(uint64_t count,
double weight)
30 Stop(int64_t bankAccount, std::string state)
38 TEST(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");
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");
84 TEST(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, 1);
107 for (
auto & statistic : collector.CollectedStatistics())
113 TEST(StatisticsTests, TestStatisticsPrinting)
122 EXPECT_FALSE(testOutputDir.Exists());
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());
158 TEST(StatisticsTests, TestCreateOutputFile)
180 EXPECT_EQ(statsFile.path(),
"/tmp/test-module-ABC-stats.log");
182 EXPECT_EQ(cool0.path(),
"/tmp/test-module-ABC-cool-0");
183 EXPECT_EQ(cool1.path(),
"/tmp/test-module-ABC-cool-1");
185 EXPECT_EQ(nice0.path(),
"/tmp/test-module-ABC-nice-0.txt");
186 EXPECT_EQ(nice1.path(),
"/tmp/test-module-ABC-nice-1.txt");
TEST(StatisticsTests, TestStatisticsMeasurements)
void Stop(int64_t bankAccount, std::string state)
MyTestStatistics(jlm::util::Statistics::Id id, const jlm::util::FilePath &sourceFile)
void Start(uint64_t count, double weight)
static FilePath TempDirectoryPath()
const std::string & to_str() const noexcept
FilePath Join(const std::string &other) const
void SetUniqueString(std::string uniqueString)
File createOutputFile(std::string fileNameSuffix, bool includeCount=false)
util::Timer & GetTimer(const std::string &name)
const util::FilePath & GetSourceFile() const
Statistics(const Statistics::Id &statisticsId, util::FilePath sourceFile)
bool HasTimer(const std::string &name) const noexcept
const T & GetMeasurementValue(const std::string &name) const
util::Timer & AddTimer(std::string name)
IteratorRange< MeasurementList::const_iterator > GetMeasurements() const
IteratorRange< TimerList::const_iterator > GetTimers() const
size_t GetTimerElapsedNanoseconds(const std::string &name) const
bool HasMeasurement(const std::string &name) const noexcept
Statistics::Id GetId() const noexcept
void AddMeasurement(std::string name, T value)
static void remove(Node *node)