|
@@ -3,6 +3,7 @@
|
|
|
#include <unistd.h>
|
|
|
#include <stdio.h>
|
|
|
#include <stdbool.h>
|
|
|
+#include <stdarg.h>
|
|
|
#include <dirent.h>
|
|
|
#include <api/fs/fs.h>
|
|
|
#include <locale.h>
|
|
@@ -804,3 +805,39 @@ bool pmu_have_event(const char *pname, const char *name)
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
+static FILE *perf_pmu__open_file(struct perf_pmu *pmu, const char *name)
|
|
|
+{
|
|
|
+ struct stat st;
|
|
|
+ char path[PATH_MAX];
|
|
|
+ const char *sysfs;
|
|
|
+
|
|
|
+ sysfs = sysfs__mountpoint();
|
|
|
+ if (!sysfs)
|
|
|
+ return NULL;
|
|
|
+
|
|
|
+ snprintf(path, PATH_MAX,
|
|
|
+ "%s" EVENT_SOURCE_DEVICE_PATH "%s/%s", sysfs, pmu->name, name);
|
|
|
+
|
|
|
+ if (stat(path, &st) < 0)
|
|
|
+ return NULL;
|
|
|
+
|
|
|
+ return fopen(path, "r");
|
|
|
+}
|
|
|
+
|
|
|
+int perf_pmu__scan_file(struct perf_pmu *pmu, const char *name, const char *fmt,
|
|
|
+ ...)
|
|
|
+{
|
|
|
+ va_list args;
|
|
|
+ FILE *file;
|
|
|
+ int ret = EOF;
|
|
|
+
|
|
|
+ va_start(args, fmt);
|
|
|
+ file = perf_pmu__open_file(pmu, name);
|
|
|
+ if (file) {
|
|
|
+ ret = vfscanf(file, fmt, args);
|
|
|
+ fclose(file);
|
|
|
+ }
|
|
|
+ va_end(args);
|
|
|
+ return ret;
|
|
|
+}
|