diff options
author | 2020-07-30 14:26:28 +0000 | |
---|---|---|
committer | 2020-09-22 16:38:03 +0000 | |
commit | 6ee484df4191c92372b88423dc7a4a8beaeddc41 (patch) | |
tree | b5e54fb393682dd66b578564303e51b37f055fa1 | |
parent | 5cfc6e5bb8f30ac68d4dad7be3147a937d810fc5 (diff) |
Add listener callback to keep track of tracing state in SCC
Test: N/A
Change-Id: Iae1fe69b65a449f7e94fecaa17081022b0888c7b
-rw-r--r-- | libs/gui/Android.bp | 9 | ||||
-rw-r--r-- | libs/gui/ISurfaceComposer.cpp | 18 | ||||
-rw-r--r-- | libs/gui/TransactionTracing.cpp | 53 | ||||
-rw-r--r-- | libs/gui/aidl/android/gui/ITransactionTraceListener.aidl | 6 | ||||
-rw-r--r-- | libs/gui/include/gui/ISurfaceComposer.h | 8 | ||||
-rw-r--r-- | libs/gui/include/gui/TransactionTracing.h | 41 | ||||
-rw-r--r-- | libs/gui/tests/Surface_test.cpp | 8 | ||||
-rw-r--r-- | services/surfaceflinger/SurfaceFlinger.cpp | 12 | ||||
-rw-r--r-- | services/surfaceflinger/SurfaceFlinger.h | 3 | ||||
-rw-r--r-- | services/surfaceflinger/SurfaceInterceptor.cpp | 33 | ||||
-rw-r--r-- | services/surfaceflinger/SurfaceInterceptor.h | 6 | ||||
-rw-r--r-- | services/surfaceflinger/tests/unittests/mock/MockSurfaceInterceptor.h | 1 |
12 files changed, 192 insertions, 6 deletions
diff --git a/libs/gui/Android.bp b/libs/gui/Android.bp index ae265cab8f..a0e9cbf2eb 100644 --- a/libs/gui/Android.bp +++ b/libs/gui/Android.bp @@ -30,6 +30,12 @@ cc_library_headers { min_sdk_version: "29", } +filegroup { + name: "libgui_aidl", + srcs: ["aidl/**/*.aidl"], + path: "aidl/", +} + cc_library_shared { name: "libgui", vendor_available: false, @@ -42,6 +48,7 @@ cc_library_shared { srcs: [ ":framework_native_aidl", + ":libgui_aidl", ":libgui_bufferqueue_sources", "BitTube.cpp", @@ -74,6 +81,7 @@ cc_library_shared { "SurfaceControl.cpp", "SurfaceComposerClient.cpp", "SyncFeatures.cpp", + "TransactionTracing.cpp", "view/Surface.cpp", "bufferqueue/1.0/B2HProducerListener.cpp", "bufferqueue/1.0/H2BGraphicBufferProducer.cpp", @@ -145,6 +153,7 @@ cc_library_static { defaults: ["libgui_bufferqueue-defaults"], srcs: [ + ":libgui_aidl", ":libgui_bufferqueue_sources", ], } diff --git a/libs/gui/ISurfaceComposer.cpp b/libs/gui/ISurfaceComposer.cpp index 5b7d2c561e..7a2f656b76 100644 --- a/libs/gui/ISurfaceComposer.cpp +++ b/libs/gui/ISurfaceComposer.cpp @@ -20,6 +20,8 @@ #include <stdint.h> #include <sys/types.h> +#include <android/gui/ITransactionTraceListener.h> + #include <binder/Parcel.h> #include <binder/IPCThreadState.h> #include <binder/IServiceManager.h> @@ -1197,6 +1199,15 @@ public: return reply.readInt32(); } + + virtual status_t addTransactionTraceListener( + const sp<gui::ITransactionTraceListener>& listener) { + Parcel data, reply; + SAFE_PARCEL(data.writeInterfaceToken, ISurfaceComposer::getInterfaceDescriptor()); + SAFE_PARCEL(data.writeStrongBinder, IInterface::asBinder(listener)); + + return remote()->transact(BnSurfaceComposer::ADD_TRANSACTION_TRACE_LISTENER, data, &reply); + } }; // Out-of-line virtual method definition to trigger vtable emission in this @@ -2026,6 +2037,13 @@ status_t BnSurfaceComposer::onTransact( reply->writeInt32(result); return NO_ERROR; } + case ADD_TRANSACTION_TRACE_LISTENER: { + CHECK_INTERFACE(ISurfaceComposer, data, reply); + sp<gui::ITransactionTraceListener> listener; + SAFE_PARCEL(data.readStrongBinder, &listener); + + return addTransactionTraceListener(listener); + } default: { return BBinder::onTransact(code, data, reply, flags); } diff --git a/libs/gui/TransactionTracing.cpp b/libs/gui/TransactionTracing.cpp new file mode 100644 index 0000000000..eedc3df009 --- /dev/null +++ b/libs/gui/TransactionTracing.cpp @@ -0,0 +1,53 @@ +/* + * Copyright 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gui/TransactionTracing.h" +#include "gui/ISurfaceComposer.h" + +#include <private/gui/ComposerService.h> + +namespace android { + +sp<TransactionTraceListener> TransactionTraceListener::sInstance = nullptr; +std::mutex TransactionTraceListener::sMutex; + +TransactionTraceListener::TransactionTraceListener() {} + +sp<TransactionTraceListener> TransactionTraceListener::getInstance() { + const std::lock_guard<std::mutex> lock(sMutex); + + if (sInstance == nullptr) { + sInstance = new TransactionTraceListener; + + sp<ISurfaceComposer> sf(ComposerService::getComposerService()); + sf->addTransactionTraceListener(sInstance); + } + + return sInstance; +} + +binder::Status TransactionTraceListener::onToggled(bool enabled) { + ALOGD("TransactionTraceListener: onToggled listener called"); + mTracingEnabled = enabled; + + return binder::Status::ok(); +} + +bool TransactionTraceListener::isTracingEnabled() { + return mTracingEnabled; +} + +} // namespace android
\ No newline at end of file diff --git a/libs/gui/aidl/android/gui/ITransactionTraceListener.aidl b/libs/gui/aidl/android/gui/ITransactionTraceListener.aidl new file mode 100644 index 0000000000..5cd12fdc2b --- /dev/null +++ b/libs/gui/aidl/android/gui/ITransactionTraceListener.aidl @@ -0,0 +1,6 @@ +package android.gui; + +/** @hide */ +interface ITransactionTraceListener { + void onToggled(boolean enabled); +}
\ No newline at end of file diff --git a/libs/gui/include/gui/ISurfaceComposer.h b/libs/gui/include/gui/ISurfaceComposer.h index 7c25b974fe..3627debcdd 100644 --- a/libs/gui/include/gui/ISurfaceComposer.h +++ b/libs/gui/include/gui/ISurfaceComposer.h @@ -22,6 +22,7 @@ #include <binder/IBinder.h> #include <binder/IInterface.h> +#include <android/gui/ITransactionTraceListener.h> #include <gui/IScreenCaptureListener.h> #include <gui/ITransactionCompletedListener.h> @@ -486,6 +487,12 @@ public: */ virtual status_t setFrameTimelineVsync(const sp<IGraphicBufferProducer>& surface, int64_t frameTimelineVsyncId) = 0; + + /* + * Adds a TransactionTraceListener to listen for transaction tracing state updates. + */ + virtual status_t addTransactionTraceListener( + const sp<gui::ITransactionTraceListener>& listener) = 0; }; // ---------------------------------------------------------------------------- @@ -546,6 +553,7 @@ public: SET_FRAME_RATE, ACQUIRE_FRAME_RATE_FLEXIBILITY_TOKEN, SET_FRAME_TIMELINE_VSYNC, + ADD_TRANSACTION_TRACE_LISTENER, // Always append new enum to the end. }; diff --git a/libs/gui/include/gui/TransactionTracing.h b/libs/gui/include/gui/TransactionTracing.h new file mode 100644 index 0000000000..9efba47a18 --- /dev/null +++ b/libs/gui/include/gui/TransactionTracing.h @@ -0,0 +1,41 @@ +/* + * Copyright 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include <android/gui/BnTransactionTraceListener.h> +#include <utils/Mutex.h> + +namespace android { + +class TransactionTraceListener : public gui::BnTransactionTraceListener { + static std::mutex sMutex; + static sp<TransactionTraceListener> sInstance; + + TransactionTraceListener(); + +public: + static sp<TransactionTraceListener> getInstance(); + + binder::Status onToggled(bool enabled) override; + + bool isTracingEnabled(); + +private: + bool mTracingEnabled = false; +}; + +} // namespace android diff --git a/libs/gui/tests/Surface_test.cpp b/libs/gui/tests/Surface_test.cpp index 2508ebd05a..b8b8e4f4cb 100644 --- a/libs/gui/tests/Surface_test.cpp +++ b/libs/gui/tests/Surface_test.cpp @@ -677,8 +677,7 @@ public: NewFrameEventsEntry mNewFrameEntryOverride = { 0, 0, 0, nullptr }; }; - -class FakeSurfaceComposer : public ISurfaceComposer{ +class FakeSurfaceComposer : public ISurfaceComposer { public: ~FakeSurfaceComposer() override {} @@ -878,6 +877,11 @@ public: return NO_ERROR; } + status_t addTransactionTraceListener( + const sp<gui::ITransactionTraceListener>& /*listener*/) override { + return NO_ERROR; + } + protected: IBinder* onAsBinder() override { return nullptr; } diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index e860dff52d..4b91da82c3 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -4885,6 +4885,7 @@ status_t SurfaceFlinger::CheckTransactCodeCredentials(uint32_t code) { } return OK; } + case ADD_TRANSACTION_TRACE_LISTENER: case CAPTURE_DISPLAY_BY_ID: { IPCThreadState* ipc = IPCThreadState::self(); const int uid = ipc->getCallingUid(); @@ -6230,6 +6231,17 @@ void SurfaceFlinger::enableRefreshRateOverlay(bool enable) { })); } +status_t SurfaceFlinger::addTransactionTraceListener( + const sp<gui::ITransactionTraceListener>& listener) { + if (!listener) { + return BAD_VALUE; + } + + mInterceptor->addTransactionTraceListener(listener); + + return NO_ERROR; +} + } // namespace android #if defined(__gl_h_) diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h index 5cd9dea80f..d6a75c34dc 100644 --- a/services/surfaceflinger/SurfaceFlinger.h +++ b/services/surfaceflinger/SurfaceFlinger.h @@ -596,6 +596,9 @@ private: status_t setFrameTimelineVsync(const sp<IGraphicBufferProducer>& surface, int64_t frameTimelineVsyncId) override; + status_t addTransactionTraceListener( + const sp<gui::ITransactionTraceListener>& listener) override; + // Implements IBinder::DeathRecipient. void binderDied(const wp<IBinder>& who) override; diff --git a/services/surfaceflinger/SurfaceInterceptor.cpp b/services/surfaceflinger/SurfaceInterceptor.cpp index d6b53381aa..9d705e5999 100644 --- a/services/surfaceflinger/SurfaceInterceptor.cpp +++ b/services/surfaceflinger/SurfaceInterceptor.cpp @@ -45,9 +45,22 @@ SurfaceInterceptor::SurfaceInterceptor(SurfaceFlinger* flinger) { } +void SurfaceInterceptor::addTransactionTraceListener( + const sp<gui::ITransactionTraceListener>& listener) { + sp<IBinder> asBinder = IInterface::asBinder(listener); + + std::scoped_lock lock(mListenersMutex); + + asBinder->linkToDeath(this); + + listener->onToggled(mEnabled); // notifies of current state + + mTraceToggledListeners.emplace(asBinder, listener); +} + void SurfaceInterceptor::binderDied(const wp<IBinder>& who) { - // TODO: Implement - (void)who; + std::scoped_lock lock(mListenersMutex); + mTraceToggledListeners.erase(who); } void SurfaceInterceptor::enable(const SortedVector<sp<Layer>>& layers, @@ -57,8 +70,14 @@ void SurfaceInterceptor::enable(const SortedVector<sp<Layer>>& layers, return; } ATRACE_CALL(); + { + std::scoped_lock lock(mListenersMutex); + for (const auto& [_, listener] : mTraceToggledListeners) { + listener->onToggled(true); + } + } mEnabled = true; - std::lock_guard<std::mutex> protoGuard(mTraceMutex); + std::scoped_lock<std::mutex> protoGuard(mTraceMutex); saveExistingDisplaysLocked(displays); saveExistingSurfacesLocked(layers); } @@ -68,8 +87,14 @@ void SurfaceInterceptor::disable() { return; } ATRACE_CALL(); - std::lock_guard<std::mutex> protoGuard(mTraceMutex); + { + std::scoped_lock lock(mListenersMutex); + for (const auto& [_, listener] : mTraceToggledListeners) { + listener->onToggled(false); + } + } mEnabled = false; + std::scoped_lock<std::mutex> protoGuard(mTraceMutex); status_t err(writeProtoFileLocked()); ALOGE_IF(err == PERMISSION_DENIED, "Could not save the proto file! Permission denied"); ALOGE_IF(err == NOT_ENOUGH_DATA, "Could not save the proto file! There are missing fields"); diff --git a/services/surfaceflinger/SurfaceInterceptor.h b/services/surfaceflinger/SurfaceInterceptor.h index 62cc717c77..4908bae5da 100644 --- a/services/surfaceflinger/SurfaceInterceptor.h +++ b/services/surfaceflinger/SurfaceInterceptor.h @@ -60,6 +60,8 @@ public: virtual void disable() = 0; virtual bool isEnabled() = 0; + virtual void addTransactionTraceListener( + const sp<gui::ITransactionTraceListener>& listener) = 0; virtual void binderDied(const wp<IBinder>& who) = 0; // Intercept display and surface transactions @@ -99,6 +101,7 @@ public: void disable() override; bool isEnabled() override; + void addTransactionTraceListener(const sp<gui::ITransactionTraceListener>& listener) override; void binderDied(const wp<IBinder>& who) override; // Intercept display and surface transactions @@ -199,6 +202,9 @@ private: std::mutex mTraceMutex {}; Trace mTrace {}; SurfaceFlinger* const mFlinger; + std::mutex mListenersMutex; + std::map<wp<IBinder>, sp<gui::ITransactionTraceListener>> mTraceToggledListeners + GUARDED_BY(mListenersMutex); }; } // namespace impl diff --git a/services/surfaceflinger/tests/unittests/mock/MockSurfaceInterceptor.h b/services/surfaceflinger/tests/unittests/mock/MockSurfaceInterceptor.h index 2f3f5242ae..e2c8a65b5f 100644 --- a/services/surfaceflinger/tests/unittests/mock/MockSurfaceInterceptor.h +++ b/services/surfaceflinger/tests/unittests/mock/MockSurfaceInterceptor.h @@ -33,6 +33,7 @@ public: const DefaultKeyedVector<wp<IBinder>, DisplayDeviceState>&)); MOCK_METHOD0(disable, void()); MOCK_METHOD0(isEnabled, bool()); + MOCK_METHOD1(addTransactionTraceListener, void(const sp<gui::ITransactionTraceListener>&)); MOCK_METHOD1(binderDied, void(const wp<IBinder>&)); MOCK_METHOD6(saveTransaction, void(const Vector<ComposerState>&, |