void Shot2Shot::stop(void)
{
    if (gShot2Shot.isRunning()) {
        if (gPnPBreakdown.isRunning())
            PnPBreakdown::step("Shot2Shot::stop");
            LOGD("shot2shot latency: %lld us.", gShot2Shot.timeUs());
        gShot2Shot.stop();
    }
}
void HDRShot2Preview::stop(void)
{
    if (gHDRShot2Preview.isRunning() && gHDRCalled) {
        gHDRCalled = false;
        if (gPnPBreakdown.isRunning())
            PnPBreakdown::step("HDRShot2Preview::stop");
        LOGD("hdr shot2preview latency: %lld us", gHDRShot2Preview.timeUs());
        gHDRShot2Preview.stop();
    }
}
/**
 * Stops the launch2FocusLock trace and prints out results.
 */
void Launch2FocusLock::stop(void)
{
    if (gLaunch2FocusLock.isRunning()) {
        if (gPnPBreakdown.isRunning())
            PnPBreakdown::step("Launch2FocusLock::stop");
        LOGD("LAUNCH time calculated from create instance to lock the focus frame:\t%lld ms\n",
             gLaunch2FocusLock.timeUs() / 1000);
        gLaunch2FocusLock.stop();
    }
}
/**
 * Marks that take picture call has been issued.
 *
 * This is needed to reliably detect start and end of shot2shot
 * sequences.
 */
void Shot2Shot::takePictureCalled(void)
{
    if (gShot2Shot.isRunning() == true)
        stop();

    start();
}
/**
 * Stops the launch2preview trace and prints out results.
 */
void Launch2Preview::stop(int mFrameNum)
{
    if (gLaunch2Preview.isRunning()) {
        if (gPnPBreakdown.isRunning())
            PnPBreakdown::step("Launch2Preview::stop");
        if (mFrameNum == 1) {
            LOGD("LAUNCH time to the 1st preview frame show:\t%lld ms\n",
                 gLaunch2Preview.timeUs() / 1000);
        } else {
            LOGD("LAUNCH: skip %d frame, time to the 1st preview frame show:\t%lld ms\n",
                 (mFrameNum - 1), gLaunch2Preview.timeUs() / 1000);
        }

        gLaunch2Preview.stop();
    }
}
/**
 * Stop the performance tracer.
 */
void PnPBreakdown::stop(void)
{
    if (gPnPBreakdown.isRunning()) {
        gPnPBreakdown.formattedTrace("PnPBreakdown", __FUNCTION__);
        gPnPBreakdown.stop();
    }
}
/**
 * Starts shot2shot trace
 */
void Shot2Shot::start(void)
{
    if (gShot2Shot.isRequested()) {
        gShot2Shot.start();
        if (gPnPBreakdown.isRunning())
            PnPBreakdown::step("Shot2Shot::start");
    }
}
/**
 * Starts the FaceLock trace.
 */
void FaceLock::start(int frameNum)
{
    if (gFaceLock.isRequested() && !gFaceLock.isRunning()) {
        gFaceLock.formattedTrace("FaceLock", __FUNCTION__);
        gFaceLockFrame = frameNum;
        gFaceLock.start();
    }
}
/**
 * Stops the AAAprofiler trace and prints out results.
 */
void AAAProfiler::stop(void)
{
    if (gAAAProfiler.isRunning()) {
        LOGD("3A profiling time::\t%lldms\n",
             gAAAProfiler.timeUs() / 1000);
        gAAAProfiler.stop();
    }
}
/**
 * Starts the launch2preview trace.
 */
void Launch2Preview::start(void)
{
    if (gLaunch2Preview.isRequested()) {
        if (gPnPBreakdown.isRunning())
            PnPBreakdown::step("Launch2Preview::start");
        gLaunch2Preview.start();
    }
}
/**
 * Stops the FaceLock trace and prints out results.
 */
