2 * @file libavutil/timer.h
3 * high precision timer, useful to profile code
5 * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
7 * This file is part of FFmpeg.
9 * FFmpeg is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * FFmpeg is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with FFmpeg; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 #ifndef AVUTIL_TIMER_H
25 #define AVUTIL_TIMER_H
31 #if ARCH_X86 || ARCH_PPC || ARCH_BFIN
32 #define AV_READ_TIME read_time
34 static inline uint64_t read_time(void)
37 __asm__
volatile("rdtsc\n\t"
38 : "=a" (a
), "=d" (d
));
39 return ((uint64_t)d
<< 32) + a
;
42 static inline uint64_t read_time(void)
51 __asm__
volatile ("%0=cycles; %1=cycles2;" : "=d" (t
.p
.lo
), "=d" (t
.p
.hi
));
54 #else //FIXME check ppc64
55 static inline uint64_t read_time(void)
57 uint32_t tbu
, tbl
, temp
;
59 /* from section 2.2.1 of the 32-bit PowerPC PEM */
67 : "=r"(tbl
), "=r"(tbu
), "=r"(temp
)
71 return (((uint64_t)tbu
)<<32) | (uint64_t)tbl
;
75 #define AV_READ_TIME gethrtime
81 uint64_t tstart= AV_READ_TIME();\
83 #define STOP_TIMER(id) \
84 tend= AV_READ_TIME();\
86 static uint64_t tsum=0;\
88 static int tskip_count=0;\
89 if(tcount<2 || tend - tstart < 8*tsum/tcount || tend - tstart < 2000){\
90 tsum+= tend - tstart;\
94 if(((tcount+tskip_count)&(tcount+tskip_count-1))==0){\
95 av_log(NULL, AV_LOG_ERROR, "%"PRIu64" dezicycles in %s, %d runs, %d skips\n",\
96 tsum*10/tcount, id, tcount, tskip_count);\
101 #define STOP_TIMER(id) {}
104 #endif /* AVUTIL_TIMER_H */