libavutil/timer.h
Go to the documentation of this file.
00001 /*
00002  * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
00003  *
00004  * This file is part of FFmpeg.
00005  *
00006  * FFmpeg is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * FFmpeg is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with FFmpeg; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00019  */
00020 
00026 #ifndef AVUTIL_TIMER_H
00027 #define AVUTIL_TIMER_H
00028 
00029 #include <stdlib.h>
00030 #include <stdint.h>
00031 
00032 #include "config.h"
00033 
00034 #if   ARCH_ARM
00035 #   include "arm/timer.h"
00036 #elif ARCH_BFIN
00037 #   include "bfin/timer.h"
00038 #elif ARCH_PPC
00039 #   include "ppc/timer.h"
00040 #elif ARCH_X86
00041 #   include "x86/timer.h"
00042 #endif
00043 
00044 #if !defined(AV_READ_TIME) && HAVE_GETHRTIME
00045 #   define AV_READ_TIME gethrtime
00046 #endif
00047 
00048 #ifdef AV_READ_TIME
00049 #define START_TIMER                             \
00050     uint64_t tend;                              \
00051     uint64_t tstart = AV_READ_TIME();           \
00052 
00053 #define STOP_TIMER(id)                                                    \
00054     tend = AV_READ_TIME();                                                \
00055     {                                                                     \
00056         static uint64_t tsum   = 0;                                       \
00057         static int tcount      = 0;                                       \
00058         static int tskip_count = 0;                                       \
00059         if (tcount < 2                        ||                          \
00060             tend - tstart < 8 * tsum / tcount ||                          \
00061             tend - tstart < 2000) {                                       \
00062             tsum+= tend - tstart;                                         \
00063             tcount++;                                                     \
00064         } else                                                            \
00065             tskip_count++;                                                \
00066         if (((tcount + tskip_count) & (tcount + tskip_count - 1)) == 0) { \
00067             av_log(NULL, AV_LOG_ERROR,                                    \
00068                    "%"PRIu64" decicycles in %s, %d runs, %d skips\n",     \
00069                    tsum * 10 / tcount, id, tcount, tskip_count);          \
00070         }                                                                 \
00071     }
00072 #else
00073 #define START_TIMER
00074 #define STOP_TIMER(id) { }
00075 #endif
00076 
00077 #endif /* AVUTIL_TIMER_H */