TEST_F(MetricsTest, CounterTimer) {
MetricsCounter<DatumId::kClassVerificationTotalTime> test_counter;
{
AutoTimer timer{&test_counter}; // Sleep for 2µs so the counter will be greater than 0.
NanoSleep(2'000);
}
EXPECT_GT(CounterValue(test_counter), 0u);
}
TEST_F(MetricsTest, CounterTimerExplicitStop) {
MetricsCounter<DatumId::kClassVerificationTotalTime> test_counter;
AutoTimer timer{&test_counter}; // Sleep for 2µs so the counter will be greater than 0.
NanoSleep(2'000);
timer.Stop();
EXPECT_GT(CounterValue(test_counter), 0u);
}
TEST_F(MetricsTest, CounterTimerExplicitStart) {
MetricsCounter<DatumId::kClassVerificationTotalTime> test_counter;
{
AutoTimer timer{&test_counter, /*autostart=*/false}; // Sleep for 2µs so the counter will be greater than 0.
NanoSleep(2'000);
}
EXPECT_EQ(CounterValue(test_counter), 0u);
{
AutoTimer timer{&test_counter, /*autostart=*/false};
timer.Start(); // Sleep for 2µs so the counter will be greater than 0.
NanoSleep(2'000);
}
EXPECT_GT(CounterValue(test_counter), 0u);
}
TEST_F(MetricsTest, CounterTimerExplicitStartStop) {
MetricsCounter<DatumId::kClassVerificationTotalTime> test_counter;
AutoTimer timer{&test_counter, /*autostart=*/false}; // Sleep for 2µs so the counter will be greater than 0.
timer.Start();
NanoSleep(2'000);
timer.Stop();
EXPECT_GT(CounterValue(test_counter), 0u);
}
// Make sure values added outside the range of the histogram go into the first or last bucket.
TEST_F(MetricsTest, HistogramOutOfRangeTest) {
MetricsHistogram<DatumId::kYoungGcCollectionTime, 2, 0, 100> histogram;
// Test adding values to ArtMetrics and reporting them through a test backend.
TEST_F(MetricsTest, ArtMetricsReport) {
ArtMetrics metrics;
// Collect some data static constexpr uint64_t verification_time = 42;
metrics.ClassVerificationTotalTime()->Add(verification_time); // Add a negative value so we are guaranteed that it lands in the first bucket.
metrics.YoungGcCollectionTime()->Add(-5);
// Report and check the data class TestBackend : public TestBackendBase { public:
~TestBackend() {
EXPECT_TRUE(found_counter_);
EXPECT_TRUE(found_histogram_);
}
void ReportCounter(DatumId counter_type, uint64_t value) override { switch (counter_type) { case DatumId::kClassVerificationTotalTime:
EXPECT_EQ(value, verification_time)
<< "Unexpected value for counter " << DatumName(counter_type);
found_counter_ = true; break; case DatumId::kTimeElapsedDelta: // TimeElapsedData can be greater than 0 if the test takes more than 1ms to run
EXPECT_GE(value, 0u) << "Unexpected value for counter " << DatumName(counter_type); break; default:
EXPECT_EQ(value, 0u) << "Unexpected value for counter " << DatumName(counter_type);
}
}
void ReportHistogram(DatumId histogram_type,
int64_t,
int64_t, const std::vector<uint32_t>& buckets) override { if (histogram_type == DatumId::kYoungGcCollectionTime) {
EXPECT_EQ(buckets[0], 1u) << "Unexpected value for bucket 0 for histogram "
<< DatumName(histogram_type); for (size_t i = 1; i < buckets.size(); ++i) {
EXPECT_EQ(buckets[i], 0u) << "Unexpected value for bucket " << i << " for histogram "
<< DatumName(histogram_type);
}
found_histogram_ = true;
} else { for (size_t i = 0; i < buckets.size(); ++i) {
EXPECT_EQ(buckets[i], 0u) << "Unexpected value for bucket " << i << " for histogram "
<< DatumName(histogram_type);
}
}
}
TEST_F(MetricsTest, HistogramTimer) {
MetricsHistogram<DatumId::kYoungGcCollectionTime, 1, 0, 100> test_histogram;
{
AutoTimer timer{&test_histogram}; // Sleep for 2µs so the counter will be greater than 0.
NanoSleep(2'000);
}
EXPECT_GT(GetBuckets(test_histogram)[0], 0u);
}
// Makes sure all defined metrics are included when dumping through StreamBackend.
TEST_F(MetricsTest, StreamBackendDumpAllMetrics) {
ArtMetrics metrics;
StringBackend backend(std::make_unique<TextFormatter>());
// Make sure the metrics all have a nonzero value.
metrics.ReportAllMetricsAndResetValueMetrics({&non_zero_backend});
// Reset the metrics and make sure they are all zero again
metrics.Reset();
class ZeroBackend : public TestBackendBase { public: void ReportCounter(DatumId counter_type, uint64_t value) override { if (counter_type == DatumId::kTimeElapsedDelta) { // TimeElapsedData can be greater than 0 if the test takes more than 1ms to run
EXPECT_GE(value, 0u) << "Unexpected value for counter " << DatumName(counter_type);
} else {
EXPECT_EQ(value, 0u) << "Unexpected value for counter " << DatumName(counter_type);
}
}
void ReportHistogram([[maybe_unused]] DatumId histogram_type,
[[maybe_unused]] int64_t minimum_value,
[[maybe_unused]] int64_t maximum_value, const std::vector<uint32_t>& buckets) override { for (constauto value : buckets) {
EXPECT_EQ(value, 0u) << "Unexpected value for histogram " << DatumName(histogram_type);
}
}
} zero_backend;
// Add something to each of the metrics. #define METRIC(name, type, ...) metrics.name()->Add(42);
ART_METRICS(METRIC) #undef METRIC
class FirstBackend : public TestBackendBase { public: void ReportCounter(DatumId counter_type, uint64_t value) override {
EXPECT_NE(value, 0u) << "Unexpected value for counter " << DatumName(counter_type);
}
void ReportHistogram(DatumId histogram_type,
[[maybe_unused]] int64_t minimum_value,
[[maybe_unused]] int64_t maximum_value, const std::vector<uint32_t>& buckets) override {
EXPECT_NE(buckets[0], 0u) << "Unexpected value for bucket 0 for histogram "
<< DatumName(histogram_type); for (size_t i = 1; i < buckets.size(); i++) {
EXPECT_EQ(buckets[i], 0u) << "Unexpected value for bucket " << i << " for histogram "
<< DatumName(histogram_type);
}
}
} first_backend;
// Make sure the metrics all have a nonzero value, and they are not reset between backends.
metrics.ReportAllMetricsAndResetValueMetrics({&first_backend, &first_backend});
// After reporting, the Value Metrics should have been reset. class SecondBackend : public TestBackendBase { public: void ReportCounter(DatumId datum_id, uint64_t value) override { switch (datum_id) { // Value metrics - expected to have been reset #define CHECK_METRIC(name, ...) case DatumId::k##name:
ART_VALUE_METRICS(CHECK_METRIC) #undef CHECK_METRIC if (datum_id == DatumId::kTimeElapsedDelta) { // TimeElapsedData can be greater than 0 if the test takes more than 1ms to run
EXPECT_GE(value, 0u) << "Unexpected value for counter " << DatumName(datum_id);
} else {
EXPECT_EQ(value, 0u) << "Unexpected value for counter " << DatumName(datum_id);
} return;
// Event metrics - expected to have retained their previous value #define CHECK_METRIC(name, ...) case DatumId::k##name:
ART_EVENT_METRICS(CHECK_METRIC) #undef CHECK_METRIC
EXPECT_NE(value, 0u) << "Unexpected value for metric " << DatumName(datum_id); return;
default: // unknown metric - it should not be possible to reach this path
FAIL();
UNREACHABLE();
}
}
// All histograms are event metrics. void ReportHistogram([[maybe_unused]] DatumId histogram_type,
[[maybe_unused]] int64_t minimum_value,
[[maybe_unused]] int64_t maximum_value, const std::vector<uint32_t>& buckets) override {
EXPECT_NE(buckets[0], 0u) << "Unexpected value for bucket 0 for histogram "
<< DatumName(histogram_type); for (size_t i = 1; i < buckets.size(); i++) {
EXPECT_EQ(buckets[i], 0u) << "Unexpected value for bucket " << i << " for histogram "
<< DatumName(histogram_type);
}
}
} second_backend;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.