Commit 7d4bdab5 authored by Adrian Hunter's avatar Adrian Hunter Committed by Arnaldo Carvalho de Melo

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: default avatarAdrian 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.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent dc0a6202
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include <unistd.h> #include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdarg.h>
#include <dirent.h> #include <dirent.h>
#include <api/fs/fs.h> #include <api/fs/fs.h>
#include <locale.h> #include <locale.h>
...@@ -804,3 +805,39 @@ bool pmu_have_event(const char *pname, const char *name) ...@@ -804,3 +805,39 @@ bool pmu_have_event(const char *pname, const char *name)
} }
return false; 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;
}
...@@ -49,6 +49,9 @@ struct perf_pmu *perf_pmu__scan(struct perf_pmu *pmu); ...@@ -49,6 +49,9 @@ struct perf_pmu *perf_pmu__scan(struct perf_pmu *pmu);
void print_pmu_events(const char *event_glob, bool name_only); void print_pmu_events(const char *event_glob, bool name_only);
bool pmu_have_event(const char *pname, const char *name); bool pmu_have_event(const char *pname, const char *name);
int perf_pmu__scan_file(struct perf_pmu *pmu, const char *name, const char *fmt,
...) __attribute__((format(scanf, 3, 4)));
int perf_pmu__test(void); int perf_pmu__test(void);
struct perf_event_attr *perf_pmu__get_default_config(struct perf_pmu *pmu); struct perf_event_attr *perf_pmu__get_default_config(struct perf_pmu *pmu);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment