[M73 Dev][EFL] Disable VizDisplayCompositor for EFL port
[platform/framework/web/chromium-efl.git] / components / scheduling_metrics / total_duration_metric_reporter.cc
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.
4
5 #include "components/scheduling_metrics/total_duration_metric_reporter.h"
6
7 namespace scheduling_metrics {
8
9 namespace {
10
11 constexpr base::TimeDelta kMinimalValue = base::TimeDelta::FromSeconds(1);
12 constexpr base::TimeDelta kMaximalValue = base::TimeDelta::FromHours(1);
13 constexpr int kBucketCount = 50;
14
15 }  // namespace
16
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(),
24           kBucketCount,
25           base::Histogram::kUmaTargetedHistogramFlag)),
26       negative_histogram_(base::Histogram::FactoryGet(
27           negative_histogram_name,
28           kMinimalValue.InSeconds(),
29           kMaximalValue.InSeconds(),
30           kBucketCount,
31           base::Histogram::kUmaTargetedHistogramFlag)) {}
32
33 void TotalDurationMetricReporter::RecordAdditionalDuration(
34     base::TimeDelta duration) {
35   if (reported_value_)
36     negative_histogram_->Add(reported_value_->InSeconds());
37   reported_value_ = reported_value_.value_or(base::TimeDelta()) + duration;
38   positive_histogram_->Add(reported_value_->InSeconds());
39 }
40
41 void TotalDurationMetricReporter::Reset() {
42   reported_value_ = base::nullopt;
43 }
44
45 }  // namespace scheduling_metrics