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

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

Merge "Adding Metrics to Listeners for crystalball"

parents f4449eea c3f30aca
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -79,7 +79,6 @@ extern "C" JNIEXPORT int JNICALL Java_com_android_media_benchmark_library_Native
        vector<AMediaCodecBufferInfo> frameInfo;
        AMediaCodecBufferInfo info;
        uint32_t inputBufferOffset = 0;

        // Get frame data
        while (1) {
            status = extractor->getFrameSample(info);
@@ -110,7 +109,7 @@ extern "C" JNIEXPORT int JNICALL Java_com_android_media_benchmark_library_Native
        const char *statsFile = env->GetStringUTFChars(jStatsFile, nullptr);
        string sInputReference = string(inputReference);
        decoder->dumpStatistics(sInputReference, sCodecName, (asyncMode ? "async" : "sync"),
                                statsFile);
                                (statsFile == nullptr ? "" : statsFile));
        env->ReleaseStringUTFChars(jCodecName, codecName);
        env->ReleaseStringUTFChars(jStatsFile, statsFile);
        env->ReleaseStringUTFChars(jFileName, inputReference);
+1 −1
Original line number Diff line number Diff line
@@ -49,7 +49,7 @@ public class Decoder {
    private FileOutputStream mOutputStream;

    public Decoder() { mStats = new Stats(); }

    public Stats getStats() { return mStats; };
    /**
     * Setup of decoder
     *
+18 −2
Original line number Diff line number Diff line
@@ -33,7 +33,17 @@ public class Stats {
    private long mDeInitTimeNs;
    private long mStartTimeNs;
    private ArrayList<Integer> mFrameSizes;
    /*
     * Array for holding the wallclock time
     * for each input buffer available.
     */
    private ArrayList<Long> mInputTimer;
    /*
     * Array for holding the wallclock time
     * for each output buffer available.
     * This is used for determining the decoded
     * frame intervals.
     */
    private ArrayList<Long> mOutputTimer;

    public Stats() {
@@ -76,9 +86,15 @@ public class Stats {

    public long getDeInitTime() { return mDeInitTimeNs; }

    public long getStartTime() { return mStartTimeNs; }

    public ArrayList<Long> getOutputTimers() { return mOutputTimer; }

    public ArrayList<Long> getInputTimers() { return mInputTimer; }

    public long getTimeDiff(long sTime, long eTime) { return (eTime - sTime); }

    private long getTotalTime() {
    public long getTotalTime() {
        if (mOutputTimer.size() == 0) {
            return -1;
        }
@@ -86,7 +102,7 @@ public class Stats {
        return lastTime - mStartTimeNs;
    }

    private long getTotalSize() {
    public long getTotalSize() {
        long totalSize = 0;
        for (long size : mFrameSizes) {
            totalSize += size;
+71 −2
Original line number Diff line number Diff line
@@ -35,13 +35,18 @@
 * \param mode           the operating mode: sync/async.
 * \param statsFile      the file where the stats data is to be written.
 */
void Stats::dumpStatistics(string operation, string inputReference, int64_t durationUs,
                           string componentName, string mode, string statsFile) {
void Stats::dumpStatistics(const string& operation, const string& inputReference,
                           int64_t durationUs, const string& componentName,
                           const string& mode, const string& statsFile) {
    ALOGV("In %s", __func__);
    if (!mOutputTimer.size()) {
        ALOGE("No output produced");
        return;
    }
    if (statsFile.empty()) {
        return uploadMetrics(operation, inputReference, durationUs, componentName,
                              mode);
    }
    nsecs_t totalTimeTakenNs = getTotalTime();
    nsecs_t timeTakenPerSec = (totalTimeTakenNs * 1000000) / durationUs;
    nsecs_t timeToFirstFrameNs = *mOutputTimer.begin() - mStartTimeNs;
@@ -87,3 +92,67 @@ void Stats::dumpStatistics(string operation, string inputReference, int64_t dura
    out << rowData;
    out.close();
}

/**
 * Dumps the stats of the operation for a given input media to a listener.
 *
 * \param operation      describes the operation performed on the input media
 *                       (i.e. extract/mux/decode/encode)
 * \param inputReference input media
 * \param durationUs     is a duration of the input media in microseconds.
 * \param componentName  describes the codecName/muxFormat/mimeType.
 * \param mode           the operating mode: sync/async.
 *
 */

#define LOG_METRIC(...) \
    __android_log_print(ANDROID_LOG_INFO, "ForTimingCollector", __VA_ARGS__)

void Stats::uploadMetrics(const string& operation, const string& inputReference,
                          const int64_t& durationUs, const string& componentName,
                          const string& mode) {

    ALOGV("In %s", __func__);
    (void)durationUs;
    (void)componentName;
    if (!mOutputTimer.size()) {
        ALOGE("No output produced");
        return;
    }
    nsecs_t totalTimeTakenNs = getTotalTime();
    nsecs_t timeToFirstFrameNs = *mOutputTimer.begin() - mStartTimeNs;
    int32_t size = std::accumulate(mFrameSizes.begin(), mFrameSizes.end(), 0);
    // get min and max output intervals.
    nsecs_t intervalNs;
    nsecs_t minTimeTakenNs = INT64_MAX;
    nsecs_t maxTimeTakenNs = 0;
    nsecs_t prevIntervalNs = mStartTimeNs;
    for (int32_t idx = 0; idx < mOutputTimer.size() - 1; idx++) {
        intervalNs = mOutputTimer.at(idx) - prevIntervalNs;
        prevIntervalNs = mOutputTimer.at(idx);
        if (minTimeTakenNs > intervalNs) minTimeTakenNs = intervalNs;
        else if (maxTimeTakenNs < intervalNs) maxTimeTakenNs = intervalNs;
    }

    // Write the stats data to file.
    int64_t dataSize = size;
    int64_t bytesPerSec = ((int64_t)dataSize * 1000000000) / totalTimeTakenNs;
    (void)mode;
    (void)operation;
    (void)inputReference;
    string prefix = "CodecStats_NativeDec";
    prefix.append("_").append(componentName);
    // Reports the time taken to initialize the codec.
    LOG_METRIC("%s_CodecInitTimeNs:%lld", prefix.c_str(), (long long)mInitTimeNs);
    // Reports the time taken to free the codec.
    LOG_METRIC("%s_CodecDeInitTimeNs:%lld", prefix.c_str(), (long long)mDeInitTimeNs);
    // Reports the min time taken between output frames from the codec
    LOG_METRIC("%s_CodecMinTimeNs:%lld", prefix.c_str(), (long long)minTimeTakenNs);
    // Reports the max time between the output frames from the codec
    LOG_METRIC("%s_CodecMaxTimeNs:%lld", prefix.c_str(), (long long)maxTimeTakenNs);
    // Report raw throughout ( bytes/sec ) of the codec for the entire media
    LOG_METRIC("%s_ProcessedBytesPerSec:%lld", prefix.c_str(), (long long)bytesPerSec);
    // Reports the time taken to get the first frame from the codec
    LOG_METRIC("%s_TimeforFirstFrame:%lld", prefix.c_str(), (long long)timeToFirstFrameNs);

}
+7 −3
Original line number Diff line number Diff line
@@ -102,8 +102,12 @@ class Stats {
        return (*(mOutputTimer.end() - 1) - mStartTimeNs);
    }

    void dumpStatistics(string operation, string inputReference, int64_t duarationUs,
                        string codecName = "", string mode = "", string statsFile = "");
};
    void dumpStatistics(const string& operation, const string& inputReference,
                        int64_t duarationUs, const string& componentName = "",
                        const string& mode = "", const string& statsFile = "");

    void uploadMetrics(const string& operation, const string& inputReference,
                      const int64_t& durationUs, const string& componentName = "",
                      const string& mode = "");
};
#endif  // __STATS_H__