[M73 Dev][EFL] Disable VizDisplayCompositor for EFL port
[platform/framework/web/chromium-efl.git] / components / scheduling_metrics / task_duration_metric_reporter.h
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 #ifndef COMPONENTS_SCHEDULING_METRICS_TASK_DURATION_METRIC_REPORTER_H_
6 #define COMPONENTS_SCHEDULING_METRICS_TASK_DURATION_METRIC_REPORTER_H_
7
8 #include <memory>
9
10 #include "base/component_export.h"
11 #include "base/macros.h"
12 #include "base/metrics/histogram.h"
13 #include "base/time/time.h"
14
15 namespace base {
16 class HistogramBase;
17 }
18
19 namespace scheduling_metrics {
20
21 // A helper class to report total task runtime split by the different types of
22 // |TypeClass|. Only full seconds are reported. Note that partial seconds are
23 // rounded up/down, so that on average the correct value is reported when many
24 // reports are added.
25 //
26 // |TaskClass| is an enum which should have kClass field.
27 template <class TaskClass>
28 class TaskDurationMetricReporter {
29  public:
30   // Note that 1000*1000 is used to get microseconds precision.
31   explicit TaskDurationMetricReporter(const char* metric_name)
32       : value_per_type_histogram_(new base::ScaledLinearHistogram(
33             metric_name,
34             1,
35             static_cast<int>(TaskClass::kCount),
36             static_cast<int>(TaskClass::kCount) + 1,
37             1000 * 1000,
38             base::HistogramBase::kUmaTargetedHistogramFlag)){};
39
40   void RecordTask(TaskClass task_class, base::TimeDelta duration) {
41     DCHECK_LT(static_cast<int>(task_class),
42               static_cast<int>(TaskClass::kCount));
43
44     // To get mircoseconds precision, duration is converted to microseconds
45     // since |value_per_type_histogram_| is constructed with a scale of
46     // 1000*1000.
47     if (!duration.is_zero()) {
48       value_per_type_histogram_->AddScaledCount(
49           static_cast<int>(task_class),
50           base::saturated_cast<int>(duration.InMicroseconds()));
51     }
52   }
53
54  private:
55   std::unique_ptr<base::ScaledLinearHistogram> value_per_type_histogram_;
56
57   DISALLOW_COPY_AND_ASSIGN(TaskDurationMetricReporter);
58 };
59
60 }  // namespace scheduling_metrics
61
62 #endif  // COMPONENTS_SCHEDULING_METRICS_TASK_DURATION_METRIC_REPORTER_H_