yading@11: /* yading@11: * copyright (c) 2006 Michael Niedermayer yading@11: * yading@11: * This file is part of FFmpeg. yading@11: * yading@11: * FFmpeg is free software; you can redistribute it and/or yading@11: * modify it under the terms of the GNU Lesser General Public yading@11: * License as published by the Free Software Foundation; either yading@11: * version 2.1 of the License, or (at your option) any later version. yading@11: * yading@11: * FFmpeg is distributed in the hope that it will be useful, yading@11: * but WITHOUT ANY WARRANTY; without even the implied warranty of yading@11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU yading@11: * Lesser General Public License for more details. yading@11: * yading@11: * You should have received a copy of the GNU Lesser General Public yading@11: * License along with FFmpeg; if not, write to the Free Software yading@11: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA yading@11: */ yading@11: yading@11: /** yading@11: * @file yading@11: * high precision timer, useful to profile code yading@11: */ yading@11: yading@11: #ifndef AVUTIL_TIMER_H yading@11: #define AVUTIL_TIMER_H yading@11: yading@11: #include yading@11: #include yading@11: #include yading@11: yading@11: #include "config.h" yading@11: yading@11: #if ARCH_ARM yading@11: # include "arm/timer.h" yading@11: #elif ARCH_BFIN yading@11: # include "bfin/timer.h" yading@11: #elif ARCH_PPC yading@11: # include "ppc/timer.h" yading@11: #elif ARCH_X86 yading@11: # include "x86/timer.h" yading@11: #endif yading@11: yading@11: #if !defined(AV_READ_TIME) && HAVE_GETHRTIME yading@11: # define AV_READ_TIME gethrtime yading@11: #endif yading@11: yading@11: #ifdef AV_READ_TIME yading@11: #define START_TIMER \ yading@11: uint64_t tend; \ yading@11: uint64_t tstart = AV_READ_TIME(); \ yading@11: yading@11: #define STOP_TIMER(id) \ yading@11: tend = AV_READ_TIME(); \ yading@11: { \ yading@11: static uint64_t tsum = 0; \ yading@11: static int tcount = 0; \ yading@11: static int tskip_count = 0; \ yading@11: if (tcount < 2 || \ yading@11: tend - tstart < 8 * tsum / tcount || \ yading@11: tend - tstart < 2000) { \ yading@11: tsum+= tend - tstart; \ yading@11: tcount++; \ yading@11: } else \ yading@11: tskip_count++; \ yading@11: if (((tcount + tskip_count) & (tcount + tskip_count - 1)) == 0) { \ yading@11: av_log(NULL, AV_LOG_ERROR, \ yading@11: "%"PRIu64" decicycles in %s, %d runs, %d skips\n", \ yading@11: tsum * 10 / tcount, id, tcount, tskip_count); \ yading@11: } \ yading@11: } yading@11: #else yading@11: #define START_TIMER yading@11: #define STOP_TIMER(id) { } yading@11: #endif yading@11: yading@11: #endif /* AVUTIL_TIMER_H */