File: predictor_jank_tracker.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (93 lines) | stat: -rw-r--r-- 3,403 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CC_METRICS_PREDICTOR_JANK_TRACKER_H_
#define CC_METRICS_PREDICTOR_JANK_TRACKER_H_

#include <optional>

#include "base/time/time.h"
#include "cc/cc_export.h"
#include "cc/metrics/event_metrics.h"
#include "cc/metrics/scroll_jank_ukm_reporter.h"

namespace cc {

class CC_EXPORT PredictorJankTracker {
 public:
  PredictorJankTracker();
  ~PredictorJankTracker();

  PredictorJankTracker(const PredictorJankTracker&) = delete;
  PredictorJankTracker& operator=(const PredictorJankTracker);

  // Emits predictor scroll jank metrics for every frame relative
  // to the previous and the next frame.
  // For more details about the how a frame is deemed janky after
  // delta prediction is applied please check:
  // http://doc/1Y0u0Tq5eUZff75nYUzQVw6JxmbZAW9m64pJidmnGWsY
  void ReportLatestScrollDelta(float delta,
                               base::TimeTicks presentation_ts,
                               base::TimeDelta vsync_interval,
                               std::optional<EventMetrics::TraceId> trace_id);

  // Whenever a new scroll starts, data inside this class will be erased
  // as it should be comparing neighbouring frames only.
  void ResetCurrentScrollReporting();

  void set_scroll_jank_ukm_reporter(
      ScrollJankUkmReporter* scroll_jank_ukm_reporter) {
    scroll_jank_ukm_reporter_ = scroll_jank_ukm_reporter;
  }

  static float GetSlowScrollDeltaThreshold();
  static float GetSlowScrollJankyThreshold();
  static float GetFastScrollJankyThreshold();

 private:
  // The metric works by storing a sliding window of the previous two
  // frames, this function moves the sliding window storing the newer
  // frame information.
  void StoreLatestFrameData(float delta,
                            base::TimeTicks presentation_ts,
                            std::optional<EventMetrics::TraceId> trace_id);

  void ReportJankyFrame(float next_delta,
                        float janky_value,
                        bool contains_missed_vsyncs,
                        bool slow_scroll,
                        std::optional<EventMetrics::TraceId> trace_id);

  // Finds if a sequence of 3 consecutive frames were presnted in
  // consecutive vsyncs, or some vsyncs were missed.
  bool ContainsMissedVSync(base::TimeTicks& presentation_ts,
                           base::TimeDelta& vsync_interval);
  void ReportJankyFramePercentage();

  // Data holder for deltas and presentation timestamps in previous frames
  struct FrameData {
    // Delta for the previous frame in pixels.
    float prev_delta_ = 0;
    // The EventLatency event_trace_id value if available.
    std::optional<EventMetrics::TraceId> prev_trace_id_;
    // Delta for the current frame in pixels.
    float cur_delta_ = 0;
    // The EventLatency event_trace_id value if available.
    std::optional<EventMetrics::TraceId> cur_trace_id_;

    // Presentation timestamp of the previous frame.
    base::TimeTicks prev_presentation_ts_;
    // Presentation timestamp for the currentframe.
    base::TimeTicks cur_presentation_ts_;
  } frame_data_;

  float total_frames_ = 0;
  float janky_frames_ = 0;

  raw_ptr<ScrollJankUkmReporter> scroll_jank_ukm_reporter_ = nullptr;
};

}  // namespace cc

#endif  // CC_METRICS_PREDICTOR_JANK_TRACKER_H_