xref: /aosp_15_r20/external/mesa3d/src/panfrost/perf/quick.c (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 #include <xf86drm.h>
2 #include <stdio.h>
3 #include <lib/kmod/pan_kmod.h>
4 #include <lib/pan_props.h>
5 #include "pan_perf.h"
6 
7 int
main(void)8 main(void)
9 {
10    int fd = drmOpenWithType("panfrost", NULL, DRM_NODE_RENDER);
11 
12    if (fd < 0) {
13       fprintf(stderr, "No panfrost device\n");
14       exit(1);
15    }
16 
17    void *ctx = ralloc_context(NULL);
18    struct panfrost_perf *perf = rzalloc(ctx, struct panfrost_perf);
19 
20    panfrost_perf_init(perf, fd);
21 
22    int ret = panfrost_perf_enable(perf);
23 
24    if (ret < 0) {
25       fprintf(stderr, "failed to enable counters (%d)\n", ret);
26       fprintf(
27          stderr,
28          "try `# echo Y > /sys/module/panfrost/parameters/unstable_ioctls`\n");
29 
30       exit(1);
31    }
32 
33    sleep(1);
34 
35    panfrost_perf_dump(perf);
36 
37    for (unsigned i = 0; i < perf->cfg->n_categories; ++i) {
38       const struct panfrost_perf_category *cat = &perf->cfg->categories[i];
39       printf("%s\n", cat->name);
40 
41       for (unsigned j = 0; j < cat->n_counters; ++j) {
42          const struct panfrost_perf_counter *ctr = &cat->counters[j];
43          uint32_t val = panfrost_perf_counter_read(ctr, perf);
44          printf("%s (%s): %u\n", ctr->name, ctr->symbol_name, val);
45       }
46 
47       printf("\n");
48    }
49 
50    if (panfrost_perf_disable(perf) < 0) {
51       fprintf(stderr, "failed to disable counters\n");
52       exit(1);
53    }
54 
55    return 0;
56 }
57