5ff8efa9 |
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, |
10 | pp_z80, |
11 | pp_msh2, |
12 | pp_ssh2, |
13 | pp_dummy, |
14 | pp_total_points |
15 | }; |
16 | |
17 | struct pp_counters |
18 | { |
19 | unsigned long long counter[pp_total_points]; |
20 | }; |
21 | |
22 | extern struct pp_counters *pp_counters; |
23 | |
24 | #ifdef __i386__ |
25 | static __attribute__((always_inline)) inline unsigned int pprof_get_one(void) |
26 | { |
27 | unsigned long long ret; |
28 | __asm__ __volatile__ ("rdtsc" : "=A" (ret)); |
29 | return (unsigned int)ret; |
30 | } |
31 | |
32 | #elif defined(__GP2X__) |
33 | // XXX: MMSP2 only |
34 | extern volatile unsigned long *gp2x_memregl; |
35 | #define pprof_get_one() (unsigned int)gp2x_memregl[0x0a00 >> 2] |
36 | |
37 | #else |
38 | #error no timer |
39 | #endif |
40 | |
41 | #define pprof_start(point) { \ |
42 | unsigned int pp_start_##point = pprof_get_one() |
43 | #define pprof_end(point) \ |
44 | pp_counters->counter[pp_##point] += pprof_get_one() - pp_start_##point; \ |
45 | } |
46 | // subtract for recursive stuff |
47 | #define pprof_end_sub(point) \ |
48 | pp_counters->counter[pp_##point] -= pprof_get_one() - pp_start_##point; \ |
49 | } |
50 | |
51 | extern void pprof_init(void); |
52 | extern void pprof_finish(void); |
53 | |
54 | #endif // __PPROF_H__ |