timer.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /**
  2. * @file
  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. #ifndef AVUTIL_TIMER_H
  24. #define AVUTIL_TIMER_H
  25. #include <stdlib.h>
  26. #include <stdint.h>
  27. #include "config.h"
  28. #if ARCH_ARM
  29. # include "arm/timer.h"
  30. #elif ARCH_BFIN
  31. # include "bfin/timer.h"
  32. #elif ARCH_PPC
  33. # include "ppc/timer.h"
  34. #elif ARCH_X86
  35. # include "x86/timer.h"
  36. #endif
  37. #if !defined(AV_READ_TIME) && HAVE_GETHRTIME
  38. # define AV_READ_TIME gethrtime
  39. #endif
  40. #ifdef AV_READ_TIME
  41. #define START_TIMER \
  42. uint64_t tend;\
  43. uint64_t tstart= AV_READ_TIME();\
  44. #define STOP_TIMER(id) \
  45. tend= AV_READ_TIME();\
  46. {\
  47. static uint64_t tsum=0;\
  48. static int tcount=0;\
  49. static int tskip_count=0;\
  50. if(tcount<2 || tend - tstart < 8*tsum/tcount || tend - tstart < 2000){\
  51. tsum+= tend - tstart;\
  52. tcount++;\
  53. }else\
  54. tskip_count++;\
  55. if(((tcount+tskip_count)&(tcount+tskip_count-1))==0){\
  56. av_log(NULL, AV_LOG_ERROR, "%"PRIu64" dezicycles in %s, %d runs, %d skips\n",\
  57. tsum*10/tcount, id, tcount, tskip_count);\
  58. }\
  59. }
  60. #else
  61. #define START_TIMER
  62. #define STOP_TIMER(id) {}
  63. #endif
  64. #endif /* AVUTIL_TIMER_H */