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

Commit 071c3c87 authored by Ray Essick's avatar Ray Essick Committed by android-build-merger
Browse files

Merge "Benchmark Timer : add support for frameSizes" am: 09df6240 am: eedc9bba am: f1a300c6

am: 0a5c1237

Change-Id: I74883019b94f126d2e8aea50fde6914c7e207681
parents aca6e671 0a5c1237
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ cc_library_static {

    srcs: [
        "BenchmarkCommon.cpp",
        "Timer.cpp",
        "Stats.cpp",
    ],

    export_include_dirs: ["."],
+2 −2
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@ void CallBackHandle::ioThread() {
void OnInputAvailableCB(AMediaCodec *codec, void *userdata, int32_t index) {
    ALOGV("OnInputAvailableCB: index(%d)", index);
    CallBackHandle *self = (CallBackHandle *)userdata;
    self->getTimer()->addInputTime();
    self->getStats()->addInputTime();
    self->mIOQueue.push([self, codec, index]() { self->onInputAvailable(codec, index); });
}

@@ -40,7 +40,7 @@ void OnOutputAvailableCB(AMediaCodec *codec, void *userdata, int32_t index,
    ALOGV("OnOutputAvailableCB: index(%d), (%d, %d, %lld, 0x%x)", index, bufferInfo->offset,
          bufferInfo->size, (long long)bufferInfo->presentationTimeUs, bufferInfo->flags);
    CallBackHandle *self = (CallBackHandle *)userdata;
    self->getTimer()->addOutputTime();
    self->getStats()->addOutputTime();
    AMediaCodecBufferInfo bufferInfoCopy = *bufferInfo;
    self->mIOQueue.push([self, codec, index, bufferInfoCopy]() {
        AMediaCodecBufferInfo bc = bufferInfoCopy;
+8 −6
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@
#include <media/NdkMediaCodec.h>
#include <media/NdkMediaError.h>

#include "Timer.h"
#include "Stats.h"

using namespace std;

@@ -69,11 +69,13 @@ class CallBackQueue {

class CallBackHandle {
  public:
    CallBackHandle() : mSawError(false), mIsDone(false), mTimer(nullptr) {}
    CallBackHandle() : mSawError(false), mIsDone(false), mStats(nullptr) {
        mStats = new Stats();
    }

    virtual ~CallBackHandle() {
        if (mIOThread.joinable()) mIOThread.join();
        if (mTimer) delete mTimer;
        if (mStats) delete mStats;
    }

    void ioThread();
@@ -94,7 +96,7 @@ class CallBackHandle {
        (void)bufferInfo;
    }

    virtual Timer *getTimer() { return mTimer; }
    Stats *getStats() { return mStats; }

    // Keep a queue of all function callbacks.
    typedef function<void()> IOTask;
@@ -103,8 +105,8 @@ class CallBackHandle {
    bool mSawError;
    bool mIsDone;

  private:
    Timer *mTimer;
  protected:
    Stats *mStats;
};

// Async API's callback
+5 −3
Original line number Diff line number Diff line
@@ -15,13 +15,13 @@
 */

//#define LOG_NDEBUG 0
#define LOG_TAG "Timer"
#define LOG_TAG "Stats"

#include <iostream>
#include <stdint.h>
#include <utils/Log.h>

#include "Timer.h"
#include "Stats.h"

/**
 * Dumps the stats of the operation for a given input media.
@@ -31,7 +31,7 @@
 * \param inputReference input media
 * \param duarationUs    is a duration of the input media in microseconds.
 */
void Timer::dumpStatistics(std::string operation, std::string inputReference, int64_t duarationUs) {
void Stats::dumpStatistics(std::string operation, std::string inputReference, int64_t duarationUs) {
    ALOGV("In %s", __func__);
    if (!mOutputTimer.size()) {
        ALOGE("No output produced");
@@ -40,6 +40,7 @@ void Timer::dumpStatistics(std::string operation, std::string inputReference, in
    nsecs_t totalTimeTakenNs = getTotalTime();
    nsecs_t timeTakenPerSec = (totalTimeTakenNs * 1000000) / duarationUs;
    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;
@@ -59,6 +60,7 @@ void Timer::dumpStatistics(std::string operation, std::string inputReference, in
    std::cout << "Time to first frame in nano sec : " << timeToFirstFrameNs << endl;
    std::cout << "Time taken (in nano sec) to " << operation
              << " 1 sec of content : " << timeTakenPerSec << endl;
    std::cout << "Total bytes " << operation << "ed : " << size << endl;
    std::cout << "Minimum Time in nano sec : " << minTimeTakenNs << endl;
    std::cout << "Maximum Time in nano sec : " << maxTimeTakenNs << endl;
    std::cout << "Destroy Time in nano sec : " << mDeInitTimeNs << endl;
+12 −9
Original line number Diff line number Diff line
@@ -14,8 +14,8 @@
 * limitations under the License.
 */

#ifndef __TIMER_H__
#define __TIMER_H__
#ifndef __STATS_H__
#define __STATS_H__

#include <sys/time.h>
#include <algorithm>
@@ -25,22 +25,22 @@

using namespace std;

class Timer {
class Stats {
  public:
    Timer() {
    Stats() {
        mInitTimeNs = 0;
        mDeInitTimeNs = 0;
    }

    ~Timer() {
        if (!mInputTimer.empty()) mInputTimer.clear();
        if (!mOutputTimer.empty()) mOutputTimer.clear();
    ~Stats() {
        reset();
    }

  private:
    nsecs_t mInitTimeNs;
    nsecs_t mDeInitTimeNs;
    nsecs_t mStartTimeNs;
    std::vector<int32_t> mFrameSizes;
    std::vector<nsecs_t> mInputTimer;
    std::vector<nsecs_t> mOutputTimer;

@@ -53,11 +53,14 @@ class Timer {

    void setStartTime() { mStartTimeNs = systemTime(CLOCK_MONOTONIC); }

    void addFrameSize(int32_t size) { mFrameSizes.push_back(size); }

    void addInputTime() { mInputTimer.push_back(systemTime(CLOCK_MONOTONIC)); }

    void addOutputTime() { mOutputTimer.push_back(systemTime(CLOCK_MONOTONIC)); }

    void resetTimers() {
    void reset() {
        if (!mFrameSizes.empty()) mFrameSizes.clear();
        if (!mInputTimer.empty()) mInputTimer.clear();
        if (!mOutputTimer.empty()) mOutputTimer.clear();
    }
@@ -78,4 +81,4 @@ class Timer {
    void dumpStatistics(std::string operation, std::string inputReference, int64_t duarationUs);
};

#endif  // __TIMER_H__
#endif  // __STATS_H__
Loading