void FaceLock::stop(int mFaceNum)
{
    if (gFaceLock.isRunning()) {
        LOGD("FaceLock face num: %d , Need frame: %d , From preview frame got to face lock successfully:\t%lld ms\n",
             mFaceNum, gFaceLockFrame, gFaceLock.timeUs() / 1000);
        gFaceLock.mRequested = false;
        gFaceLock.stop();
    }
}
/**
 * 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();
    }
}
/**
 * Prints ShutterLag trace results.
 */
void ShutterLag::snapshotTaken(struct timeval *ts)
{
    if (gShutterLag.isRunning()) {
        LOGD("ShutterLag from takePicture() to shot taken:\t%lldms\n",
             (((nsecs_t(ts->tv_sec)*1000000LL
             +  nsecs_t(ts->tv_usec))
             - gShutterLag.mStartAt/1000)/1000));
    }
}
/**
 * Starts the SwitchCameras trace.
 */
void SwitchCameras::start(int cameraid)
{
    if (gSwitchCameras.isRequested()) {
        if (gPnPBreakdown.isRunning())
            PnPBreakdown::step("Switch::start");
        gSwitchCamerasCalled = false;
        gSwitchCamerasOriginalVideoMode = false;
        gSwitchCamerasVideoMode = false;
        gSwitchCamerasOriginalCameraId = cameraid;
        gSwitchCameras.start();
    }
}
/**
 * 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());
   }
}
/**
 * Stops the SwitchCameras trace and prints out results.
 */
void SwitchCameras::stop(void)
{
    if (gSwitchCameras.isRunning() && gSwitchCamerasCalled == true) {
        if (gPnPBreakdown.isRunning())
            PnPBreakdown::step("Switch::stop");
        if (gSwitchCamerasOriginalVideoMode == gSwitchCamerasVideoMode) {
            LOGD("Using %s mode, Switch from %s camera to %s camera, SWITCH time::\t%lldms\n",
                    (gSwitchCamerasVideoMode ? "video" : "camera"),
                    ((gSwitchCamerasOriginalCameraId == 0) ? "back" : "front"),
                    ((gSwitchCamerasOriginalCameraId == 1) ? "back" : "front"),
                    gSwitchCameras.timeUs() / 1000);
        } else {
            LOGD("Using %s camera, Switch from %s mode to %s mode, SWITCH time::\t%lldms\n",
                    ((gSwitchCamerasOriginalCameraId == 0) ? "back" : "front"),
                    (gSwitchCamerasOriginalVideoMode ? "video" : "camera"),
                    (gSwitchCamerasVideoMode ? "video" : "camera"),
                    gSwitchCameras.timeUs() / 1000);
        }
        gSwitchCamerasCalled = false;
        gSwitchCameras.stop();
    }
}
/**
 * Stop the performance tracer.
 */
void IOBreakdown::stop(void)
{
    if (gIOBreakdown.isRunning()) {
        gIOBreakdown.formattedTrace("IOBreakdown", __FUNCTION__);
        gIOBreakdown.stop();
    }

    if (mMemInfoEnabled) {
        if(mPipeFD >= 0)
            if (::close(mPipeFD) < 0)
                LOGE("Close trace_pipe error!");

        if(mDbgFD >= 0)
            if (::close(mDbgFD) < 0)
                LOGE("Close dbgopt error!");

        mPipeFD = -1;
        mDbgFD = -1;
        mMemInfoEnabled = false;
    }
}
/**
 * get current preview frame num
 */
void FaceLock::getCurFrameNum(const int mFrameNum)
{
    if (gFaceLock.isRunning()) {
        gFaceLockFrame = mFrameNum - gFaceLockFrame;
    }
}
/**
 * Marks that HDR call has been issued.
 *
 * This is needed to reliably detect start and end of HDR shot2preview
 * sequences.
 */
void HDRShot2Preview::HDRCalled(void)
{
    if (gHDRShot2Preview.isRunning()) {
        gHDRCalled = true;
    }
}
/**
 * Starts HDR Shot2Preview trace
 */
void HDRShot2Preview::start(void)
{
    if (gHDRShot2Preview.isRequested() && !gHDRShot2Preview.isRunning()) {
        gHDRShot2Preview.start();
    }
}