Skip to content

Commit

Permalink
[M116] The signal handler observes all necessary histogram with type
Browse files Browse the repository at this point in the history
If the same histogram is used as enum and value, then the handler only
stores value and not enum. This affects the aggregates depending on
when a new models with the value type was added. Make sure the handler
stores the histogram with all the necessary types.

(cherry picked from commit 4e0a7fb)

Bug: 1456749
Change-Id: Ia9182545f33116f3922e4f27ee36334f937fd7c3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4632397
Reviewed-by: Tommy Nyquist <nyquist@chromium.org>
Commit-Queue: Siddhartha S <ssid@chromium.org>
Cr-Original-Commit-Position: refs/heads/main@{#1160943}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4641629
Cr-Commit-Position: refs/branch-heads/5845@{#107}
Cr-Branched-From: 5a5dff6-refs/heads/main@{#1160321}
  • Loading branch information
ssiddhartha authored and Chromium LUCI CQ committed Jun 26, 2023
1 parent b2dd24c commit 5e1d0df
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void HistogramSignalHandler::SetRelevantHistograms(
histogram_name,
base::BindRepeating(&HistogramSignalHandler::OnHistogramSample,
weak_ptr_factory_.GetWeakPtr(), signal_type));
histogram_observers_[histogram_name] = std::move(histogram_observer);
histogram_observers_[pair] = std::move(histogram_observer);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ class HistogramSignalHandler {

// Tracks the histogram names we are currently listening to along with their
// corresponding observers.
using HistogramSignal = std::pair<std::string, proto::SignalType>;
std::map<
std::string,
HistogramSignal,
std::unique_ptr<base::StatisticsRecorder::ScopedHistogramSampleObserver>>
histogram_observers_;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,28 @@ TEST_F(HistogramSignalHandlerTest, HistogramsAreRecorded) {
task_environment_.RunUntilIdle();
}

TEST_F(HistogramSignalHandlerTest, HistogramAsValueAndEnum) {
histogram_signal_handler_->EnableMetrics(true);

// Add the same histogram as enum and as value type, the observer should write
// 2 samples to database.
std::set<std::pair<std::string, proto::SignalType>> histograms;
histograms.insert(
std::make_pair(kExpectedHistogram, proto::SignalType::HISTOGRAM_ENUM));
histograms.insert(
std::make_pair(kExpectedHistogram, proto::SignalType::HISTOGRAM_VALUE));
histogram_signal_handler_->SetRelevantHistograms(histograms);

// Record a registered histogram sample. It should be recorded.
EXPECT_CALL(*signal_database_, WriteSample(proto::SignalType::HISTOGRAM_ENUM,
kExpectedHash, Eq(1), _));
EXPECT_CALL(*signal_database_, WriteSample(proto::SignalType::HISTOGRAM_VALUE,
kExpectedHash, Eq(1), _));

UMA_HISTOGRAM_BOOLEAN(kExpectedHistogram, true);
task_environment_.RunUntilIdle();
}

TEST_F(HistogramSignalHandlerTest, DisableMetrics) {
SetupHistograms();

Expand Down

0 comments on commit 5e1d0df

Please sign in to comment.