17ec681f3Smrg#include <stdio.h>
27ec681f3Smrg#include <lib/pan_device.h>
37ec681f3Smrg#include "pan_perf.h"
47ec681f3Smrg
57ec681f3Smrgint main(void) {
67ec681f3Smrg        int fd = drmOpenWithType("panfrost", NULL, DRM_NODE_RENDER);
77ec681f3Smrg
87ec681f3Smrg        if (fd < 0) {
97ec681f3Smrg                fprintf(stderr, "No panfrost device\n");
107ec681f3Smrg                exit(1);
117ec681f3Smrg        }
127ec681f3Smrg
137ec681f3Smrg        void *ctx = ralloc_context(NULL);
147ec681f3Smrg        struct panfrost_perf *perf = rzalloc(ctx, struct panfrost_perf);
157ec681f3Smrg
167ec681f3Smrg        struct panfrost_device dev = {};
177ec681f3Smrg        panfrost_open_device(ctx, fd, &dev);
187ec681f3Smrg
197ec681f3Smrg        panfrost_perf_init(perf, &dev);
207ec681f3Smrg        int ret = panfrost_perf_enable(perf);
217ec681f3Smrg
227ec681f3Smrg        if (ret < 0) {
237ec681f3Smrg                fprintf(stderr, "failed to enable counters (%d)\n", ret);
247ec681f3Smrg                fprintf(stderr, "try `# echo Y > /sys/module/panfrost/parameters/unstable_ioctls`\n");
257ec681f3Smrg
267ec681f3Smrg                exit(1);
277ec681f3Smrg        }
287ec681f3Smrg
297ec681f3Smrg        sleep(1);
307ec681f3Smrg
317ec681f3Smrg        panfrost_perf_dump(perf);
327ec681f3Smrg
337ec681f3Smrg        for (unsigned i = 0; i < perf->cfg->n_categories; ++i) {
347ec681f3Smrg                const struct panfrost_perf_category *cat = &perf->cfg->categories[i];
357ec681f3Smrg                printf("%s\n", cat->name);
367ec681f3Smrg
377ec681f3Smrg                for (unsigned j = 0; j < cat->n_counters; ++j) {
387ec681f3Smrg                        const struct panfrost_perf_counter *ctr = &cat->counters[j];
397ec681f3Smrg                        uint32_t val = panfrost_perf_counter_read(ctr, perf);
407ec681f3Smrg                        printf("%s (%s): %u\n", ctr->name, ctr->symbol_name, val);
417ec681f3Smrg                }
427ec681f3Smrg
437ec681f3Smrg                printf("\n");
447ec681f3Smrg        }
457ec681f3Smrg
467ec681f3Smrg        if (panfrost_perf_disable(perf) < 0) {
477ec681f3Smrg                fprintf(stderr, "failed to disable counters\n");
487ec681f3Smrg                exit(1);
497ec681f3Smrg        }
507ec681f3Smrg
517ec681f3Smrg        panfrost_close_device(&dev);
527ec681f3Smrg}
53