[M108 Migration][VD] Avoid pending frame counter becoming negative
[platform/framework/web/chromium-efl.git] / cc / metrics / jank_metrics.h
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.
4
5 #ifndef CC_METRICS_JANK_METRICS_H_
6 #define CC_METRICS_JANK_METRICS_H_
7
8 #include <memory>
9 #include <queue>
10 #include <utility>
11
12 #include "base/time/time.h"
13 #include "cc/metrics/frame_sequence_metrics.h"
14
15 namespace cc {
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 {
27  public:
28   JankMetrics(FrameSequenceTrackerType tracker_type,
29               FrameInfo::SmoothEffectDrivingThread effective_thread);
30   ~JankMetrics();
31
32   JankMetrics(const JankMetrics&) = delete;
33   JankMetrics& operator=(const JankMetrics&) = delete;
34
35   void AddFrameWithNoUpdate(uint32_t sequence_number,
36                             base::TimeDelta frame_interval);
37
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);
44
45   void AddSubmitFrame(uint32_t frame_token, uint32_t sequence_number);
46
47   // Merge the current jank count with a previously unreported jank metrics.
48   void Merge(std::unique_ptr<JankMetrics> jank_metrics);
49
50   // Report Graphics.Smoothness.(Jank|MaxStale).* metrics.
51   void ReportJankMetrics(int frames_expected);
52
53   // Reset the internal jank count
54   void Reset();
55
56   int jank_count() const { return jank_count_; }
57
58   base::TimeDelta max_staleness() const { return max_staleness_; }
59   FrameInfo::SmoothEffectDrivingThread thread_type() const {
60     return effective_thread_;
61   }
62
63  private:
64   // The type of the tracker this JankMetrics object is attached to.
65   const FrameSequenceTrackerType tracker_type_;
66
67   // The thread that contributes to the janks detected by the current
68   // JankMetrics object.
69   const FrameInfo::SmoothEffectDrivingThread effective_thread_;
70
71   // Number of janks detected.
72   int jank_count_ = 0;
73
74   // The time when the last presentation occurs
75   base::TimeTicks last_presentation_timestamp_;
76
77   // The sequence number associated with the last presented frame
78   uint32_t last_presentation_frame_id_ = 0u;
79
80   // The interval before the previous frame presentation.
81   base::TimeDelta prev_frame_delta_;
82
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_;
86
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_;
90
91   // The maximum frame staleness that occurred during the tracker's lifetime.
92   base::TimeDelta max_staleness_;
93 };
94
95 }  // namespace cc
96
97 #endif  // CC_METRICS_JANK_METRICS_H_