1 /* RetroArch - A frontend for libretro. 2 * Copyright (C) 2010-2014 - Hans-Kristian Arntzen 3 * Copyright (C) 2011-2017 - Daniel De Matteis 4 * 5 * RetroArch is free software: you can redistribute it and/or modify it under the terms 6 * of the GNU General Public License as published by the Free Software Found- 7 * ation, either version 3 of the License, or (at your option) any later version. 8 * 9 * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 10 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 11 * PURPOSE. See the GNU General Public License for more details. 12 * 13 * You should have received a copy of the GNU General Public License along with RetroArch. 14 * If not, see <http://www.gnu.org/licenses/>. 15 */ 16 17 #ifndef _PERFORMANCE_COUNTERS_H 18 #define _PERFORMANCE_COUNTERS_H 19 20 #include <stdint.h> 21 #include <boolean.h> 22 23 #include <retro_common_api.h> 24 #include <libretro.h> 25 #include <features/features_cpu.h> 26 27 RETRO_BEGIN_DECLS 28 29 #ifndef MAX_COUNTERS 30 #define MAX_COUNTERS 64 31 #endif 32 33 typedef struct rarch_timer 34 { 35 int64_t current; 36 int64_t timeout_us; 37 int64_t timeout_end; 38 bool timer_begin; 39 bool timer_end; 40 } rarch_timer_t; 41 42 struct retro_perf_counter **retro_get_perf_counter_rarch(void); 43 44 struct retro_perf_counter **retro_get_perf_counter_libretro(void); 45 46 unsigned retro_get_perf_count_rarch(void); 47 48 unsigned retro_get_perf_count_libretro(void); 49 50 void rarch_perf_register(struct retro_perf_counter *perf); 51 52 #define performance_counter_init(perf, name) \ 53 perf.ident = name; \ 54 if (!perf.registered) \ 55 rarch_perf_register(&perf) 56 57 #define performance_counter_start_internal(is_perfcnt_enable, perf) \ 58 if ((is_perfcnt_enable)) \ 59 { \ 60 perf.call_cnt++; \ 61 perf.start = cpu_features_get_perf_counter(); \ 62 } 63 64 #define performance_counter_stop_internal(is_perfcnt_enable, perf) \ 65 if ((is_perfcnt_enable)) \ 66 perf.total += cpu_features_get_perf_counter() - perf.start 67 68 /** 69 * performance_counter_start: 70 * @perf : pointer to performance counter 71 * 72 * Start performance counter. 73 **/ 74 #define performance_counter_start_plus(is_perfcnt_enable, perf) performance_counter_start_internal(is_perfcnt_enable, perf) 75 76 /** 77 * performance_counter_stop: 78 * @perf : pointer to performance counter 79 * 80 * Stop performance counter. 81 **/ 82 #define performance_counter_stop_plus(is_perfcnt_enable, perf) performance_counter_stop_internal(is_perfcnt_enable, perf) 83 84 RETRO_END_DECLS 85 86 #endif 87