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