1 // Copyright 2020 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_JANK_METRICS_H_
6 #define CC_METRICS_JANK_METRICS_H_
12 #include "base/time/time.h"
13 #include "cc/metrics/frame_sequence_metrics.h"
16 // This class reports 3 sets of metrics related to janks:
17 // - Graphics.Smoothness.Jank.*: Percent of frames that have longer
18 // presentation interval than its previous frame.
19 // Reports one percentage number per tracker.
20 // - Graphics.Smoothness.Stale.*: The difference between the real presentation
21 // interval and its expected value. Reports one
22 // TimeDelta per frame.
23 // - Graphics.Smoothness.MaxStale.*: The maximum staleness value that occurred
24 // during the course of an interaction.
25 // Reports one TimeDelta per tracker.
26 class CC_EXPORT JankMetrics {
28 JankMetrics(FrameSequenceTrackerType tracker_type,
29 FrameInfo::SmoothEffectDrivingThread effective_thread);
32 JankMetrics(const JankMetrics&) = delete;
33 JankMetrics& operator=(const JankMetrics&) = delete;
35 void AddFrameWithNoUpdate(uint32_t sequence_number,
36 base::TimeDelta frame_interval);
38 // Check if a jank occurs based on the timestamps of recent presentations.
39 // If there is a jank, increment |jank_count_| and log a trace event.
40 // Graphics.Smoothness.Stale.* metrics are reported in this function.
41 void AddPresentedFrame(uint32_t presented_frame_token,
42 base::TimeTicks current_presentation_timestamp,
43 base::TimeDelta frame_interval);
45 void AddSubmitFrame(uint32_t frame_token, uint32_t sequence_number);
47 // Merge the current jank count with a previously unreported jank metrics.
48 void Merge(std::unique_ptr<JankMetrics> jank_metrics);
50 // Report Graphics.Smoothness.(Jank|MaxStale).* metrics.
51 void ReportJankMetrics(int frames_expected);
53 // Reset the internal jank count
56 int jank_count() const { return jank_count_; }
58 base::TimeDelta max_staleness() const { return max_staleness_; }
59 FrameInfo::SmoothEffectDrivingThread thread_type() const {
60 return effective_thread_;
64 // The type of the tracker this JankMetrics object is attached to.
65 const FrameSequenceTrackerType tracker_type_;
67 // The thread that contributes to the janks detected by the current
68 // JankMetrics object.
69 const FrameInfo::SmoothEffectDrivingThread effective_thread_;
71 // Number of janks detected.
74 // The time when the last presentation occurs
75 base::TimeTicks last_presentation_timestamp_;
77 // The sequence number associated with the last presented frame
78 uint32_t last_presentation_frame_id_ = 0u;
80 // The interval before the previous frame presentation.
81 base::TimeDelta prev_frame_delta_;
83 // A queue storing {frame token, sequence number} for all submitted
84 // frames, in ascending order of frame token.
85 std::queue<std::pair<uint32_t, uint32_t>> queue_frame_token_and_id_;
87 // A queue storing {sequence number, frame interval} of unprocessed no-update
88 // frames, in ascending order of sequence number.
89 std::queue<std::pair<uint32_t, base::TimeDelta>> queue_frame_id_and_interval_;
91 // The maximum frame staleness that occurred during the tracker's lifetime.
92 base::TimeDelta max_staleness_;
97 #endif // CC_METRICS_JANK_METRICS_H_