xref: /linux/tools/perf/tests/util.c (revision d0b73b488c55df905ea8faaad079f8535629ed26)
1 #include <stdio.h>
2 #include <unistd.h>
3 #include <stdlib.h>
4 #include <sys/types.h>
5 #include <sys/stat.h>
6 #include <fcntl.h>
7 #include "tests.h"
8 #include "debugfs.h"
9 
10 int trace_event__id(const char *evname)
11 {
12 	char *filename;
13 	int err = -1, fd;
14 
15 	if (asprintf(&filename,
16 		     "%s/syscalls/%s/id",
17 		     tracing_events_path, evname) < 0)
18 		return -1;
19 
20 	fd = open(filename, O_RDONLY);
21 	if (fd >= 0) {
22 		char id[16];
23 		if (read(fd, id, sizeof(id)) > 0)
24 			err = atoi(id);
25 		close(fd);
26 	}
27 
28 	free(filename);
29 	return err;
30 }
31