Skip to contentSkip to conversation

perf evsel: Carve out event modifier formatting

tip:perf/core tip-bot for Arnaldo Carvalho de Melo 1 participant 1 message Jun 20, 2012 perf events

lore
Share & tools
lore
#0 lore raw
Commit-ID:  27f18617b01dbbc928e9bd3731d1766222fb7e0d
Gitweb:     http://git.kernel.org/tip/27f18617b01dbbc928e9bd3731d1766222fb7e0d
Author:     Arnaldo Carvalho de Melo <[email protected]>
AuthorDate: Mon, 11 Jun 2012 13:33:09 -0300
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Tue, 19 Jun 2012 13:06:20 -0300

perf evsel: Carve out event modifier formatting

Quoted 1 line

From perf_evsel__hw_name, so that we can use it for the other kinds of

events (tracepoints, software, hw cache, etc).

Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 tools/perf/util/evsel.c |   17 +++++++++++------
 1 files changed, 11 insertions(+), 6 deletions(-)
tools/perf/util/evsel.c +11 -6
index 9f6cebd..dab8938 100644
@@ -86,16 +86,15 @@ const char *__perf_evsel__hw_name(u64 config)
 	return "unknown-hardware";
 }
 
-static int perf_evsel__hw_name(struct perf_evsel *evsel, char *bf, size_t size)
+static int perf_evsel__add_modifiers(struct perf_evsel *evsel, char *bf, size_t size)
 {
-	int colon = 0;
+	int colon = 0, r = 0;
 	struct perf_event_attr *attr = &evsel->attr;
-	int r = scnprintf(bf, size, "%s", __perf_evsel__hw_name(attr->config));
 	bool exclude_guest_default = false;
 
 #define MOD_PRINT(context, mod)	do {					\
 		if (!attr->exclude_##context) {				\
-			if (!colon) colon = r++;			\
+			if (!colon) colon = ++r;			\
 			r += scnprintf(bf + r, size - r, "%c", mod);	\
 		} } while(0)
 
@@ -108,7 +107,7 @@ static int perf_evsel__hw_name(struct perf_evsel *evsel, char *bf, size_t size)
 
 	if (attr->precise_ip) {
 		if (!colon)
-			colon = r++;
+			colon = ++r;
 		r += scnprintf(bf + r, size - r, "%.*s", attr->precise_ip, "ppp");
 		exclude_guest_default = true;
 	}
@@ -119,10 +118,16 @@ static int perf_evsel__hw_name(struct perf_evsel *evsel, char *bf, size_t size)
 	}
 #undef MOD_PRINT
 	if (colon)
-		bf[colon] = ':';
+		bf[colon - 1] = ':';
 	return r;
 }
 
+static int perf_evsel__hw_name(struct perf_evsel *evsel, char *bf, size_t size)
+{
+	int r = scnprintf(bf, size, "%s", __perf_evsel__hw_name(evsel->attr.config));
+	return r + perf_evsel__add_modifiers(evsel, bf + r, size - r);
+}
+
 int perf_evsel__name(struct perf_evsel *evsel, char *bf, size_t size)
 {
 	int ret;