1 // Copyright 2021 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_INJECTOR_H_
6 #define CC_METRICS_JANK_INJECTOR_H_
8 #include "base/task/single_thread_task_runner.h"
9 #include "cc/cc_export.h"
10 #include "components/viz/common/frame_sinks/begin_frame_args.h"
16 class CC_EXPORT ScopedJankInjectionEnabler {
18 ScopedJankInjectionEnabler();
19 ~ScopedJankInjectionEnabler();
21 ScopedJankInjectionEnabler(const ScopedJankInjectionEnabler&) = delete;
22 ScopedJankInjectionEnabler& operator=(const ScopedJankInjectionEnabler&) =
26 class CC_EXPORT JankInjector {
28 struct CC_EXPORT JankConfig {
29 uint32_t target_dropped_frames_percent = 10;
31 // How many consecutive frames to drop (when a frame is dropped).
32 uint32_t dropped_frame_cluster_size = 1;
39 JankInjector(const JankInjector&) = delete;
40 JankInjector& operator=(const JankInjector&) = delete;
42 static bool IsEnabled(const GURL& url);
44 void ScheduleJankIfNeeded(const viz::BeginFrameArgs& args,
45 base::SingleThreadTaskRunner* task_runner);
47 const JankConfig& config() const { return config_; }
50 bool ShouldJankCurrentFrame(const viz::BeginFrameArgs& args) const;
51 void ScheduleJank(const viz::BeginFrameArgs& args,
52 base::SingleThreadTaskRunner* task_runner);
57 uint64_t total_frames_ = 0;
58 uint64_t janked_frames_ = 0;
59 bool did_jank_last_time_ = false;
64 #endif // CC_METRICS_JANK_INJECTOR_H_