Skip to contentSkip to conversation

perf: Add support for arch- and processor-dependent symbolic event names

PATCH New Corey Ashford 1 participant 1 message Mar 8, 2010 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf: Add support for arch- and processor-dependent symbolic event names

This patch adds support for arch- and processor-dependent symbolic event names to the "perf stat" tool, and could be expanded to other "perf *" commands fairly easily, I suspect.

To support arch-dependent event names without adding arch-dependent code to perf, I added a callout mechanism whereby perf will look for the environment variable: PERF_ARCH_DEP_LIB, and if it exists, it will try to open the string value of that variable as a shared object. If that succeeds, it looks for the symbol "parse_arch_dep_event". If that exists, that function will be called by parse_events() before all of the other event parsing functions in parse-events.c. It is passed the same arguments as the other parse_*_event functions, namely the event string and a pointer to an event attribute structure.

As the code existed, "perf stat" would print out the count results, but for raw
events (which is how arch-dependent events are supported in perf_events), it would just print out a raw code. This is not acceptable, especially when a symbolic name was placed on the command line. So I changed the code to save away the event name that was passed on the command line, rather than doing a reverse translation to an event string based on the event type and config fields of the attr structure. In this way, there's no need for a reverse translation function in the arch-dependent library; only a event string->attr struct function is needed.

This patch was stimulated by the availability of Stephane Eranian's libpfm4 which supports translating arch- and processor-specific symbolic event names and attributes to a perf_event_attr struct. With a very thin layer on top of libpfm4, perf can make use of it with this patch.

---

 tools/perf/Makefile            |    2 +-
 tools/perf/util/parse-events.c |   71 +++++++++++++++++++++++++++++++++++++--
 2 files changed, 68 insertions(+), 5 deletions(-)
tools/perf/Makefile +1 -1
index 2d53738..0ffafa0 100644
@@ -199,7 +199,7 @@ ifndef PERF_DEBUG
 endif
 
 CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror $(CFLAGS_OPTIMIZE) -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS)
-EXTLIBS = -lpthread -lrt -lelf -lm
+EXTLIBS = -lpthread -lrt -lelf -lm -ldl
 ALL_CFLAGS = $(CFLAGS)
 ALL_LDFLAGS = $(LDFLAGS)
 STRIP ?= strip
tools/perf/util/parse-events.c +67 -4

131 lines not on this page · raw message