diff options
Diffstat (limited to 'lib/igt_perf.c')
-rw-r--r-- | lib/igt_perf.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/igt_perf.c b/lib/igt_perf.c index 45cccff0..961a858a 100644 --- a/lib/igt_perf.c +++ b/lib/igt_perf.c @@ -2,6 +2,8 @@ #include <fcntl.h> #include <unistd.h> #include <stdlib.h> +#include <string.h> +#include <errno.h> #include "igt_perf.h" @@ -24,3 +26,33 @@ uint64_t i915_type_id(void) return strtoull(buf, 0, 0); } +static int _perf_open(int config, int group, int format) +{ + struct perf_event_attr attr; + + memset(&attr, 0, sizeof (attr)); + + attr.type = i915_type_id(); + if (attr.type == 0) + return -ENOENT; + + attr.config = config; + + if (group >= 0) + format &= ~PERF_FORMAT_GROUP; + + attr.read_format = format; + + return perf_event_open(&attr, -1, 0, group, 0); +} + +int perf_i915_open(int config) +{ + return _perf_open(config, -1, PERF_FORMAT_TOTAL_TIME_ENABLED); +} + +int perf_i915_open_group(int config, int group) +{ + return _perf_open(config, group, + PERF_FORMAT_TOTAL_TIME_ENABLED | PERF_FORMAT_GROUP); +} |