yading@11
|
1 /*
|
yading@11
|
2 * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
|
yading@11
|
3 *
|
yading@11
|
4 * This file is part of FFmpeg.
|
yading@11
|
5 *
|
yading@11
|
6 * FFmpeg is free software; you can redistribute it and/or
|
yading@11
|
7 * modify it under the terms of the GNU Lesser General Public
|
yading@11
|
8 * License as published by the Free Software Foundation; either
|
yading@11
|
9 * version 2.1 of the License, or (at your option) any later version.
|
yading@11
|
10 *
|
yading@11
|
11 * FFmpeg is distributed in the hope that it will be useful,
|
yading@11
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
yading@11
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
yading@11
|
14 * Lesser General Public License for more details.
|
yading@11
|
15 *
|
yading@11
|
16 * You should have received a copy of the GNU Lesser General Public
|
yading@11
|
17 * License along with FFmpeg; if not, write to the Free Software
|
yading@11
|
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
yading@11
|
19 */
|
yading@11
|
20
|
yading@11
|
21 /**
|
yading@11
|
22 * @file
|
yading@11
|
23 * high precision timer, useful to profile code
|
yading@11
|
24 */
|
yading@11
|
25
|
yading@11
|
26 #ifndef AVUTIL_TIMER_H
|
yading@11
|
27 #define AVUTIL_TIMER_H
|
yading@11
|
28
|
yading@11
|
29 #include <stdlib.h>
|
yading@11
|
30 #include <stdint.h>
|
yading@11
|
31 #include <inttypes.h>
|
yading@11
|
32
|
yading@11
|
33 #include "config.h"
|
yading@11
|
34
|
yading@11
|
35 #if ARCH_ARM
|
yading@11
|
36 # include "arm/timer.h"
|
yading@11
|
37 #elif ARCH_BFIN
|
yading@11
|
38 # include "bfin/timer.h"
|
yading@11
|
39 #elif ARCH_PPC
|
yading@11
|
40 # include "ppc/timer.h"
|
yading@11
|
41 #elif ARCH_X86
|
yading@11
|
42 # include "x86/timer.h"
|
yading@11
|
43 #endif
|
yading@11
|
44
|
yading@11
|
45 #if !defined(AV_READ_TIME) && HAVE_GETHRTIME
|
yading@11
|
46 # define AV_READ_TIME gethrtime
|
yading@11
|
47 #endif
|
yading@11
|
48
|
yading@11
|
49 #ifdef AV_READ_TIME
|
yading@11
|
50 #define START_TIMER \
|
yading@11
|
51 uint64_t tend; \
|
yading@11
|
52 uint64_t tstart = AV_READ_TIME(); \
|
yading@11
|
53
|
yading@11
|
54 #define STOP_TIMER(id) \
|
yading@11
|
55 tend = AV_READ_TIME(); \
|
yading@11
|
56 { \
|
yading@11
|
57 static uint64_t tsum = 0; \
|
yading@11
|
58 static int tcount = 0; \
|
yading@11
|
59 static int tskip_count = 0; \
|
yading@11
|
60 if (tcount < 2 || \
|
yading@11
|
61 tend - tstart < 8 * tsum / tcount || \
|
yading@11
|
62 tend - tstart < 2000) { \
|
yading@11
|
63 tsum+= tend - tstart; \
|
yading@11
|
64 tcount++; \
|
yading@11
|
65 } else \
|
yading@11
|
66 tskip_count++; \
|
yading@11
|
67 if (((tcount + tskip_count) & (tcount + tskip_count - 1)) == 0) { \
|
yading@11
|
68 av_log(NULL, AV_LOG_ERROR, \
|
yading@11
|
69 "%"PRIu64" decicycles in %s, %d runs, %d skips\n", \
|
yading@11
|
70 tsum * 10 / tcount, id, tcount, tskip_count); \
|
yading@11
|
71 } \
|
yading@11
|
72 }
|
yading@11
|
73 #else
|
yading@11
|
74 #define START_TIMER
|
yading@11
|
75 #define STOP_TIMER(id) { }
|
yading@11
|
76 #endif
|
yading@11
|
77
|
yading@11
|
78 #endif /* AVUTIL_TIMER_H */
|