Debian Codegraph @

src/panfrost/perf/quick.c

raw
1 /*
2 * Copyright © 2021 Collabora, Ltd.
3 * SPDX-License-Identifier: MIT
4 */
5
6 #include <xf86drm.h>
7 #include <stdio.h>
8 #include <lib/kmod/pan_kmod.h>
9 #include <lib/pan_props.h>
10 #include "pan_perf.h"
11
12 int
13 main(void)
14 {
15 int fd = drmOpenWithType("panfrost", NULL, DRM_NODE_RENDER);
16
17 if (fd < 0) {
18 fprintf(stderr, "No panfrost device\n");
19 exit(1);
20 }
21
22 void *ctx = ralloc_context(NULL);
23 struct pan_perf *perf = rzalloc(ctx, struct pan_perf);
24
25 pan_perf_init(perf, fd);
26
27 int ret = pan_perf_enable(perf);
28
29 if (ret < 0) {
30 fprintf(stderr, "failed to enable counters (%d)\n", ret);
31 fprintf(
32 stderr,
33 "try `# echo Y > /sys/module/panfrost/parameters/unstable_ioctls`\n");
34
35 exit(1);
36 }
37
38 sleep(1);
39
40 pan_perf_dump(perf);
41
42 for (unsigned i = 0; i < perf->cfg->n_categories; ++i) {
43 const struct pan_perf_category *cat = &perf->cfg->categories[i];
44 printf("%s\n", cat->name);
45
46 for (unsigned j = 0; j < cat->n_counters; ++j) {
47 const struct pan_perf_counter *ctr = &cat->counters[j];
48 uint32_t val = pan_perf_counter_read(ctr, perf);
49 printf("%s (%s): %u\n", ctr->name, ctr->symbol_name, val);
50 }
51
52 printf("\n");
53 }
54
55 if (pan_perf_disable(perf) < 0) {
56 fprintf(stderr, "failed to disable counters\n");
57 exit(1);
58 }
59
60 return 0;
61 }