summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Vishnu Nair <vishnun@google.com> 2024-06-26 00:38:32 +0000
committer Vishnu Nair <vishnun@google.com> 2024-06-26 19:46:33 -0700
commit5a93ccb90b8507c806417c160c7c30a62d6f1bc2 (patch)
treea3508d30df95001bf3784c0d9c3affaa6d7dc0c7
parent5832cfde21db2e6720422b60e3ef98c526472058 (diff)
Add trace slices to capture tasks important for latency monitoring
Add a trace slices for: - for all post composition work on main thread - transaction callbacks - screenshot work on main thread Flag: EXEMPT adding trace slices + trivial refactor Bug: 333623207 Test: perfetto Change-Id: I6ca0a80941327edc0c78decf82176459d15d4595
-rw-r--r--services/surfaceflinger/RegionSamplingThread.cpp5
-rw-r--r--services/surfaceflinger/SurfaceFlinger.cpp8
-rw-r--r--services/surfaceflinger/SurfaceFlinger.h2
-rw-r--r--services/surfaceflinger/TransactionCallbackInvoker.cpp17
4 files changed, 18 insertions, 14 deletions
diff --git a/services/surfaceflinger/RegionSamplingThread.cpp b/services/surfaceflinger/RegionSamplingThread.cpp
index 5add290e96..86867d350f 100644
--- a/services/surfaceflinger/RegionSamplingThread.cpp
+++ b/services/surfaceflinger/RegionSamplingThread.cpp
@@ -358,9 +358,8 @@ void RegionSamplingThread::captureSample() {
if (FlagManager::getInstance().single_hop_screenshot() &&
FlagManager::getInstance().ce_fence_promise()) {
std::vector<sp<LayerFE>> layerFEs;
- auto displayState =
- mFlinger.getDisplayAndLayerSnapshotsFromMainThread(renderAreaBuilder,
- getLayerSnapshotsFn, layerFEs);
+ auto displayState = mFlinger.getSnapshotsFromMainThread(renderAreaBuilder,
+ getLayerSnapshotsFn, layerFEs);
fenceResult =
mFlinger.captureScreenshot(renderAreaBuilder, buffer, kRegionSampling, kGrayscale,
kIsProtected, nullptr, displayState, layerFEs)
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 5b40acf030..5d8c7283d8 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -2907,6 +2907,7 @@ CompositeResultsPerDisplay SurfaceFlinger::composite(
}
}
+ ATRACE_NAME("postComposition");
mTimeStats->recordFrameDuration(pacesetterTarget.frameBeginTime().ns(), systemTime());
// Send a power hint after presentation is finished.
@@ -8153,12 +8154,12 @@ bool SurfaceFlinger::layersHasProtectedLayer(const std::vector<sp<LayerFE>>& lay
// Accessing display requires mStateLock, and contention for this lock
// is reduced when grabbed from the main thread, thus also reducing
// risk of deadlocks.
-std::optional<SurfaceFlinger::OutputCompositionState>
-SurfaceFlinger::getDisplayAndLayerSnapshotsFromMainThread(
+std::optional<SurfaceFlinger::OutputCompositionState> SurfaceFlinger::getSnapshotsFromMainThread(
RenderAreaBuilderVariant& renderAreaBuilder, GetLayerSnapshotsFunction getLayerSnapshotsFn,
std::vector<sp<LayerFE>>& layerFEs) {
return mScheduler
->schedule([=, this, &renderAreaBuilder, &layerFEs]() REQUIRES(kMainThreadContext) {
+ ATRACE_NAME("getSnapshotsFromMainThread");
auto layers = getLayerSnapshotsFn();
for (auto& [layer, layerFE] : layers) {
attachReleaseFenceFutureToLayer(layer, layerFE.get(), ui::INVALID_LAYER_STACK);
@@ -8188,8 +8189,7 @@ void SurfaceFlinger::captureScreenCommon(RenderAreaBuilderVariant renderAreaBuil
FlagManager::getInstance().ce_fence_promise()) {
std::vector<sp<LayerFE>> layerFEs;
auto displayState =
- getDisplayAndLayerSnapshotsFromMainThread(renderAreaBuilder, getLayerSnapshotsFn,
- layerFEs);
+ getSnapshotsFromMainThread(renderAreaBuilder, getLayerSnapshotsFn, layerFEs);
const bool supportsProtected = getRenderEngine().supportsProtectedContent();
bool hasProtectedLayer = false;
diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h
index ee541c4364..34f48cd928 100644
--- a/services/surfaceflinger/SurfaceFlinger.h
+++ b/services/surfaceflinger/SurfaceFlinger.h
@@ -896,7 +896,7 @@ private:
using OutputCompositionState = compositionengine::impl::OutputCompositionState;
- std::optional<OutputCompositionState> getDisplayAndLayerSnapshotsFromMainThread(
+ std::optional<OutputCompositionState> getSnapshotsFromMainThread(
RenderAreaBuilderVariant& renderAreaBuilder,
GetLayerSnapshotsFunction getLayerSnapshotsFn, std::vector<sp<LayerFE>>& layerFEs);
diff --git a/services/surfaceflinger/TransactionCallbackInvoker.cpp b/services/surfaceflinger/TransactionCallbackInvoker.cpp
index 222ae30acb..8721538880 100644
--- a/services/surfaceflinger/TransactionCallbackInvoker.cpp
+++ b/services/surfaceflinger/TransactionCallbackInvoker.cpp
@@ -26,6 +26,7 @@
#include "TransactionCallbackInvoker.h"
#include "BackgroundExecutor.h"
#include "Utils/FenceUtils.h"
+#include "utils/Trace.h"
#include <cinttypes>
@@ -164,7 +165,7 @@ void TransactionCallbackInvoker::addPresentFence(sp<Fence> presentFence) {
void TransactionCallbackInvoker::sendCallbacks(bool onCommitOnly) {
// For each listener
auto completedTransactionsItr = mCompletedTransactions.begin();
- BackgroundExecutor::Callbacks callbacks;
+ ftl::SmallVector<ListenerStats, 10> listenerStatsToSend;
while (completedTransactionsItr != mCompletedTransactions.end()) {
auto& [listener, transactionStatsDeque] = *completedTransactionsItr;
ListenerStats listenerStats;
@@ -199,10 +200,7 @@ void TransactionCallbackInvoker::sendCallbacks(bool onCommitOnly) {
// keep it as an IBinder due to consistency reasons: if we
// interface_cast at the IPC boundary when reading a Parcel,
// we get pointers that compare unequal in the SF process.
- callbacks.emplace_back([stats = std::move(listenerStats)]() {
- interface_cast<ITransactionCompletedListener>(stats.listener)
- ->onTransactionCompleted(stats);
- });
+ listenerStatsToSend.emplace_back(std::move(listenerStats));
}
}
completedTransactionsItr++;
@@ -212,7 +210,14 @@ void TransactionCallbackInvoker::sendCallbacks(bool onCommitOnly) {
mPresentFence.clear();
}
- BackgroundExecutor::getInstance().sendCallbacks(std::move(callbacks));
+ BackgroundExecutor::getInstance().sendCallbacks(
+ {[listenerStatsToSend = std::move(listenerStatsToSend)]() {
+ ATRACE_NAME("TransactionCallbackInvoker::sendCallbacks");
+ for (auto& stats : listenerStatsToSend) {
+ interface_cast<ITransactionCompletedListener>(stats.listener)
+ ->onTransactionCompleted(stats);
+ }
+ }});
}
// -----------------------------------------------------------------------