SF: add trace points for dispatcher system
Adds initial tracing points for the dispatcher and predictor vsync
signal dispatch system, along with some helper classes to turn traces
on and off based on system properties.
Verbose tracing can be turned on with 'setprop debug.sf.vsp_trace 1'
Test: boot with tracepoints on, see intended traces
Bug: 144927823
Change-Id: Ib6764404b77881887f338a41a25daa1d7068dc1f
diff --git a/services/surfaceflinger/Scheduler/VSyncDispatchTimerQueue.cpp b/services/surfaceflinger/Scheduler/VSyncDispatchTimerQueue.cpp
index 2e5b6e9..d0f18ab 100644
--- a/services/surfaceflinger/Scheduler/VSyncDispatchTimerQueue.cpp
+++ b/services/surfaceflinger/Scheduler/VSyncDispatchTimerQueue.cpp
@@ -52,6 +52,13 @@
return {mArmedInfo->mActualWakeupTime};
}
+std::optional<nsecs_t> VSyncDispatchTimerQueueEntry::targetVsync() const {
+ if (!mArmedInfo) {
+ return {};
+ }
+ return {mArmedInfo->mActualVsyncTime};
+}
+
ScheduleResult VSyncDispatchTimerQueueEntry::schedule(nsecs_t workDuration, nsecs_t earliestVsync,
VSyncTracker& tracker, nsecs_t now) {
auto nextVsyncTime =
@@ -143,9 +150,21 @@
rearmTimerSkippingUpdateFor(now, mCallbacks.end());
}
+void VSyncDispatchTimerQueue::TraceBuffer::note(std::string_view name, nsecs_t alarmIn,
+ nsecs_t vsFor) {
+ if (ATRACE_ENABLED()) {
+ snprintf(str_buffer.data(), str_buffer.size(), "%.4s%s%" PRId64 "%s%" PRId64,
+ name.substr(0, kMaxNamePrint).data(), kTraceNamePrefix, alarmIn,
+ kTraceNameSeparator, vsFor);
+ }
+ ATRACE_NAME(str_buffer.data());
+}
+
void VSyncDispatchTimerQueue::rearmTimerSkippingUpdateFor(
nsecs_t now, CallbackMap::iterator const& skipUpdateIt) {
std::optional<nsecs_t> min;
+ std::optional<nsecs_t> targetVsync;
+ std::optional<std::string_view> nextWakeupName;
for (auto it = mCallbacks.begin(); it != mCallbacks.end(); it++) {
auto& callback = it->second;
if (!callback->wakeupTime()) {
@@ -157,13 +176,19 @@
}
auto const wakeupTime = *callback->wakeupTime();
if (!min || (min && *min > wakeupTime)) {
+ nextWakeupName = callback->name();
min = wakeupTime;
+ targetVsync = callback->targetVsync();
}
}
if (min && (min < mIntendedWakeupTime)) {
+ if (targetVsync && nextWakeupName) {
+ mTraceBuffer.note(*nextWakeupName, *min - now, *targetVsync - now);
+ }
setTimer(*min, now);
} else {
+ ATRACE_NAME("cancel timer");
cancelTimer();
}
}