Support injecting jank into Scheduler for testing purposes
Injects a fraction of a frame's expected present time as a jank. This is
mainly to avoid thinking about hard-coding milliseconds.
Also supports delaying this jank injection, since the Perfetto UI
currently steals any ADB session
Bug: 296636083
Test: TouchLatency + perfetto
Change-Id: If08616e68c3e7b3d6eaed6f6ff5cbc6ad444481e
diff --git a/services/surfaceflinger/Scheduler/Scheduler.cpp b/services/surfaceflinger/Scheduler/Scheduler.cpp
index d72ae1f..68e2ce9 100644
--- a/services/surfaceflinger/Scheduler/Scheduler.cpp
+++ b/services/surfaceflinger/Scheduler/Scheduler.cpp
@@ -211,6 +211,17 @@
targeters.try_emplace(id, &targeter);
}
+ if (flagutils::vrrConfigEnabled() &&
+ CC_UNLIKELY(mPacesetterFrameDurationFractionToSkip > 0.f)) {
+ const auto period = pacesetterTargeter.target().expectedFrameDuration();
+ const auto skipDuration = Duration::fromNs(
+ static_cast<nsecs_t>(period.ns() * mPacesetterFrameDurationFractionToSkip));
+ ATRACE_FORMAT("Injecting jank for %f%% of the frame (%" PRId64 " ns)",
+ mPacesetterFrameDurationFractionToSkip * 100, skipDuration.ns());
+ std::this_thread::sleep_for(skipDuration);
+ mPacesetterFrameDurationFractionToSkip = 0.f;
+ }
+
const auto resultsPerDisplay = compositor.composite(pacesetterId, targeters);
compositor.sample();