Statistics
| Branch: | Revision:

ffmpeg / libavutil / timer.h @ 439ccc4e

History | View | Annotate | Download (1.88 KB)

1
/**
2
 * @file libavutil/timer.h
3
 * high precision timer, useful to profile code
4
 *
5
 * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
6
 *
7
 * This file is part of FFmpeg.
8
 *
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.
13
 *
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.
18
 *
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
22
 */
23

    
24
#ifndef AVUTIL_TIMER_H
25
#define AVUTIL_TIMER_H
26

    
27
#include <stdlib.h>
28
#include <stdint.h>
29
#include "config.h"
30

    
31
#if   ARCH_BFIN
32
#   include "bfin/timer.h"
33
#elif ARCH_PPC
34
#   include "ppc/timer.h"
35
#elif ARCH_X86
36
#   include "x86/timer.h"
37
#endif
38

    
39
#if !defined(AV_READ_TIME) && HAVE_GETHRTIME
40
#   define AV_READ_TIME gethrtime
41
#endif
42

    
43
#ifdef AV_READ_TIME
44
#define START_TIMER \
45
uint64_t tend;\
46
uint64_t tstart= AV_READ_TIME();\
47

    
48
#define STOP_TIMER(id) \
49
tend= AV_READ_TIME();\
50
{\
51
    static uint64_t tsum=0;\
52
    static int tcount=0;\
53
    static int tskip_count=0;\
54
    if(tcount<2 || tend - tstart < 8*tsum/tcount || tend - tstart < 2000){\
55
        tsum+= tend - tstart;\
56
        tcount++;\
57
    }else\
58
        tskip_count++;\
59
    if(((tcount+tskip_count)&(tcount+tskip_count-1))==0){\
60
        av_log(NULL, AV_LOG_ERROR, "%"PRIu64" dezicycles in %s, %d runs, %d skips\n",\
61
               tsum*10/tcount, id, tcount, tskip_count);\
62
    }\
63
}
64
#else
65
#define START_TIMER
66
#define STOP_TIMER(id) {}
67
#endif
68

    
69
#endif /* AVUTIL_TIMER_H */