blob: 4caf344500a7b64e2cb3b207eb761bf6b731d8d3 [file] [log] [blame]
/*
**
** Copyright 2017, Samsung Electronics Co. LTD
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
/*!
* \file ExynosCameraAutoTimer.h
* \brief hearder file for ExynosCameraAutoTimer
* \author Sangwoo.Park(sw5771.park@samsung.com)
* \date 2013/06/18
*
* <b>Revision History: </b>
* - 2013/06/18 : Sangwoo.Park(sw5771.park@samsung.com) \n
* Initial version
*
*/
#ifndef EXYNOS_CAMERA_AUTO_TIMER_H
#define EXYNOS_CAMERA_AUTO_TIMER_H
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <utils/Timers.h>
#include <utils/threads.h>
namespace android {
class ExynosCameraDurationTimer {
public:
ExynosCameraDurationTimer()
{
memset(&m_startTime, 0x00, sizeof(struct timeval));
memset(&m_stopTime, 0x00, sizeof(struct timeval));
}
~ExynosCameraDurationTimer() {}
void start()
{
gettimeofday(&m_startTime, NULL);
};
void stop()
{
gettimeofday(&m_stopTime, NULL);
};
uint64_t durationMsecs() const
{
nsecs_t stop = ((nsecs_t)m_stopTime.tv_sec) * 1000LL + ((nsecs_t)m_stopTime.tv_usec) / 1000LL;
nsecs_t start = ((nsecs_t)m_startTime.tv_sec) * 1000LL + ((nsecs_t)m_startTime.tv_usec) / 1000LL;
return stop - start;
};
uint64_t durationUsecs() const
{
nsecs_t stop = ((nsecs_t)m_stopTime.tv_sec) * 1000000LL + ((nsecs_t)m_stopTime.tv_usec);
nsecs_t start = ((nsecs_t)m_startTime.tv_sec) * 1000000LL + ((nsecs_t)m_startTime.tv_usec);
return stop - start;
};
private:
struct timeval m_startTime;
struct timeval m_stopTime;
};
class ExynosCameraAutoTimer {
private:
ExynosCameraAutoTimer(void)
{}
public:
inline ExynosCameraAutoTimer(char *strLog)
{
if (m_create(strLog) == false)
ALOGE("ERR(%s):m_create() fail", __func__);
}
inline ExynosCameraAutoTimer(const char *strLog)
{
char *strTemp = (char*)strLog;
if (m_create(strTemp) == false)
ALOGE("ERR(%s):m_create() fail", __func__);
}
inline virtual ~ExynosCameraAutoTimer()
{
uint64_t durationTime;
m_timer.stop();
durationTime = m_timer.durationMsecs();
if (m_logStr) {
ALOGD("DEBUG:duration time(%5d msec):(%s)",
(int)durationTime, m_logStr);
} else {
ALOGD("DEBUG:duration time(%5d msec):(NULL)",
(int)durationTime);
}
}
private:
bool m_create(char *strLog)
{
m_logStr = strLog;
m_timer.start();
return true;
}
private:
ExynosCameraDurationTimer m_timer;
char *m_logStr;
};
}; /* namespace android */
#endif /* EXYNOS_CAMERA_AUTO_TIMER_H */