Tests that pretty-printing a ChunkedTimeSeriesCounter limits the number or printed samples to 64 or lower.
| 1623 | /// Tests that pretty-printing a ChunkedTimeSeriesCounter limits the number or printed |
| 1624 | /// samples to 64 or lower. |
| 1625 | TEST_P(TimeSeriesCounterResampleTest, TestPrettyPrint) { |
| 1626 | ObjectPool pool; |
| 1627 | RuntimeProfile* profile = RuntimeProfile::Create(&pool, "Profile"); |
| 1628 | |
| 1629 | const TimeSeriesTestParam& param = GetParam(); |
| 1630 | FLAGS_periodic_counter_update_period_ms = 500; |
| 1631 | const int test_period = FLAGS_periodic_counter_update_period_ms; |
| 1632 | |
| 1633 | // Add a counter with a sample function that counts up, starting from 0. |
| 1634 | int value = 0; |
| 1635 | auto sample_fn = [&value]() { return value++; }; |
| 1636 | // We increase the value of this flag to allow the counter to store enough samples. |
| 1637 | FLAGS_status_report_interval_ms = 50000; |
| 1638 | RuntimeProfile::TimeSeriesCounter* counter = |
| 1639 | profile->AddChunkedTimeSeriesCounter("TestCounter", TUnit::UNIT, sample_fn); |
| 1640 | |
| 1641 | // Stop counter updates from interfering with the rest of the test. |
| 1642 | StopAndClearCounter(profile, counter); |
| 1643 | |
| 1644 | // Reset value after previous values have been retrieved. |
| 1645 | value = 0; |
| 1646 | for (int i = 0; i < param.num_samples; ++i) counter->AddSample(test_period); |
| 1647 | |
| 1648 | int num_samples = 0; |
| 1649 | int result_period = 0; |
| 1650 | // Retrieve and validate samples. |
| 1651 | const int64_t* samples = counter->GetSamplesTest(&num_samples, &result_period); |
| 1652 | ASSERT_EQ(num_samples, param.num_samples); |
| 1653 | // No resampling happens with ChunkedTimeSeriesCounter. |
| 1654 | ASSERT_EQ(result_period, test_period); |
| 1655 | |
| 1656 | for (int i = 0; i < param.num_samples; ++i) ASSERT_EQ(samples[i], i); |
| 1657 | |
| 1658 | stringstream pretty; |
| 1659 | profile->PrettyPrint(&pretty); |
| 1660 | const string pretty_str = pretty.str(); |
| 1661 | |
| 1662 | for (const char* e : param.expected) EXPECT_STR_CONTAINS(pretty_str, e); |
| 1663 | } |
| 1664 | |
| 1665 | INSTANTIATE_TEST_SUITE_P(VariousNumbers, TimeSeriesCounterResampleTest, |
| 1666 | ::testing::Values( |
nothing calls this directly
no test coverage detected