1 // Copyright 2018 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "components/scheduling_metrics/total_duration_metric_reporter.h"
7 namespace scheduling_metrics {
11 constexpr base::TimeDelta kMinimalValue = base::TimeDelta::FromSeconds(1);
12 constexpr base::TimeDelta kMaximalValue = base::TimeDelta::FromHours(1);
13 constexpr int kBucketCount = 50;
17 TotalDurationMetricReporter::TotalDurationMetricReporter(
18 const char* positive_histogram_name,
19 const char* negative_histogram_name)
20 : positive_histogram_(base::Histogram::FactoryGet(
21 positive_histogram_name,
22 kMinimalValue.InSeconds(),
23 kMaximalValue.InSeconds(),
25 base::Histogram::kUmaTargetedHistogramFlag)),
26 negative_histogram_(base::Histogram::FactoryGet(
27 negative_histogram_name,
28 kMinimalValue.InSeconds(),
29 kMaximalValue.InSeconds(),
31 base::Histogram::kUmaTargetedHistogramFlag)) {}
33 void TotalDurationMetricReporter::RecordAdditionalDuration(
34 base::TimeDelta duration) {
36 negative_histogram_->Add(reported_value_->InSeconds());
37 reported_value_ = reported_value_.value_or(base::TimeDelta()) + duration;
38 positive_histogram_->Add(reported_value_->InSeconds());
41 void TotalDurationMetricReporter::Reset() {
42 reported_value_ = base::nullopt;
45 } // namespace scheduling_metrics