Skip to contentSkip to conversation

Add support for JSON event files.

PATCH Superseded Sukadev Bhattiprolu 5 participants 25 messages Apr 14, 2015 – Apr 18, 2015 perf events

v9 of 21 Superseded Latest is v21 →

lore
Share & tools
lore
#0 lore raw

v9 cover Add support for JSON event files.

This is another attempt to resurrect Andi Kleen's patchset so users can specify perf events by their event names rather than raw codes.

This is a rebase of Andi Kleen's patchset from Jul 30, 2014[1] to 4.0. (I fixed minor and not so minor conflicts).

This patchset includes the perf-download tool that was dropped and sets the default download location to the (tools/perf/pmu-events/arch/... directory in Linus's tree.

A follow-on patchset will include the actual JSON files for Powerpc, which are currently available on github[2].

[1] https://lkml.org/lkml/2014/7/30/693
[2] https://github.com/open-power/power-pmu-events

Andi Kleen (9):
perf, tools: Add jsmn `jasmine' JSON parser
perf, tools: Add support for text descriptions of events and alias
add
perf, tools, list: Update perf list to output descriptions perf, tools: Add support for reading JSON event files perf, tools: Automatically look for event file name for cpu perf, tools: Query terminal width and use in perf list perf, tools: Add a new pmu interface to iterate over all events perf, tools, test: Add test case for alias and JSON parsing perf, tools: Add a --no-desc flag to perf list

Sukadev Bhattiprolu (2):
powerpc/perf: Implement get_cpu_str()
perf-download: Download the events json file

 tools/perf/Documentation/perf-download.txt |   31 +++
 tools/perf/Documentation/perf-list.txt     |   29 ++-
 tools/perf/Documentation/perf-record.txt   |    9 +-
 tools/perf/Documentation/perf-stat.txt     |    8 +-
 tools/perf/Makefile.perf                   |   12 +-
 tools/perf/arch/powerpc/util/header.c      |   12 ++
 tools/perf/arch/x86/util/header.c          |   19 +-
 tools/perf/builtin-list.c                  |   18 +-
 tools/perf/builtin-record.c                |    3 +
 tools/perf/builtin-stat.c                  |    2 +
 tools/perf/perf-download.sh                |  171 +++++++++++++++
 tools/perf/tests/aliases.c                 |   59 ++++++
 tools/perf/tests/builtin-test.c            |    4 +
 tools/perf/tests/tests.h                   |    1 +
 tools/perf/util/cache.h                    |    1 +
 tools/perf/util/jevents.c                  |  287 +++++++++++++++++++++++++
 tools/perf/util/jevents.h                  |    9 +
 tools/perf/util/jsmn.c                     |  313 ++++++++++++++++++++++++++++
 tools/perf/util/jsmn.h                     |   67 ++++++
 tools/perf/util/json.c                     |  162 ++++++++++++++
 tools/perf/util/json.h                     |   13 ++
 tools/perf/util/pager.c                    |   15 ++
 tools/perf/util/parse-events.c             |    4 +-
 tools/perf/util/parse-events.h             |    2 +-
 tools/perf/util/pmu.c                      |  160 +++++++++++---
 tools/perf/util/pmu.h                      |    5 +-
 26 files changed, 1365 insertions(+), 51 deletions(-)
 create mode 100644 tools/perf/Documentation/perf-download.txt
 create mode 100755 tools/perf/perf-download.sh
 create mode 100644 tools/perf/tests/aliases.c
 create mode 100644 tools/perf/util/jevents.c
 create mode 100644 tools/perf/util/jevents.h
 create mode 100644 tools/perf/util/jsmn.c
 create mode 100644 tools/perf/util/jsmn.h
 create mode 100644 tools/perf/util/json.c
 create mode 100644 tools/perf/util/json.h
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH v9 1/11 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.

---

Changelog[v9] (by Sukadev Bhattiprolu)
Rebase to 4.0 and fix minor conflicts in tools/perf/Makefile.perf Report error if specified events file is invalid.

v2: Address review feedback.
v3: Minor checkpatch fixes.

---
 tools/perf/Makefile.perf |    4 +
 tools/perf/util/jsmn.c   |  313 ++++++++++++++++++++++++++++++++++++++++++++++
 tools/perf/util/jsmn.h   |   67 ++++++++++
 tools/perf/util/json.c   |  160 ++++++++++++++++++++++++
 tools/perf/util/json.h   |   13 ++
 5 files changed, 557 insertions(+)
 create mode 100644 tools/perf/util/jsmn.c
 create mode 100644 tools/perf/util/jsmn.h
 create mode 100644 tools/perf/util/json.c
 create mode 100644 tools/perf/util/json.h
tools/perf/Makefile.perf +4 -0
index aa6a504..a558eb3 100644
@@ -331,6 +331,8 @@ LIB_H += ui/ui.h
 LIB_H += util/data.h
 LIB_H += util/kvm-stat.h
 LIB_H += util/thread-stack.h
+LIB_H += util/jsmn.h
+LIB_H += util/json.h
 
 LIB_OBJS += $(OUTPUT)util/abspath.o
 LIB_OBJS += $(OUTPUT)util/alias.o
@@ -410,6 +412,8 @@ LIB_OBJS += $(OUTPUT)util/data.o
 LIB_OBJS += $(OUTPUT)util/tsc.o
 LIB_OBJS += $(OUTPUT)util/cloexec.o
 LIB_OBJS += $(OUTPUT)util/thread-stack.o
+LIB_OBJS += $(OUTPUT)util/jsmn.o
+LIB_OBJS += $(OUTPUT)util/json.o
 
 LIB_OBJS += $(OUTPUT)ui/setup.o
 LIB_OBJS += $(OUTPUT)ui/helpline.o
tools/perf/util/jsmn.c new file +313 -0

313 lines not on this page · raw message

tools/perf/util/jsmn.h new file +67 -0

67 lines not on this page · raw message

tools/perf/util/json.c new file +160 -0

160 lines not on this page · raw message

tools/perf/util/json.h new file +13 -0
new file mode 100644
index 0000000..37dd9e9
@@ -0,0 +1,13 @@
+#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);
+
+#endif
Signature · 1 line
1.7.9.5
#2 lore raw

PATCH v9 2/11 perf, tools: Add support for text descriptions of events and alias add

In reply to Sukadev Bhattiprolu

From: Andi Kleen <[email protected]>

Change pmu.c to allow descriptions of events and add interfaces to add aliases at runtime from another file. To be used by jevents in a followon patch

---
Changelog[v9] by Sukadev Bhattiprolu
Rebase to 4.0
v2: Move perf list changes to other patch.

---
 tools/perf/util/json.c |    1 +
 tools/perf/util/pmu.c  |   48 +++++++++++++++++++++++++++++++++---------------
 tools/perf/util/pmu.h  |    1 +
 3 files changed, 35 insertions(+), 15 deletions(-)
tools/perf/util/json.c +1 -0
index e20001f..2219844 100644
@@ -38,6 +38,7 @@
 #include "jsmn.h"
 #include "json.h"
 #include <linux/kernel.h>
+#include "debug.h"
 
 static char *mapfile(const char *fn, size_t *size)
 {
tools/perf/util/pmu.c +33 -15

76 lines not on this page · raw message

tools/perf/util/pmu.h +1 -0
index 6b1249f..d06496d 100644
@@ -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
#3 lore raw

PATCH v9 3/11 perf, tools, list: Update perf list to output descriptions

In reply to Sukadev Bhattiprolu

From: Andi Kleen <[email protected]>

Add support to perf list to print aliases with descriptions. Support word wrapping for descriptions.
Fix up the sorting code to put aliases with descriptions last.

---

Changelov[v9] by Sukadev Bhattiprolu
Rebase to 4.0 and fix conflicts in tools/perf/util/pmu.c

---
 tools/perf/util/pmu.c |   86 ++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 70 insertions(+), 16 deletions(-)
tools/perf/util/pmu.c +70 -16
index 527da74..623b107 100644
@@ -877,11 +877,51 @@ 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 downloaded event list 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++;
+	}
+}
+
+static int get_columns(void)
+{
+	/*
+	 * Should ask the terminal with TIOCGWINSZ here, but we
+	 * need the original fd before the pager.
+	 */
+	return 79;
 }
 
 void print_pmu_events(const char *event_glob, bool name_only)
@@ -891,7 +931,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 = get_columns();
 
 	pmu = NULL;
 	len = 0;
@@ -901,14 +943,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 &&
@@ -917,11 +960,14 @@ void print_pmu_events(const char *event_glob, bool name_only)
 						       event_glob))))
 				continue;
 
-			if (is_cpu && !name_only)
-				name = format_alias_or(buf, sizeof(buf), pmu, alias);
+			aliases[j].name = name;
+			if (is_cpu && !name_only && !alias->desc)
+				aliases[j].name = format_alias_or(buf,
+						sizeof(buf), pmu, alias);
 
-			aliases[j] = strdup(name);
-			if (aliases[j] == NULL)
+			aliases[j].name = strdup(aliases[j].name);
+			aliases[j].desc = alias->desc;
+			if (aliases[j].name == NULL)
 				goto out_enomem;
 			j++;
 		}
@@ -929,25 +975,33 @@ void print_pmu_events(const char *event_glob, bool name_only)
 			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 && printed)
+				printf("\n");
+			printf("  %-50s [", aliases[j].name);
+			wordwrap(aliases[j].desc, 53, columns, 1);
+			printf("]\n");
+		} else
+			printf("  %-50s [Kernel PMU event]\n", aliases[j].name);
+		zfree(&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;
 
Signature · 1 line
1.7.9.5
#4 lore raw

PATCH v9 4/11 perf, tools: Add support for reading JSON event files

In reply to Sukadev Bhattiprolu

From: Andi Kleen <[email protected]>

Add a parser for 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 parser code knows how to convert the JSON fields
to perf fields. The conversion code is straight forward. It 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.

The events are handled using the existing alias machinery.

We output the BriefDescription in perf list.

Right now the json file can be specified as an argument to perf stat/record/list. Followon patches will automate this.

JSON files look like this:

[

  {
    "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",
    "MSRIndex": "0",
    "MSRValue": "0",
    "TakenAlone": "0",
    "CounterMask": "0",
    "Invert": "0",
    "AnyThread": "0",
    "EdgeDetect": "0",
    "PEBS": "0",
    "PRECISE_STORE": "0",
    "Errata": "null",
    "Offcore": "0"

}
]

---
Changelog[v9] by Sukadev Bhattiprolu
Rebase to 4.0 and fix conflicts in:
tools/perf/Documentation/perf-record.txt tools/perf/builtin-list.c tools/perf/builtin-record.c tools/perf/util/pmu.h
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

---
 tools/perf/Documentation/perf-list.txt   |   12 +-
 tools/perf/Documentation/perf-record.txt |    9 +-
 tools/perf/Documentation/perf-stat.txt   |    8 +-
 tools/perf/Makefile.perf                 |    2 +
 tools/perf/builtin-list.c                |    2 +
 tools/perf/builtin-record.c              |    3 +
 tools/perf/builtin-stat.c                |    2 +
 tools/perf/util/jevents.c                |  247 ++++++++++++++++++++++++++++++
 tools/perf/util/jevents.h                |    8 +
 tools/perf/util/json.c                   |    1 +
 tools/perf/util/pmu.c                    |   14 ++
 tools/perf/util/pmu.h                    |    1 +
 12 files changed, 305 insertions(+), 4 deletions(-)
 create mode 100644 tools/perf/util/jevents.c
 create mode 100644 tools/perf/util/jevents.h
tools/perf/Documentation/perf-list.txt +10 -2
index 3e2aec9..205ac40 100644
@@ -15,8 +15,16 @@ DESCRIPTION
 This command displays the symbolic event types which can be selected in the
 various perf commands with the -e option.
 
-[[EVENT_MODIFIERS]]
-EVENT MODIFIERS
+OPTIONS
+-------
+--events-file=::
+Specify JSON event list file to use for parsing events. Files can be
+automatically downloaded with perf download.
+The JSON event file can be also specified with the EVENTMAP environment
+variable.
+
+
+[[EVENT_MODIFIERS]] EVENT MODIFIERS
 ---------------
 
 Events can optionally have a modifier by appending a colon and one or
tools/perf/Documentation/perf-record.txt +8 -1
index 31e9774..13f34b0 100644
@@ -235,6 +235,13 @@ Capture machine state (registers) at interrupt, i.e., on counter overflows for
 each sample. List of captured registers depends on the architecture. This option
 is off by default.
 
+--events-file=::
+Specify JSON event list file to use for parsing events. Must be specified
+before the -e option. Files can be automatically downloaded with perf download.
+The JSON event file can be also specified with the EVENTMAP environment
+variable.
+
+
 SEE ALSO
 --------
-linkperf:perf-stat[1], linkperf:perf-list[1]
+linkperf:perf-stat[1], linkperf:perf-list[1], linkperf:perf-download[1]
tools/perf/Documentation/perf-stat.txt +7 -1
index 04e150d..3853245 100644
@@ -154,6 +154,12 @@ filter out the startup phase of the program, which is often very different.
 
 Print statistics of transactional execution if supported.
 
+--events-file=::
+Specify JSON event list file to use for parsing events. Must be specified before
+the -e option. Files can be automatically downloaded with perf download.
+The JSON event file can be also specified with the EVENTMAP environment
+variable.
+
 EXAMPLES
 --------
 
@@ -174,4 +180,4 @@ $ perf stat -- make -j
 
 SEE ALSO
 --------
-linkperf:perf-top[1], linkperf:perf-list[1]
+linkperf:perf-top[1], linkperf:perf-list[1], linkperf:perf-download[1]
tools/perf/Makefile.perf +2 -0
index a558eb3..d9c1a4c 100644
@@ -333,6 +333,7 @@ LIB_H += util/kvm-stat.h
 LIB_H += util/thread-stack.h
 LIB_H += util/jsmn.h
 LIB_H += util/json.h
+LIB_H += util/jevents.h
 
 LIB_OBJS += $(OUTPUT)util/abspath.o
 LIB_OBJS += $(OUTPUT)util/alias.o
@@ -414,6 +415,7 @@ LIB_OBJS += $(OUTPUT)util/cloexec.o
 LIB_OBJS += $(OUTPUT)util/thread-stack.o
 LIB_OBJS += $(OUTPUT)util/jsmn.o
 LIB_OBJS += $(OUTPUT)util/json.o
+LIB_OBJS += $(OUTPUT)util/jevents.o
 
 LIB_OBJS += $(OUTPUT)ui/setup.o
 LIB_OBJS += $(OUTPUT)ui/helpline.o
tools/perf/builtin-list.c +2 -0
index 198f3c3..fd07cc1 100644
@@ -22,6 +22,8 @@ int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused)
 	bool raw_dump = false;
 	struct option list_options[] = {
 		OPT_BOOLEAN(0, "raw-dump", &raw_dump, "Dump raw events"),
+		OPT_STRING(0, "events-file", &json_file, "json file",
+			   "Read event json file"),
 		OPT_END()
 	};
 	const char * const list_usage[] = {
tools/perf/builtin-record.c +3 -0
index 404ab34..365c9d4 100644
@@ -27,6 +27,7 @@
 #include "util/cpumap.h"
 #include "util/thread_map.h"
 #include "util/data.h"
+#include "util/pmu.h"
 
 #include <unistd.h>
 #include <sched.h>
@@ -839,6 +840,8 @@ struct option __record_options[] = {
 		    "use per-thread mmaps"),
 	OPT_BOOLEAN('I', "intr-regs", &record.opts.sample_intr_regs,
 		    "Sample machine registers on interrupt"),
+	OPT_STRING(0, "events-file", &json_file, "json file",
+		   "Read event json file"),
 	OPT_END()
 };
 
tools/perf/builtin-stat.c +2 -0
index e598e4e..f4ff31b 100644
@@ -1757,6 +1757,8 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
 		     "aggregate counts per physical processor core", AGGR_CORE),
 	OPT_UINTEGER('D', "delay", &initial_delay,
 		     "ms to wait before starting measurement after program start"),
+	OPT_STRING(0, "events-file", &json_file, "json file",
+		   "Read event json file"),
 	OPT_END()
 	};
 	const char * const stat_usage[] = {
tools/perf/util/jevents.c new file +247 -0

247 lines not on this page · raw message

tools/perf/util/jevents.h new file +8 -0
new file mode 100644
index 0000000..fbc4549
@@ -0,0 +1,8 @@
+#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);
+
+#endif
tools/perf/util/json.c +1 -0
index 2219844..45acadf 100644
@@ -37,6 +37,7 @@
 #include <unistd.h>
 #include "jsmn.h"
 #include "json.h"
+#include "util/debug.h"
 #include <linux/kernel.h>
 #include "debug.h"
 
tools/perf/util/pmu.c +14 -0
index 623b107..d7e5e1b 100644
@@ -11,6 +11,9 @@
 #include "pmu.h"
 #include "parse-events.h"
 #include "cpumap.h"
+#include "jevents.h"
+
+const char *json_file;
 
 struct perf_pmu_format {
 	char *name;
@@ -316,6 +319,14 @@ static int pmu_aliases_parse(char *dir, struct list_head *head)
 	return ret;
 }
 
+static int add_alias(void *data, char *name, char *event, char *desc)
+{
+	struct list_head *head = (struct list_head *)data;
+
+	__perf_pmu__new_alias(head, name, NULL, desc, event);
+	return 0;
+}
+
 /*
  * Reading the pmu event aliases definition, which should be located at:
  * /sys/bus/event_source/devices/<dev>/events as sysfs group attributes.
@@ -471,6 +482,9 @@ static struct perf_pmu *pmu_lookup(const char *name)
 	if (pmu_aliases(name, &aliases))
 		return NULL;
 
+	if (!strcmp(name, "cpu") && json_file)
+		json_events(json_file, add_alias, &aliases);
+
 	if (pmu_type(name, &type))
 		return NULL;
 
tools/perf/util/pmu.h +1 -0
index d06496d..f8dac0f 100644
@@ -77,4 +77,5 @@ int perf_pmu__test(void);
 
 struct perf_event_attr *perf_pmu__get_default_config(struct perf_pmu *pmu);
 
+extern const char *json_file;
 #endif /* __PMU_H */
Signature · 1 line
1.7.9.5
#5 lore raw

PATCH v9 5/11 perf, tools: Automatically look for event file name for cpu

In reply to Sukadev Bhattiprolu

From: Andi Kleen <[email protected]>

When no JSON event file is specified automatically look for a suitable file in ~/.cache/pmu-events.

The event file format is per architecture, but can be extended for other architectures.

---
Changelog[v9] by Sukadev Bhattiprolu
Rebase to 4.0 and fix.
v2: Supports XDG_CACHE_HOME and defaults to ~/.cache/pmu-events
v3: Minor updates and handle EVENTMAP.
v4: Unify with header.c. Now uses CPUID directly.

---
 tools/perf/arch/x86/util/header.c |   19 +++++++++++++++---
 tools/perf/util/jevents.c         |   40 +++++++++++++++++++++++++++++++++++++
 tools/perf/util/jevents.h         |    1 +
 tools/perf/util/pmu.c             |    2 +-
 4 files changed, 58 insertions(+), 4 deletions(-)
tools/perf/arch/x86/util/header.c +16 -3
index 146d12a..76e0ece 100644
@@ -5,6 +5,7 @@
 #include <string.h>
 
 #include "../../util/header.h"
+#include "../../util/jevents.h"
 
 static inline void
 cpuid(unsigned int op, unsigned int *a, unsigned int *b, unsigned int *c,
@@ -19,8 +20,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 +49,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 +58,15 @@ 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_cpu_str(void)
+{
+	char *buf = malloc(128);
+	__get_cpuid(buf, 128, "%s-%d-%X-core");
+	return buf;
+}
tools/perf/util/jevents.c +40 -0
index 023757c..ef4c047 100644
@@ -39,6 +39,44 @@
 #include "json.h"
 #include "jevents.h"
 
+__attribute__((weak)) char *get_cpu_str(void)
+{
+	return NULL;
+}
+
+static const char *json_default_name(void)
+{
+	char *cache;
+	char *idstr = get_cpu_str();
+	char *res = NULL;
+	char *home = NULL;
+	char *emap;
+
+	emap = getenv("EVENTMAP");
+	if (emap) {
+		if (access(emap, R_OK) == 0)
+			return emap;
+		if (asprintf(&idstr, "%s-core", emap) < 0)
+			return NULL;
+	}
+
+	cache = getenv("XDG_CACHE_HOME");
+	if (!cache) {
+		home = getenv("HOME");
+		if (!home || asprintf(&cache, "%s/.cache", home) < 0)
+			goto out;
+	}
+	if (cache && idstr)
+		res = mkpath("%s/pmu-events/%s.json",
+			     cache,
+			     idstr);
+	if (home)
+		free(cache);
+out:
+	free(idstr);
+	return res;
+}
+
 static void addfield(char *map, char **dst, const char *sep,
 		     const char *a, jsmntok_t *bt)
 {
@@ -171,6 +209,8 @@ int json_events(const char *fn,
 	int i, j, len;
 	char *map;
 
+	if (!fn)
+		fn = json_default_name();
 	tokens = parse_json(fn, &map, &size, &len);
 	if (!tokens)
 		return -EIO;
tools/perf/util/jevents.h +1 -0
index fbc4549..86a94dd 100644
@@ -4,5 +4,6 @@
 int json_events(const char *fn,
 		int (*func)(void *data, char *name, char *event, char *desc),
 		void *data);
+char *get_cpu_str(void);
 
 #endif
tools/perf/util/pmu.c +1 -1
index d7e5e1b..274aa18 100644
@@ -482,7 +482,7 @@ static struct perf_pmu *pmu_lookup(const char *name)
 	if (pmu_aliases(name, &aliases))
 		return NULL;
 
-	if (!strcmp(name, "cpu") && json_file)
+	if (!strcmp(name, "cpu"))
 		json_events(json_file, add_alias, &aliases);
 
 	if (pmu_type(name, &type))
Signature · 1 line
1.7.9.5
#6 lore raw

PATCH v9 6/11 powerpc/perf: Implement get_cpu_str()

In reply to Sukadev Bhattiprolu

With a file ~/.cache/pmu-events/004d0100-core.json describing Power8 PMU events we would need to run:

	perf stat \
		--events-file ~/.cache/pmu-events/004d0100-core.json \
		-e pm_cyc sleep 1

With this get_cpu_str(), on Powerpc, we can skip the --events-file option and run:

perf stat -e pm_cyc sleep 1

---
Changelog[v9] by Sukadev Bhattiprolu

	Rebase to 4.0.

Changelog[v3]:
[Tobias Klauser]: Fix some changelog damage to patch.

Changelog[v2]:
[Michael Ellerman]: Use PVR instead of AUXV variables

---
 tools/perf/arch/powerpc/util/header.c |   12 ++++++++++++
 1 file changed, 12 insertions(+)
tools/perf/arch/powerpc/util/header.c +12 -0
index 6c1b8a7..306bf35 100644
@@ -6,6 +6,7 @@
 
 #include "../../util/header.h"
 #include "../../util/util.h"
+#include "../../util/jevents.h"
 
 #define mfspr(rn)       ({unsigned long rval; \
 			 asm volatile("mfspr %0," __stringify(rn) \
@@ -32,3 +33,14 @@ get_cpuid(char *buffer, size_t sz)
 	}
 	return -1;
 }
+
+char *
+get_cpu_str(void)
+{
+	char *bufp;
+
+	if (asprintf(&bufp, "%.8lx-core", mfspr(SPRN_PVR)) < 0)
+		bufp = NULL;
+
+	return bufp;
+}
Signature · 1 line
1.7.9.5
#7 lore raw

PATCH v9 7/11 perf, tools: Query terminal width and use in perf list

In reply to Sukadev Bhattiprolu

From: 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.

---
Changelog[v9] by Sukadev Bhattiprolu

	Rebase to 4.0.
---
 tools/perf/util/cache.h |    1 +
 tools/perf/util/pager.c |   15 +++++++++++++++
 tools/perf/util/pmu.c   |   12 ++----------
 3 files changed, 18 insertions(+), 10 deletions(-)
tools/perf/util/cache.h +1 -0
index d04d770..f1990c9 100644
@@ -32,6 +32,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
index 31ee02d..9761202 100644
@@ -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 -10
index 274aa18..2150455 100644
@@ -11,6 +11,7 @@
 #include "pmu.h"
 #include "parse-events.h"
 #include "cpumap.h"
+#include "cache.h"
 #include "jevents.h"
 
 const char *json_file;
@@ -929,15 +930,6 @@ static void wordwrap(char *s, int start, int max, int corr)
 	}
 }
 
-static int get_columns(void)
-{
-	/*
-	 * Should ask the terminal with TIOCGWINSZ here, but we
-	 * need the original fd before the pager.
-	 */
-	return 79;
-}
-
 void print_pmu_events(const char *event_glob, bool name_only)
 {
 	struct perf_pmu *pmu;
@@ -947,7 +939,7 @@ void print_pmu_events(const char *event_glob, bool name_only)
 	int len, j;
 	struct pair *aliases;
 	int numdesc = 0;
-	int columns = get_columns();
+	int columns = pager_get_columns();
 
 	pmu = NULL;
 	len = 0;
Signature · 1 line
1.7.9.5
#9 lore raw

PATCH v9 9/11 perf, tools, test: Add test case for alias and JSON parsing

In reply to Sukadev Bhattiprolu

From: Andi Kleen <[email protected]>

Add a simple test case to perf test that parses all the available events, including json events.

This needs adding an all event iterator to pmu.c

---
Changelog[v9] by Sukadev Bhattiprolu
Rebase to 4.0 and fix conflicts in:
tools/perf/tests/builtin-test.c
tools/perf/tests/tests.h
Changelog:
v2: Rename identifiers
v3: Only iterate cpu pmu to avoid bogus errors.
Move pmu iterator to extra patch
v4: Include aliases.c again
v5: Include util/debug.h

---
 tools/perf/Makefile.perf        |    1 +
 tools/perf/tests/aliases.c      |   59 +++++++++++++++++++++++++++++++++++++++
 tools/perf/tests/builtin-test.c |    4 +++
 tools/perf/tests/tests.h        |    1 +
 4 files changed, 65 insertions(+)
 create mode 100644 tools/perf/tests/aliases.c
tools/perf/Makefile.perf +1 -0
index d9c1a4c..d9c03c4 100644
@@ -456,6 +456,7 @@ endif
 LIB_OBJS += $(OUTPUT)tests/code-reading.o
 LIB_OBJS += $(OUTPUT)tests/sample-parsing.o
 LIB_OBJS += $(OUTPUT)tests/parse-no-sample-id-all.o
+LIB_OBJS += $(OUTPUT)tests/aliases.o
 ifndef NO_DWARF_UNWIND
 ifeq ($(ARCH),$(filter $(ARCH),x86 arm))
 LIB_OBJS += $(OUTPUT)tests/dwarf-unwind.o
tools/perf/tests/aliases.c new file +59 -0

59 lines not on this page · raw message

tools/perf/tests/builtin-test.c +4 -0
index 4b7d9ab..2324b1c 100644
@@ -167,6 +167,10 @@ static struct test {
 		.func = test__fdarray__add,
 	},
 	{
+		.desc = "Test parsing JSON aliases",
+		.func = test__aliases,
+	},
+	{
 		.func = NULL,
 	},
 };
tools/perf/tests/tests.h +1 -0
index 00e776a..ddce231 100644
@@ -51,6 +51,7 @@ int test__hists_cumulate(void);
 int test__switch_tracking(void);
 int test__fdarray__filter(void);
 int test__fdarray__add(void);
+int test__aliases(void);
 
 #if defined(__x86_64__) || defined(__i386__) || defined(__arm__)
 #ifdef HAVE_DWARF_UNWIND_SUPPORT
Signature · 1 line
1.7.9.5
#8 lore raw

PATCH v9 8/11 perf, tools: Add a new pmu interface to iterate over all events

In reply to Sukadev Bhattiprolu

From: Andi Kleen <[email protected]>

With calling a callback. To be used in test code added in the next patch.

---
Changelog[v9] by Sukadev Bhattiprolu
Rebase to 4.0 and fix conflicts in:
tools/perf/util/pmu.c
tools/perf/util/pmu.h

---
 tools/perf/util/pmu.c |   18 ++++++++++++++++++
 tools/perf/util/pmu.h |    1 +
 2 files changed, 19 insertions(+)
tools/perf/util/pmu.c +18 -0
index 2150455..82f7654 100644
@@ -1068,3 +1068,21 @@ int perf_pmu__scan_file(struct perf_pmu *pmu, const char *name, const char *fmt,
 	va_end(args);
 	return ret;
 }
+
+int pmu_iterate_events(int (*func)(const char *pmu, const char *name))
+{
+	int ret = 0;
+	struct perf_pmu *pmu;
+	struct perf_pmu_alias *alias;
+
+	perf_pmu__find("cpu"); /* Load PMUs */
+	pmu = NULL;
+	while ((pmu = perf_pmu__scan(pmu)) != NULL) {
+		list_for_each_entry(alias, &pmu->aliases, list) {
+			ret = func(pmu->name, alias->name);
+			if (ret != 0)
+				break;
+		}
+	}
+	return ret;
+}
tools/perf/util/pmu.h +1 -0
index f8dac0f..889cadf 100644
@@ -76,6 +76,7 @@ int perf_pmu__scan_file(struct perf_pmu *pmu, const char *name, const char *fmt,
 int perf_pmu__test(void);
 
 struct perf_event_attr *perf_pmu__get_default_config(struct perf_pmu *pmu);
+int pmu_iterate_events(int (*func)(const char *, const char *name));
 
 extern const char *json_file;
 #endif /* __PMU_H */
Signature · 1 line
1.7.9.5
#10 lore raw

PATCH v9 10/11 perf, tools: Add a --no-desc flag to perf list

In reply to 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.

Before:

% perf list
...
baclears.any [Counts the total number when the front end is
resteered, mainly when the BPU cannot provide a correct prediction and this is corrected by other branch handling mechanisms at the front end]
br_inst_exec.all_branches [Speculative and retired branches]

After:

% perf list --no-desc
...
baclears.any [Kernel PMU event]
br_inst_exec.all_branches [Kernel PMU event]

---
Changelog[v9] by Sukadev Bhattiprolu
Rebase to 4.0 and fix conflicts in
tools/perf/builtin-list.c
v2: Rename --quiet to --no-desc. Add option to man page.

---
 tools/perf/Documentation/perf-list.txt |    5 ++++-
 tools/perf/builtin-list.c              |   16 +++++++++++-----
 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(+), 12 deletions(-)
tools/perf/Documentation/perf-list.txt +4 -1
index 205ac40..7479efe 100644
@@ -8,7 +8,7 @@ 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
 -----------
@@ -23,6 +23,9 @@ automatically downloaded with perf download.
 The JSON event file can be also specified with the EVENTMAP environment
 variable.
 
+--no-desc::
+Don't print descriptions.
+
 
 [[EVENT_MODIFIERS]] EVENT MODIFIERS
 ---------------
tools/perf/builtin-list.c +11 -5
index fd07cc1..76dc23b 100644
@@ -16,6 +16,8 @@
 #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;
@@ -24,10 +26,12 @@ int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused)
 		OPT_BOOLEAN(0, "raw-dump", &raw_dump, "Dump raw events"),
 		OPT_STRING(0, "events-file", &json_file, "json file",
 			   "Read event json file"),
+		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 [--events-file FILE] [--no-desc] [hw|sw|cache|tracepoint|pmu|event_glob]",
 		NULL
 	};
 
@@ -39,12 +43,12 @@ int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused)
 	setup_pager();
 
 	if (raw_dump) {
-		print_events(NULL, true);
+		print_events(NULL, true, !desc_flag);
 		return 0;
 	}
 
 	if (argc == 0) {
-		print_events(NULL, false);
+		print_events(NULL, false, !desc_flag);
 		return 0;
 	}
 
@@ -63,13 +67,15 @@ int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused)
 			 strcmp(argv[i], "hwcache") == 0)
 			print_hwcache_events(NULL, false);
 		else if (strcmp(argv[i], "pmu") == 0)
-			print_pmu_events(NULL, false);
+			print_pmu_events(NULL, false, !desc_flag);
+		else if (strcmp(argv[i], "--raw-dump") == 0)
+			print_events(NULL, true, !desc_flag);
 		else {
 			char *sep = strchr(argv[i], ':'), *s;
 			int sep_idx;
 
 			if (sep == NULL) {
-				print_events(argv[i], false);
+				print_events(argv[i], false, !desc_flag);
 				continue;
 			}
 			sep_idx = sep - argv[i];
tools/perf/util/parse-events.c +2 -2
index 7f8ec6c..039ba78 100644
@@ -1336,7 +1336,7 @@ static void print_symbol_events(const char *event_glob, unsigned type,
 /*
  * 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 silent)
 {
 	if (!name_only) {
 		printf("\n");
@@ -1351,7 +1351,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, silent);
 
 	if (event_glob != NULL)
 		return;
tools/perf/util/parse-events.h +1 -1
index ff6e1fa..202f81b 100644
@@ -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);
 void print_events_type(u8 type);
 void print_tracepoint_events(const char *subsys_glob, const char *event_glob,
 			     bool name_only);
tools/perf/util/pmu.c +2 -2
index 82f7654..b3c1937 100644
@@ -930,7 +930,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;
@@ -992,7 +992,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 && printed)
 				printf("\n");
 			printf("  %-50s [", aliases[j].name);
tools/perf/util/pmu.h +1 -1
index 889cadf..5e375d6 100644
@@ -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
#11 lore raw

PATCH v9 11/11 perf-download: Download the events json file

In reply to Sukadev Bhattiprolu

Add a downloader to automatically download the right files from a download site.

This is implemented as a script calling curl, similar to perf archive. The perf driver automatically calls the right binary. The downloader is extensible, but currently only implements an Intel and Powerpc event download. It would be straightforward to add support for other architectures.

For now, there could be slight variations in how individual architectures organize the JSON files. Eg. Powerpc has a simple mapping from its PVR to cpu family eg power8's events file, which x86 uses, CPU vendor, family model to locate the specific file to download.

The downloaded event files are put into ~/.cache/pmu-events, where the builtin event parser in util/* can find them automatically.

Changelog[v9] (by Sukadev Bhattiprolu)
Add the perf-download script back into patchset. Set default download location to the tools/perf/pmu-events/ directory in Linus's tree.
Include code to parse/download powerpc JSON files. Remove Acked-by: Namhyung Kim since this patch has major changes

---
 tools/perf/Documentation/perf-download.txt |   31 +++++
 tools/perf/Documentation/perf-list.txt     |   12 +-
 tools/perf/Makefile.perf                   |    5 +-
 tools/perf/perf-download.sh                |  171 ++++++++++++++++++++++++++++
 4 files changed, 217 insertions(+), 2 deletions(-)
 create mode 100644 tools/perf/Documentation/perf-download.txt
 create mode 100755 tools/perf/perf-download.sh
tools/perf/Documentation/perf-download.txt new file +31 -0
new file mode 100644
index 0000000..9e5b28e
@@ -0,0 +1,31 @@
+perf-download(1)
+===============
+
+NAME
+----
+perf-download - Download event files for current CPU.
+
+SYNOPSIS
+--------
+[verse]
+'perf download' [vendor-family-model]
+
+DESCRIPTION
+-----------
+This command automatically downloads the event list for the current CPU and
+stores them in $XDG_CACHE_HOME/pmu-events (or $HOME/.cache/pmu-events).
+The other tools automatically look for them there. The CPU can be also
+specified at the command line.
+
+The downloading is done using http through wget, which needs
+to be installed. When behind a firewall the proxies
+may also need to be set up using "export https_proxy=...."
+
+The user should regularly call this to download updated event lists
+for the current CPU.
+
+Note the downloaded files are stored per user, so if perf is
+used as both normal user and with sudo the event files may
+also need to be moved to root's home directory with
+sudo mkdir /root/.cache ; sud cp -r ~/.cache/pmu-events /root/.cache
+after downloading.
tools/perf/Documentation/perf-list.txt +11 -1
index 7479efe..98637e8 100644
@@ -66,6 +66,16 @@ Sampling). Examples to use IBS:
  perf record -a -e r076:p ...          # same as -e cpu-cycles:p
  perf record -a -e r0C1:p ...          # use ibs op counting micro-ops
 
+PER CPU EVENT LISTS
+-------------------
+
+For some CPUs (particularly modern Intel CPUs) "perf download" can
+download additional CPU specific event definitions, which then
+become visible in perf list and available in the other perf tools.
+
+This obsoletes the raw event description method described below
+for most cases.
+
 RAW HARDWARE EVENT DESCRIPTOR
 -----------------------------
 Even when an event is not available in a symbolic form within perf right now,
@@ -141,6 +151,6 @@ types specified.
 SEE ALSO
 --------
 linkperf:perf-stat[1], linkperf:perf-top[1],
-linkperf:perf-record[1],
+linkperf:perf-record[1], linkperf:perf-download[1],
 http://www.intel.com/Assets/PDF/manual/253669.pdf[Intel® 64 and IA-32 Architectures Software Developer's Manual Volume 3B: System Programming Guide],
 http://support.amd.com/us/Processor_TechDocs/24593_APM_v2.pdf[AMD64 Architecture Programmer’s Manual Volume 2: System Programming]
tools/perf/Makefile.perf +4 -1
index d9c03c4..9f955b1 100644
@@ -136,6 +136,7 @@ SCRIPT_SH =
 
 SCRIPT_SH += perf-archive.sh
 SCRIPT_SH += perf-with-kcore.sh
+SCRIPT_SH += perf-download.sh
 
 grep-libs = $(filter -l%,$(1))
 strip-libs = $(filter-out -l%,$(1))
@@ -946,6 +947,8 @@ endif
 		$(INSTALL) $(OUTPUT)perf-archive -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)'
 	$(call QUIET_INSTALL, perf-with-kcore) \
 		$(INSTALL) $(OUTPUT)perf-with-kcore -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)'
+	$(call QUIET_INSTALL, perf-download) \
+		$(INSTALL) $(OUTPUT)perf-download -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)'
 ifndef NO_LIBPERL
 	$(call QUIET_INSTALL, perl-scripts) \
 		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl/Perf-Trace-Util/lib/Perf/Trace'; \
@@ -991,7 +994,7 @@ config-clean:
 	@$(MAKE) -C config/feature-checks clean >/dev/null
 
 clean: $(LIBTRACEEVENT)-clean $(LIBAPIKFS)-clean config-clean
-	$(call QUIET_CLEAN, core-objs)  $(RM) $(LIB_OBJS) $(BUILTIN_OBJS) $(LIB_FILE) $(OUTPUT)perf-archive $(OUTPUT)perf-with-kcore $(OUTPUT)perf.o $(LANG_BINDINGS) $(GTK_OBJS)
+	$(call QUIET_CLEAN, core-objs)  $(RM) $(LIB_OBJS) $(BUILTIN_OBJS) $(LIB_FILE) $(OUTPUT)perf-archive $(OUTPUT)perf-with-kcore $(OUTPUT)perf-download $(OUTPUT)perf.o $(LANG_BINDINGS) $(GTK_OBJS)
 	$(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)PERF-CFLAGS $(OUTPUT)PERF-FEATURES $(OUTPUT)util/*-bison* $(OUTPUT)util/*-flex*
 	$(QUIET_SUBDIR0)Documentation $(QUIET_SUBDIR1) clean
tools/perf/perf-download.sh new file +171 -0

171 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#12 lore raw

'perf upgrade' (was: Re: [PATCH v9 00/11] Add support for JSON event files.)

In reply to Sukadev Bhattiprolu
Quoted 5 lines · Sukadev Bhattiprolu

This is another attempt to resurrect Andi Kleen's patchset so users can specify perf events by their event names rather than raw codes.

This is a rebase of Andi Kleen's patchset from Jul 30, 2014[1] to 4.0. (I fixed minor and not so minor conflicts).

So this series shows some progress, but instead of this limited checkout ability I'd still prefer it if 'perf download' downloaded the latest perf code itself and built it - it shouldn't be limited to just a small subset of the perf source code!

There's a few Git tricks we can use to make this palatable on most systems.

To save disk space and network bandwith this could be done using Git's 'shallow clone' feature:

   git clone --depth 1 --bare

The initial checkout finishes in 1.5 minutes here, a continent away from korg. The resulting repository size is just 143MB.

The code could also check whether the user has already a ~/linux.git repository around, and use --reference ~/linux.git in that case. In such a case the cloning takes just 2 seconds.

To get the source code we could use Git's 'sparse checkout' feature:

git config core.sparsecheckout true
echo tools/ > .git/info/sparse-checkout
git checkout tools/

Note that a sparse checkout build will need a few relatively simple other files as well, for the few files not in tools/ that the perf build needs - mostly include files.

I've attached below a working test script that will create a buildable tools/perf/ repository into ~/.perf/git/ of the latest tip/perf/core tree from kernel.org.

With ~/linux.git primed it takes under 10 seconds to execute. perf builds fine in the directory. The whole directory together with the Git repo is 53 MB - that could be shrunk some more if needed.

If there's no local Linux repository to fall back on to then the initial step takes 1.5 minutes (depending on network bandwidth) and another 140MB for the Git objects. It's a lot faster after that.

That way 'perf download' could also be renamed to 'perf upgrade'.

Building perf ought to be possible even on fairly limited development systems and our auto-detection and library install suggestions are pretty good.

And note that once we have that there's no reason to move the event descriptions into a separate file - it can be part of the perf binary itself.

Quoted 3 lines

This patchset includes the perf-download tool that was dropped and sets the default download location to the (tools/perf/pmu-events/arch/... directory in Linus's tree.

So the way I think this would work best is for 'perf upgrade' to have different levels, similar to what the kernel has:

  perf upgrade devel               # pick files up from Arnaldo's korg tree
  perf upgrade next                # pick files up from tip.git on korg
  perf upgrade rc                  # pick files up from linus's Git tree
  perf upgrade stable              # pick files up the latest -stable version

'perf upgrade' would default to the most conservative, -stable variant, but of course users could pick whichever variant they prefer.

There's some limitations (such as if the build fails - but we want to fix such cases anyway), but note the fundamental power of this
approach: 'perf upgrade' could turn any developer who has a perf binary into a perf tester and even into a contributor.

There's no need to even know Git or other development details - the latest code could be picked up and built.

'perf upgrade distro' could be offered as a way to downgrade to whatever previous (distro) perf version the user was using.

Likewise, later on this approach could be generalized into tools/build/ to enable self-hosting for other tools in tools/ as well, if they so desire.

Thanks,

Ingo

============================>
#!/bin/bash
#
# Simple script that fetches the 'perf' utility from Linus's tree, builds and

# installs it, by creating a shallow clone and a sparse checkout for Linux's
# tools/ directory and related dependencies:
#

DIR=~/.perf/git

rm -rf $DIR
mkdir -p $DIR || { echo 'error: No write permissions in the current directory?'; exit -1; } cd $DIR

#REPO=git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git #BRANCH=HEAD REPO=git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git BRANCH=perf/core

REFERENCE="."
[ -d ~/linux/.git ] && REFERENCE=~/linux/
[ -d ~/linux.git/.git ] && REFERENCE=~/linux.git/
[ -d ~/tip/.git ] && REFERENCE=~/tip/
[ -d ~/tip.git/.git ] && REFERENCE=~/tip.git/

git clone --reference $REFERENCE --depth 1 --bare $REPO --branch $BRANCH .git git config --local core.bare false

git config --local core.sparseCheckout true
git remote remove origin
git remote add -f origin $REPO -t $BRANCH

(
echo '/tools/*'
echo '/lib/*'
echo '/include/*'
echo '/arch/x86/lib/*'
echo '/arch/x86/include/*'
echo 'Makefile'
echo '/scripts/*'

) > .git/info/sparse-checkout

git checkout $BRANCH

make -C tools/perf/ install

#13 lore raw

Re: 'perf upgrade' (was: Re: [PATCH v9 00/11] Add support for JSON event files.)

Quoted 5 lines · Ingo Molnar
Quoted 3 lines · Sukadev Bhattiprolu

This is another attempt to resurrect Andi Kleen's patchset so users can specify perf events by their event names rather than raw codes.

Quoted 7 lines
Quoted 2 lines

This is a rebase of Andi Kleen's patchset from Jul 30, 2014[1] to 4.0. (I fixed minor and not so minor conflicts).

So this series shows some progress, but instead of this limited checkout ability I'd still prefer it if 'perf download' downloaded the latest perf code itself and built it - it shouldn't be limited to just a small subset of the perf source code!

Ingo, can you please stop blocking this? It's getting ridiculous.

We've been waiting over 8 months for this to go in.

While we've been waiting most of our users have learnt to use operf instead, which doesn't require raw codes.

I would also add that exactly zero users have asked for a feature where perf downloads and rebuilds itself. In fact many of them would consider that a security breach.

cheers

#14 lore raw

Re: 'perf upgrade' (was: Re: [PATCH v9 00/11] Add support for JSON event files.)

Quoted 9 lines · Michael Ellerman
Quoted 8 lines · Ingo Molnar
Quoted 5 lines · Sukadev Bhattiprolu

This is another attempt to resurrect Andi Kleen's patchset so users can specify perf events by their event names rather than raw codes.

This is a rebase of Andi Kleen's patchset from Jul 30, 2014[1] to 4.0. (I fixed minor and not so minor conflicts).

Quoted 8 lines
Quoted 4 lines

So this series shows some progress, but instead of this limited checkout ability I'd still prefer it if 'perf download' downloaded the latest perf code itself and built it - it shouldn't be limited to just a small subset of the perf source code!

Ingo, can you please stop blocking this? It's getting ridiculous.

We've been waiting over 8 months for this to go in.

We just merged a patch series that was first sent in 2013. Some things take time to get right.

Quoted 6 lines

While we've been waiting most of our users have learnt to use operf instead, which doesn't require raw codes.

I would also add that exactly zero users have asked for a feature where perf downloads and rebuilds itself. In fact many of them would consider that a security breach.

Fetching tracing scripts, plugins or other instrumentation scripts can be considered a 'security breach' as well. Fetching external tables (or network access to begin with) can be considered a 'security breach' as well, depending on how restricted an environment is.

But we don't design our code based on the most restrictive environments that are hostile to open source concepts!

Unfortunate users that are not allowed to update open source code that they are using should probably not update it. The other 99.9% of perf users would benefit from a properly done upgrading/updating feature.

Please stop thinking in terms of restricted, closed environments. Packaged perf will still work fine for them, and changes will still trickle down to them.

Thanks,

Ingo

#24 lore raw

Re: 'perf upgrade' (was: Re: [PATCH v9 00/11] Add support for JSON event files.)

In reply to Ingo Molnar
Quoted 6 lines · Ingo Molnar
Quoted 3 lines · Sukadev Bhattiprolu

This is another attempt to resurrect Andi Kleen's patchset so users can specify perf events by their event names rather than raw codes.

Quoted 7 lines
Quoted 2 lines

This is a rebase of Andi Kleen's patchset from Jul 30, 2014[1] to 4.0. (I fixed minor and not so minor conflicts).

So this series shows some progress, but instead of this limited checkout ability I'd still prefer it if 'perf download' downloaded the latest perf code itself and built it - it shouldn't be limited to just a small subset of the perf source code!

I'm not against that idea (and can see it being useful in some cases[1]), but this would need some authentication.

Otherwise it would be a "$bigbrother/nsa/anyone controling your network can run everything on your computer" style hole.

The original JSON files don't have this problem because they didn't contain any code.

-Andi

[1] especially to work around the broken perf setup on d./u. distros.

#15 lore raw

Re: 'perf upgrade' (was: Re: [PATCH v9 00/11] Add support for JSON event files.)

In reply to Ingo Molnar
Quoted 16 lines · Ingo Molnar
Quoted 14 lines · Michael Ellerman
Quoted 12 lines · Ingo Molnar
Quoted 5 lines · Sukadev Bhattiprolu

This is another attempt to resurrect Andi Kleen's patchset so users can specify perf events by their event names rather than raw codes.

This is a rebase of Andi Kleen's patchset from Jul 30, 2014[1] to 4.0. (I fixed minor and not so minor conflicts).

So this series shows some progress, but instead of this limited checkout ability I'd still prefer it if 'perf download' downloaded the latest perf code itself and built it - it shouldn't be limited to just a small subset of the perf source code!

Quoted 6 lines
Quoted 3 lines

Ingo, can you please stop blocking this? It's getting ridiculous.

We've been waiting over 8 months for this to go in.

We just merged a patch series that was first sent in 2013. Some things take time to get right.

The first attempt to get symbolic event name support into perf was sent in 2010, that's FIVE years ago [1].

And what complicated feature are we asking for? The ability to map a human readable name to a hex code, it has the complexity of a first year programming assignment.

Variations have been submitted by IBM [1], by Facebook [2], now by Intel, and Google have just given up and carry the libpfm4 patch in their perf tool [3].

Can we please just get this merged.

If you *then* want to add support for perf auto-updating that's fine, but don't conflate the two.

cheers

[1]: https://lkml.org/lkml/2010/3/11/146
[2]: http://article.gmane.org/gmane.comp.linux.perfmon2.devel/2912
[3]: https://github.com/David-Levinthal/gooda/blob/master/gooda-analyzer/perf-patches/linux-v3.17/0001-perf-tools-add-support-for-libpfm4.patch

#16 lore raw

Re: 'perf upgrade' (was: Re: [PATCH v9 00/11] Add support for JSON event files.)

Quoted 5 lines · Michael Ellerman
Quoted 2 lines

We just merged a patch series that was first sent in 2013. Some things take time to get right.

The first attempt to get symbolic event name support into perf was sent in 2010, that's FIVE years ago [1].

kgdb took even longer, I think it was first proposed before 2000, over 10 years before it got merged?

fs/overlayfs/ took similarly long I think, the first (Unionfs) patches I remember were from around 2003 - 11 years before the functionality was merged?

Quoted 3 lines

And what complicated feature are we asking for? The ability to map a human readable name to a hex code, it has the complexity of a first year programming assignment.

No, what you are asking for, and which I NAK-ed, is:

- to add a very limited 'update perf' capability which only updates a single issue that you care about, with no ability to do more. The 'perf upgrade' prototype I sent can update all or part of perf. (The latest version is attached further below.)

- to break the 'single binary' property of perf that many people rely on

- to add JSON parsing overhead to every invocation of perf instead of pre-parsing the event tables at build time and putting them into a nice data structure.

- to blindly follow some poorly constructed vendor format with no high level structure, that IMHO didn't work very well when OProfile was written, and misrepresenting it as 'symbolic event names'.

Take a look at:

     https://download.01.org/perfmon/HSW/Haswell_core_V17.json

and weep. How is one supposed to see the higher level structure of the events with a format like that?

- to add an ABI to support those vendor files

And those are IMHO five good technical reasons to disagree with your approach.

My suggestion to resolve the technical objections and lift the NAK would be:

- to add the tables to the source code, in a more human readable format and (optionally) structure the event names better into a higher level hierarchy, than the humungous linear dumps with no explanations that you propose - while still supporting the 'raw' vendor event names you want to use, for those people who are used to them.

- to pre-parse the event descriptions at build time - beyond the speedup this also keeps the 'single binary' property of perf.

- to upgrade perf as a whole unit: this helps not just your usecase but many other usecases as well.

For those who only want to update event tables: with 'perf upgrade stable' basically only new event tables (backported to -stable) would be picked up, plus regression fixes: it pretty much does what your proposed 'perf download' solution does, except it's much more capable.

Saying 'no' and suggesting better solutions is my job as a maintainer.

Thanks,

Ingo

======={ perf-upgrade.sh }===========>

#!/bin/bash
#
# Simple script that fetches the 'perf' utility from Linus's tree, builds and

# installs it, by creating a shallow clone and a sparse checkout for Linux's
# tools/ directory and related dependencies:
#

DIR=~/.perf/git

rm -rf $DIR
mkdir -p $DIR || { echo 'error: No write permissions in the current directory?'; exit -1; } cd $DIR

#REPO=git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git #BRANCH=HEAD REPO=git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git BRANCH=perf/core

REFERENCE="."
[ -d ~/linux/.git ] && REFERENCE=~/linux/
[ -d ~/linux.git/.git ] && REFERENCE=~/linux.git/

[ -d ~/tip/.git       ] && REFERENCE=~/tip/
[ -d ~/tip.git/.git   ] && REFERENCE=~/tip.git/
[ -d ~/git/linux      ] && REFERENCE=~/git/linux/

git clone --reference $REFERENCE --depth 1 --bare $REPO --branch $BRANCH .git git config --local core.bare false

git config --local core.sparseCheckout true
git remote remove origin
git remote add -f origin $REPO -t $BRANCH

(
echo '/tools/*'
echo '/lib/*'
echo '/include/*'
echo '/arch/x86/lib/*'
echo '/arch/x86/include/*'
echo 'Makefile'
echo '/scripts/*'

) > .git/info/sparse-checkout

git checkout $BRANCH

make -C tools/perf/ install

#17 lore raw

Re: 'perf upgrade' (was: Re: [PATCH v9 00/11] Add support for JSON event files.)

Quoted 9 lines

My suggestion to resolve the technical objections and lift the NAK would be:

- to add the tables to the source code, in a more human readable format and (optionally) structure the event names better into a higher level hierarchy, than the humungous linear dumps with no explanations that you propose - while still supporting the 'raw' vendor event names you want to use, for those people who are used to them.

Trying to understand what you mean with high level hierarchy:

Do you mean something like the oprofile event / unit mask split, with events having a default unit mask?

This one actually works poorly for modern Intel systems, as
unit masks can completely change the behavior, so there is
not necessarily a direct relation between the name before the dot and the one after, or a concept of a "default" unit mask.

Or do you mean someone creating a tree hierarchy of events to systematically debug some particular problem?

I implemented this in my toplev tool here:
https://github.com/andikleen/pmu-tools/wiki/toplev-manual
http://github.com/andikleen/pmu-tools

But it's quite complicated and cannot really be done portable in a full way without completely turning perf into an architecture specific tool (which I assume you're opposed to)

Or just some sections grouping events into different topics? "branches", "caches", "execution" or somesuch.

I think this could be done with the JSON format. Just add a new header. Print them as sections in perf list.

Or do you mean something like the perf cache events tables? We already have those. But they cannot replace direct micro architectural specific events, as the cache event tables do not necessarily express everything a given micro architecture supports. And also there is a lot of documentation using the vendor event names, which the users then want to use.

If it's something else please explain.

Quoted 3 lines

- to pre-parse the event descriptions at build time - beyond the speedup

FWIW I just measured it and the overhead parse time for the haswell JSON file on my laptop is about 33ms.

# with event map
% time ./obj-perf/perf list > /dev/null
real    0m0.045s
user    0m0.041s
sys     0m0.003s

% export EVENTMAP=/dev/zero
% time perf list > /dev/null

real    0m0.011s
user    0m0.004s
sys     0m0.006s
Quoted 2 lines

- to upgrade perf as a whole unit: this helps not just your usecase but many other usecases as well.

With the downloader it actually automatically downloads any missing files, so the upgrading just works.

-Andi

#18 lore raw

Re: 'perf upgrade' (was: Re: [PATCH v9 00/11] Add support for JSON event files.)

In reply to Ingo Molnar
| 
| * Michael Ellerman <[email protected]> wrote:
| 
| > > We just merged a patch series that was first sent in 2013. Some 
| > > things take time to get right.
| > 
| > The first attempt to get symbolic event name support into perf was 
| > sent in 2010, that's FIVE years ago [1].
| 
| kgdb took even longer, I think it was first proposed before 2000, over 
| 10 years before it got merged?
| 
| fs/overlayfs/ took similarly long I think, the first (Unionfs) patches 
| I remember were from around 2003 - 11 years before the functionality 
| was merged?
| 
| > And what complicated feature are we asking for? The ability to map a 
| > human readable name to a hex code, it has the complexity of a first 
| > year programming assignment.
| 
| No, what you are asking for, and which I NAK-ed, is:
| 
|  - to add a very limited 'update perf' capability which only updates a
|    single issue that you care about, with no ability to do more.

Yes, we are trying to solve one really annoying problem without precluding the ability to do more (aka leave things better than they are even if we can't solve everything).

Besides, I thought the discussion was where to host the JSON files. I was not aware of the requirement to download/rebuild perf or not use JSON at all (i.e generate data structures during build?).

|    The 'perf upgrade' prototype I sent can update all or part of perf. 
|    (The latest version is attached further below.)
| 
|  - to break the 'single binary' property of perf that many people rely on

Thats the part, I am having trouble with.

If the JSON files are like /etc/perfconfig, we don't need to rebuild the binary when a config file changes right?

Second, if I build perf on my Power8 box, would the perf binary only include events on my specific revision of the CPU or all Power8 versions? Would the perf binary from Power8 include events from all revisions of Power7 and Power8?

If we include all possible revisions of the CPU, we would bloat perf.

If not we break the ability/convenience of copying rpms from one system to the other? And we need to rebuild perf if the CPU on my system is replaced and there are a couple of new event codes in the new CPU?

| 
|  - to add JSON parsing overhead to every invocation of perf instead of
|    pre-parsing the event tables at build time and putting them into 
|    a nice data structure.
| 
|  - to blindly follow some poorly constructed vendor format with no 
|    high level structure, that IMHO didn't work very well when OProfile 
|    was written, and misrepresenting it as 'symbolic event names'.
| 
|    Take a look at:
| 
|      https://download.01.org/perfmon/HSW/Haswell_core_V17.json
| 
|    and weep.

Evil vendor formats, but to be fair, here is what _we_ have today:

	perf stat -e r10068,r20036,r40060,r40ac sleep 1

	 Performance counter stats for 'sleep 1':

		   554,608      r10068                                                      
		    47,948      r20036                                                      
		   491,084      r40060                                                      
		       249      r40ac                                                       

	       1.001561257 seconds time elapsed

| How is one supposed to see the higher level structure of
| the events with a format like that?

True, having events like 'cycles', 'branches' makes sense, but there are so many different flavors of "run cycles" events in just Power8.

    PM_ANY_THRD_RUN_CYC,
    PM_MRK_RUN_CYC,
    PM_RUN_CYC,
    PM_RUN_CYC_SMT2_MODE,
    PM_RUN_CYC_SMT2_SHRD_MODE,
    PM_RUN_CYC_SMT2_SPLIT_MODE,
    PM_RUN_CYC_SMT4_MODE,
    PM_RUN_CYC_SMT8_MODE,
    PM_RUN_CYC_ST_MODE,
    PM_THRD_ALL_RUN_CYC,
    PM_TM_TRANS_RUN_CYC,
    PM_TM_TX_PASS_RUN_CYC,

Are we trying to build a high level structures across architectures?

| 
|  - to add an ABI to support those vendor files
| 
| And those are IMHO five good technical reasons to disagree with your 
| approach.
| 
| My suggestion to resolve the technical objections and lift the NAK 
| would be:
| 
|  - to add the tables to the source code, in a more human readable 
|    format and (optionally) structure the event names better into a 
|    higher level hierarchy, than the humungous linear dumps with no 
|    explanations that you propose - while still supporting the 'raw' 
|    vendor event names you want to use, for those people who are used 
|    to them.
| 

A bit confused.

Have the JSON files in the tree and generate the C structure during build?

Or, ditch the JSON files and add something like this in say, tools/perf/arch/powerpc/util/power8-events.h?

static const  struct events power8_events[] = {
    [ 0 ] = {
        .name = "PM_1LPAR_CYC",
        .code = 0x1f05e,
        .brief_desc = " "Number of cycles in single lpar mode. All threads in the core are assigned to the same lpar,",
        .public_desc = "Number of cycles in single lpar mode.,",
      },

If we have the JSON files, would the 'make install' put the JSON files in ~/.cache/pmu-events or in a standard location?

|  - to pre-parse the event descriptions at build time - beyond the 
|    speedup this also keeps the 'single binary' property of perf.
| 
|  - to upgrade perf as a whole unit: this helps not just your usecase
|    but many other usecases as well.

I will try the perf upgrade below, but the only clear use case I have is for the event files. I am a little confused about the use case for downloading and rebuilding perf.

Building perf requires more packages than simply running perf. Most users just run perf without needing to rebuild.

Running perf doesn't require root access but if we want to install JSON files in standard locations (to get latest event codes for instance) we will need root access.

Or should ~/.cache/pmu-events/*.json complement the event codes builtin to the perf binary?

Sukadev

#23 lore raw

Re: 'perf upgrade' (was: Re: [PATCH v9 00/11] Add support for JSON event files.)

In reply to Ingo Molnar

Ingo Molnar [[email protected]] wrote:

Meant to Cc Tom Huynh as they had a related patchset a few months ago.

| 
| * Michael Ellerman <[email protected]> wrote:
| 
| > On Tue, 2015-04-14 at 10:55 +0200, Ingo Molnar wrote:
| > > * Sukadev Bhattiprolu <[email protected]> wrote:
| > > 
| > > > This is another attempt to resurrect Andi Kleen's patchset so users
| > > > can specify perf events by their event names rather than raw codes.
| > > > 
| > > > This is a rebase of Andi Kleen's patchset from Jul 30, 2014[1] to 4.0.
| > > > (I fixed minor and not so minor conflicts).
| > > 
| > > So this series shows some progress, but instead of this limited 
| > > checkout ability I'd still prefer it if 'perf download' downloaded 
| > > the latest perf code itself and built it - it shouldn't be limited 
| > > to just a small subset of the perf source code!
| > 
| > Ingo, can you please stop blocking this? It's getting ridiculous.
| > 
| > We've been waiting over 8 months for this to go in.
| 
| We just merged a patch series that was first sent in 2013. Some things 
| take time to get right.

I used to rebuild git years ago to work around bugs in rebase, but rarely need to rebuild these days, because it is stable. I am guessing it is the same for most users of perf.

IOW, perf download/upgrade can be extended to fetch and build, but dont' understand why that is _required_ to _use_ the JSON files.

- perf having an ability to parse JSON files
- perf downloading JSON files
- perf downloading latest source code
- perf downloading dependent RPMS/packages to build (which seem to be tied to distros)

all seem like independent steps to me. If current design can be tweaked to not constrain future choices, we should definitely do that.

If not, can we make incremental progress on this?

If necessary, we could add an option to 'perf upgrade' to fetch only the JSON files? Or by default, 'perf upgrade' can assume --all and download everything it can download.

In the future we can add --json-files, --sources etc and still ahve --all fetch everything it can.

Sukadev

#19 lore raw

Re: 'perf upgrade' (was: Re: [PATCH v9 00/11] Add support for JSON event files.)

In reply to Sukadev Bhattiprolu

On Wed, Apr 15, 2015 at 01:50:42PM -0700, Sukadev Bhattiprolu wrote:

SNIP

Quoted 11 lines
| 
|  - to blindly follow some poorly constructed vendor format with no 
|    high level structure, that IMHO didn't work very well when OProfile 
|    was written, and misrepresenting it as 'symbolic event names'.
| 
|    Take a look at:
| 
|      https://download.01.org/perfmon/HSW/Haswell_core_V17.json
| 
|    and weep.
Quoted 3 lines

Evil vendor formats, but to be fair, here is what _we_ have today:

	perf stat -e r10068,r20036,r40060,r40ac sleep 1

hum, you could also use the 'cpu/event=.../' syntax right? It's not symbolic name, just to be fair ;-)

jirka

#20 lore raw

Re: 'perf upgrade' (was: Re: [PATCH v9 00/11] Add support for JSON event files.)

Quoted 15 lines · Jiri Olsa

On Wed, Apr 15, 2015 at 01:50:42PM -0700, Sukadev Bhattiprolu wrote:

SNIP

Quoted 11 lines
| 
|  - to blindly follow some poorly constructed vendor format with no 
|    high level structure, that IMHO didn't work very well when OProfile 
|    was written, and misrepresenting it as 'symbolic event names'.
| 
|    Take a look at:
| 
|      https://download.01.org/perfmon/HSW/Haswell_core_V17.json
| 
|    and weep.
Quoted 5 lines
Quoted 3 lines

Evil vendor formats, but to be fair, here is what _we_ have today:

	perf stat -e r10068,r20036,r40060,r40ac sleep 1

hum, you could also use the 'cpu/event=.../' syntax right?

That's even worse -- same hex numbers, just more redundancy.

All the other profilers support symbolic names, which is what users want.

-Andi

Signature · 1 line
[email protected] -- Speaking for myself only
#21 lore raw

Re: 'perf upgrade' (was: Re: [PATCH v9 00/11] Add support for JSON event files.)

Quoted 16 lines · Andi Kleen
Quoted 15 lines · Jiri Olsa

On Wed, Apr 15, 2015 at 01:50:42PM -0700, Sukadev Bhattiprolu wrote:

SNIP

Quoted 11 lines
| 
|  - to blindly follow some poorly constructed vendor format with no 
|    high level structure, that IMHO didn't work very well when OProfile 
|    was written, and misrepresenting it as 'symbolic event names'.
| 
|    Take a look at:
| 
|      https://download.01.org/perfmon/HSW/Haswell_core_V17.json
| 
|    and weep.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Evil vendor formats, but to be fair, here is what _we_ have today:

	perf stat -e r10068,r20036,r40060,r40ac sleep 1

hum, you could also use the 'cpu/event=.../' syntax right?

That's even worse -- same hex numbers, just more redundancy.

no, it's far more readable then the rXXXX format, you can just put in whatevent is in the spec.. event,umask,any etc and dont bother with making rXXXX value

but I mentioned it just to give the whole picture, I agree that we need the symbolic names support

jirka

#22 lore raw

Re: 'perf upgrade' (was: Re: [PATCH v9 00/11] Add support for JSON event files.)

In reply to Sukadev Bhattiprolu

On Wed, Apr 15, 2015 at 01:50:42PM -0700, Sukadev Bhattiprolu wrote:

SNIP

Quoted 34 lines
| 
|  - to add an ABI to support those vendor files
| 
| And those are IMHO five good technical reasons to disagree with your 
| approach.
| 
| My suggestion to resolve the technical objections and lift the NAK 
| would be:
| 
|  - to add the tables to the source code, in a more human readable 
|    format and (optionally) structure the event names better into a 
|    higher level hierarchy, than the humungous linear dumps with no 
|    explanations that you propose - while still supporting the 'raw' 
|    vendor event names you want to use, for those people who are used 
|    to them.
| 

A bit confused.

Have the JSON files in the tree and generate the C structure during build?

Or, ditch the JSON files and add something like this in say, tools/perf/arch/powerpc/util/power8-events.h?

static const  struct events power8_events[] = {
    [ 0 ] = {
        .name = "PM_1LPAR_CYC",
        .code = 0x1f05e,
        .brief_desc = " "Number of cycles in single lpar mode. All threads in the core are assigned to the same lpar,",
        .public_desc = "Number of cycles in single lpar mode.,",
      },
Quoted 2 lines

If we have the JSON files, would the 'make install' put the JSON files in ~/.cache/pmu-events or in a standard location?

IIUC the intention is not to have external event data files but have them compiled into perf binary.. like we could have JSON with events description under perf source and build it into 'struct perf_pmu_alias' data duting the build..

the pmu.c alias logic would need a little adjustments, but it seems doable to me

jirka