From 89a6bb71996cab0208fc5c9d074c2fd1243ba2be Mon Sep 17 00:00:00 2001 From: Mikhail Naganov Date: Wed, 31 Jan 2024 13:55:08 -0800 Subject: [PATCH] audio: Add tracing to audio I/O and effect processing Emit trace events for audio reads and writes and effect processing functions. This is to match the HIDL implementation. Bug: 321233946 Test: `record_android_trace` with `audio` category enabled Change-Id: I26907b09243fd3e5aaa470a0fb930b34addd3093 --- audio/aidl/default/EffectImpl.cpp | 3 +++ audio/aidl/default/Stream.cpp | 8 +++++--- audio/aidl/default/bluetooth/StreamBluetooth.cpp | 14 ++++++-------- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/audio/aidl/default/EffectImpl.cpp b/audio/aidl/default/EffectImpl.cpp index c29bf79945..c97a03e8a3 100644 --- a/audio/aidl/default/EffectImpl.cpp +++ b/audio/aidl/default/EffectImpl.cpp @@ -15,7 +15,9 @@ */ #include +#define ATRACE_TAG ATRACE_TAG_AUDIO #define LOG_TAG "AHAL_EffectImpl" +#include #include "effect-impl/EffectImpl.h" #include "effect-impl/EffectTypes.h" #include "include/effect-impl/EffectTypes.h" @@ -298,6 +300,7 @@ IEffect::Status EffectImpl::status(binder_status_t status, size_t consumed, size } void EffectImpl::process() { + ATRACE_CALL(); /** * wait for the EventFlag without lock, it's ok because the mEfGroup pointer will not change * in the life cycle of workerThread (threadLoop). diff --git a/audio/aidl/default/Stream.cpp b/audio/aidl/default/Stream.cpp index cf0870e2d4..807348fad7 100644 --- a/audio/aidl/default/Stream.cpp +++ b/audio/aidl/default/Stream.cpp @@ -16,14 +16,14 @@ #include +#define ATRACE_TAG ATRACE_TAG_AUDIO #define LOG_TAG "AHAL_Stream" +#include #include #include #include +#include -#include - -#include "core-impl/Module.h" #include "core-impl/Stream.h" using aidl::android::hardware::audio::common::AudioOffloadMetadata; @@ -312,6 +312,7 @@ StreamInWorkerLogic::Status StreamInWorkerLogic::cycle() { } bool StreamInWorkerLogic::read(size_t clientSize, StreamDescriptor::Reply* reply) { + ATRACE_CALL(); StreamContext::DataMQ* const dataMQ = mContext->getDataMQ(); const size_t byteCount = std::min({clientSize, dataMQ->availableToWrite(), mDataBufferSize}); const bool isConnected = mIsConnected; @@ -583,6 +584,7 @@ StreamOutWorkerLogic::Status StreamOutWorkerLogic::cycle() { } bool StreamOutWorkerLogic::write(size_t clientSize, StreamDescriptor::Reply* reply) { + ATRACE_CALL(); StreamContext::DataMQ* const dataMQ = mContext->getDataMQ(); const size_t readByteCount = dataMQ->availableToRead(); const size_t frameSize = mContext->getFrameSize(); diff --git a/audio/aidl/default/bluetooth/StreamBluetooth.cpp b/audio/aidl/default/bluetooth/StreamBluetooth.cpp index a73af1b6b4..77e48df26e 100644 --- a/audio/aidl/default/bluetooth/StreamBluetooth.cpp +++ b/audio/aidl/default/bluetooth/StreamBluetooth.cpp @@ -16,12 +16,13 @@ #include +#define ATRACE_TAG ATRACE_TAG_AUDIO #define LOG_TAG "AHAL_StreamBluetooth" #include #include #include +#include -#include "BluetoothAudioSession.h" #include "core-impl/StreamBluetooth.h" using aidl::android::hardware::audio::common::frameCountFromDurationUs; @@ -109,13 +110,10 @@ StreamBluetooth::StreamBluetooth(StreamContext* context, const Metadata& metadat } const size_t fc = std::min(frameCount, mPreferredFrameCount); const size_t bytesToTransfer = fc * mFrameSizeBytes; - if (mIsInput) { - const size_t totalRead = mBtDeviceProxy->readData(buffer, bytesToTransfer); - *actualFrameCount = std::max(*actualFrameCount, totalRead / mFrameSizeBytes); - } else { - const size_t totalWrite = mBtDeviceProxy->writeData(buffer, bytesToTransfer); - *actualFrameCount = std::max(*actualFrameCount, totalWrite / mFrameSizeBytes); - } + const size_t bytesTransferred = mIsInput ? mBtDeviceProxy->readData(buffer, bytesToTransfer) + : mBtDeviceProxy->writeData(buffer, bytesToTransfer); + *actualFrameCount = bytesTransferred / mFrameSizeBytes; + ATRACE_INT("BTdropped", bytesToTransfer - bytesTransferred); PresentationPosition presentation_position; if (!mBtDeviceProxy->getPresentationPosition(presentation_position)) { presentation_position.remoteDeviceAudioDelayNanos =