linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lin Ming <ming.m.lin@intel.com>
To: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@elte.hu>,
	Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>,
	Paul Mundt <lethal@linux-sh.org>,
	"eranian@gmail.com" <eranian@gmail.com>,
	"Gary.Mohr@Bull.com" <Gary.Mohr@bull.com>,
	"arjan@linux.intel.com" <arjan@linux.intel.com>,
	"Zhang, Yanmin" <yanmin_zhang@linux.intel.com>,
	Paul Mackerras <paulus@samba.org>,
	"David S. Miller" <davem@davemloft.net>,
	Russell King <rmk+kernel@arm.linux.org.uk>,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	Will Deacon <will.deacon@arm.com>,
	Maynard Johnson <mpjohn@us.ibm.com>, Carl Love <carll@us.ibm.com>,
	"greg@kroah.com" <greg@kroah.com>,
	Kay Sievers <kay.sievers@vrfy.org>,
	lkml <linux-kernel@vger.kernel.org>
Subject: [RFC][PATCH v2 11/11] perf top: demo of how to use the sysfs interface
Date: Wed, 19 May 2010 01:49:52 +0000	[thread overview]
Message-ID: <1274233792.3036.90.camel@localhost> (raw)

Just a temporary patch to show how to use the pmu sysfs interface...

Signed-off-by: Lin Ming <ming.m.lin@intel.com>
---
 tools/perf/builtin-top.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index adc179d..eaa9405 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -1206,6 +1206,7 @@ static void start_counter(int i, int counter)
 	struct perf_event_attr *attr;
 	int cpu;
 	int thread_index;
+	int sys_fd;
 
 	cpu = profile_cpu;
 	if (target_tid == -1 && profile_cpu == -1)
@@ -1226,9 +1227,21 @@ static void start_counter(int i, int counter)
 
 	for (thread_index = 0; thread_index < thread_num; thread_index++) {
 try_again:
+		/*
+		 * This is just an ugly demo of how to use the sysfs interface.
+		 * You can also parse the <event-name> and open sys file as,
+		 * sys_fd = open("/sys/devices/system/cpu/events/<event-name>/event_source/id", O_RDONLY);
+		 */
+		sys_fd = open("/sys/devices/system/cpu/event_source/id", O_RDONLY);
+		if (sys_fd != -1)
+			attr->type |= (sys_fd << PERF_EVENT_ATTR_TYPE_BITS) | PERF_EVENT_FD;
+
 		fd[i][counter][thread_index] = sys_perf_event_open(attr,
 				all_tids[thread_index], cpu, group_fd, 0);
 
+		if (sys_fd != -1)
+			close(sys_fd);
+
 		if (fd[i][counter][thread_index] < 0) {
 			int err = errno;
 





             reply	other threads:[~2010-05-18 17:49 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-19  1:49 Lin Ming [this message]
2010-05-19 18:18 ` [RFC][PATCH v2 11/11] perf top: demo of how to use the sysfs interface Corey Ashford
2010-05-20  1:17   ` Lin Ming
2010-05-20  1:33     ` Corey Ashford
2010-05-20  2:08       ` Lin Ming
2010-05-20  8:27         ` Corey Ashford
2010-05-20  9:21           ` Lin Ming
2010-05-20 18:06             ` Corey Ashford
2010-05-20 20:08       ` Peter Zijlstra
2010-05-21  0:21         ` Corey Ashford

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=1274233792.3036.90.camel@localhost \
    --to=ming.m.lin@intel.com \
    --cc=Gary.Mohr@bull.com \
    --cc=acme@redhat.com \
    --cc=arjan@linux.intel.com \
    --cc=carll@us.ibm.com \
    --cc=cjashfor@linux.vnet.ibm.com \
    --cc=davem@davemloft.net \
    --cc=eranian@gmail.com \
    --cc=fweisbec@gmail.com \
    --cc=greg@kroah.com \
    --cc=kay.sievers@vrfy.org \
    --cc=lethal@linux-sh.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=mpjohn@us.ibm.com \
    --cc=paulus@samba.org \
    --cc=peterz@infradead.org \
    --cc=rmk+kernel@arm.linux.org.uk \
    --cc=will.deacon@arm.com \
    --cc=yanmin_zhang@linux.intel.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).