pprof.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #ifndef __PPROF_H__
  2. #define __PPROF_H__
  3. enum pprof_points {
  4. pp_main,
  5. pp_frame,
  6. pp_draw,
  7. pp_sound,
  8. pp_m68k,
  9. pp_s68k,
  10. pp_mem68,
  11. pp_z80,
  12. pp_msh2,
  13. pp_ssh2,
  14. pp_memsh,
  15. pp_dummy,
  16. pp_total_points
  17. };
  18. extern struct pp_counters *pp_counters;
  19. extern int *refcounts;
  20. #ifdef __i386__
  21. typedef unsigned long long pp_type;
  22. static __attribute__((always_inline)) inline unsigned int pprof_get_one(void)
  23. {
  24. unsigned long long ret;
  25. __asm__ __volatile__ ("rdtsc" : "=A" (ret));
  26. return (unsigned int)ret;
  27. }
  28. #define unglitch_timer(x)
  29. #elif defined(__GP2X__)
  30. typedef unsigned long pp_type;
  31. #if 0
  32. // XXX: MMSP2 only, timer sometimes seems to return lower vals?
  33. extern volatile unsigned long *gp2x_memregl;
  34. #define pprof_get_one() (unsigned int)gp2x_memregl[0x0a00 >> 2]
  35. #define unglitch_timer(di) \
  36. if ((signed int)(di) < 0) di = 0
  37. #else
  38. extern unsigned int (*gp2x_get_ticks_us)(void);
  39. #define pprof_get_one() gp2x_get_ticks_us()
  40. #define unglitch_timer(di) \
  41. if ((signed int)(di) < 0) di = 0
  42. #endif
  43. #else
  44. #error no timer
  45. #endif
  46. struct pp_counters
  47. {
  48. pp_type counter[pp_total_points];
  49. };
  50. #define pprof_start(point) { \
  51. unsigned int pp_start_##point = pprof_get_one(); refcounts[pp_##point]++
  52. #define pprof_end(point) \
  53. { \
  54. unsigned int di = pprof_get_one() - pp_start_##point; \
  55. unglitch_timer(di); \
  56. if (!--refcounts[pp_##point]) pp_counters->counter[pp_##point] += di; \
  57. } \
  58. }
  59. // subtract for recursive stuff
  60. #define pprof_end_sub(point) \
  61. { \
  62. unsigned int di = pprof_get_one() - pp_start_##point; \
  63. unglitch_timer(di); \
  64. if (--refcounts[pp_##point]) pp_counters->counter[pp_##point] -= di; \
  65. } \
  66. }
  67. extern void pprof_init(void);
  68. extern void pprof_finish(void);
  69. #endif // __PPROF_H__