21
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23
* high precision timer, useful to profile code
24
26
#ifndef AVUTIL_TIMER_H
25
27
#define AVUTIL_TIMER_H
27
29
#include <stdlib.h>
28
30
#include <stdint.h>
29
33
#include "config.h"
35
#if HAVE_MACH_MACH_TIME_H
36
#include <mach/mach_time.h>
32
42
# include "arm/timer.h"
34
# include "bfin/timer.h"
36
44
# include "ppc/timer.h"
38
46
# include "x86/timer.h"
41
#if !defined(AV_READ_TIME) && HAVE_GETHRTIME
42
# define AV_READ_TIME gethrtime
49
#if !defined(AV_READ_TIME)
51
# define AV_READ_TIME gethrtime
52
# elif HAVE_MACH_ABSOLUTE_TIME
53
# define AV_READ_TIME mach_absolute_time
57
#ifndef FF_TIMER_UNITS
58
# define FF_TIMER_UNITS "UNITS"
45
61
#ifdef AV_READ_TIME
48
uint64_t tstart= AV_READ_TIME();\
64
uint64_t tstart = AV_READ_TIME(); \
50
#define STOP_TIMER(id) \
51
tend= AV_READ_TIME();\
53
static uint64_t tsum=0;\
55
static int tskip_count=0;\
56
if(tcount<2 || tend - tstart < 8*tsum/tcount || tend - tstart < 2000){\
57
tsum+= tend - tstart;\
61
if(((tcount+tskip_count)&(tcount+tskip_count-1))==0){\
62
av_log(NULL, AV_LOG_ERROR, "%"PRIu64" dezicycles in %s, %d runs, %d skips\n",\
63
tsum*10/tcount, id, tcount, tskip_count);\
66
#define STOP_TIMER(id) \
67
tend = AV_READ_TIME(); \
69
static uint64_t tsum = 0; \
70
static int tcount = 0; \
71
static int tskip_count = 0; \
73
tend - tstart < 8 * tsum / tcount || \
74
tend - tstart < 2000) { \
75
tsum+= tend - tstart; \
79
if (((tcount + tskip_count) & (tcount + tskip_count - 1)) == 0) { \
80
av_log(NULL, AV_LOG_ERROR, \
81
"%"PRIu64" " FF_TIMER_UNITS " in %s, %d runs, %d skips\n", \
82
tsum * 10 / tcount, id, tcount, tskip_count); \
67
86
#define START_TIMER
68
#define STOP_TIMER(id) {}
87
#define STOP_TIMER(id) { }
71
90
#endif /* AVUTIL_TIMER_H */