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 #ifndef COMPONENTS_SCHEDULING_METRICS_TOTAL_DURATION_METRIC_REPORTER_H_
6 #define COMPONENTS_SCHEDULING_METRICS_TOTAL_DURATION_METRIC_REPORTER_H_
8 #include "base/component_export.h"
9 #include "base/metrics/histogram.h"
10 #include "base/optional.h"
11 #include "base/time/time.h"
13 namespace scheduling_metrics {
15 // Helper class to measure the total duration of the event accounting for
16 // possibility of the renderer process going away at any point.
18 // This is implemented by "undoing" old total value and "applying" new one
19 // each time RecordAdditionalDuration() is called.
20 // "Undoing" is implemented by having a second "negative" histogram, so to
21 // obtain the result, |positive_histogram - negative_histogram| difference
22 // should be analysed.
23 class COMPONENT_EXPORT(SCHEDULING_METRICS) TotalDurationMetricReporter {
25 TotalDurationMetricReporter(const char* positive_histogram_name,
26 const char* negative_histogram_name);
28 void RecordAdditionalDuration(base::TimeDelta duration);
33 base::Optional<base::TimeDelta> reported_value_;
35 base::HistogramBase* positive_histogram_;
36 base::HistogramBase* negative_histogram_;
39 } // namespace scheduling_metrics
41 #endif // COMPONENTS_SCHEDULING_METRICS_TOTAL_DURATION_METRIC_REPORTER_H_