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