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