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

Commit f8701c40 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "transcoding: add more dumps for jobs"

parents 358a0844 0579c6f3
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -282,16 +282,16 @@ void TranscodingClientManager::dumpAllClients(int fd, const Vector<String16>& ar
    char buffer[SIZE];
    std::scoped_lock lock{mLock};

    snprintf(buffer, SIZE, "    Total num of Clients: %zu\n", mClientIdToClientMap.size());
    result.append(buffer);

    if (mClientIdToClientMap.size() > 0) {
        snprintf(buffer, SIZE, "========== Dumping all clients =========\n");
        snprintf(buffer, SIZE, "\n========== Dumping all clients =========\n");
        result.append(buffer);
    }

    snprintf(buffer, SIZE, "  Total num of Clients: %zu\n", mClientIdToClientMap.size());
    result.append(buffer);

    for (const auto& iter : mClientIdToClientMap) {
        snprintf(buffer, SIZE, "    -- Client id: %lld  name: %s\n", (long long)iter.first,
        snprintf(buffer, SIZE, "    Client %lld:  pkg: %s\n", (long long)iter.first,
                 iter.second->mClientName.c_str());
        result.append(buffer);
    }
+59 −19
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@

#include <inttypes.h>
#include <media/TranscodingJobScheduler.h>
#include <media/TranscodingUidPolicy.h>
#include <utils/Log.h>

#include <utility>
@@ -36,6 +37,21 @@ String8 TranscodingJobScheduler::jobToString(const JobKeyType& jobKey) {
    return String8::format("{client:%lld, job:%d}", (long long)jobKey.first, jobKey.second);
}

//static
const char* TranscodingJobScheduler::jobStateToString(const Job::State jobState) {
    switch (jobState) {
    case Job::State::NOT_STARTED:
        return "NOT_STARTED";
    case Job::State::RUNNING:
        return "RUNNING";
    case Job::State::PAUSED:
        return "PAUSED";
    default:
        break;
    }
    return "(unknown)";
}

TranscodingJobScheduler::TranscodingJobScheduler(
        const std::shared_ptr<TranscoderInterface>& transcoder,
        const std::shared_ptr<UidPolicyInterface>& uidPolicy,
@@ -60,24 +76,46 @@ void TranscodingJobScheduler::dumpAllJobs(int fd, const Vector<String16>& args _
    char buffer[SIZE];
    std::scoped_lock lock{mLock};

    snprintf(buffer, SIZE, " \n\n   Total num of Jobs: %zu\n", mJobMap.size());
    snprintf(buffer, SIZE, "\n========== Dumping all jobs queues =========\n");
    result.append(buffer);

    if (mJobMap.size() > 0) {
        snprintf(buffer, SIZE, "========== Dumping all jobs =========\n");
    snprintf(buffer, SIZE, "  Total num of Jobs: %zu\n", mJobMap.size());
    result.append(buffer);

    std::vector<int32_t> uids(mUidSortedList.begin(), mUidSortedList.end());
    // Exclude last uid, which is for offline queue
    uids.pop_back();
    std::vector<std::string> packageNames;
    if (TranscodingUidPolicy::getNamesForUids(uids, &packageNames)) {
        uids.push_back(OFFLINE_UID);
        packageNames.push_back("(offline)");
    }

    for (auto uidIt = mUidSortedList.begin(); uidIt != mUidSortedList.end(); uidIt++) {
        for (auto jobIt = mJobQueues[*uidIt].begin(); jobIt != mJobQueues[*uidIt].end(); jobIt++) {
            if (mJobMap.count(*jobIt) != 0) {
                TranscodingRequestParcel& request = mJobMap[*jobIt].request;
                snprintf(buffer, SIZE, "Job: %s Client: %d\n", request.sourceFilePath.c_str(),
                         request.clientUid);
    for (int32_t i = 0; i < uids.size(); i++) {
        const uid_t uid = uids[i];

            } else {
                snprintf(buffer, SIZE, "Failed to look up Job %s  \n", jobToString(*jobIt).c_str());
        if (mJobQueues[uid].empty()) {
            continue;
        }
        snprintf(buffer, SIZE, "    Uid: %d, pkg: %s\n", uid,
                 packageNames.empty() ? "(unknown)" : packageNames[i].c_str());
        result.append(buffer);
        snprintf(buffer, SIZE, "      Num of jobs: %zu\n", mJobQueues[uid].size());
        result.append(buffer);
        for (auto& jobKey : mJobQueues[uid]) {
            auto jobIt = mJobMap.find(jobKey);
            if (jobIt == mJobMap.end()) {
                snprintf(buffer, SIZE, "Failed to look up Job %s  \n", jobToString(jobKey).c_str());
                result.append(buffer);
                continue;
            }
            Job& job = jobIt->second;
            TranscodingRequestParcel& request = job.request;
            snprintf(buffer, SIZE, "      Job: %s, %s, %d%%\n", jobToString(jobKey).c_str(),
                     jobStateToString(job.state), job.lastProgress);
            result.append(buffer);
            snprintf(buffer, SIZE, "        Src: %s\n", request.sourceFilePath.c_str());
            result.append(buffer);
            snprintf(buffer, SIZE, "        Dst: %s\n", request.destinationFilePath.c_str());
            result.append(buffer);
        }
    }
@@ -240,6 +278,7 @@ bool TranscodingJobScheduler::submit(ClientIdType clientId, JobIdType jobId, uid
    mJobMap[jobKey].key = jobKey;
    mJobMap[jobKey].uid = uid;
    mJobMap[jobKey].state = Job::NOT_STARTED;
    mJobMap[jobKey].lastProgress = 0;
    mJobMap[jobKey].request = request;
    mJobMap[jobKey].callback = callback;

@@ -431,6 +470,7 @@ void TranscodingJobScheduler::onProgressUpdate(ClientIdType clientId, JobIdType
        if (callback != nullptr) {
            callback->onProgressUpdate(jobId, progress);
        }
        mJobMap[jobKey].lastProgress = progress;
    });
}

@@ -509,15 +549,15 @@ void TranscodingJobScheduler::validateState_l() {
                        "mUidList and mJobQueues size mismatch");

    int32_t totalJobs = 0;
    for (auto uidIt = mUidSortedList.begin(); uidIt != mUidSortedList.end(); uidIt++) {
        LOG_ALWAYS_FATAL_IF(mJobQueues.count(*uidIt) != 1, "mJobQueues count for uid %d is not 1",
                            *uidIt);
        for (auto jobIt = mJobQueues[*uidIt].begin(); jobIt != mJobQueues[*uidIt].end(); jobIt++) {
            LOG_ALWAYS_FATAL_IF(mJobMap.count(*jobIt) != 1, "mJobs count for job %s is not 1",
                                jobToString(*jobIt).c_str());
    for (auto uid : mUidSortedList) {
        LOG_ALWAYS_FATAL_IF(mJobQueues.count(uid) != 1, "mJobQueues count for uid %d is not 1",
                            uid);
        for (auto& jobKey : mJobQueues[uid]) {
            LOG_ALWAYS_FATAL_IF(mJobMap.count(jobKey) != 1, "mJobs count for job %s is not 1",
                                jobToString(jobKey).c_str());
        }

        totalJobs += mJobQueues[*uidIt].size();
        totalJobs += mJobQueues[uid].size();
    }
    LOG_ALWAYS_FATAL_IF(mJobMap.size() != totalJobs,
                        "mJobs size doesn't match total jobs counted from uid queues");
+24 −0
Original line number Diff line number Diff line
@@ -21,7 +21,9 @@
#include <aidl/android/media/IResourceManagerService.h>
#include <android/binder_manager.h>
#include <android/binder_process.h>
#include <android/content/pm/IPackageManagerNative.h>
#include <binder/ActivityManager.h>
#include <binder/IServiceManager.h>
#include <cutils/misc.h>  // FIRST_APPLICATION_UID
#include <inttypes.h>
#include <media/TranscodingUidPolicy.h>
@@ -109,6 +111,28 @@ void TranscodingUidPolicy::UidObserver::binderDied(const wp<IBinder>& /*who*/) {

////////////////////////////////////////////////////////////////////////////

//static
bool TranscodingUidPolicy::getNamesForUids(const std::vector<int32_t>& uids,
                                           std::vector<std::string>* names) {
    names->clear();
    sp<IServiceManager> sm(defaultServiceManager());
    sp<IBinder> binder(sm->getService(String16("package_native")));
    if (binder == nullptr) {
        ALOGE("getService package_native failed");
        return false;
    }

    sp<content::pm::IPackageManagerNative> packageMgr =
            interface_cast<content::pm::IPackageManagerNative>(binder);
    binder::Status status = packageMgr->getNamesForUids(uids, names);

    if (!status.isOk() || names->size() != uids.size()) {
        names->clear();
        return false;
    }
    return true;
}

TranscodingUidPolicy::TranscodingUidPolicy()
      : mAm(std::make_shared<ActivityManager>()),
        mUidObserver(new UidObserver(this)),
+3 −1
Original line number Diff line number Diff line
@@ -82,11 +82,12 @@ private:
    struct Job {
        JobKeyType key;
        uid_t uid;
        enum JobState {
        enum State {
            NOT_STARTED,
            RUNNING,
            PAUSED,
        } state;
        int32_t lastProgress;
        TranscodingRequest request;
        std::weak_ptr<ITranscodingClientCallback> callback;
    };
@@ -127,6 +128,7 @@ private:
    void validateState_l();

    static String8 jobToString(const JobKeyType& jobKey);
    static const char* jobStateToString(const Job::State jobState);
};

}  // namespace android
+3 −0
Original line number Diff line number Diff line
@@ -47,6 +47,9 @@ public:
    void unregisterMonitorUid(uid_t uid) override;
    std::unordered_set<uid_t> getTopUids() const override;
    void setCallback(const std::shared_ptr<UidPolicyCallbackInterface>& cb) override;
    // ~UidPolicyInterface

    static bool getNamesForUids(const std::vector<int32_t>& uids, std::vector<std::string>* names);

private:
    void onUidStateChanged(uid_t uid, int32_t procState);
Loading