add per game configs (by popular demand, no controls yet though)
[pcsx_rearmed.git] / frontend / pcnt.h
1
2 enum pcounters {
3         PCNT_ALL,
4         PCNT_GPU,
5         PCNT_SPU,
6         PCNT_BLIT,
7         PCNT_TEST,
8         PCNT_CNT
9 };
10
11 #ifdef PCNT
12
13 static const char *pcnt_names[PCNT_CNT] = { "", "gpu", "spu", "blit", "test" };
14
15 #define PCNT_FRAMES 10
16
17 extern unsigned int pcounters[PCNT_CNT];
18 extern unsigned int pcounter_starts[PCNT_CNT];
19
20 #define pcnt_start(id) \
21         pcounter_starts[id] = pcnt_get()
22
23 #define pcnt_end(id) \
24         pcounters[id] += pcnt_get() - pcounter_starts[id]
25
26 void pcnt_hook_plugins(void);
27
28 static inline void pcnt_print(float fps)
29 {
30         static int print_counter;
31         unsigned int total, rem;
32         int i;
33
34         for (i = 0; i < PCNT_CNT; i++)
35                 pcounters[i] /= 1000 * PCNT_FRAMES;
36
37         rem = total = pcounters[PCNT_ALL];
38         for (i = 1; i < PCNT_CNT; i++)
39                 rem -= pcounters[i];
40         if (!total)
41                 total++;
42
43         if (--print_counter < 0) {
44                 printf("     ");
45                 for (i = 1; i < PCNT_CNT; i++)
46                         printf("%5s ", pcnt_names[i]);
47                 printf("%5s\n", "rem");
48                 print_counter = 30;
49         }
50
51         printf("%4.1f ", fps);
52         for (i = 1; i < PCNT_CNT; i++)
53                 printf("%5u ", pcounters[i]);
54         printf("%5u (", rem);
55         for (i = 1; i < PCNT_CNT; i++)
56                 printf("%2u ", pcounters[i] * 100 / total);
57         printf("%2u) %u\n", rem * 100 / total, total);
58
59         memset(pcounters, 0, sizeof(pcounters));
60 }
61
62 static inline unsigned int pcnt_get(void)
63 {
64         unsigned int val;
65 #ifdef __ARM_ARCH_7A__
66         __asm__ volatile("mrc p15, 0, %0, c9, c13, 0"
67                          : "=r"(val));
68 #else
69         val = 0;
70 #endif
71         return val;
72 }
73
74 #else
75
76 #define pcnt_start(id)
77 #define pcnt_end(id)
78 #define pcnt_hook_plugins()
79 #define pcnt_print(fps)
80
81 #endif