diff options
author | 2024-03-29 16:29:13 +0000 | |
---|---|---|
committer | 2024-03-29 22:46:11 +0000 | |
commit | c0bf3899a3eaf6db2a9baa1b014bdf058e9ce5c8 (patch) | |
tree | e69d959126abfeeb2231b61c6eb68a1658a409dd | |
parent | 4aeb67df1c9f8e432f4743a7633556bd91efa3c9 (diff) |
Add tracing for InputConsumer lifetime
This will help understand when it's created and destroyed. This also helps disambiguate between multiple InputConsumers in the same process.
Test procedure:
1. Add "system tracing" to quick settings from developer options (enable
the quick settings tile for system tracing)
2. Start system tracing via UI of quick settings
3. Open all apps and do some swipes
4. Click "stop tracing"
5. Pull the logs to the device `adb pull /data/local/traces/ ~/trace`
6. Go to https://ui.perfetto.dev/
7. Click "open trace file" and navigate to the local file
8. In the trace, open the process of interest. In this case, it's the
launcher process
9. Scroll down to "InputConsumer processing"
10. The "cookie" field of each entry is the sequence number of this
event (but not the event id).
Bug: 311142655
Test: perfetto test procedure described above
Change-Id: If8cdadd3604e8e3ab24c45a5ccf4ea9ffa9fee4a
-rw-r--r-- | include/input/InputConsumer.h | 5 | ||||
-rw-r--r-- | libs/input/InputConsumer.cpp | 21 |
2 files changed, 22 insertions, 4 deletions
diff --git a/include/input/InputConsumer.h b/include/input/InputConsumer.h index 560e804c68..611478cbeb 100644 --- a/include/input/InputConsumer.h +++ b/include/input/InputConsumer.h @@ -111,6 +111,11 @@ private: std::shared_ptr<InputChannel> mChannel; + // TODO(b/311142655): delete this temporary tracing after the ANR bug is fixed + const std::string mProcessingTraceTag; + const std::string mLifetimeTraceTag; + const int32_t mLifetimeTraceCookie; + // The current input message. InputMessage mMsg; diff --git a/libs/input/InputConsumer.cpp b/libs/input/InputConsumer.cpp index 41ecfe3cfd..be2110e42b 100644 --- a/libs/input/InputConsumer.cpp +++ b/libs/input/InputConsumer.cpp @@ -14,6 +14,7 @@ * limitations under the License. */ +#include <cstdint> #define LOG_TAG "InputTransport" #define ATRACE_TAG ATRACE_TAG_INPUT @@ -194,9 +195,21 @@ InputConsumer::InputConsumer(const std::shared_ptr<InputChannel>& channel) InputConsumer::InputConsumer(const std::shared_ptr<InputChannel>& channel, bool enableTouchResampling) - : mResampleTouch(enableTouchResampling), mChannel(channel), mMsgDeferred(false) {} + : mResampleTouch(enableTouchResampling), + mChannel(channel), + mProcessingTraceTag(StringPrintf("InputConsumer processing on %s (%p)", + mChannel->getName().c_str(), this)), + mLifetimeTraceTag(StringPrintf("InputConsumer lifetime on %s (%p)", + mChannel->getName().c_str(), this)), + mLifetimeTraceCookie( + static_cast<int32_t>(reinterpret_cast<std::uintptr_t>(this) & 0xFFFFFFFF)), + mMsgDeferred(false) { + ATRACE_ASYNC_BEGIN(mLifetimeTraceTag.c_str(), /*cookie=*/mLifetimeTraceCookie); +} -InputConsumer::~InputConsumer() {} +InputConsumer::~InputConsumer() { + ATRACE_ASYNC_END(mLifetimeTraceTag.c_str(), /*cookie=*/mLifetimeTraceCookie); +} bool InputConsumer::isTouchResamplingEnabled() { return property_get_bool(PROPERTY_RESAMPLING_ENABLED, true); @@ -228,7 +241,7 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory, bool consum mMsg.header.seq); // Trace the event processing timeline - event was just read from the socket - ATRACE_ASYNC_BEGIN("InputConsumer processing", /*cookie=*/mMsg.header.seq); + ATRACE_ASYNC_BEGIN(mProcessingTraceTag.c_str(), /*cookie=*/mMsg.header.seq); } if (result) { // Consume the next batched event unless batches are being held for later. @@ -769,7 +782,7 @@ status_t InputConsumer::sendUnchainedFinishedSignal(uint32_t seq, bool handled) popConsumeTime(seq); // Trace the event processing timeline - event was just finished - ATRACE_ASYNC_END("InputConsumer processing", /*cookie=*/seq); + ATRACE_ASYNC_END(mProcessingTraceTag.c_str(), /*cookie=*/seq); } return result; } |