diff options
author | Adrian Hunter <adrian.hunter@intel.com> | 2014-07-31 02:00:50 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2014-09-17 16:08:09 -0400 |
commit | 7d4bdab5a441772bfc757d7f9eea9465ec5de0ec (patch) | |
tree | a0930d0dec69feb55fef8432f2bef7891c55675a /tools | |
parent | dc0a6202421170a6d8d2c6f5176575b3f60e0f85 (diff) |
perf tools: Add perf_pmu__scan_file()
Add a function to scan a sysfs file within the pmu device directory.
This will be used to read capability values from the PMU 'caps'
subdirectory.
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1406786474-9306-8-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/perf/util/pmu.c | 37 | ||||
-rw-r--r-- | tools/perf/util/pmu.h | 3 |
2 files changed, 40 insertions, 0 deletions
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 438bb261f391..22a4ad5a927a 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c | |||
@@ -3,6 +3,7 @@ | |||
3 | #include <unistd.h> | 3 | #include <unistd.h> |
4 | #include <stdio.h> | 4 | #include <stdio.h> |
5 | #include <stdbool.h> | 5 | #include <stdbool.h> |
6 | #include <stdarg.h> | ||
6 | #include <dirent.h> | 7 | #include <dirent.h> |
7 | #include <api/fs/fs.h> | 8 | #include <api/fs/fs.h> |
8 | #include <locale.h> | 9 | #include <locale.h> |
@@ -804,3 +805,39 @@ bool pmu_have_event(const char *pname, const char *name) | |||
804 | } | 805 | } |
805 | return false; | 806 | return false; |
806 | } | 807 | } |
808 | |||
809 | static FILE *perf_pmu__open_file(struct perf_pmu *pmu, const char *name) | ||
810 | { | ||
811 | struct stat st; | ||
812 | char path[PATH_MAX]; | ||
813 | const char *sysfs; | ||
814 | |||
815 | sysfs = sysfs__mountpoint(); | ||
816 | if (!sysfs) | ||
817 | return NULL; | ||
818 | |||
819 | snprintf(path, PATH_MAX, | ||
820 | "%s" EVENT_SOURCE_DEVICE_PATH "%s/%s", sysfs, pmu->name, name); | ||
821 | |||
822 | if (stat(path, &st) < 0) | ||
823 | return NULL; | ||
824 | |||
825 | return fopen(path, "r"); | ||
826 | } | ||
827 | |||
828 | int perf_pmu__scan_file(struct perf_pmu *pmu, const char *name, const char *fmt, | ||
829 | ...) | ||
830 | { | ||
831 | va_list args; | ||
832 | FILE *file; | ||
833 | int ret = EOF; | ||
834 | |||
835 | va_start(args, fmt); | ||
836 | file = perf_pmu__open_file(pmu, name); | ||
837 | if (file) { | ||
838 | ret = vfscanf(file, fmt, args); | ||
839 | fclose(file); | ||
840 | } | ||
841 | va_end(args); | ||
842 | return ret; | ||
843 | } | ||
diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index 413b9a63c38d..0f5c0a88fdc8 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h | |||
@@ -49,6 +49,9 @@ struct perf_pmu *perf_pmu__scan(struct perf_pmu *pmu); | |||
49 | void print_pmu_events(const char *event_glob, bool name_only); | 49 | void print_pmu_events(const char *event_glob, bool name_only); |
50 | bool pmu_have_event(const char *pname, const char *name); | 50 | bool pmu_have_event(const char *pname, const char *name); |
51 | 51 | ||
52 | int perf_pmu__scan_file(struct perf_pmu *pmu, const char *name, const char *fmt, | ||
53 | ...) __attribute__((format(scanf, 3, 4))); | ||
54 | |||
52 | int perf_pmu__test(void); | 55 | int perf_pmu__test(void); |
53 | 56 | ||
54 | struct perf_event_attr *perf_pmu__get_default_config(struct perf_pmu *pmu); | 57 | struct perf_event_attr *perf_pmu__get_default_config(struct perf_pmu *pmu); |