1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/omx-plugin/include/gb/utils/Timers.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,134 @@ 1.4 +/* 1.5 + * Copyright (C) 2005 The Android Open Source Project 1.6 + * 1.7 + * Licensed under the Apache License, Version 2.0 (the "License"); 1.8 + * you may not use this file except in compliance with the License. 1.9 + * You may obtain a copy of the License at 1.10 + * 1.11 + * http://www.apache.org/licenses/LICENSE-2.0 1.12 + * 1.13 + * Unless required by applicable law or agreed to in writing, software 1.14 + * distributed under the License is distributed on an "AS IS" BASIS, 1.15 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1.16 + * See the License for the specific language governing permissions and 1.17 + * limitations under the License. 1.18 + */ 1.19 + 1.20 +// 1.21 +// Timer functions. 1.22 +// 1.23 +#ifndef _LIBS_UTILS_TIMERS_H 1.24 +#define _LIBS_UTILS_TIMERS_H 1.25 + 1.26 +#include <stdint.h> 1.27 +#include <sys/types.h> 1.28 +#include <sys/time.h> 1.29 + 1.30 +// ------------------------------------------------------------------ 1.31 +// C API 1.32 + 1.33 +#ifdef __cplusplus 1.34 +extern "C" { 1.35 +#endif 1.36 + 1.37 +typedef int64_t nsecs_t; // nano-seconds 1.38 + 1.39 +static inline nsecs_t seconds_to_nanoseconds(nsecs_t secs) 1.40 +{ 1.41 + return secs*1000000000; 1.42 +} 1.43 + 1.44 +static inline nsecs_t milliseconds_to_nanoseconds(nsecs_t secs) 1.45 +{ 1.46 + return secs*1000000; 1.47 +} 1.48 + 1.49 +static inline nsecs_t microseconds_to_nanoseconds(nsecs_t secs) 1.50 +{ 1.51 + return secs*1000; 1.52 +} 1.53 + 1.54 +static inline nsecs_t nanoseconds_to_seconds(nsecs_t secs) 1.55 +{ 1.56 + return secs/1000000000; 1.57 +} 1.58 + 1.59 +static inline nsecs_t nanoseconds_to_milliseconds(nsecs_t secs) 1.60 +{ 1.61 + return secs/1000000; 1.62 +} 1.63 + 1.64 +static inline nsecs_t nanoseconds_to_microseconds(nsecs_t secs) 1.65 +{ 1.66 + return secs/1000; 1.67 +} 1.68 + 1.69 +static inline nsecs_t s2ns(nsecs_t v) {return seconds_to_nanoseconds(v);} 1.70 +static inline nsecs_t ms2ns(nsecs_t v) {return milliseconds_to_nanoseconds(v);} 1.71 +static inline nsecs_t us2ns(nsecs_t v) {return microseconds_to_nanoseconds(v);} 1.72 +static inline nsecs_t ns2s(nsecs_t v) {return nanoseconds_to_seconds(v);} 1.73 +static inline nsecs_t ns2ms(nsecs_t v) {return nanoseconds_to_milliseconds(v);} 1.74 +static inline nsecs_t ns2us(nsecs_t v) {return nanoseconds_to_microseconds(v);} 1.75 + 1.76 +static inline nsecs_t seconds(nsecs_t v) { return s2ns(v); } 1.77 +static inline nsecs_t milliseconds(nsecs_t v) { return ms2ns(v); } 1.78 +static inline nsecs_t microseconds(nsecs_t v) { return us2ns(v); } 1.79 + 1.80 +enum { 1.81 + SYSTEM_TIME_REALTIME = 0, // system-wide realtime clock 1.82 + SYSTEM_TIME_MONOTONIC = 1, // monotonic time since unspecified starting point 1.83 + SYSTEM_TIME_PROCESS = 2, // high-resolution per-process clock 1.84 + SYSTEM_TIME_THREAD = 3 // high-resolution per-thread clock 1.85 +}; 1.86 + 1.87 +// return the system-time according to the specified clock 1.88 +#ifdef __cplusplus 1.89 +nsecs_t systemTime(int clock = SYSTEM_TIME_MONOTONIC); 1.90 +#else 1.91 +nsecs_t systemTime(int clock); 1.92 +#endif // def __cplusplus 1.93 + 1.94 +#ifdef __cplusplus 1.95 +} // extern "C" 1.96 +#endif 1.97 + 1.98 +// ------------------------------------------------------------------ 1.99 +// C++ API 1.100 + 1.101 +#ifdef __cplusplus 1.102 + 1.103 +namespace android { 1.104 +/* 1.105 + * Time the duration of something. 1.106 + * 1.107 + * Includes some timeval manipulation functions. 1.108 + */ 1.109 +class DurationTimer { 1.110 +public: 1.111 + DurationTimer() {} 1.112 + ~DurationTimer() {} 1.113 + 1.114 + // Start the timer. 1.115 + void start(); 1.116 + // Stop the timer. 1.117 + void stop(); 1.118 + // Get the duration in microseconds. 1.119 + long long durationUsecs() const; 1.120 + 1.121 + // Subtract two timevals. Returns the difference (ptv1-ptv2) in 1.122 + // microseconds. 1.123 + static long long subtractTimevals(const struct timeval* ptv1, 1.124 + const struct timeval* ptv2); 1.125 + 1.126 + // Add the specified amount of time to the timeval. 1.127 + static void addToTimeval(struct timeval* ptv, long usec); 1.128 + 1.129 +private: 1.130 + struct timeval mStartWhen; 1.131 + struct timeval mStopWhen; 1.132 +}; 1.133 + 1.134 +}; // android 1.135 +#endif // def __cplusplus 1.136 + 1.137 +#endif // _LIBS_UTILS_TIMERS_H