1 /* 2 * Copyright (c) 2021 Rockchip Electronics Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef __MPP_TIME_H__ 17 #define __MPP_TIME_H__ 18 19 #include "rk_type.h" 20 #include "mpp_thread.h" 21 22 #if defined(_WIN32) && !defined(__MINGW32CE__) 23 #include <windows.h> 24 #define msleep Sleep 25 #define sleep(x) Sleep((x)*1000) 26 #else 27 #include <unistd.h> 28 #define msleep(x) usleep((x)*1000) 29 #endif 30 31 typedef void* MppClock; 32 typedef void* MppTimer; 33 typedef void* MppStopwatch; 34 35 #ifdef __cplusplus 36 extern "C" { 37 #endif 38 39 RK_S64 mpp_time(); 40 void mpp_time_diff(RK_S64 start, RK_S64 end, RK_S64 limit, const char *fmt); 41 MppClock mpp_clock_get(const char *name); 42 void mpp_clock_put(MppClock clock); 43 void mpp_clock_enable(MppClock clock, RK_U32 enable); 44 RK_S64 mpp_clock_start(MppClock clock); 45 RK_S64 mpp_clock_pause(MppClock clock); 46 RK_S64 mpp_clock_reset(MppClock clock); 47 RK_S64 mpp_clock_get_sum(MppClock clock); 48 RK_S64 mpp_clock_get_count(MppClock clock); 49 const char *mpp_clock_get_name(MppClock clock); 50 MppTimer mpp_timer_get(const char *name); 51 void mpp_timer_set_callback(MppTimer timer, MppThreadFunc func, void *ctx); 52 void mpp_timer_set_timing(MppTimer timer, RK_S32 initial, RK_S32 interval); 53 void mpp_timer_set_enable(MppTimer timer, RK_S32 enable); 54 void mpp_timer_put(MppTimer timer); 55 MppStopwatch mpp_stopwatch_get(const char *name); 56 void mpp_stopwatch_set_show_on_exit(MppStopwatch stopwatch, RK_S32 show_on_exit); 57 void mpp_stopwatch_record(MppStopwatch stopwatch, const char *event); 58 void mpp_stopwatch_put(MppStopwatch timer); 59 RK_S64 mpp_stopwatch_elapsed_time(MppStopwatch stopwatch); 60 61 #ifdef __cplusplus 62 } 63 #endif 64 65 #ifdef __cplusplus 66 class AutoTiming { 67 public: 68 AutoTiming(const char *name = __FUNCTION__); 69 ~AutoTiming(); 70 private: 71 const char *mName; 72 RK_S64 mStart; 73 RK_S64 mEnd; 74 75 AutoTiming(const AutoTiming &); 76 AutoTiming &operator = (const AutoTiming&); 77 }; 78 79 #endif 80 81 #define AUTO_TIMER_STRING(name, cnt) name ## cnt 82 #define AUTO_TIMER_NAME_STRING(name, cnt) AUTO_TIMER_STRING(name, cnt) 83 #define AUTO_TIMER_NAME(name) AUTO_TIMER_NAME_STRING(name, __COUNTER__) 84 #define AUTO_TIMING() AutoTiming AUTO_TIMER_NAME(auto_timing)(__FUNCTION__) 85 86 #endif 87