[M108 Migration][VD] Avoid pending frame counter becoming negative
[platform/framework/web/chromium-efl.git] / cc / metrics / throughput_ukm_reporter.h
1 // Copyright 2019 The Chromium Authors
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 CC_METRICS_THROUGHPUT_UKM_REPORTER_H_
6 #define CC_METRICS_THROUGHPUT_UKM_REPORTER_H_
7
8 #include "base/memory/raw_ptr.h"
9 #include "cc/cc_export.h"
10 #include "cc/metrics/frame_sequence_metrics.h"
11 #include "third_party/abseil-cpp/absl/types/optional.h"
12
13 namespace cc {
14 class UkmManager;
15
16 enum class AggregationType {
17   kAllAnimations,
18   kAllInteractions,
19   kAllSequences,
20 };
21
22 // A helper class that takes throughput data from a FrameSequenceTracker and
23 // talk to UkmManager to report it.
24 class CC_EXPORT ThroughputUkmReporter {
25  public:
26   explicit ThroughputUkmReporter(UkmManager* ukm_manager);
27   ~ThroughputUkmReporter();
28
29   ThroughputUkmReporter(const ThroughputUkmReporter&) = delete;
30   ThroughputUkmReporter& operator=(const ThroughputUkmReporter&) = delete;
31
32   void ReportThroughputUkm(const absl::optional<int>& slower_throughput_percent,
33                            const absl::optional<int>& impl_throughput_percent,
34                            const absl::optional<int>& main_throughput_percent,
35                            FrameSequenceTrackerType type);
36
37   void ReportAggregateThroughput(AggregationType aggregation_type,
38                                  int throughput);
39
40   uint32_t GetSamplesToNextEventForTesting(int index);
41
42  private:
43   // Sampling control. We sample the event here to not throttle the UKM system.
44   // Currently, the same sampling rate is applied to all existing trackers. We
45   // might want to iterate on this based on the collected data.
46   uint32_t samples_to_next_event_[static_cast<int>(
47       FrameSequenceTrackerType::kMaxType)] = {0};
48   uint32_t samples_for_aggregated_report_ = 0;
49
50   // This is pointing to the LayerTreeHostImpl::ukm_manager_, which is
51   // initialized right after the LayerTreeHostImpl is created. So when this
52   // pointer is initialized, there should be no trackers yet.
53   const raw_ptr<UkmManager> ukm_manager_;
54 };
55
56 }  // namespace cc
57
58 #endif  // CC_METRICS_THROUGHPUT_UKM_REPORTER_H_