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

Commit 87b3ec03 authored by Yin-Chia Yeh's avatar Yin-Chia Yeh
Browse files

Camera: Add component name to status tracker

To improve waitUntilDrained debugging experience.

Change-Id: Ifc7b92516dd97c985e40a0cda578ee91170cd2b0
parent 5ce77ca4
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -510,7 +510,8 @@ status_t HeicCompositeStream::configureStream() {

    sp<camera3::StatusTracker> statusTracker = mStatusTracker.promote();
    if (statusTracker != nullptr) {
        mStatusId = statusTracker->addComponent();
        std::string name = std::string("HeicStream ") + std::to_string(getStreamId());
        mStatusId = statusTracker->addComponent(name);
    }

    run("HeicCompositeStreamProc");
+4 −3
Original line number Diff line number Diff line
@@ -270,7 +270,7 @@ status_t Camera3Device::initializeCommonLocked() {
    }

    /** Register in-flight map to the status tracker */
    mInFlightStatusId = mStatusTracker->addComponent();
    mInFlightStatusId = mStatusTracker->addComponent("InflightRequests");

    if (mUseHalBufManager) {
        res = mRequestBufferSM.initialize(mStatusTracker);
@@ -1768,6 +1768,7 @@ status_t Camera3Device::waitUntilDrainedLocked(nsecs_t maxExpectedDuration) {
            maxExpectedDuration);
    status_t res = waitUntilStateThenRelock(/*active*/ false, maxExpectedDuration);
    if (res != OK) {
        mStatusTracker->dumpActiveComponents();
        SET_ERR_L("Error waiting for HAL to drain: %s (%d)", strerror(-res),
                res);
    }
@@ -3785,7 +3786,7 @@ Camera3Device::RequestThread::RequestThread(wp<Camera3Device> parent,
        mSessionParamKeys(sessionParamKeys),
        mLatestSessionParams(sessionParamKeys.size()),
        mUseHalBufManager(useHalBufManager) {
    mStatusId = statusTracker->addComponent();
    mStatusId = statusTracker->addComponent("RequestThread");
}

Camera3Device::RequestThread::~RequestThread() {}
@@ -5619,7 +5620,7 @@ status_t Camera3Device::RequestBufferStateMachine::initialize(

    std::lock_guard<std::mutex> lock(mLock);
    mStatusTracker = statusTracker;
    mRequestBufferStatusId = statusTracker->addComponent();
    mRequestBufferStatusId = statusTracker->addComponent("BufferRequestSM");
    return OK;
}

+2 −1
Original line number Diff line number Diff line
@@ -330,7 +330,8 @@ status_t Camera3Stream::finishConfiguration(/*out*/bool* streamReconfigured) {
    // Register for idle tracking
    sp<StatusTracker> statusTracker = mStatusTracker.promote();
    if (statusTracker != 0 && mStatusId == StatusTracker::NO_STATUS_ID) {
        mStatusId = statusTracker->addComponent();
        std::string name = std::string("Stream ") + std::to_string(mId);
        mStatusId = statusTracker->addComponent(name.c_str());
    }

    // Check if the stream configuration is unchanged, and skip reallocation if
+22 −3
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@ StatusTracker::StatusTracker(wp<Camera3Device> parent) :
StatusTracker::~StatusTracker() {
}

int StatusTracker::addComponent() {
int StatusTracker::addComponent(std::string componentName) {
    int id;
    ssize_t err;
    {
@@ -49,8 +49,12 @@ int StatusTracker::addComponent() {
        ALOGV("%s: Adding new component %d", __FUNCTION__, id);

        err = mStates.add(id, IDLE);
        ALOGE_IF(err < 0, "%s: Can't add new component %d: %s (%zd)",
                __FUNCTION__, id, strerror(-err), err);
        if (componentName.empty()) {
            componentName = std::to_string(id);
        }
        mComponentNames.add(id, componentName);
        ALOGE_IF(err < 0, "%s: Can't add new component %d (%s): %s (%zd)",
                __FUNCTION__, id, componentName.c_str(), strerror(-err), err);
    }

    if (err >= 0) {
@@ -68,6 +72,7 @@ void StatusTracker::removeComponent(int id) {
        Mutex::Autolock l(mLock);
        ALOGV("%s: Removing component %d", __FUNCTION__, id);
        idx = mStates.removeItem(id);
        mComponentNames.removeItem(id);
    }

    if (idx >= 0) {
@@ -80,6 +85,20 @@ void StatusTracker::removeComponent(int id) {
}


void StatusTracker::dumpActiveComponents() {
    Mutex::Autolock l(mLock);
    if (mDeviceState == IDLE) {
        ALOGI("%s: all components are IDLE", __FUNCTION__);
        return;
    }
    for (size_t i = 0; i < mStates.size(); i++) {
        if (mStates.valueAt(i) == ACTIVE) {
            ALOGI("%s: component %d (%s) is active", __FUNCTION__, mStates.keyAt(i),
                    mComponentNames.valueAt(i).c_str());
        }
    }
}

void StatusTracker::markComponentIdle(int id, const sp<Fence>& componentFence) {
    markComponent(id, IDLE, componentFence);
}
+5 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#ifndef ANDROID_SERVERS_CAMERA3_STATUSTRACKER_H
#define ANDROID_SERVERS_CAMERA3_STATUSTRACKER_H

#include <string>
#include <utils/Condition.h>
#include <utils/Errors.h>
#include <utils/List.h>
@@ -54,7 +55,7 @@ class StatusTracker: public Thread {
    // Add a component to track; returns non-negative unique ID for the new
    // component on success, negative error code on failure.
    // New components start in the idle state.
    int addComponent();
    int addComponent(std::string componentName);

    // Remove existing component from idle tracking. Ignores unknown IDs
    void removeComponent(int id);
@@ -68,6 +69,8 @@ class StatusTracker: public Thread {
    // Set the state of a tracked component to be active. Ignores unknown IDs.
    void markComponentActive(int id);

    void dumpActiveComponents();

    virtual void requestExit();
  protected:

@@ -105,6 +108,7 @@ class StatusTracker: public Thread {

    // Current component states
    KeyedVector<int, ComponentState> mStates;
    KeyedVector<int, std::string> mComponentNames;
    // Merged fence for all processed state changes
    sp<Fence> mIdleFence;
    // Current overall device state