10 #include <pico/pico_int.h>
12 int rc_mem[pp_total_points];
14 struct pp_counters *pp_counters;
15 int *refcounts = rc_mem;
18 static unsigned long devMem;
19 volatile unsigned long *gp2x_memregl;
20 volatile unsigned short *gp2x_memregs;
24 int this_is_new_shmem = 1;
29 devMem = open("/dev/mem", O_RDWR);
32 perror("pprof: open failed");
35 gp2x_memregl = (unsigned long *)mmap(0, 0x10000, PROT_READ|PROT_WRITE, MAP_SHARED, devMem, 0xc0000000);
36 if (gp2x_memregl == (unsigned long *)-1)
38 perror("pprof: mmap failed");
41 gp2x_memregs = (unsigned short *)gp2x_memregl;
45 unsigned int tmp = pprof_get_one();
46 printf("pprof: measured diff is %u\n", pprof_get_one() - tmp);
49 shmemkey = ftok(".", 0x02ABC32E);
52 perror("pprof: ftok failed");
57 shmemid = shmget(shmemkey, sizeof(*pp_counters),
58 IPC_CREAT | IPC_EXCL | 0644);
62 shmemid = shmget(shmemkey, sizeof(*pp_counters),
66 perror("pprof: shmget failed");
69 this_is_new_shmem = 0;
72 shmem = shmat(shmemid, NULL, 0);
73 if (shmem == (void *)-1)
75 perror("pprof: shmat failed");
80 if (this_is_new_shmem) {
81 memset(pp_counters, 0, sizeof(*pp_counters));
82 printf("pprof: pp_counters cleared.\n");
86 void pprof_finish(void)
89 shmctl(shmemid, IPC_RMID, NULL);
94 #define IT(n) { pp_##n, #n }
113 int main(int argc, char *argv[])
115 pp_type old[pp_total_points], new[pp_total_points];
120 if (pp_counters == NULL)
124 base = atoi(argv[1]);
126 memset(old, 0, sizeof(old));
129 if ((l & 0x1f) == 0) {
130 for (i = 0; i < ARRAY_SIZE(pp_tab); i++)
131 printf("%6s ", pp_tab[i].name);
135 memcpy(new, pp_counters->counter, sizeof(new));
136 for (i = 0; i < ARRAY_SIZE(pp_tab); i++)
138 pp_type idiff = new[i] - old[i];
139 pp_type bdiff = (new[base] - old[base]) | 1;
140 printf("%6.2f ", (double)idiff * 100.0 / bdiff);
144 memcpy(old, new, sizeof(old));
148 usleep(atoi(argv[2]));