/**
 * Mark an intermediate step in breakdown tracer.
 *
 * @arg func, the function name which called it.
 * @arg not, a string printed with the breakdown trace
 * @arg mFrameNum, the num of the frame got from ISP.
 */
void PnPBreakdown::step(const char *func, const char* note, const int mFrameNum)
{
    if (gPnPBreakdown.isRunning()) {
        if (!note)
            note = "";
        if (mFrameNum < 0)
            LOGD("PnPBreakdown-step %s:%s, Time: %lld us, Diff: %lld us",
                 func, note, gPnPBreakdown.timeUs(), gPnPBreakdown.lastTimeUs());
        else
            LOGD("PnPBreakdown-step %s:%s[%d], Time: %lld us, Diff: %lld us",
                 func, note, mFrameNum, gPnPBreakdown.timeUs(), gPnPBreakdown.lastTimeUs());
   }
}
IOBreakdown::~IOBreakdown()
{
    char memData[MEM_DATA_LEN]={0};
    if (!mNote)
        mNote = "";
    if (mMemInfoEnabled) {
        mMemMutex.lock();

        if (mDbgFD < 0) {
            LOGD("dgbopt isn't opened.");
        } else {
            ::write(mDbgFD, DBG_CTRL, 3);
            if (mPipeFD < 0) {
                LOGD("trace_pipe isn't opened.");
            } else {
                int n;
                do {
                    n = ::read(mPipeFD, memData, MEM_DATA_LEN - 1);
                }while (n<=0);
                LOGD("memory <%s,%d>:%s", mNote, n, memData);
            }
        }
        mMemMutex.unlock();
    }

    LOGD("IOBreakdown-step %s:%s, Time: %lld us, Diff: %lld us",
             mFuncName, mNote, gIOBreakdown.timeUs(), gIOBreakdown.lastTimeUs());
}
/**
 * To indicate the performance and memory for every IOCTL call.
 *
 * @arg func, the function name which called it.
 * @arg note, a string printed with IOCTL information.
 */
IOBreakdown::IOBreakdown(const char *func, const char *note):
 mFuncName(func)
,mNote(note)
{
    if (gIOBreakdown.isRunning()) {
        gIOBreakdown.timeUs();
        gIOBreakdown.lastTimeUs();
    }
}