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.
5 #ifndef CC_METRICS_THROUGHPUT_UKM_REPORTER_H_
6 #define CC_METRICS_THROUGHPUT_UKM_REPORTER_H_
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"
16 enum class AggregationType {
22 // A helper class that takes throughput data from a FrameSequenceTracker and
23 // talk to UkmManager to report it.
24 class CC_EXPORT ThroughputUkmReporter {
26 explicit ThroughputUkmReporter(UkmManager* ukm_manager);
27 ~ThroughputUkmReporter();
29 ThroughputUkmReporter(const ThroughputUkmReporter&) = delete;
30 ThroughputUkmReporter& operator=(const ThroughputUkmReporter&) = delete;
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);
37 void ReportAggregateThroughput(AggregationType aggregation_type,
40 uint32_t GetSamplesToNextEventForTesting(int index);
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;
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_;
58 #endif // CC_METRICS_THROUGHPUT_UKM_REPORTER_H_