From 0b37987027174067f8ce9d30ea4c573bfff76ea0 Mon Sep 17 00:00:00 2001 From: dhacker29 Date: Tue, 5 Nov 2013 00:35:16 -0600 Subject: [PATCH] Add back DurationTimer to fix camera.msm8960 load cannot locate symbol "_ZN7android13DurationTimer5startEv" Change-Id: I29d3283b644c773e6d798d17b2ef139a470048da --- include/utils/Timers.h | 39 ++++++++++++++++++++++++++ libutils/Timers.cpp | 62 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+) diff --git a/include/utils/Timers.h b/include/utils/Timers.h index d0154216..92f66c94 100644 --- a/include/utils/Timers.h +++ b/include/utils/Timers.h @@ -103,4 +103,43 @@ int toMillisecondTimeoutDelay(nsecs_t referenceTime, nsecs_t timeoutTime); } // extern "C" #endif +// ------------------------------------------------------------------ +// C++ API + +#ifdef __cplusplus + +namespace android { +/* + * Time the duration of something. + * + * Includes some timeval manipulation functions. + */ +class DurationTimer { +public: + DurationTimer() {} + ~DurationTimer() {} + + // Start the timer. + void start(); + // Stop the timer. + void stop(); + // Get the duration in microseconds. + long long durationUsecs() const; + + // Subtract two timevals. Returns the difference (ptv1-ptv2) in + // microseconds. + static long long subtractTimevals(const struct timeval* ptv1, + const struct timeval* ptv2); + + // Add the specified amount of time to the timeval. + static void addToTimeval(struct timeval* ptv, long usec); + +private: + struct timeval mStartWhen; + struct timeval mStopWhen; +}; + +}; // android +#endif // def __cplusplus + #endif // _LIBS_UTILS_TIMERS_H diff --git a/libutils/Timers.cpp b/libutils/Timers.cpp index 5293cd2a..d4f85164 100644 --- a/libutils/Timers.cpp +++ b/libutils/Timers.cpp @@ -70,3 +70,65 @@ int toMillisecondTimeoutDelay(nsecs_t referenceTime, nsecs_t timeoutTime) } return timeoutDelayMillis; } + + +/* + * =========================================================================== + * DurationTimer + * =========================================================================== + */ + +using namespace android; + +// Start the timer. +void DurationTimer::start(void) +{ + gettimeofday(&mStartWhen, NULL); +} + +// Stop the timer. +void DurationTimer::stop(void) +{ + gettimeofday(&mStopWhen, NULL); +} + +// Get the duration in microseconds. +long long DurationTimer::durationUsecs(void) const +{ + return (long) subtractTimevals(&mStopWhen, &mStartWhen); +} + +// Subtract two timevals. Returns the difference (ptv1-ptv2) in +// microseconds. +/*static*/ long long DurationTimer::subtractTimevals(const struct timeval* ptv1, + const struct timeval* ptv2) +{ + long long stop = ((long long) ptv1->tv_sec) * 1000000LL + + ((long long) ptv1->tv_usec); + long long start = ((long long) ptv2->tv_sec) * 1000000LL + + ((long long) ptv2->tv_usec); + return stop - start; +} + +// Add the specified amount of time to the timeval. +/*static*/ void DurationTimer::addToTimeval(struct timeval* ptv, long usec) +{ + if (usec < 0) { + ALOG(LOG_WARN, "", "Negative values not supported in addToTimeval\n"); + return; + } + + // normalize tv_usec if necessary + if (ptv->tv_usec >= 1000000) { + ptv->tv_sec += ptv->tv_usec / 1000000; + ptv->tv_usec %= 1000000; + } + + ptv->tv_usec += usec % 1000000; + if (ptv->tv_usec >= 1000000) { + ptv->tv_usec -= 1000000; + ptv->tv_sec++; + } + ptv->tv_sec += usec / 1000000; +} +