Fix: when SamplesStatsCounter is empty it's not propagated to the Histogram perf output
Bug: None Change-Id: I5664c39ed702b8ca581d28a08900f7a7d435d6ac Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/212610 Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Commit-Queue: Artem Titov <titovartem@webrtc.org> Cr-Commit-Position: refs/heads/master@{#33512}
This commit is contained in:
@ -18,6 +18,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "api/numerics/samples_stats_counter.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/strings/string_builder.h"
|
||||
#include "rtc_base/synchronization/mutex.h"
|
||||
@ -298,6 +299,10 @@ void PrintResult(absl::string_view measurement,
|
||||
for (size_t i = 0; i < timed_samples.size(); ++i) {
|
||||
samples[i] = timed_samples[i].value;
|
||||
}
|
||||
// If we have an empty counter, default it to 0.
|
||||
if (samples.empty()) {
|
||||
samples.push_back(0);
|
||||
}
|
||||
|
||||
GetPerfWriter().LogResultList(graph_name.str(), trace, samples, units,
|
||||
important, improve_direction);
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include <memory>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "api/numerics/samples_stats_counter.h"
|
||||
#include "rtc_base/logging.h"
|
||||
#include "rtc_base/strings/string_builder.h"
|
||||
#include "rtc_base/synchronization/mutex.h"
|
||||
|
@ -103,6 +103,83 @@ TEST_F(PerfTest, TestGetPerfResultsHistograms) {
|
||||
EXPECT_EQ(hist2.unit().unit(), proto::MS_BEST_FIT_FORMAT);
|
||||
}
|
||||
|
||||
TEST_F(PerfTest, TestGetPerfResultsHistogramsWithEmptyCounter) {
|
||||
ClearPerfResults();
|
||||
::testing::internal::CaptureStdout();
|
||||
|
||||
SamplesStatsCounter empty_counter;
|
||||
PrintResult("measurement", "_modifier", "story", empty_counter, "ms", false);
|
||||
|
||||
proto::HistogramSet histogram_set;
|
||||
EXPECT_TRUE(histogram_set.ParseFromString(GetPerfResults()))
|
||||
<< "Expected valid histogram set";
|
||||
|
||||
ASSERT_EQ(histogram_set.histograms_size(), 1)
|
||||
<< "Should be one histogram: measurement_modifier";
|
||||
const proto::Histogram& hist = histogram_set.histograms(0);
|
||||
|
||||
EXPECT_EQ(hist.name(), "measurement_modifier");
|
||||
|
||||
// Spot check some things in here (there's a more thorough test on the
|
||||
// histogram writer itself).
|
||||
EXPECT_EQ(hist.unit().unit(), proto::MS_BEST_FIT_FORMAT);
|
||||
EXPECT_EQ(hist.sample_values_size(), 1);
|
||||
EXPECT_EQ(hist.sample_values(0), 0);
|
||||
|
||||
EXPECT_EQ(hist.diagnostics().diagnostic_map().count("stories"), 1u);
|
||||
const proto::Diagnostic& stories =
|
||||
hist.diagnostics().diagnostic_map().at("stories");
|
||||
ASSERT_EQ(stories.generic_set().values_size(), 1);
|
||||
EXPECT_EQ(stories.generic_set().values(0), "\"story\"");
|
||||
|
||||
std::string expected = "RESULT measurement_modifier: story= {0,0} ms\n";
|
||||
EXPECT_EQ(expected, ::testing::internal::GetCapturedStdout());
|
||||
}
|
||||
|
||||
TEST_F(PerfTest, TestGetPerfResultsHistogramsWithStatsCounter) {
|
||||
ClearPerfResults();
|
||||
::testing::internal::CaptureStdout();
|
||||
|
||||
SamplesStatsCounter counter;
|
||||
counter.AddSample(1);
|
||||
counter.AddSample(2);
|
||||
counter.AddSample(3);
|
||||
counter.AddSample(4);
|
||||
counter.AddSample(5);
|
||||
PrintResult("measurement", "_modifier", "story", counter, "ms", false);
|
||||
|
||||
proto::HistogramSet histogram_set;
|
||||
EXPECT_TRUE(histogram_set.ParseFromString(GetPerfResults()))
|
||||
<< "Expected valid histogram set";
|
||||
|
||||
ASSERT_EQ(histogram_set.histograms_size(), 1)
|
||||
<< "Should be one histogram: measurement_modifier";
|
||||
const proto::Histogram& hist = histogram_set.histograms(0);
|
||||
|
||||
EXPECT_EQ(hist.name(), "measurement_modifier");
|
||||
|
||||
// Spot check some things in here (there's a more thorough test on the
|
||||
// histogram writer itself).
|
||||
EXPECT_EQ(hist.unit().unit(), proto::MS_BEST_FIT_FORMAT);
|
||||
EXPECT_EQ(hist.sample_values_size(), 5);
|
||||
EXPECT_EQ(hist.sample_values(0), 1);
|
||||
EXPECT_EQ(hist.sample_values(1), 2);
|
||||
EXPECT_EQ(hist.sample_values(2), 3);
|
||||
EXPECT_EQ(hist.sample_values(3), 4);
|
||||
EXPECT_EQ(hist.sample_values(4), 5);
|
||||
|
||||
EXPECT_EQ(hist.diagnostics().diagnostic_map().count("stories"), 1u);
|
||||
const proto::Diagnostic& stories =
|
||||
hist.diagnostics().diagnostic_map().at("stories");
|
||||
ASSERT_EQ(stories.generic_set().values_size(), 1);
|
||||
EXPECT_EQ(stories.generic_set().values(0), "\"story\"");
|
||||
|
||||
// mean = 3; std = sqrt(2)
|
||||
std::string expected =
|
||||
"RESULT measurement_modifier: story= {3,1.4142136} ms\n";
|
||||
EXPECT_EQ(expected, ::testing::internal::GetCapturedStdout());
|
||||
}
|
||||
|
||||
#endif // WEBRTC_ENABLE_PROTOBUF
|
||||
|
||||
#if GTEST_HAS_DEATH_TEST
|
||||
|
Reference in New Issue
Block a user