All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org,
	Adrian Hunter <adrian.hunter@intel.com>,
	David Ahern <dsahern@gmail.com>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Jiri Olsa <jolsa@redhat.com>, Namhyung Kim <namhyung@gmail.com>,
	Paul Mackerras <paulus@samba.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Stephane Eranian <eranian@google.com>,
	Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 13/13] perf tools: Add perf_pmu__scan_file()
Date: Mon,  8 Sep 2014 18:18:09 -0300	[thread overview]
Message-ID: <1410211089-28668-14-git-send-email-acme@kernel.org> (raw)
In-Reply-To: <1410211089-28668-1-git-send-email-acme@kernel.org>

From: Adrian Hunter <adrian.hunter@intel.com>

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>
---
 tools/perf/util/pmu.c | 37 +++++++++++++++++++++++++++++++++++++
 tools/perf/util/pmu.h |  3 +++
 2 files changed, 40 insertions(+)

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 @@
 #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;
+}
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);
 void print_pmu_events(const char *event_glob, bool name_only);
 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);
 
 struct perf_event_attr *perf_pmu__get_default_config(struct perf_pmu *pmu);
-- 
1.9.3


  parent reply	other threads:[~2014-09-08 21:19 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-08 21:17 [GIT PULL 00/13] perf/core improvements and fixes Arnaldo Carvalho de Melo
2014-09-08 21:17 ` [PATCH 01/13] perf tools: Add +field argument support for --sort option Arnaldo Carvalho de Melo
2014-09-08 21:17 ` [PATCH 02/13] perf tools powerpc: Fix build issue when DWARF support is disabled Arnaldo Carvalho de Melo
2014-09-08 21:17 ` [PATCH 03/13] perf kvm stat report: Save pid string in opts.target.pid Arnaldo Carvalho de Melo
2014-09-08 21:18 ` [PATCH 04/13] perf kvm stat report: Enable the target.system_wide flag Arnaldo Carvalho de Melo
2014-09-08 21:18 ` [PATCH 05/13] perf kvm stat report: Unify the title bar output Arnaldo Carvalho de Melo
2014-09-08 21:18 ` [PATCH 06/13] perf tools: Allow to specify lib compile variable for spec usage Arnaldo Carvalho de Melo
2014-09-08 21:18 ` [PATCH 07/13] perf tools: Add feature checks to .gitignore Arnaldo Carvalho de Melo
2014-09-08 21:18 ` [PATCH 08/13] perf tools: Let a user specify a PMU event without any config terms Arnaldo Carvalho de Melo
2014-09-08 21:18 ` [PATCH 09/13] perf tools: Add perf-with-kcore script Arnaldo Carvalho de Melo
2014-09-08 21:18 ` [PATCH 10/13] perf tools: Build programs to copy 32-bit compatibility VDSOs Arnaldo Carvalho de Melo
2014-09-08 21:18 ` [PATCH 11/13] perf tools: Add support for " Arnaldo Carvalho de Melo
2014-09-08 21:18 ` [PATCH 12/13] perf tools: Let default config be defined for a PMU Arnaldo Carvalho de Melo
2014-09-08 21:18 ` Arnaldo Carvalho de Melo [this message]
2014-09-09  4:59 ` [GIT PULL 00/13] perf/core improvements and fixes Ingo Molnar
2014-09-09  7:14   ` Adrian Hunter
2014-09-09  7:45     ` Stephane Eranian
2014-09-09  7:55       ` Adrian Hunter
2014-09-09 14:53     ` Ingo Molnar
2014-09-09  8:48 ` Adrian Hunter
2014-09-09 13:12   ` Arnaldo Carvalho de Melo
2014-09-09 14:54     ` Ingo Molnar
2014-09-09 15:59       ` Arnaldo Carvalho de Melo
2014-09-09 19:08   ` Arnaldo Carvalho de Melo
2014-09-10 13:19     ` Adrian Hunter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1410211089-28668-14-git-send-email-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=adrian.hunter@intel.com \
    --cc=dsahern@gmail.com \
    --cc=eranian@google.com \
    --cc=fweisbec@gmail.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@gmail.com \
    --cc=paulus@samba.org \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.