perf: Add support for PMU events in JSON format
cover perf: Add support for PMU events in JSON format
CPUs support a large number of performance monitoring events (PMU events) and often these events are very specific to an architecture/model of the CPU. To use most of these PMU events with perf we currently have to identify the events by their raw codes:
perf stat -e r100f2 sleep 1
This patchset allows architectures to specify these PMU events in a JSON files which are defined in the tools/perf/pmu-events/arch/ directory of the mainline tree
Eg: snippet from 004d0100.json (in patch 4)
[
{
"EventCode": "0x100f2",
"EventName": "PM_1PLUS_PPC_CMPL",
"BriefDescription": "1 or more ppc insts finished,",
"PublicDescription": "1 or more ppc insts finished (completed).,"
},
]When building the perf tool, this patchset, first builds/uses a 'jevents' which locates all the JSON files for the architecture (currently Powerpc). The jevents binary then translates the JSON files into into a C-style "PMU events table":
struct pmu_event pme_power8[] = {
...
{
.name = "pm_1plus_ppc_cmpl",
.event = "event=0x100f2",
.desc = "1 or more ppc insts finished,",
},
...
}where the "power8" in the table name is derived from the name of the JSON file.
The jevents binary also looks for a "mapfile" to map a processor model/ version to a specific events table:
$ cat mapfile.csv 004b0000,1,power8.json,core 004c0000,1,power8.json,core 004d0000,1,power8.json,core
and uses this to build a mapping table:
struct pmu_events_map pmu_events_map[] = {
{
.cpuid = "004b0000",
.version = "1",
.type = "core",
.table = pme_power8
},This mapping and events tables for the architecture are then included in the perf binary during build.
At run time, perf identifies the specific events table, based on the model of the CPU perf is running on. Perf uses that table to create event aliases which would allow the user to specify the event as:
perf stat -e pm_1plus_ppc_cmpl sleep 1
Note:
- All known events tables for the architecture are included in the perf binary.
- Inconsistencies between the JSON files and the mapfile can result in build failures in perf (although jevents try to recover from some and continue the build by leaving out event aliases).
- For architectures that don't have any JSON files, an empty mapping table is created and they should continue to build)
Thanks to input from Andi Kleen, Jiri Olsa, Namhyung Kim and Ingo Molnar.
These patches are available from
[email protected]:sukadev/linux.git #branch json-v11
Andi Kleen (8):
perf, tools: Add jsmn `jasmine' JSON parser
jevents: Program to convert JSON file to C style file perf, tools: Handle header line in mapfile perf, tools: Allow events with dot
perf, tools: Support CPU id matching for x86 v2 perf, tools: Support alias descriptions
perf, tools: Query terminal width and use in perf list perf, tools: Add a --no-desc flag to perf list
Sukadev Bhattiprolu (2):
Use pmu_events_map table to create event aliases
perf: Add power8 PMU events in JSON format
tools/perf/Documentation/perf-list.txt | 8 +- tools/perf/Makefile.perf | 25 +- tools/perf/arch/powerpc/util/header.c | 11 + tools/perf/arch/x86/util/header.c | 24 +- tools/perf/builtin-list.c | 12 +- tools/perf/pmu-events/Build | 10 + tools/perf/pmu-events/README | 67 + tools/perf/pmu-events/arch/powerpc/mapfile.csv | 17 + tools/perf/pmu-events/arch/powerpc/power8.json | 6380 ++++++++++++++++++++++++ tools/perf/pmu-events/jevents.c | 686 +++ tools/perf/pmu-events/jevents.h | 17 + tools/perf/pmu-events/jsmn.c | 313 ++ tools/perf/pmu-events/jsmn.h | 67 + tools/perf/pmu-events/json.c | 162 + tools/perf/pmu-events/json.h | 36 + tools/perf/pmu-events/pmu-events.h | 35 + tools/perf/util/cache.h | 1 + tools/perf/util/header.h | 3 +- tools/perf/util/pager.c | 15 + tools/perf/util/parse-events.c | 4 +- tools/perf/util/parse-events.h | 2 +- tools/perf/util/parse-events.l | 5 +- tools/perf/util/pmu.c | 185 +- tools/perf/util/pmu.h | 3 +- 24 files changed, 8036 insertions(+), 52 deletions(-) create mode 100644 tools/perf/pmu-events/Build create mode 100644 tools/perf/pmu-events/README create mode 100644 tools/perf/pmu-events/arch/powerpc/mapfile.csv create mode 100644 tools/perf/pmu-events/arch/powerpc/power8.json create mode 100644 tools/perf/pmu-events/jevents.c create mode 100644 tools/perf/pmu-events/jevents.h create mode 100644 tools/perf/pmu-events/jsmn.c create mode 100644 tools/perf/pmu-events/jsmn.h create mode 100644 tools/perf/pmu-events/json.c create mode 100644 tools/perf/pmu-events/json.h create mode 100644 tools/perf/pmu-events/pmu-events.h
Signature · 1 line
1.7.9.5
PATCH 1/10 perf, tools: Add jsmn `jasmine' JSON parser
From: Andi Kleen <[email protected]>
I need a JSON parser. This adds the simplest JSON parser I could find -- Serge Zaitsev's jsmn `jasmine' -- to the perf library. I merely converted it to (mostly) Linux style and added support for non 0 terminated input.
The parser is quite straight forward and does not copy any data, just returns tokens with offsets into the input buffer. So it's relatively efficient and simple to use.
The code is not fully checkpatch clean, but I didn't want to completely fork the upstream code.
Original source: http://zserge.bitbucket.org/jsmn.html
In addition I added a simple wrapper that mmaps a json file and provides some straight forward access functions.
Used in follow-on patches to parse event files.
---
v2: Address review feedback.
v3: Minor checkpatch fixes.
v4 (by Sukadev Bhattiprolu)
- Rebase to 4.0 and fix minor conflicts in tools/perf/Makefile.perf
- Report error if specified events file is invalid.
v5 (Sukadev Bhattiprolu)
- Move files to tools/perf/pmu-events/ since parsing of JSON file now occurs when _building_ rather than running perf.
--- tools/perf/pmu-events/jsmn.c | 313 ++++++++++++++++++++++++++++++++++++++++++ tools/perf/pmu-events/jsmn.h | 67 +++++++++ tools/perf/pmu-events/json.c | 162 ++++++++++++++++++++++ tools/perf/pmu-events/json.h | 36 +++++ 4 files changed, 578 insertions(+) create mode 100644 tools/perf/pmu-events/jsmn.c create mode 100644 tools/perf/pmu-events/jsmn.h create mode 100644 tools/perf/pmu-events/json.c create mode 100644 tools/perf/pmu-events/json.h
tools/perf/pmu-events/jsmn.c new file +313 -0
@@ -0,0 +1,313 @@ +/* +* Copyright (c) 2010 Serge A. Zaitsev +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +* +* Slightly modified by AK to not assume 0 terminated input. +*/ + +#include <stdlib.h> +#include "jsmn.h" + +/* +* Allocates a fresh unused token from the token pool. +*/ +static jsmntok_t *jsmn_alloc_token (jsmn_parser *parser, +jsmntok_t *tokens,size_t num_tokens) +{ +jsmntok_t *tok; + +if ((unsigned )parser->toknext >= num_tokens) +return NULL ; + tok = &tokens[parser->toknext++]; + tok->start = tok->end =-1 ; + tok->size =0 ; +return tok; +} + +/* +* Fills token type and boundaries. +*/ +static void jsmn_fill_token (jsmntok_t *token,jsmntype_t type, +int start,int end) +{ + token->type = type; + token->start = start; + token->end = end; + token->size =0 ; +} + +/* +* Fills next available token with JSON primitive. +*/ +static jsmnerr_t jsmn_parse_primitive (jsmn_parser *parser,const char *js, +size_t len, +jsmntok_t *tokens,size_t num_tokens) +{ +jsmntok_t *token; +int start; + + start = parser->pos; + +for (; parser->pos < len; parser->pos++) { +switch (js[parser->pos]) { +#ifndef JSMN_STRICT +/* +* In strict mode primitive must be followed by "," +* or "}" or "]" +*/ +case ':' : +#endif +case '\t' : +case '\r' : +case '\n' : +case ' ' : +case ',' : +case ']' : +case '}' : + goto found; +default : +break ; + } +if (js[parser->pos] <32 || js[parser->pos] >=127 ) { + parser->pos = start; +return JSMN_ERROR_INVAL ; + } + } +#ifdef JSMN_STRICT +/* +* In strict mode primitive must be followed by a +* comma/object/array. +*/ + parser->pos = start; +return JSMN_ERROR_PART ; +#endif + +found: + token =jsmn_alloc_token (parser, tokens, num_tokens); +if (token ==NULL ) { + parser->pos = start; +return JSMN_ERROR_NOMEM ; + } +jsmn_fill_token (token,JSMN_PRIMITIVE , start, parser->pos); + parser->pos--;/* parent sees closing brackets */ +return JSMN_SUCCESS ; +} + +/* +* Fills next token with JSON string. +*/ +static jsmnerr_t jsmn_parse_string (jsmn_parser *parser,const char *js, +size_t len, +jsmntok_t *tokens,size_t num_tokens) +{ +jsmntok_t *token; +int start = parser->pos; + +/* Skip starting quote */ + parser->pos++; + +for (; parser->pos < len; parser->pos++) { +char c = js[parser->pos]; + +/* Quote: end of string */ +if (c =='\"' ) { + token =jsmn_alloc_token (parser, tokens, num_tokens); +if (token ==NULL ) { + parser->pos = start; +return JSMN_ERROR_NOMEM ; + } +jsmn_fill_token (token,JSMN_STRING , start+1 , + parser->pos); +return JSMN_SUCCESS ; + } + +/* Backslash: Quoted symbol expected */ +if (c =='\\' ) { + parser->pos++; +switch (js[parser->pos]) { +/* Allowed escaped symbols */ +case '\"' : +case '/' : +case '\\' : +case 'b' : +case 'f' : +case 'r' : +case 'n' : +case 't' : +break ; +/* Allows escaped symbol \uXXXX */ +case 'u' : +/* TODO */ +break ; +/* Unexpected symbol */ +default : + parser->pos = start; +return JSMN_ERROR_INVAL ; + } + } + } + parser->pos = start; +return JSMN_ERROR_PART ; +} + +/* +* Parse JSON string and fill tokens. +*/ +jsmnerr_t jsmn_parse (jsmn_parser *parser,const char *js,size_t len, +jsmntok_t *tokens,unsigned int num_tokens) +{ +jsmnerr_t r; +int i; +jsmntok_t *token; + +for (; parser->pos < len; parser->pos++) { +char c; +jsmntype_t type; + + c = js[parser->pos]; +switch (c) { +case '{' : +case '[' : + token =jsmn_alloc_token (parser, tokens, num_tokens); +if (token ==NULL ) +return JSMN_ERROR_NOMEM ; +if (parser->toksuper !=-1 ) + tokens[parser->toksuper].size++; + token->type = (c =='{' ?JSMN_OBJECT :JSMN_ARRAY ); + token->start = parser->pos; + parser->toksuper = parser->toknext -1 ; +break ; +case '}' : +case ']' : + type = (c =='}' ?JSMN_OBJECT :JSMN_ARRAY ); +for (i = parser->toknext -1 ; i >=0 ; i--) { + token = &tokens[i]; +if (token->start !=-1 && token->end ==-1 ) { +if (token->type != type) +return JSMN_ERROR_INVAL ; + parser->toksuper =-1 ; + token->end = parser->pos +1 ; +break ; + } + } +/* Error if unmatched closing bracket */ +if (i ==-1 ) +return JSMN_ERROR_INVAL ; +for (; i >=0 ; i--) { + token = &tokens[i]; +if (token->start !=-1 && token->end ==-1 ) { + parser->toksuper = i; +break ; + } + } +break ; +case '\"' : + r =jsmn_parse_string (parser, js, len, tokens, + num_tokens); +if (r <0 ) +return r; +if (parser->toksuper !=-1 ) + tokens[parser->toksuper].size++; +break ; +case '\t' : +case '\r' : +case '\n' : +case ':' : +case ',' : +case ' ' : +break ; +#ifdef JSMN_STRICT +/* +* In strict mode primitives are: +* numbers and booleans. +*/ +case '-' : +case '0' : +case '1' : +case '2' : +case '3' : +case '4' : +case '5' : +case '6' : +case '7' : +case '8' : +case '9' : +case 't' : +case 'f' : +case 'n' : +#else +/* +* In non-strict mode every unquoted value +* is a primitive. +*/ +/*FALL THROUGH */ +default : +#endif + r =jsmn_parse_primitive (parser, js, len, tokens, + num_tokens); +if (r <0 ) +return r; +if (parser->toksuper !=-1 ) + tokens[parser->toksuper].size++; +break ; + +#ifdef JSMN_STRICT +/* Unexpected char in strict mode */ +default : +return JSMN_ERROR_INVAL ; +#endif + } + } + +for (i = parser->toknext -1 ; i >=0 ; i--) { +/* Unmatched opened object or array */ +if (tokens[i].start !=-1 && tokens[i].end ==-1 ) +return JSMN_ERROR_PART ; + } + +return JSMN_SUCCESS ; +} + +/* +* Creates a new parser based over a given buffer with an array of tokens +* available. +*/ +void jsmn_init (jsmn_parser *parser) +{ + parser->pos =0 ; + parser->toknext =0 ; + parser->toksuper =-1 ; +} + +const char *jsmn_strerror (jsmnerr_t err) +{ +switch (err) { +case JSMN_ERROR_NOMEM : +return "No enough tokens" ; +case JSMN_ERROR_INVAL : +return "Invalid character inside JSON string" ; +case JSMN_ERROR_PART : +return "The string is not a full JSON packet, more bytes expected" ; +case JSMN_SUCCESS : +return "Success" ; +default : +return "Unknown json error" ; + } +}
tools/perf/pmu-events/jsmn.h new file +67 -0
67 lines not on this page · raw message
tools/perf/pmu-events/json.c new file +162 -0
162 lines not on this page · raw message
tools/perf/pmu-events/json.h new file +36 -0
@@ -0,0 +1,36 @@ +#ifndef JSON_H +#define JSON_H 1 + +#include "jsmn.h" + +jsmntok_t *parse_json (const char *fn,char **map,size_t *size,int *len); +void free_json (char *map,size_t size,jsmntok_t *tokens); +int json_line (char *map,jsmntok_t *t); +const char *json_name (jsmntok_t *t); +int json_streq (char *map,jsmntok_t *t,const char *s); +int json_len (jsmntok_t *t); + +extern int verbose; + +typedef unsigned int bool ; + +#ifndef true +#define true 1 +#endif + +extern int eprintf (int level,int var,const char *fmt, ...); +#define pr_fmt (fmt) fmt + +#define pr_err (fmt, ...) \ + eprintf(0, verbose, pr_fmt(fmt), ##__VA_ARGS__) + +#ifndef roundup +#define roundup (x, y) ( \ +{ \ + const typeof(y) __y = y; \ + (((x) + (__y - 1)) / __y) * __y; \ +} \ +) +#endif + +#endif
Signature · 1 line
1.7.9.5
PATCH 2/10 jevents: Program to convert JSON file to C style file
In reply to Sukadev BhattiproluFrom: Andi Kleen <[email protected]>
This is a modified version of an earlier patch by Andi Kleen.
We expect architectures to describe the performance monitoring events for each CPU in a corresponding JSON file, which look like:
[
{
"EventCode": "0x00",
"UMask": "0x01",
"EventName": "INST_RETIRED.ANY",
"BriefDescription": "Instructions retired from execution.",
"PublicDescription": "Instructions retired from execution.",
"Counter": "Fixed counter 1",
"CounterHTOff": "Fixed counter 1",
"SampleAfterValue": "2000003",
"SampleAfterValue": "2000003",
"MSRIndex": "0",
"MSRValue": "0",
"TakenAlone": "0",
"CounterMask": "0",
"Invert": "0",
"AnyThread": "0",
"EdgeDetect": "0",
"PEBS": "0",
"PRECISE_STORE": "0",
"Errata": "null",
"Offcore": "0"
}
]We also expect the architectures to provide a mapping between individual CPUs to their JSON files. Eg:
GenuineIntel-6-1E,V1,/NHM-EP/NehalemEP_core_V1.json,core
which maps each CPU, identified by [vendor, family, model, version, type] to a JSON file.
Given these files, the program, jevents::
- locates all JSON files for the architecture,
- parses each JSON file and generates a C-style "PMU-events table" (pmu-events.c)
- locates a mapfile for the architecture
- builds a global table, mapping each model of CPU to the corresponding PMU-events table.
The 'pmu-events.c' is generated when building perf and added to libperf.a. The global table pmu_events_map[] table in this pmu-events.c will be used in perf in a follow-on patch.
If the architecture does not have any JSON files or there is an error in processing them, an empty mapping file is created. This would allow the build of perf to proceed even if we are not able to provide aliases for events.
The parser for JSON files allows parsing Intel style JSON event files. This allows to use an Intel event list directly with perf. The Intel event lists can be quite large and are too big to store in unswappable kernel memory.
The conversion from JSON to C-style is straight forward. The parser knows (very little) Intel specific information, and can be easily extended to handle fields for other CPUs.
The parser code is partially shared with an independent parsing library, which is 2-clause BSD licenced. To avoid any conflicts I marked those files as BSD licenced too. As part of perf they become GPLv2.
v2: Address review feedback. Rename option to --event-files
v3: Add JSON example
v4: Update manpages.
v5: Don't remove dot in fixname. Fix compile error. Add include
protection. Comment realloc.
v6: Include debug/util.h
v7: (Sukadev Bhattiprolu)
Rebase to 4.0 and fix some conflicts.
v8: (Sukadev Bhattiprolu)
Move jevents.[hc] to tools/perf/pmu-events/
Rewrite to locate and process arch specific JSON and "map" files; and generate a C file.
(Removed acked-by Namhyung Kim due to modest changes to patch) Compile the generated pmu-events.c and add the pmu-events.o to libperf.a
v9: [Sukadev Bhattiprolu/Andi Kleen] Rename ->vfm to ->cpuid and use
that field to encode the PVR in Power.
Allow blank lines in mapfile.
[Jiri Olsa] Pass ARCH as a parameter to jevents so we don't have to detect it.
[Jiri Olsa] Use the infrastrastructure to build pmu-events/perf (Makefile changes from Jiri included in this patch). [Jiri Olsa, Andi Kleen] Detect changes to JSON files and rebuild pmu-events.o only if necessary.
--- tools/perf/Makefile.perf | 25 +- tools/perf/pmu-events/Build | 10 + tools/perf/pmu-events/README | 67 ++++ tools/perf/pmu-events/jevents.c | 684 ++++++++++++++++++++++++++++++++++++ tools/perf/pmu-events/jevents.h | 17 + tools/perf/pmu-events/pmu-events.h | 35 ++ 6 files changed, 834 insertions(+), 4 deletions(-) create mode 100644 tools/perf/pmu-events/Build create mode 100644 tools/perf/pmu-events/README create mode 100644 tools/perf/pmu-events/jevents.c create mode 100644 tools/perf/pmu-events/jevents.h create mode 100644 tools/perf/pmu-events/pmu-events.h
tools/perf/Makefile.perf +21 -4
@@ -270,14 +270,29 @@ strip: $(PROGRAMS) $(OUTPUT)perf PERF_IN := $(OUTPUT)perf-in.o +JEVENTS := $(OUTPUT)pmu-events/jevents +JEVENTS_IN := $(OUTPUT)pmu-events/jevents-in.o +PMU_EVENTS_IN := $(OUTPUT)pmu-events/pmu-events-in.o + +export JEVENTS + export srctree OUTPUT RM CC LD AR CFLAGS V BISON FLEX build := -f $(srctree)/tools/build/Makefile.build dir=. obj $(PERF_IN): $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)common-cmds.h FORCE $(Q)$(MAKE) $(build)=perf -$(OUTPUT)perf: $(PERFLIBS) $(PERF_IN) - $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $(PERF_IN) $(LIBS) -o $@ +$(JEVENTS_IN): FORCE + $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=pmu-events obj=jevents + +$(JEVENTS): $(JEVENTS_IN) + $(QUIET_LINK)$(CC) $(JEVENTS_IN) -o $@ + +$(OUTPUT)perf: $(PERFLIBS) $(PERF_IN) $(PMU_EVENTS_IN) + $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $(PERF_IN) $(PMU_EVENTS_IN) $(LIBS) -o $@ + +$(PMU_EVENTS_IN): $(JEVENTS) FORCE + $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=pmu-events obj=pmu-events $(GTK_IN): FORCE $(Q)$(MAKE) $(build)=gtk
@@ -306,6 +321,8 @@ perf.spec $(SCRIPTS) \ ifneq ($(OUTPUT),) %.o: $(OUTPUT)%.o @echo " # Redirected target $@ => $(OUTPUT)$@" +pmu-events/%.o: $(OUTPUT)pmu-events/%.o + @echo " # Redirected target $@ => $(OUTPUT)$@" util/%.o: $(OUTPUT)util/%.o @echo " # Redirected target $@ => $(OUTPUT)$@" bench/%.o: $(OUTPUT)bench/%.o
@@ -529,8 +546,8 @@ clean: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean config-clean $(call QUIET_CLEAN, core-objs) $(RM) $(LIB_FILE) $(OUTPUT)perf-archive $(OUTPUT)perf-with-kcore $(LANG_BINDINGS) $(Q)find . -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete $(Q)$(RM) .config-detected - $(call QUIET_CLEAN, core-progs) $(RM) $(ALL_PROGRAMS) perf perf-read-vdso32 perf-read-vdsox32 - $(call QUIET_CLEAN, core-gen) $(RM) *.spec *.pyc *.pyo */*.pyc */*.pyo $(OUTPUT)common-cmds.h TAGS tags cscope* $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)FEATURE-DUMP $(OUTPUT)util/*-bison* $(OUTPUT)util/*-flex* + $(call QUIET_CLEAN, core-progs) $(RM) $(ALL_PROGRAMS) perf perf-read-vdso32 perf-read-vdsox32 $(OUTPUT)pmu-events/jevents $(srctree)/tools/perf/pmu-events/pmu-events.c + $(call QUIET_CLEAN, core-gen) $(RM) *.spec *.pyc *.pyo */*.pyc */*.pyo $(OUTPUT)common-cmds.h TAGS tags cscope* $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)FEATURE-DUMP $(OUTPUT)util/*-bison* $(OUTPUT)util/*-flex* $(OUTPUT)pmu-events/pmu-events.c $(QUIET_SUBDIR0)Documentation $(QUIET_SUBDIR1) clean $(python-clean)
tools/perf/pmu-events/Build new file +10 -0
@@ -0,0 +1,10 @@ +jevents-y += json.o jsmn.o jevents.o +pmu-events-y += pmu-events.o +JSON = $(shell find pmu-events/arch/$(ARCH) -name '*.json') + +# +# Locate/process JSON files in pmu-events/arch/ +# directory and create tables in pmu-events.c. +# +$(OUTPUT)pmu-events/pmu-events.c: $(JSON) + $(Q)$(call echo-cmd,gen)$(JEVENTS) $(ARCH) pmu-events/arch $(OUTPUT)pmu-events/pmu-events.c
tools/perf/pmu-events/README new file +67 -0
67 lines not on this page · raw message
tools/perf/pmu-events/jevents.c new file +684 -0
684 lines not on this page · raw message
tools/perf/pmu-events/jevents.h new file +17 -0
@@ -0,0 +1,17 @@ +#ifndef JEVENTS_H +#define JEVENTS_H 1 + +int json_events (const char *fn, +int (*func)(void *data,char *name,char *event,char *desc), +void *data); +char *get_cpu_str (void ); + +#ifndef min +#define min (x, y) ({ \ + typeof(x) _min1 = (x); \ + typeof(y) _min2 = (y); \ + (void) (&_min1 == &_min2); \ + _min1 < _min2 ? _min1 : _min2; }) +#endif + +#endif
tools/perf/pmu-events/pmu-events.h new file +35 -0
@@ -0,0 +1,35 @@ +#ifndef PMU_EVENTS_H +#define PMU_EVENTS_H + +/* +* Describe each PMU event. Each CPU has a table of PMU events. +*/ +struct pmu_event { +const char *name; +const char *event; +const char *desc; +}; + +/* +* +* Map a CPU to its table of PMU events. The CPU is identified by the +* cpuid field, which is an arch-specific identifier for the CPU. +* The identifier specified in tools/perf/pmu-events/arch/xxx/mapfile +* must match the get_cpustr() in tools/perf/arch/xxx/util/header.c) +* +* The cpuid can contain any character other than the comma. +*/ +struct pmu_events_map { +const char *cpuid; +const char *version; +const char *type;/* core, uncore etc */ +struct pmu_event *table; +}; + +/* +* Global table mapping each known CPU for the architecture to its +* table of PMU events. +*/ +extern struct pmu_events_map pmu_events_map[]; + +#endif
Signature · 1 line
1.7.9.5
Re: [PATCH 02/10] jevents: Program to convert JSON file to C style file
On Wed, May 27, 2015 at 02:23:21PM -0700, Sukadev Bhattiprolu wrote:
SNIP
tools/perf/pmu-events/Build line 3
Quoted 10 lines
tools/perf/pmu-events/Build new file +3
-0@@ -0,0 +1,10 @@ +jevents-y += json.o jsmn.o jevents.o +pmu-events-y += pmu-events.o +JSON = $(shell find pmu-events/arch/$(ARCH) -name '*.json')
you might want to check if there's the directory first, or if there's a way to tell find to be quiet or ignore that
find: ‘pmu-events/arch/x86’: No such file or directory
CC pmu-events/json.o CC pmu-events/jsmn.o CC pmu-events/jevents.o LD pmu-events/jevents-in.o LINK pmu-events/jevents
find: ‘pmu-events/arch/x86’: No such file or directory pmu-events/jevents: Error walking file tree pmu-events/arch/x86 Creating empty pmu_events_map[] table
CC pmu-events/pmu-events.o
jirka
Re: [PATCH 02/10] jevents: Program to convert JSON file to C style file
In reply to Sukadev BhattiproluOn Wed, May 27, 2015 at 02:23:21PM -0700, Sukadev Bhattiprolu wrote:
SNIP
Quoted 7 lines
$(PERF_IN): $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)common-cmds.h FORCE
tools/perf/Makefile.perf +1
-2$(Q)$(MAKE) $(build)=perf -$(OUTPUT)perf: $(PERFLIBS) $(PERF_IN) - $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $(PERF_IN) $(LIBS) -o $@ +$(JEVENTS_IN): FORCE
tools/perf/Makefile.perf strip: $(PROGRAMS) $(OUTPUT)perf · line 295
Quoted 10 lines
tools/perf/Makefile.perf +10
-0+ $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=pmu-events obj=jevents + +$(JEVENTS): $(JEVENTS_IN) + $(QUIET_LINK)$(CC) $(JEVENTS_IN) -o $@ + +$(OUTPUT)perf: $(PERFLIBS) $(PERF_IN) $(PMU_EVENTS_IN) + $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $(PERF_IN) $(PMU_EVENTS_IN) $(LIBS) -o $@ + +$(PMU_EVENTS_IN): $(JEVENTS) FORCE + $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=pmu-events obj=pmu-events
nit.. please move this above perf target, so it's grouped with the rest of the jevents stuff
jirka
Quoted 12 lines
$(GTK_IN): FORCE
tools/perf/Makefile.perf +2
-0$(Q)$(MAKE) $(build)=gtk@@ -306,6 +321,8 @@ perf.spec $(SCRIPTS) \ ifneq ($(OUTPUT),) %.o: $(OUTPUT)%.o @echo " # Redirected target $@ => $(OUTPUT)$@" +pmu-events/%.o: $(OUTPUT)pmu-events/%.o + @echo " # Redirected target $@ => $(OUTPUT)$@" util/%.o: $(OUTPUT)util/%.o @echo " # Redirected target $@ => $(OUTPUT)$@" bench/%.o: $(OUTPUT)bench/%.o
SNIP
PATCH 3/10 Use pmu_events_map table to create event aliases
In reply to Sukadev BhattiproluAt run time, (i.e when perf is starting up), locate the specific events table for the current CPU and create event aliases for each of the events.
Use these aliases to parse user's specified perf event.
Changelog[v2]
[Andi Kleen] Replace the pmu_events_map->vfm field with a simple
generic "cpuid" string and use that string to find the matching mapfile entry.
--- tools/perf/arch/powerpc/util/header.c | 11 ++++ tools/perf/util/header.h | 3 +- tools/perf/util/pmu.c | 103 ++++++++++++++++++++++++++++----- 3 files changed, 103 insertions(+), 14 deletions(-)
tools/perf/arch/powerpc/util/header.c +11 -0
@@ -32,3 +32,14 @@ get_cpuid(char *buffer, size_t sz) }return -1 ; } + +char * +get_cpuid_str (void ) +{ +char *bufp; + +if (asprintf (&bufp,"%.8lx" ,mfspr (SPRN_PVR )) <0 ) + bufp =NULL ; + +return bufp; +}
tools/perf/util/header.h +2 -1
@@ -8,7 +8,6 @@#include <linux/types.h> #include "event.h" -enum {HEADER_RESERVED =0 ,/* always cleared */ HEADER_FIRST_FEATURE =1 ,
@@ -156,4 +155,6 @@ int write_padded(int fd, const void *bf, size_t count, size_t count_aligned);*/ int get_cpuid (char *buffer,size_t sz); +char *get_cpuid_str (void ); +#endif /* __PERF_HEADER_H */
tools/perf/util/pmu.c +90 -13
152 lines not on this page · raw message
Signature · 1 line
1.7.9.5
Re: [PATCH 03/10] Use pmu_events_map table to create event aliases
Quoted 6 lines · Sukadev Bhattiprolu
At run time, (i.e when perf is starting up), locate the specific events table for the current CPU and create event aliases for each of the events.
Use these aliases to parse user's specified perf event.
Signed-off-by Sukadev Bhattiprolu <[email protected]>
please prefix the subject with 'perf tools'
SNIP
Quoted 12 lines
tools/perf/util/pmu.c +12
-0+/* +* From the pmu_events_map, find the table of PMU events that corresponds +* to the current running CPU. Then, add all PMU events from that table +* as aliases. +*/ +static int pmu_add_cpu_aliases (void *data) +{ +struct list_head *head = (struct list_head *)data; +int i; +struct pmu_events_map *map; +struct pmu_event *pe; +char *cpuid;
tools/perf/util/pmu.c perf_pmu__get_default_config(struct perf_pmu *pmu __maybe_unused) · line 487
Quoted 10 lines
tools/perf/util/pmu.c +10
-0+ + cpuid =get_cpuid_str (); +if (!cpuid) +return 0 ; + + i =0 ; +while (1 ) { + map = &pmu_events_map[i++]; +if (!map->table) +return 0 ;
leaking cpuid
Quoted 23 lines
tools/perf/util/pmu.c +23
-0+ +if (!strcmp (map->cpuid, cpuid)) +break ; + } + +/* +* Found a matching PMU events table. Create aliases +*/ + i =0 ; +while (1 ) { + pe = &map->table[i++]; +if (!pe->name) +break ; + +/* need type casts to override 'const' */ +__perf_pmu__new_alias (head, (char *)pe->name,NULL , + (char *)pe->desc, (char *)pe->event); + } + +free (cpuid); + +return 0 ; +}
SNIP
PATCH 4/10 perf, tools: Handle header line in mapfile
In reply to Sukadev BhattiproluFrom: Andi Kleen <[email protected]>
Support a header line in the mapfile.csv, to match the existing mapfiles
--- tools/perf/pmu-events/jevents.c | 2 ++ 1 file changed, 2 insertions(+)
tools/perf/pmu-events/jevents.c +2 -0
@@ -452,6 +452,8 @@ static int process_mapfile(FILE *outfp, char *fpath)if (line[0 ] =='#' || line[0 ] =='\n' )continue ; +if (!strncmp (line,"Family" ,6 )) +continue ;if (line[strlen (line)-1 ] !='\n' ) {/* TODO Deal with lines longer than 16K */
Signature · 1 line
1.7.9.5
Re: [PATCH 04/10] perf, tools: Handle header line in mapfile
Quoted 15 lines · Sukadev Bhattiprolu
From: Andi Kleen <[email protected]>
Support a header line in the mapfile.csv, to match the existing mapfiles
Signed-off-by Andi Kleen <[email protected]>--- tools/perf/pmu-events/jevents.c | 2 ++ 1 file changed, 2 insertions(+)tools/perf/pmu-events/jevents.c +0
-0
tools/perf/pmu-events/jevents.c static int process_mapfile(FILE *outfp, char *fpath) · line 456
Quoted 5 lines
tools/perf/pmu-events/jevents.c +2
-0@@ -452,6 +452,8 @@ static int process_mapfile(FILE *outfp, char *fpath)if (line[0 ] =='#' || line[0 ] =='\n' )continue ; +if (!strncmp (line,"Family" ,6 )) +continue ;
I think we should fix mapfiles to put the 'Family' starting line as a comment.. the way powerpc mapfile is done
jirka
Quoted 6 lines
tools/perf/pmu-events/jevents.c +0
-0if (line[strlen (line)-1 ] !='\n' ) {/* TODO Deal with lines longer than 16K */ Signature · 1 line
1.7.9.5
Re: [PATCH 04/10] perf, tools: Handle header line in mapfile
Jiri Olsa [[email protected]] wrote:
| > if (line[0] == '#' || line[0] == '\n') | > continue; | > + if (!strncmp(line, "Family", 6)) | > + continue; | | I think we should fix mapfiles to put the 'Family' starting | line as a comment.. the way powerpc mapfile is done
You mean add something like this to the Intel mapfile:
# Power8 entries 004d0100,1,power8.json,core
and drop this patch?
Re: [PATCH 04/10] perf, tools: Handle header line in mapfile
Quoted 9 lines · Sukadev Bhattiprolu
Jiri Olsa [[email protected]] wrote:
| > if (line[0] == '#' || line[0] == '\n') | > continue; | > + if (!strncmp(line, "Family", 6)) | > + continue; | | I think we should fix mapfiles to put the 'Family' starting | line as a comment.. the way powerpc mapfile is done
Quoted 6 lines
You mean add something like this to the Intel mapfile:
# Power8 entries 004d0100,1,power8.json,coreand drop this patch?
right
jirka
Re: [PATCH 04/10] perf, tools: Handle header line in mapfile
Quoted 10 lines · Jiri Olsa
Quoted 9 lines · Sukadev Bhattiprolu
Jiri Olsa [[email protected]] wrote:
| > if (line[0] == '#' || line[0] == '\n') | > continue; | > + if (!strncmp(line, "Family", 6)) | > + continue; | | I think we should fix mapfiles to put the 'Family' starting | line as a comment.. the way powerpc mapfile is done
Quoted 8 lines
Quoted 6 lines
You mean add something like this to the Intel mapfile:
# Power8 entries 004d0100,1,power8.json,coreand drop this patch?
right
But it's a CSV file. CSV files are supposed to have column headers. There are lots of tools that work better with them if they have headers. Please keep the header.
-Andi
Signature · 1 line
[email protected] -- Speaking for myself only
Re: [PATCH 04/10] perf, tools: Handle header line in mapfile
Quoted 16 lines · Andi Kleen
Quoted 15 lines · Jiri Olsa
Quoted 14 lines · Sukadev Bhattiprolu
Jiri Olsa [[email protected]] wrote:
| > if (line[0] == '#' || line[0] == '\n') | > continue; | > + if (!strncmp(line, "Family", 6)) | > + continue; | | I think we should fix mapfiles to put the 'Family' starting | line as a comment.. the way powerpc mapfile is doneYou mean add something like this to the Intel mapfile:
# Power8 entries 004d0100,1,power8.json,core
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
and drop this patch?
right
But it's a CSV file. CSV files are supposed to have column headers. There are lots of tools that work better with them if they have headers.
header could be behind '#'
Quoted 1 line
Please keep the header.
hum, do all arch start with 'Family' column? I guess not, so eventualy we will need to add first column of each arch in here? ending up with list of 'keywords' which we ignore
or let's just ignore first line?
I'd rather go with just one comment char and place the header behind it
jirka
PATCH 5/10 perf, tools: Allow events with dot
In reply to Sukadev BhattiproluFrom: Andi Kleen <[email protected]>
The Intel events use a dot to separate event name and unit mask. Allow dot in names in the scanner, and remove special handling of dot as EOF. Also remove the hack in jevents to replace dot with underscore. This way dotted events can be specified directly by the user.
I'm not fully sure this change to the scanner is correct (what was the dot special case good for?), but I haven't found anything that breaks with it so far at least.
V2: Add the dot to name too, to handle events outside cpu//
--- tools/perf/util/parse-events.l | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
tools/perf/util/parse-events.l +2 -3
@@ -98,8 +98,8 @@ event [^,{}/]+ num_dec [0-9]+ num_hex 0x[a-fA-F0-9]+ num_raw_hex [a-fA-F0-9]+ -name [a-zA-Z_*?][a-zA-Z0-9_*?]* -name_minus [a-zA-Z_*?][a-zA-Z0-9\-_*?]* +name [a-zA-Z_*?][a-zA-Z0-9_*?.]* +name_minus [a-zA-Z_*?][a-zA-Z0-9\-_*?.]* /* If you add a modifier you need to update check_modifier() */ modifier_event [ukhpGHSDI]+ modifier_bp [rwx]{1,3}
@@ -137,7 +137,6 @@ modifier_bp [rwx]{1,3} return PE_EVENT_NAME; } -. | <<EOF>> { BEGIN(INITIAL); yyless(0); }
Signature · 1 line
1.7.9.5
PATCH 6/10 perf, tools: Support CPU id matching for x86 v2
In reply to Sukadev BhattiproluFrom: Andi Kleen <[email protected]>
Implement the code to match CPU types to mapfile types for x86 based on CPUID. This extends an existing similar function, but changes it to use the x86 mapfile cpu description. This allows to resolve event lists generated by jevents.
v2: Update to new get_cpuid_str() interface
--- tools/perf/arch/x86/util/header.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-)
tools/perf/arch/x86/util/header.c +21 -3
@@ -19,8 +19,8 @@ cpuid(unsigned int op, unsigned int *a, unsigned int *b, unsigned int *c, : "a" (op)); } -int -get_cpuid (char *buffer,size_t sz) +static int +__get_cpuid (char *buffer,size_t sz,const char *fmt) {unsigned int a, b, c, d, lvl;int family =-1 , model =-1 , step =-1 ;
@@ -48,7 +48,7 @@ get_cpuid(char *buffer, size_t sz)if (family >=0x6 ) model += ((a >>16 ) &0xf ) <<4 ; } - nb =scnprintf (buffer, sz,"%s,%u,%u,%u$" , vendor, family, model, step); + nb =scnprintf (buffer, sz, fmt, vendor, family, model, step);/* look for end marker to ensure the entire data fit */ if (strchr (buffer,'$' )) {
@@ -57,3 +57,21 @@ get_cpuid(char *buffer, size_t sz) }return -1 ; } + +int +get_cpuid (char *buffer,size_t sz) +{ +return __get_cpuid (buffer, sz,"%s,%u,%u,%u$" ); +} + +char * +get_cpuid_str (void ) +{ +char *buf =malloc (128 ); + +if (__get_cpuid (buf,128 ,"%s-%u-%X$" ) <0 ) { +free (buf); +return NULL ; + } +return buf; +}
Signature · 1 line
1.7.9.5
PATCH 7/10 perf, tools: Support alias descriptions
In reply to Sukadev BhattiproluFrom: Andi Kleen <[email protected]>
Add support to print alias descriptions in perf list, which are taken from the generated event files.
The sorting code is changed to put the events with descriptions at the end. The descriptions are printed as possibly multiple word wrapped lines.
Example output:
% perf list
...
arith.fpu_div
[Divide operations executed]
arith.fpu_div_active
[Cycles when divider is busy executing divide operations]
Changelog
- Delete a redundant free()
--- tools/perf/util/pmu.c | 83 +++++++++++++++++++++++++++++++++++++------------ tools/perf/util/pmu.h | 1 + 2 files changed, 64 insertions(+), 20 deletions(-)
tools/perf/util/pmu.c +63 -20
@@ -232,10 +232,7 @@ static int __perf_pmu__new_alias(struct list_head *list, char *name, char *dir,perf_pmu__parse_snapshot (alias, dir, name); } -/* -* TODO: pickup description from Andi's patchset -*/ -//alias->desc = desc ? strdpu(desc) : NULL; + alias->desc = desc ?strdup (desc) :NULL ;list_add_tail (&alias->list, list);
@@ -936,11 +933,42 @@ static char *format_alias_or(char *buf, int len, struct perf_pmu *pmu,return buf; } -static int cmp_string (const void *a,const void *b) +struct pair { +char *name; +char *desc; +}; + +static int cmp_pair (const void *a,const void *b) { -const char *const *as = a; -const char *const *bs = b; -return strcmp (*as, *bs); +const struct pair *as = a; +const struct pair *bs = b; + +/* Put extra events last */ +if (!!as->desc != !!bs->desc) +return !!as->desc - !!bs->desc; +return strcmp (as->name, bs->name); +} + +static void wordwrap (char *s,int start,int max,int corr) +{ +int column = start; +int n; + +while (*s) { +int wlen =strcspn (s," \t" ); + +if (column + wlen >= max && column > start) { +printf ("\n%*s" , start,"" ); + column = start + corr; + } + n =printf ("%s%.*s" , column > start ?" " :"" , wlen, s); +if (n <=0 ) +break ; + s += wlen; + column += n; +while (isspace (*s)) + s++; + } }void print_pmu_events (const char *event_glob,bool name_only)
@@ -950,7 +978,9 @@ void print_pmu_events(const char *event_glob, bool name_only)char buf[1024 ];int printed =0 ;int len, j; -char **aliases; +struct pair *aliases; +int numdesc =0 ; +int columns =78 ; pmu =NULL ; len =0 ;
@@ -960,14 +990,15 @@ void print_pmu_events(const char *event_glob, bool name_only)if (pmu->selectable) len++; } - aliases =zalloc (sizeof (char *) * len); + aliases =zalloc (sizeof (struct pair ) * len);if (!aliases) goto out_enomem; pmu =NULL ; j =0 ;while ((pmu =perf_pmu__scan (pmu)) !=NULL ) {list_for_each_entry (alias, &pmu->aliases, list) { -char *name =format_alias (buf,sizeof (buf), pmu, alias); +char *name = alias->desc ? alias->name : +format_alias (buf,sizeof (buf), pmu, alias);bool is_cpu = !strcmp (pmu->name,"cpu" ); if (event_glob != NULL &&
@@ -976,37 +1007,49 @@ void print_pmu_events(const char *event_glob, bool name_only) event_glob))))continue ; -if (is_cpu && !name_only) +if (is_cpu && !name_only && !alias->desc) name =format_alias_or (buf,sizeof (buf), pmu, alias); - aliases[j] =strdup (name); -if (aliases[j] ==NULL ) - goto out_enomem; + aliases[j].name = name; +if (is_cpu && !name_only && !alias->desc) + aliases[j].name =format_alias_or (buf,sizeof (buf), + pmu, alias); + aliases[j].name =strdup (aliases[j].name); +/* failure harmless */ + aliases[j].desc = alias->desc; j++; }if (pmu->selectable) {char *s;if (asprintf (&s,"%s//" , pmu->name) <0 ) goto out_enomem; - aliases[j] = s; + aliases[j].name = s; j++; } } len = j; -qsort (aliases, len,sizeof (char *), cmp_string); +qsort (aliases, len,sizeof (struct pair ), cmp_pair);for (j =0 ; j < len; j++) {if (name_only) { -printf ("%s " , aliases[j]); +printf ("%s " , aliases[j].name);continue ; } -printf (" %-50s [Kernel PMU event]\n" , aliases[j]); +if (aliases[j].desc) { +if (numdesc++ ==0 ) +printf ("\n" ); +printf (" %-50s\n" , aliases[j].name); +printf ("%*s" ,8 ,"[" ); +wordwrap (aliases[j].desc,8 , columns,0 ); +printf ("]\n" ); + }else +printf (" %-50s [Kernel PMU event]\n" , aliases[j].name); printed++; }if (printed)printf ("\n" ); out_free:for (j =0 ; j < len; j++) -zfree (&aliases[j]); +zfree (&aliases[j].name);zfree (&aliases);return ;
tools/perf/util/pmu.h +1 -0
@@ -37,6 +37,7 @@ struct perf_pmu_info {struct perf_pmu_alias {char *name; +char *desc;struct list_head terms;/* HEAD struct parse_events_term -> list */ struct list_head list;/* ELEM */ char unit[UNIT_MAX_LEN +1 ];
Signature · 1 line
1.7.9.5
PATCH 8/10 perf, tools: Query terminal width and use in perf list
In reply to Sukadev BhattiproluFrom: Andi Kleen <[email protected]>
Automatically adapt the now wider and word wrapped perf list output to wider terminals. This requires querying the terminal before the auto pager takes over, and exporting this information from the pager subsystem.
--- tools/perf/util/cache.h | 1 + tools/perf/util/pager.c | 15 +++++++++++++++ tools/perf/util/pmu.c | 3 ++- 3 files changed, 18 insertions(+), 1 deletion(-)
tools/perf/util/cache.h +1 -0
@@ -33,6 +33,7 @@ extern void setup_pager(void);extern const char *pager_program;extern int pager_in_use (void );extern int pager_use_color; +int pager_get_columns (void );char *alias_lookup (const char *alias);int split_cmdline (char *cmdline,const char ***argv);
tools/perf/util/pager.c +15 -0
@@ -1,6 +1,7 @@#include "cache.h" #include "run-command.h" #include "sigchain.h" +#include <sys/ioctl.h> /* * This is split up from the rest of git so that we can do
@@ -8,6 +9,7 @@*/ static int spawned_pager; +static int pager_columns;static void pager_preexec (void ) {
@@ -47,9 +49,12 @@ static void wait_for_pager_signal(int signo)void setup_pager (void ) {const char *pager =getenv ("PERF_PAGER" ); +struct winsize sz;if (!isatty (1 ))return ; +if (ioctl (1 ,TIOCGWINSZ , &sz) ==0 ) + pager_columns = sz.ws_col;if (!pager) {if (!pager_program)perf_config (perf_default_config,NULL );
@@ -98,3 +103,13 @@ int pager_in_use(void) env =getenv ("PERF_PAGER_IN_USE" );return env ?perf_config_bool ("PERF_PAGER_IN_USE" , env) :0 ; } + +int pager_get_columns (void ) +{ +char *s; + + s =getenv ("COLUMNS" ); +if (s) +return atoi (s); +return (pager_columns ? pager_columns :80 ) -2 ; +}
tools/perf/util/pmu.c +2 -1
@@ -13,6 +13,7 @@#include "pmu-events/pmu-events.h" #include "cpumap.h" #include "header.h" +#include "cache.h" struct perf_pmu_format {char *name;
@@ -980,7 +981,7 @@ void print_pmu_events(const char *event_glob, bool name_only)int len, j;struct pair *aliases;int numdesc =0 ; -int columns =78 ; +int columns =pager_get_columns (); pmu =NULL ; len =0 ;
Signature · 1 line
1.7.9.5
PATCH 9/10 perf, tools: Add a --no-desc flag to perf list
In reply to Sukadev BhattiproluFrom: Andi Kleen <[email protected]>
Add a --no-desc flag to perf list to not print the event descriptions that were earlier added for JSON events. This may be useful to get a less crowded listing.
It's still default to print descriptions as that is the more useful default for most users.
v2: Rename --quiet to --no-desc. Add option to man page.
--- tools/perf/Documentation/perf-list.txt | 8 +++++++- tools/perf/builtin-list.c | 12 ++++++++---- tools/perf/util/parse-events.c | 4 ++-- tools/perf/util/parse-events.h | 2 +- tools/perf/util/pmu.c | 4 ++-- tools/perf/util/pmu.h | 2 +- 6 files changed, 21 insertions(+), 11 deletions(-)
tools/perf/Documentation/perf-list.txt +7 -1
@@ -8,13 +8,19 @@ perf-list - List all symbolic event types SYNOPSIS -------- [verse] -'perf list' [hw|sw|cache|tracepoint|pmu|event_glob] +'perf list' [--no-desc] [hw|sw|cache|tracepoint|pmu|event_glob] DESCRIPTION ----------- This command displays the symbolic event types which can be selected in the various perf commands with the -e option. +OPTIONS +------- +--no-desc:: +Don't print descriptions. + + [[EVENT_MODIFIERS]] EVENT MODIFIERS ---------------
tools/perf/builtin-list.c +8 -4
@@ -16,16 +16,20 @@#include "util/pmu.h" #include "util/parse-options.h" +static bool desc_flag = true; +int cmd_list (int argc,const char **argv,const char *prefix__maybe_unused ) {int i;bool raw_dump = false;struct option list_options[] = {OPT_BOOLEAN (0 ,"raw-dump" , &raw_dump,"Dump raw events" ), +OPT_BOOLEAN ('d' ,"desc" , &desc_flag, +"Print extra event descriptions. --no-desc to not print." ),OPT_END () };const char *const list_usage[] = { -"perf list [hw|sw|cache|tracepoint|pmu|event_glob]" , +"perf list [--no-desc] [hw|sw|cache|tracepoint|pmu|event_glob]" ,NULL };
@@ -40,7 +44,7 @@ int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused)printf ("\nList of pre-defined events (to be used in -e):\n\n" );if (argc ==0 ) { -print_events (NULL , raw_dump); +print_events (NULL , raw_dump, !desc_flag);return 0 ; }
@@ -59,13 +63,13 @@ int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused) strcmp(argv[i], "hwcache") == 0)print_hwcache_events (NULL , raw_dump); else if (strcmp(argv[i], "pmu") == 0) - print_pmu_events(NULL, raw_dump); + print_pmu_events(NULL, raw_dump, !desc_flag); else {char *sep =strchr (argv[i],':' ), *s;int sep_idx;if (sep ==NULL ) { -print_events (argv[i], raw_dump); +print_events (argv[i], raw_dump, !desc_flag);continue ; } sep_idx = sep - argv[i];
tools/perf/util/parse-events.c +2 -2
@@ -1419,7 +1419,7 @@ out_enomem:/* * Print the help text for the event symbols: */ -void print_events (const char *event_glob,bool name_only) +void print_events (const char *event_glob,bool name_only,bool quiet_flag) {print_symbol_events (event_glob,PERF_TYPE_HARDWARE , event_symbols_hw,PERF_COUNT_HW_MAX , name_only);
@@ -1429,7 +1429,7 @@ void print_events(const char *event_glob, bool name_only)print_hwcache_events (event_glob, name_only); -print_pmu_events (event_glob, name_only); +print_pmu_events (event_glob, name_only, quiet_flag);if (event_glob !=NULL )return ;
tools/perf/util/parse-events.h +1 -1
@@ -115,7 +115,7 @@ void parse_events_update_lists(struct list_head *list_event, struct list_head *list_all);void parse_events_error (void *data,void *scanner,char const *msg); -void print_events (const char *event_glob,bool name_only); +void print_events (const char *event_glob,bool name_only,bool quiet);struct event_symbol {const char *symbol;
tools/perf/util/pmu.c +2 -2
@@ -972,7 +972,7 @@ static void wordwrap(char *s, int start, int max, int corr) } } -void print_pmu_events (const char *event_glob,bool name_only) +void print_pmu_events (const char *event_glob,bool name_only,bool quiet_flag) {struct perf_pmu *pmu;struct perf_pmu_alias *alias;
@@ -1035,7 +1035,7 @@ void print_pmu_events(const char *event_glob, bool name_only)printf ("%s " , aliases[j].name);continue ; } -if (aliases[j].desc) { +if (aliases[j].desc && !quiet_flag) {if (numdesc++ ==0 )printf ("\n" );printf (" %-50s\n" , aliases[j].name);
tools/perf/util/pmu.h +1 -1
@@ -67,7 +67,7 @@ int perf_pmu__format_parse(char *dir, struct list_head *head);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 quiet);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,
Signature · 1 line
1.7.9.5
Re: [PATCH 09/10] perf, tools: Add a --no-desc flag to perf list
Quoted 8 lines · Sukadev Bhattiprolu
From: Andi Kleen <[email protected]>
Add a --no-desc flag to perf list to not print the event descriptions that were earlier added for JSON events. This may be useful to get a less crowded listing.
It's still default to print descriptions as that is the more useful default for most users.
I might not be typical user, but the first thing I tried to explore was 'perf list -v' ;-)
would it be better to have just the list with event names for:
$ perf list
and with descriptions for:
$ perf list -v
not sure we already discussed this..
jirka
Re: [PATCH 09/10] perf, tools: Add a --no-desc flag to perf list
Quoted 13 lines · Jiri Olsa
Quoted 8 lines · Sukadev Bhattiprolu
From: Andi Kleen <[email protected]>
Add a --no-desc flag to perf list to not print the event descriptions that were earlier added for JSON events. This may be useful to get a less crowded listing.
It's still default to print descriptions as that is the more useful default for most users.
I might not be typical user, but the first thing I tried to explore was 'perf list -v' ;-)
Quoted 7 lines
would it be better to have just the list with event names for:
$ perf listand with descriptions for:
$ perf list -vnot sure we already discussed this..
It was discussed last time. I think it's better to have descriptions by default. Far more user friendly.
One thing we could in theory do with -v is to switch between Brief and Public Description (the later is often more verbose). Would need some changes to the alias code to have two descriptions though.
-Andi
Signature · 1 line
[email protected] -- Speaking for myself only
PATCH 10/10 perf: Add power8 PMU events in JSON format
In reply to Sukadev BhattiproluThe power8.json file describes the PMU events in the Power8 processor. The jevents program from the prior patch will use this power8.json files to create tables which will then be used in perf to build aliases for PMU events. This in turn would allow users to specify these PMU events by name rather than raw event code:
$ perf stat -e pm_1plus_ppc_cmpl sleep 1
Changelog[v2]
- [Andi Kleen] Replace the vendor-family-model,version fields with cpuid,version fields (to simplify mapfile)
- Reuse the JSON files when possible (i.e multiple cpuids can refer to the same JSON file) - so drop the 004d0100.json and use power8.json in multiple entries in mapfile.
- [Namhyung Kim] Remove text in "PublicDescription" field if it is identical to (or prefix of) "BriefDescription" field for the event.
- Add PVRs for other Power8 models to mapfile
--- tools/perf/pmu-events/arch/powerpc/mapfile.csv | 19 + tools/perf/pmu-events/arch/powerpc/power8.json | 6380 ++++++++++++++++++++++++ 2 files changed, 6399 insertions(+) create mode 100644 tools/perf/pmu-events/arch/powerpc/mapfile.csv create mode 100644 tools/perf/pmu-events/arch/powerpc/power8.json
tools/perf/pmu-events/arch/powerpc/mapfile.csv new file +19 -0
@@ -0,0 +1,19 @@ +# Format: +# PVR,Version,JSON/file/pathname,Type +# +# where +# PVR Processor version +# Version could be used to track version of of JSON file +# but currently unused. +# JSON/file/pathname is the path to JSON file, relative +# to tools/perf/pmu-events/arch/powerpc/. +# Type is core, uncore etc +# +# Multiple PVRs could map to a single JSON file. +# + +# Power8 entries +004b0000,1,power8.json,core +004c0000,1,power8.json,core +004d0000,1,power8.json,core +004d0100,1,power8.json,core
tools/perf/pmu-events/arch/powerpc/power8.json new file +6380 -0
2,981 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.7.9.5
Part of the diff is not shown here. View the raw message.
On Wed, May 27, 2015 at 02:23:19PM -0700, Sukadev Bhattiprolu wrote:
SNIP
Quoted 15 lines
At run time, perf identifies the specific events table, based on the model of the CPU perf is running on. Perf uses that table to create event aliases which would allow the user to specify the event as:
perf stat -e
pm_1plus_ppc_cmplsleep 1Note:
- All known events tables for the architecture are included in the perf binary.- Inconsistencies between the JSON files and the mapfile can result in build failures in perf (although jevents try to recover from some and continue the build by leaving out event aliases).
Quoted 8 lines
- For architectures that don't have any JSON files, an empty mapping table is created and they should continue to build)
Thanks to input from Andi Kleen, Jiri Olsa, Namhyung Kim and Ingo Molnar.
These patches are available from
[email protected]:sukadev/linux.git #branch json-v11
could you please also pull in Andi's changes with x86 events? it seems to be under his tree branch perf/builtin-json-2, follwing commits:
b68aa7b0d4e4 perf, tools: Add Broadwell V9 event file 1873bf40be27 perf, tools: Add HaswellX V12 event file dc9a37d4f96c perf, tools: Add Bonnell V1 event file f8cce1c4abb6 perf, tools: Add Silvermont V8 event file c92a43e0a6c9 perf, tools: Add Haswell V18 event file 67ac6d3d8e2f perf, tools: Add IvyBridge V14 event file 3777bd7a8bf2 perf, tools: Add IvyTown V16 event file 21f34ff8ddb3 perf, tools: Add Jaketown V17 event file 22b22b279559 perf, tools: Add SandyBridge V11 event file 542c99a4836d perf, tools: Add WestmereEP-DP V1 event file b2f0315e50b3 perf, tools: Add WestmereEP-SP V1 event file 82601ad46a58 perf, tools: Add WestmereEX V1 event file a52987f230e0 perf, tools: Add NehalemEP V1 event file a8fedce09cc1 perf, tools: Add NehalemEX V1 event file
no need to post them ATM.. just to have all stuff on one place will ease up testing
Andi, you'd be ok with that I guess ;-)
thanks,
jirka
On Thu, May 28, 2015 at 01:42:06PM +0200, Jiri Olsa wrote:
SNIP
Quoted 21 lines
Quoted 1 line
[email protected]:sukadev/linux.git #branch json-v11
could you please also pull in Andi's changes with x86 events? it seems to be under his tree branch perf/builtin-json-2, follwing commits:
b68aa7b0d4e4perf, tools: Add Broadwell V9 event file1873bf40be27perf, tools: Add HaswellX V12 event filedc9a37d4f96cperf, tools: Add Bonnell V1 event filef8cce1c4abb6perf, tools: Add Silvermont V8 event filec92a43e0a6c9perf, tools: Add Haswell V18 event file67ac6d3d8e2fperf, tools: Add IvyBridge V14 event file3777bd7a8bf2perf, tools: Add IvyTown V16 event file21f34ff8ddb3perf, tools: Add Jaketown V17 event file22b22b279559perf, tools: Add SandyBridge V11 event file542c99a4836dperf, tools: Add WestmereEP-DP V1 event fileb2f0315e50b3perf, tools: Add WestmereEP-SP V1 event file82601ad46a58perf, tools: Add WestmereEX V1 event filea52987f230e0perf, tools: Add NehalemEP V1 event filea8fedce09cc1perf, tools: Add NehalemEX V1 event file
Quoted 4 lines
no need to post them ATM.. just to have all stuff on one place will ease up testing
Andi, you'd be ok with that I guess ;-)
also could you please rebase this on latest Arnaldo's perf/core?
thanks,
jirka
On Wed, May 27, 2015 at 02:23:19PM -0700, Sukadev Bhattiprolu wrote:
SNIP
Quoted 7 lines
- All known events tables for the architecture are included in the perf binary.
- Inconsistencies between the JSON files and the mapfile can result in build failures in perf (although jevents try to recover from some and continue the build by leaving out event aliases).
Quoted 8 lines
- For architectures that don't have any JSON files, an empty mapping table is created and they should continue to build)
Thanks to input from Andi Kleen, Jiri Olsa, Namhyung Kim and Ingo Molnar.
These patches are available from
[email protected]:sukadev/linux.git #branch json-v11
found it publicly accessable/clone-able under:
https://github.com/sukadev/linux.git
jirka