Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dc099c2c authored by Andy Hung's avatar Andy Hung
Browse files

AudioFlinger: Preserve recent MMapThread history for dumpsys

Test: Aaudio tests, check audioflinger dumpsys
Bug: 116026119
Change-Id: Ib891686480b2579e4d3b2e419c83aec0a79ba812
parent 05fa8856
Loading
Loading
Loading
Loading
+15 −19
Original line number Diff line number Diff line
@@ -56,7 +56,6 @@
#include <system/audio_effects/effect_ns.h>
#include <system/audio_effects/effect_aec.h>

#include <audio_utils/FdToString.h>
#include <audio_utils/primitives.h>

#include <json/json.h>
@@ -2300,15 +2299,7 @@ status_t AudioFlinger::closeOutput_nonvirtual(audio_io_handle_t output)
        if (playbackThread != NULL) {
            ALOGV("closeOutput() %d", output);

            {
                // Dump thread before deleting for history
                audio_utils::FdToString fdToString;
                const int fd = fdToString.fd();
                if (fd >= 0) {
                    playbackThread->dump(fd, {} /* args */);
                    mThreadLog.logs(-1 /* time */, fdToString.getStringAndClose());
                }
            }
            dumpToThreadLog_l(playbackThread);

            if (playbackThread->type() == ThreadBase::MIXER) {
                for (size_t i = 0; i < mPlaybackThreads.size(); i++) {
@@ -2341,6 +2332,7 @@ status_t AudioFlinger::closeOutput_nonvirtual(audio_io_handle_t output)
            if (mmapThread == 0) {
                return BAD_VALUE;
            }
            dumpToThreadLog_l(mmapThread);
            mMmapThreads.removeItem(output);
            ALOGD("closing mmapThread %p", mmapThread.get());
        }
@@ -2549,15 +2541,7 @@ status_t AudioFlinger::closeInput_nonvirtual(audio_io_handle_t input)
        if (recordThread != 0) {
            ALOGV("closeInput() %d", input);

            {
                // Dump thread before deleting for history
                audio_utils::FdToString fdToString;
                const int fd = fdToString.fd();
                if (fd >= 0) {
                    recordThread->dump(fd, {} /* args */);
                    mThreadLog.logs(-1 /* time */, fdToString.getStringAndClose());
                }
            }
            dumpToThreadLog_l(recordThread);

            // If we still have effect chains, it means that a client still holds a handle
            // on at least one effect. We must either move the chain to an existing thread with the
@@ -2601,6 +2585,7 @@ status_t AudioFlinger::closeInput_nonvirtual(audio_io_handle_t input)
            if (mmapThread == 0) {
                return BAD_VALUE;
            }
            dumpToThreadLog_l(mmapThread);
            mMmapThreads.removeItem(input);
        }
        const sp<AudioIoDescriptor> ioDesc = new AudioIoDescriptor();
@@ -2799,6 +2784,17 @@ void AudioFlinger::purgeStaleEffects_l() {
    return;
}

// dumpToThreadLog_l() must be called with AudioFlinger::mLock held
void AudioFlinger::dumpToThreadLog_l(const sp<ThreadBase> &thread)
{
    audio_utils::FdToString fdToString;
    const int fd = fdToString.fd();
    if (fd >= 0) {
        thread->dump(fd, {} /* args */);
        mThreadLog.logs(-1 /* time */, fdToString.getStringAndClose());
    }
}

// checkThread_l() must be called with AudioFlinger::mLock held
AudioFlinger::ThreadBase *AudioFlinger::checkThread_l(audio_io_handle_t ioHandle) const
{
+5 −1
Original line number Diff line number Diff line
@@ -66,6 +66,7 @@
#include <media/VolumeShaper.h>

#include <audio_utils/clock.h>
#include <audio_utils/FdToString.h>
#include <audio_utils/SimpleLog.h>
#include <audio_utils/TimestampVerifier.h>

@@ -426,7 +427,10 @@ private:
    void dumpClients(int fd, const Vector<String16>& args);
    void dumpInternals(int fd, const Vector<String16>& args);

    SimpleLog mThreadLog{10}; // 10 Thread history limit
    SimpleLog mThreadLog{16}; // 16 Thread history limit

    class ThreadBase;
    void dumpToThreadLog_l(const sp<ThreadBase> &thread);

    // --- Client ---
    class Client : public RefBase {
+5 −3
Original line number Diff line number Diff line
@@ -397,6 +397,8 @@ public:

                bool                isMsdDevice() const { return mIsMsdDevice; }

    virtual     void                dump(int fd, const Vector<String16>& args) = 0;

    mutable     Mutex                   mLock;

protected:
@@ -665,7 +667,7 @@ public:
                   audio_io_handle_t id, audio_devices_t device, type_t type, bool systemReady);
    virtual             ~PlaybackThread();

                void        dump(int fd, const Vector<String16>& args);
                void        dump(int fd, const Vector<String16>& args) override;
                // returns a string of audio performance related data in JSON format.
    virtual     Json::Value getJsonDump() const;

@@ -1480,7 +1482,7 @@ public:
            // return true if the caller should then do it's part of the stopping process
            bool        stop(RecordTrack* recordTrack);

            void        dump(int fd, const Vector<String16>& args);
            void        dump(int fd, const Vector<String16>& args) override;
            AudioStreamIn* clearInput();
            virtual sp<StreamHalInterface> stream() const;

@@ -1689,7 +1691,7 @@ class MmapThread : public ThreadBase
                // Sets the UID records silence
    virtual     void        setRecordSilenced(uid_t uid __unused, bool silenced __unused) {}

                void        dump(int fd, const Vector<String16>& args);
                void        dump(int fd, const Vector<String16>& args) override;
    virtual     void        dumpInternals(int fd, const Vector<String16>& args);
                void        dumpTracks(int fd, const Vector<String16>& args);