Skip to contentSkip to conversation

perf/core improvements and fixes

GIT PULL New Arnaldo Carvalho de Melo 2 participants 12 messages Aug 28, 2015 – Aug 31, 2015 perf events

lore
Share & tools
lore

Arnaldo Carvalho de Melo

author maintainer
#0 lore raw

From: Arnaldo Carvalho de Melo <[email protected]

Hi Ingo,

Please consider pulling,

- Arnaldo

The following changes since commit d1ee8bc195ffedbf91af0245a2406d6ebd2578f8:

Merge tag 'perf-core-for-mingo' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/core (2015-08-28 08:22:02 +0200)

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git tags/perf-core-for-mingo

for you to fetch changes up to 2c07144dfce366e21465cc7b0ada9f0b6dc7b7ed:

perf evlist: Add backpointer for perf_env to evlist (2015-08-28 14:54:14 -0300)

----------------------------------------------------------------
perf/core improvement and fixes:

User visible:

- Add new compaction-times python script (Tony Jones)

- Make the --[no-]-demangle/--[no-]-demangle-kernel command line options available in 'perf script' too (Mark Drayton)

- Allow for negative numbers in libtraceevent's print format, fixing up misformatting in some tracepoints (Steven Rostedt)

Infrastructure:

- perf_env/perf_evlist changes to allow accessing the data structure with the environment where some perf data was collected in functions not necessarily related to perf.data file processing (Kan Liang)

- Cleanups for the tracepoint definition location paths routines (Jiri Olsa)

- Introduce sysfs/filename__sprintf_build_id, removing code duplication (Masami Hiramatsu)

----------------------------------------------------------------
Arnaldo Carvalho de Melo (2):
perf trace: Add header with copyright and background info perf evsel: Add a backpointer to the evlist a evsel is in

Jiri Olsa (2):
perf tools: Add tracing_path and remove unneeded functions perf tools: Do not change lib/api/fs/debugfs directly

Kan Liang (2):
perf tools: Rename perf_session_env to perf_env perf evlist: Add backpointer for perf_env to evlist

Mark Drayton (1):

      perf script: Add --[no-]-demangle/--[no-]-demangle-kernel

Masami Hiramatsu (1):
perf buildid: Introduce sysfs/filename__sprintf_build_id

Steven Rostedt (1):
tools lib traceeveent: Allow for negative numbers in print format

Tony Jones (1):
perf scripts python: Add new compaction-times script

 tools/lib/traceevent/event-parse.c                 |   1 +
 tools/perf/Documentation/perf-script.txt           |   7 +
 tools/perf/arch/common.c                           |   4 +-
 tools/perf/arch/common.h                           |   2 +-
 tools/perf/builtin-buildid-cache.c                 |  14 +-
 tools/perf/builtin-buildid-list.c                  |  24 +-
 tools/perf/builtin-script.c                        |   5 +
 tools/perf/builtin-trace.c                         |  19 ++
 tools/perf/perf.c                                  |   2 +-
 .../scripts/python/bin/compaction-times-record     |   2 +
 .../scripts/python/bin/compaction-times-report     |   4 +
 tools/perf/scripts/python/compaction-times.py      | 311 +++++++++++++++++++++
 tools/perf/ui/browser.h                            |   4 +-
 tools/perf/ui/browsers/header.c                    |   2 +-
 tools/perf/ui/browsers/hists.c                     |  12 +-
 tools/perf/util/build-id.c                         |  32 +++
 tools/perf/util/build-id.h                         |   3 +
 tools/perf/util/evlist.c                           |   2 +
 tools/perf/util/evlist.h                           |   1 +
 tools/perf/util/evsel.c                            |   2 +
 tools/perf/util/evsel.h                            |   4 +
 tools/perf/util/header.c                           |   1 +
 tools/perf/util/header.h                           |   4 +-
 tools/perf/util/hist.h                             |   4 +-
 tools/perf/util/session.c                          |   2 +-
 tools/perf/util/symbol.c                           |   4 +-
 tools/perf/util/symbol.h                           |   4 +-
 tools/perf/util/util.c                             |  57 +---
 tools/perf/util/util.h                             |   2 +-
 29 files changed, 433 insertions(+), 102 deletions(-)
 create mode 100644 tools/perf/scripts/python/bin/compaction-times-record
 create mode 100644 tools/perf/scripts/python/bin/compaction-times-report
 create mode 100644 tools/perf/scripts/python/compaction-times.py
author maintainer
#1 lore raw

PATCH 1/10 perf script: Add --[no-]-demangle/--[no-]-demangle-kernel

From: Mark Drayton <[email protected]>

Sometimes when post-processing output from perf script one does not want to demangle C++ symbol names. Add an option to allow this.

Also add --[no-]demangle-kernel to be consistent with top/report/probe.

---
 tools/perf/Documentation/perf-script.txt | 7 +++++++
 tools/perf/builtin-script.c              | 5 +++++
 2 files changed, 12 insertions(+)
tools/perf/Documentation/perf-script.txt +7 -0
index c0d24791a7f3..614b2c7b0293 100644
@@ -226,6 +226,13 @@ OPTIONS
 	Display context switch events i.e. events of type PERF_RECORD_SWITCH or
 	PERF_RECORD_SWITCH_CPU_WIDE.
 
+--demangle::
+	Demangle symbol names to human readable form. It's enabled by default,
+	disable with --no-demangle.
+
+--demangle-kernel::
+	Demangle kernel symbol names to human readable form (for C++ kernels).
+
 --header
 	Show perf.data header.
 
tools/perf/builtin-script.c +5 -0
index 105332e950a9..4430340292c0 100644
@@ -1671,6 +1671,11 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
 			    itrace_parse_synth_opts),
 	OPT_BOOLEAN(0, "full-source-path", &srcline_full_filename,
 			"Show full source file name path for source lines"),
+	OPT_BOOLEAN(0, "demangle", &symbol_conf.demangle,
+			"Enable symbol demangling"),
+	OPT_BOOLEAN(0, "demangle-kernel", &symbol_conf.demangle_kernel,
+			"Enable kernel symbol demangling"),
+
 	OPT_END()
 	};
 	const char * const script_subcommands[] = { "record", "report", NULL };
Signature · 1 line
2.1.0
author maintainer
#2 lore raw

PATCH 2/10 tools lib traceeveent: Allow for negative numbers in print format

In reply to Arnaldo Carvalho de Melo

From: Steven Rostedt <[email protected]>

It was reported that "%-8s" does not parse well when used in the printk format. The '-' is what is throwing it off. Allow that to be included.

Reporter note:

Example before:

transhuge-stres-10730 [004] 5897.713989: mm_compaction_finished: node=0 zone=>-<8s order=-2119871790 ret=

Example after:

transhuge-stres-4235 [000] 453.149280: mm_compaction_finished: node=0
zone=ffffffff81815d7a order=9 ret=

(I will send patches to fix the string handling in the tracepoints so it's on par with in-kernel printing via trace_pipe:)

transhuge-stres-10921 [007] ...1 6307.140205: mm_compaction_finished: node=0
zone=Normal order=9 ret=partial

---
 tools/lib/traceevent/event-parse.c | 1 +
 1 file changed, 1 insertion(+)
tools/lib/traceevent/event-parse.c +1 -0
index 5c1867a13ef2..4d885934b919 100644
@@ -4828,6 +4828,7 @@ static void pretty_print(struct trace_seq *s, void *data, int size, struct event
 			case 'z':
 			case 'Z':
 			case '0' ... '9':
+			case '-':
 				goto cont_process;
 			case 'p':
 				if (pevent->long_size == 4)
Signature · 1 line
2.1.0
author maintainer
#3 lore raw

PATCH 3/10 perf scripts python: Add new compaction-times script

In reply to Arnaldo Carvalho de Melo

From: Tony Jones <[email protected]>

This patch creates a new script (compaction-times) to report time spent in mm compaction. It is possible to report times in nanoseconds (default) or microseconds (-u).

The option -p will break down results by process id, -pv will further decompose by each compaction entry/exit.

For each compaction entry/exit what is reported is controlled by the options:

  -t   report only timing
  -m   report migration stats
  -ms  report migration scanner stats
  -fs  report free scanner stats

The default is to report all.

Entries may be further filtered by pid, pid-range or comm (regex).

The script is useful when analysing workloads that compact memory. The most common example will be THP allocations on systems with a lot of uptime that has fragmented memory.

This is an example of using the script to analyse a thpscale from mmtests which deliberately fragments memory and allocates THP in 4 separate threads

# Recording step, one of the following;

  $ perf record -e 'compaction:mm_compaction_*' ./workload
  # or:
  $ perf script record compaction-times

# Reporting: basic
total: 2444505743ns migration: moved=357738 failed=39275
free_scanner: scanned=2705578 isolated=387875
migration_scanner: scanned=414426 isolated=397013

# Reporting: Per task stall times

  $ perf script report compaction-times -- -t -p
  total: 2444505743ns
  6384[thpscale]: 740800017ns
  6385[thpscale]: 274119512ns
  6386[thpscale]: 832961337ns
  6383[thpscale]: 596624877ns

# Reporting: Per-compaction attempts for task 6385

  $ perf script report compaction-times -- -m -pv 6385
  total: 274119512ns migration: moved=14893 failed=24285
  6385[thpscale]: 274119512ns migration: moved=14893 failed=24285
  6385[thpscale].1: 3033277ns migration: moved=511 failed=1
  6385[thpscale].2: 9592094ns migration: moved=1524 failed=12
  6385[thpscale].3: 2495587ns migration: moved=512 failed=0
  6385[thpscale].4: 2561766ns migration: moved=512 failed=0
  6385[thpscale].5: 2523521ns migration: moved=512 failed=0
  ..... output continues ...

Changes since v1:
- report stats for isolate_migratepages and isolate_freepages (Vlastimil Babka)
- refactor code to achieve above
- add help text
- output to stdout/stderr explicitly

---
 .../scripts/python/bin/compaction-times-record     |   2 +
 .../scripts/python/bin/compaction-times-report     |   4 +
 tools/perf/scripts/python/compaction-times.py      | 311 +++++++++++++++++++++
 3 files changed, 317 insertions(+)
 create mode 100644 tools/perf/scripts/python/bin/compaction-times-record
 create mode 100644 tools/perf/scripts/python/bin/compaction-times-report
 create mode 100644 tools/perf/scripts/python/compaction-times.py
tools/perf/scripts/python/bin/compaction-times-record new file +2 -0
new file mode 100644
index 000000000000..6edcd40e14e8
@@ -0,0 +1,2 @@
+#!/bin/bash
+perf record -e compaction:mm_compaction_begin -e compaction:mm_compaction_end -e compaction:mm_compaction_migratepages -e compaction:mm_compaction_isolate_migratepages -e compaction:mm_compaction_isolate_freepages $@
tools/perf/scripts/python/bin/compaction-times-report new file +4 -0
new file mode 100644
index 000000000000..3dc13897cfde
@@ -0,0 +1,4 @@
+#!/bin/bash
+#description: display time taken by mm compaction
+#args: [-h] [-u] [-p|-pv] [-t | [-m] [-fs] [-ms]] [pid|pid-range|comm-regex]
+perf script -s "$PERF_EXEC_PATH"/scripts/python/compaction-times.py $@
tools/perf/scripts/python/compaction-times.py new file +311 -0

311 lines not on this page · raw message

Signature · 1 line
2.1.0
author maintainer
#4 lore raw

PATCH 4/10 perf trace: Add header with copyright and background info

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

Cc Adrian Hunter <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 tools/perf/builtin-trace.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
tools/perf/builtin-trace.c +19 -0
index 2f1162daa3c5..4e3abba03062 100644
@@ -1,3 +1,21 @@
+/*
+ * builtin-trace.c
+ *
+ * Builtin 'trace' command:
+ *
+ * Display a continuously updated trace of any workload, CPU, specific PID,
+ * system wide, etc.  Default format is loosely strace like, but any other
+ * event may be specified using --event.
+ *
+ * Copyright (C) 2012, 2013, 2014, 2015 Red Hat Inc, Arnaldo Carvalho de Melo <[email protected]>
+ *
+ * Initially based on the 'trace' prototype by Thomas Gleixner:
+ *
+ * http://lwn.net/Articles/415728/ ("Announcing a new utility: 'trace'")
+ *
+ * Released under the GPL v2. (and only v2, not any later version)
+ */
+
 #include <traceevent/event-parse.h>
 #include "builtin.h"
 #include "util/color.h"
@@ -27,6 +45,7 @@
 
 #ifndef MADV_HWPOISON
 # define MADV_HWPOISON		100
+
 #endif
 
 #ifndef MADV_MERGEABLE
Signature · 1 line
2.1.0
author maintainer
#5 lore raw

PATCH 5/10 perf evsel: Add a backpointer to the evlist a evsel is in

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

So that functions that deal primarily with an evsel to access information that concerns the whole evlist it is in.

Cc Adrian Hunter <[email protected]>
Cc Andi Kleen <[email protected]>
Cc Andy Lutomirski <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Kan Liang <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 tools/perf/util/evlist.c | 2 ++
 tools/perf/util/evsel.c  | 2 ++
 tools/perf/util/evsel.h  | 4 ++++
 3 files changed, 8 insertions(+)
tools/perf/util/evlist.c +2 -0
index e9a5d432902c..8d00039d6a20 100644
@@ -98,6 +98,7 @@ static void perf_evlist__purge(struct perf_evlist *evlist)
 
 	evlist__for_each_safe(evlist, n, pos) {
 		list_del_init(&pos->node);
+		pos->evlist = NULL;
 		perf_evsel__delete(pos);
 	}
 
@@ -125,6 +126,7 @@ void perf_evlist__delete(struct perf_evlist *evlist)
 
 void perf_evlist__add(struct perf_evlist *evlist, struct perf_evsel *entry)
 {
+	entry->evlist = evlist;
 	list_add_tail(&entry->node, &evlist->entries);
 	entry->idx = evlist->nr_entries;
 	entry->tracking = !entry->idx;
tools/perf/util/evsel.c +2 -0
index b096ef7a240c..bac25f41a751 100644
@@ -206,6 +206,7 @@ void perf_evsel__init(struct perf_evsel *evsel,
 	evsel->leader	   = evsel;
 	evsel->unit	   = "";
 	evsel->scale	   = 1.0;
+	evsel->evlist	   = NULL;
 	INIT_LIST_HEAD(&evsel->node);
 	INIT_LIST_HEAD(&evsel->config_terms);
 	perf_evsel__object.init(evsel);
@@ -1026,6 +1027,7 @@ void perf_evsel__close_fd(struct perf_evsel *evsel, int ncpus, int nthreads)
 void perf_evsel__exit(struct perf_evsel *evsel)
 {
 	assert(list_empty(&evsel->node));
+	assert(evsel->evlist == NULL);
 	perf_evsel__free_fd(evsel);
 	perf_evsel__free_id(evsel);
 	perf_evsel__free_config_terms(evsel);
tools/perf/util/evsel.h +4 -0
index 93ac6b128149..298e6bbca200 100644
@@ -60,6 +60,9 @@ struct perf_evsel_config_term {
 
 /** struct perf_evsel - event selector
  *
+ * @evlist - evlist this evsel is in, if it is in one.
+ * @node - To insert it into evlist->entries or in other list_heads, say in
+ *         the event parsing routines.
  * @name - Can be set to retain the original event name passed by the user,
  *         so that when showing results in tools such as 'perf stat', we
  *         show the name used, not some alias.
@@ -73,6 +76,7 @@ struct perf_evsel_config_term {
  */
 struct perf_evsel {
 	struct list_head	node;
+	struct perf_evlist	*evlist;
 	struct perf_event_attr	attr;
 	char			*filter;
 	struct xyarray		*fd;
Signature · 1 line
2.1.0
author maintainer
#6 lore raw

PATCH 6/10 perf buildid: Introduce sysfs/filename__sprintf_build_id

In reply to Arnaldo Carvalho de Melo

From: Masami Hiramatsu <[email protected]>

Introduce sysfs/filename__sprintf_build_id for consolidating similar code.

---
 tools/perf/builtin-buildid-cache.c | 14 ++------------
 tools/perf/builtin-buildid-list.c  | 24 ++++++++++--------------
 tools/perf/util/build-id.c         | 32 ++++++++++++++++++++++++++++++++
 tools/perf/util/build-id.h         |  3 +++
 4 files changed, 47 insertions(+), 26 deletions(-)
tools/perf/builtin-buildid-cache.c +2 -12
index 65b4835309c7..7b8450cd33c2 100644
@@ -25,8 +25,6 @@
 static int build_id_cache__kcore_buildid(const char *proc_dir, char *sbuildid)
 {
 	char root_dir[PATH_MAX];
-	char notes[PATH_MAX];
-	u8 build_id[BUILD_ID_SIZE];
 	char *p;
 
 	strlcpy(root_dir, proc_dir, sizeof(root_dir));
@@ -35,15 +33,7 @@ static int build_id_cache__kcore_buildid(const char *proc_dir, char *sbuildid)
 	if (!p)
 		return -1;
 	*p = '\0';
-
-	scnprintf(notes, sizeof(notes), "%s/sys/kernel/notes", root_dir);
-
-	if (sysfs__read_build_id(notes, build_id, sizeof(build_id)))
-		return -1;
-
-	build_id__sprintf(build_id, sizeof(build_id), sbuildid);
-
-	return 0;
+	return sysfs__sprintf_build_id(root_dir, sbuildid);
 }
 
 static int build_id_cache__kcore_dir(char *dir, size_t sz)
@@ -138,7 +128,7 @@ static int build_id_cache__add_kcore(const char *filename, bool force)
 		return -1;
 	*p = '\0';
 
-	if (build_id_cache__kcore_buildid(from_dir, sbuildid))
+	if (build_id_cache__kcore_buildid(from_dir, sbuildid) < 0)
 		return -1;
 
 	scnprintf(to_dir, sizeof(to_dir), "%s/[kernel.kcore]/%s",
tools/perf/builtin-buildid-list.c +10 -14
index b5ca988ebfbe..918b4de29de4 100644
@@ -19,29 +19,25 @@
 
 static int sysfs__fprintf_build_id(FILE *fp)
 {
-	u8 kallsyms_build_id[BUILD_ID_SIZE];
 	char sbuild_id[SBUILD_ID_SIZE];
+	int ret;
 
-	if (sysfs__read_build_id("/sys/kernel/notes", kallsyms_build_id,
-				 sizeof(kallsyms_build_id)) != 0)
-		return -1;
+	ret = sysfs__sprintf_build_id("/", sbuild_id);
+	if (ret != sizeof(sbuild_id))
+		return ret < 0 ? ret : -EINVAL;
 
-	build_id__sprintf(kallsyms_build_id, sizeof(kallsyms_build_id),
-			  sbuild_id);
-	fprintf(fp, "%s\n", sbuild_id);
-	return 0;
+	return fprintf(fp, "%s\n", sbuild_id);
 }
 
 static int filename__fprintf_build_id(const char *name, FILE *fp)
 {
-	u8 build_id[BUILD_ID_SIZE];
 	char sbuild_id[SBUILD_ID_SIZE];
+	int ret;
 
-	if (filename__read_build_id(name, build_id,
-				    sizeof(build_id)) != sizeof(build_id))
-		return 0;
+	ret = filename__sprintf_build_id(name, sbuild_id);
+	if (ret != sizeof(sbuild_id))
+		return ret < 0 ? ret : -EINVAL;
 
-	build_id__sprintf(build_id, sizeof(build_id), sbuild_id);
 	return fprintf(fp, "%s\n", sbuild_id);
 }
 
@@ -63,7 +59,7 @@ static int perf_session__list_build_ids(bool force, bool with_hits)
 	/*
 	 * See if this is an ELF file first:
 	 */
-	if (filename__fprintf_build_id(input_name, stdout))
+	if (filename__fprintf_build_id(input_name, stdout) > 0)
 		goto out;
 
 	session = perf_session__new(&file, false, &build_id__mark_dso_hit_ops);
tools/perf/util/build-id.c +32 -0
index 4a2c2f0ead41..d909459fb54c 100644
@@ -93,6 +93,38 @@ int build_id__sprintf(const u8 *build_id, int len, char *bf)
 	return raw - build_id;
 }
 
+int sysfs__sprintf_build_id(const char *root_dir, char *sbuild_id)
+{
+	char notes[PATH_MAX];
+	u8 build_id[BUILD_ID_SIZE];
+	int ret;
+
+	if (!root_dir)
+		root_dir = "";
+
+	scnprintf(notes, sizeof(notes), "%s/sys/kernel/notes", root_dir);
+
+	ret = sysfs__read_build_id(notes, build_id, sizeof(build_id));
+	if (ret < 0)
+		return ret;
+
+	return build_id__sprintf(build_id, sizeof(build_id), sbuild_id);
+}
+
+int filename__sprintf_build_id(const char *pathname, char *sbuild_id)
+{
+	u8 build_id[BUILD_ID_SIZE];
+	int ret;
+
+	ret = filename__read_build_id(pathname, build_id, sizeof(build_id));
+	if (ret < 0)
+		return ret;
+	else if (ret != sizeof(build_id))
+		return -EINVAL;
+
+	return build_id__sprintf(build_id, sizeof(build_id), sbuild_id);
+}
+
 /* asnprintf consolidates asprintf and snprintf */
 static int asnprintf(char **strp, size_t size, const char *fmt, ...)
 {
tools/perf/util/build-id.h +3 -0
index ce2f493f057a..27a14a8a945b 100644
@@ -12,6 +12,9 @@ extern struct perf_tool build_id__mark_dso_hit_ops;
 struct dso;
 
 int build_id__sprintf(const u8 *build_id, int len, char *bf);
+int sysfs__sprintf_build_id(const char *root_dir, char *sbuild_id);
+int filename__sprintf_build_id(const char *pathname, char *sbuild_id);
+
 char *dso__build_id_filename(const struct dso *dso, char *bf, size_t size);
 
 int build_id__mark_dso_hit(struct perf_tool *tool, union perf_event *event,
Signature · 1 line
2.1.0
author maintainer
#7 lore raw

PATCH 7/10 perf tools: Add tracing_path and remove unneeded functions

In reply to Arnaldo Carvalho de Melo

From: Jiri Olsa <[email protected]>

There's no need for find_tracing_dir, because perf already searches for debugfs/tracefs mount on start and populate tracing_events_path.

Adding tracing_path to carry tracing dir string to be used in get_tracing_file instead of calling find_tracing_dir.

---
 tools/perf/util/util.c | 56 ++++----------------------------------------------
 tools/perf/util/util.h |  2 +-
 2 files changed, 5 insertions(+), 53 deletions(-)
tools/perf/util/util.c +4 -52
index f7adf1203df1..d33c34196a5a 100644
@@ -34,6 +34,7 @@ bool test_attr__enabled;
 bool perf_host  = true;
 bool perf_guest = false;
 
+char tracing_path[PATH_MAX + 1]        = "/sys/kernel/debug/tracing";
 char tracing_events_path[PATH_MAX + 1] = "/sys/kernel/debug/tracing/events";
 
 void event_attr_init(struct perf_event_attr *attr)
@@ -391,6 +392,8 @@ void set_term_quiet_input(struct termios *old)
 
 static void set_tracing_events_path(const char *tracing, const char *mountpoint)
 {
+	snprintf(tracing_path, sizeof(tracing_path), "%s/%s",
+		 mountpoint, tracing);
 	snprintf(tracing_events_path, sizeof(tracing_events_path), "%s/%s%s",
 		 mountpoint, tracing, "events");
 }
@@ -440,62 +443,11 @@ void perf_debugfs_set_path(const char *mntpt)
 	set_tracing_events_path("tracing/", mntpt);
 }
 
-static const char *find_tracefs(void)
-{
-	const char *path = __perf_tracefs_mount(NULL);
-
-	return path;
-}
-
-static const char *find_debugfs(void)
-{
-	const char *path = __perf_debugfs_mount(NULL);
-
-	if (!path)
-		fprintf(stderr, "Your kernel does not support the debugfs filesystem");
-
-	return path;
-}
-
-/*
- * Finds the path to the debugfs/tracing
- * Allocates the string and stores it.
- */
-const char *find_tracing_dir(void)
-{
-	const char *tracing_dir = "";
-	static char *tracing;
-	static int tracing_found;
-	const char *debugfs;
-
-	if (tracing_found)
-		return tracing;
-
-	debugfs = find_tracefs();
-	if (!debugfs) {
-		tracing_dir = "/tracing";
-		debugfs = find_debugfs();
-		if (!debugfs)
-			return NULL;
-	}
-
-	if (asprintf(&tracing, "%s%s", debugfs, tracing_dir) < 0)
-		return NULL;
-
-	tracing_found = 1;
-	return tracing;
-}
-
 char *get_tracing_file(const char *name)
 {
-	const char *tracing;
 	char *file;
 
-	tracing = find_tracing_dir();
-	if (!tracing)
-		return NULL;
-
-	if (asprintf(&file, "%s/%s", tracing, name) < 0)
+	if (asprintf(&file, "%s/%s", tracing_path, name) < 0)
 		return NULL;
 
 	return file;
tools/perf/util/util.h +1 -1
index 88a891562a47..291be1d84bc3 100644
@@ -83,10 +83,10 @@
 extern const char *graph_line;
 extern const char *graph_dotted_line;
 extern char buildid_dir[];
+extern char tracing_path[];
 extern char tracing_events_path[];
 extern void perf_debugfs_set_path(const char *mountpoint);
 const char *perf_debugfs_mount(const char *mountpoint);
-const char *find_tracing_dir(void);
 char *get_tracing_file(const char *name);
 void put_tracing_file(char *file);
 
Signature · 1 line
2.1.0
author maintainer
#8 lore raw

PATCH 8/10 perf tools: Do not change lib/api/fs/debugfs directly

In reply to Arnaldo Carvalho de Melo

From: Jiri Olsa <[email protected]>

The tracing_events_path is the variable we want to change via --debugfs-dir option, not the debugfs_mountpoint.

---
 tools/perf/perf.c      | 2 +-
 tools/perf/util/util.c | 1 -
 2 files changed, 1 insertion(+), 2 deletions(-)
tools/perf/perf.c +1 -1
index b857fcbd00cf..07dbff5c0e60 100644
@@ -231,7 +231,7 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
 			(*argc)--;
 		} else if (!prefixcmp(cmd, CMD_DEBUGFS_DIR)) {
 			perf_debugfs_set_path(cmd + strlen(CMD_DEBUGFS_DIR));
-			fprintf(stderr, "dir: %s\n", debugfs_mountpoint);
+			fprintf(stderr, "dir: %s\n", tracing_path);
 			if (envchanged)
 				*envchanged = 1;
 		} else if (!strcmp(cmd, "--list-cmds")) {
tools/perf/util/util.c +0 -1
index d33c34196a5a..7acafb3c5592 100644
@@ -439,7 +439,6 @@ const char *perf_debugfs_mount(const char *mountpoint)
 
 void perf_debugfs_set_path(const char *mntpt)
 {
-	snprintf(debugfs_mountpoint, strlen(debugfs_mountpoint), "%s", mntpt);
 	set_tracing_events_path("tracing/", mntpt);
 }
 
Signature · 1 line
2.1.0
author maintainer
#9 lore raw

PATCH 9/10 perf tools: Rename perf_session_env to perf_env

In reply to Arnaldo Carvalho de Melo

From: Kan Liang <[email protected]>

As it is not necessarily tied to a perf.data file and needs using in places where a perf_session is not required.

---
 tools/perf/arch/common.c        |  4 ++--
 tools/perf/arch/common.h        |  2 +-
 tools/perf/ui/browser.h         |  4 ++--
 tools/perf/ui/browsers/header.c |  2 +-
 tools/perf/ui/browsers/hists.c  | 12 ++++++------
 tools/perf/util/header.h        |  4 ++--
 tools/perf/util/hist.h          |  4 ++--
 tools/perf/util/session.c       |  2 +-
 tools/perf/util/symbol.c        |  4 ++--
 tools/perf/util/symbol.h        |  4 ++--
 10 files changed, 21 insertions(+), 21 deletions(-)
tools/perf/arch/common.c +2 -2
index b7bb42c44694..b00dfd92ea73 100644
@@ -128,7 +128,7 @@ static const char *normalize_arch(char *arch)
 	return arch;
 }
 
-static int perf_session_env__lookup_binutils_path(struct perf_session_env *env,
+static int perf_session_env__lookup_binutils_path(struct perf_env *env,
 						  const char *name,
 						  const char **path)
 {
@@ -206,7 +206,7 @@ out_error:
 	return -1;
 }
 
-int perf_session_env__lookup_objdump(struct perf_session_env *env)
+int perf_session_env__lookup_objdump(struct perf_env *env)
 {
 	/*
 	 * For live mode, env->arch will be NULL and we can use
tools/perf/arch/common.h +1 -1
index ede246eda9be..20176df69fc8 100644
@@ -5,6 +5,6 @@
 
 extern const char *objdump_path;
 
-int perf_session_env__lookup_objdump(struct perf_session_env *env);
+int perf_session_env__lookup_objdump(struct perf_env *env);
 
 #endif /* ARCH_PERF_COMMON_H */
tools/perf/ui/browser.h +2 -2
index 52be87125def..f3cef564de02 100644
@@ -61,8 +61,8 @@ int ui_browser__help_window(struct ui_browser *browser, const char *text);
 bool ui_browser__dialog_yesno(struct ui_browser *browser, const char *text);
 int ui_browser__input_window(const char *title, const char *text, char *input,
 			     const char *exit_msg, int delay_sec);
-struct perf_session_env;
-int tui__header_window(struct perf_session_env *env);
+struct perf_env;
+int tui__header_window(struct perf_env *env);
 
 void ui_browser__argv_seek(struct ui_browser *browser, off_t offset, int whence);
 unsigned int ui_browser__argv_refresh(struct ui_browser *browser);
tools/perf/ui/browsers/header.c +1 -1
index f10681717f93..edbeaaf31ace 100644
@@ -91,7 +91,7 @@ static int ui__list_menu(int argc, char * const argv[])
 	return list_menu__run(&menu);
 }
 
-int tui__header_window(struct perf_session_env *env)
+int tui__header_window(struct perf_env *env)
 {
 	int i, argc = 0;
 	char **argv;
tools/perf/ui/browsers/hists.c +6 -6
index 10c7ec041039..cf86f2d3a5e7 100644
@@ -26,7 +26,7 @@ struct hist_browser {
 	struct map_symbol   *selection;
 	struct hist_browser_timer *hbt;
 	struct pstack	    *pstack;
-	struct perf_session_env *env;
+	struct perf_env *env;
 	int		     print_seq;
 	bool		     show_dso;
 	bool		     show_headers;
@@ -1214,7 +1214,7 @@ static int hist_browser__dump(struct hist_browser *browser)
 
 static struct hist_browser *hist_browser__new(struct hists *hists,
 					      struct hist_browser_timer *hbt,
-					      struct perf_session_env *env)
+					      struct perf_env *env)
 {
 	struct hist_browser *browser = zalloc(sizeof(*browser));
 
@@ -1695,7 +1695,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
 				    bool left_exits,
 				    struct hist_browser_timer *hbt,
 				    float min_pcnt,
-				    struct perf_session_env *env)
+				    struct perf_env *env)
 {
 	struct hists *hists = evsel__hists(evsel);
 	struct hist_browser *browser = hist_browser__new(hists, hbt, env);
@@ -2016,7 +2016,7 @@ struct perf_evsel_menu {
 	struct perf_evsel *selection;
 	bool lost_events, lost_events_warned;
 	float min_pcnt;
-	struct perf_session_env *env;
+	struct perf_env *env;
 };
 
 static void perf_evsel_menu__write(struct ui_browser *browser,
@@ -2169,7 +2169,7 @@ static int __perf_evlist__tui_browse_hists(struct perf_evlist *evlist,
 					   int nr_entries, const char *help,
 					   struct hist_browser_timer *hbt,
 					   float min_pcnt,
-					   struct perf_session_env *env)
+					   struct perf_env *env)
 {
 	struct perf_evsel *pos;
 	struct perf_evsel_menu menu = {
@@ -2202,7 +2202,7 @@ static int __perf_evlist__tui_browse_hists(struct perf_evlist *evlist,
 int perf_evlist__tui_browse_hists(struct perf_evlist *evlist, const char *help,
 				  struct hist_browser_timer *hbt,
 				  float min_pcnt,
-				  struct perf_session_env *env)
+				  struct perf_env *env)
 {
 	int nr_entries = evlist->nr_entries;
 
tools/perf/util/header.h +2 -2
index 9b53b6525ce8..396e4965f0c9 100644
@@ -66,7 +66,7 @@ struct perf_header;
 int perf_file_header__read(struct perf_file_header *header,
 			   struct perf_header *ph, int fd);
 
-struct perf_session_env {
+struct perf_env {
 	char			*hostname;
 	char			*os_release;
 	char			*version;
@@ -98,7 +98,7 @@ struct perf_header {
 	u64				data_size;
 	u64				feat_offset;
 	DECLARE_BITMAP(adds_features, HEADER_FEAT_BITS);
-	struct perf_session_env 	env;
+	struct perf_env 	env;
 };
 
 struct perf_evlist;
tools/perf/util/hist.h +2 -2
index bc528d54e457..de6d58e7f0d5 100644
@@ -313,7 +313,7 @@ int hist_entry__tui_annotate(struct hist_entry *he, struct perf_evsel *evsel,
 int perf_evlist__tui_browse_hists(struct perf_evlist *evlist, const char *help,
 				  struct hist_browser_timer *hbt,
 				  float min_pcnt,
-				  struct perf_session_env *env);
+				  struct perf_env *env);
 int script_browse(const char *script_opt);
 #else
 static inline
@@ -321,7 +321,7 @@ int perf_evlist__tui_browse_hists(struct perf_evlist *evlist __maybe_unused,
 				  const char *help __maybe_unused,
 				  struct hist_browser_timer *hbt __maybe_unused,
 				  float min_pcnt __maybe_unused,
-				  struct perf_session_env *env __maybe_unused)
+				  struct perf_env *env __maybe_unused)
 {
 	return 0;
 }
tools/perf/util/session.c +1 -1
index 18722e774a69..8a4537ee9bc3 100644
@@ -170,7 +170,7 @@ static void perf_session__delete_threads(struct perf_session *session)
 	machine__delete_threads(&session->machines.host);
 }
 
-static void perf_session_env__exit(struct perf_session_env *env)
+static void perf_session_env__exit(struct perf_env *env)
 {
 	zfree(&env->hostname);
 	zfree(&env->os_release);
tools/perf/util/symbol.c +2 -2
index 46ae0532a8a6..1f97ffb158a6 100644
@@ -1853,7 +1853,7 @@ static void vmlinux_path__exit(void)
 	zfree(&vmlinux_path);
 }
 
-static int vmlinux_path__init(struct perf_session_env *env)
+static int vmlinux_path__init(struct perf_env *env)
 {
 	struct utsname uts;
 	char bf[PATH_MAX];
@@ -1964,7 +1964,7 @@ static bool symbol__read_kptr_restrict(void)
 	return value;
 }
 
-int symbol__init(struct perf_session_env *env)
+int symbol__init(struct perf_env *env)
 {
 	const char *symfs;
 
tools/perf/util/symbol.h +2 -2
index a4cde92afbad..440ba8ae888f 100644
@@ -252,8 +252,8 @@ int modules__parse(const char *filename, void *arg,
 int filename__read_debuglink(const char *filename, char *debuglink,
 			     size_t size);
 
-struct perf_session_env;
-int symbol__init(struct perf_session_env *env);
+struct perf_env;
+int symbol__init(struct perf_env *env);
 void symbol__exit(void);
 void symbol__elf_init(void);
 struct symbol *symbol__new(u64 start, u64 len, u8 binding, const char *name);
Signature · 1 line
2.1.0
author maintainer
#10 lore raw

PATCH 10/10 perf evlist: Add backpointer for perf_env to evlist

In reply to Arnaldo Carvalho de Melo

From: Kan Liang <[email protected]>

Add backpointer to perf_env in evlist, so we can easily access env when processing something where we have a evsel or evlist.

---
 tools/perf/util/evlist.h | 1 +
 tools/perf/util/header.c | 1 +
 2 files changed, 2 insertions(+)
tools/perf/util/evlist.h +1 -0
index 436e358300b1..b39a6198f4ac 100644
@@ -56,6 +56,7 @@ struct perf_evlist {
 	struct cpu_map	  *cpus;
 	struct perf_evsel *selected;
 	struct events_stats stats;
+	struct perf_env	*env;
 };
 
 struct perf_evsel_str_handler {
tools/perf/util/header.c +1 -0
index 179b2bdd157d..41814547da15 100644
@@ -2514,6 +2514,7 @@ int perf_session__read_header(struct perf_session *session)
 	if (session->evlist == NULL)
 		return -ENOMEM;
 
+	session->evlist->env = &header->env;
 	if (perf_data_file__is_pipe(file))
 		return perf_header__read_pipe(session);
 
Signature · 1 line
2.1.0
#11 lore raw
In reply to Arnaldo Carvalho de Melo
Quoted 97 lines · Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]

Hi Ingo,

Please consider pulling,

- Arnaldo

The following changes since commit d1ee8bc195ffedbf91af0245a2406d6ebd2578f8:

Merge tag 'perf-core-for-mingo' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/core (2015-08-28 08:22:02 +0200)

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git tags/perf-core-for-mingo

for you to fetch changes up to 2c07144dfce366e21465cc7b0ada9f0b6dc7b7ed:

perf evlist: Add backpointer for perf_env to evlist (2015-08-28 14:54:14 -0300)

----------------------------------------------------------------
perf/core improvement and fixes:

User visible:

- Add new compaction-times python script (Tony Jones)

- Make the --[no-]-demangle/--[no-]-demangle-kernel command line options available in 'perf script' too (Mark Drayton)

- Allow for negative numbers in libtraceevent's print format, fixing up misformatting in some tracepoints (Steven Rostedt)

Infrastructure:

- perf_env/perf_evlist changes to allow accessing the data structure with the environment where some perf data was collected in functions not necessarily related to perf.data file processing (Kan Liang)

- Cleanups for the tracepoint definition location paths routines (Jiri Olsa)

- Introduce sysfs/filename__sprintf_build_id, removing code duplication (Masami Hiramatsu)

----------------------------------------------------------------
Arnaldo Carvalho de Melo (2):
perf trace: Add header with copyright and background info perf evsel: Add a backpointer to the evlist a evsel is in

Jiri Olsa (2):
perf tools: Add tracing_path and remove unneeded functions perf tools: Do not change lib/api/fs/debugfs directly

Kan Liang (2):
perf tools: Rename perf_session_env to perf_env perf evlist: Add backpointer for perf_env to evlist

Mark Drayton (1):

      perf script: Add --[no-]-demangle/--[no-]-demangle-kernel

Masami Hiramatsu (1):
perf buildid: Introduce sysfs/filename__sprintf_build_id

Steven Rostedt (1):
tools lib traceeveent: Allow for negative numbers in print format

Tony Jones (1):
perf scripts python: Add new compaction-times script

 tools/lib/traceevent/event-parse.c                 |   1 +
 tools/perf/Documentation/perf-script.txt           |   7 +
 tools/perf/arch/common.c                           |   4 +-
 tools/perf/arch/common.h                           |   2 +-
 tools/perf/builtin-buildid-cache.c                 |  14 +-
 tools/perf/builtin-buildid-list.c                  |  24 +-
 tools/perf/builtin-script.c                        |   5 +
 tools/perf/builtin-trace.c                         |  19 ++
 tools/perf/perf.c                                  |   2 +-
 .../scripts/python/bin/compaction-times-record     |   2 +
 .../scripts/python/bin/compaction-times-report     |   4 +
 tools/perf/scripts/python/compaction-times.py      | 311 +++++++++++++++++++++
 tools/perf/ui/browser.h                            |   4 +-
 tools/perf/ui/browsers/header.c                    |   2 +-
 tools/perf/ui/browsers/hists.c                     |  12 +-
 tools/perf/util/build-id.c                         |  32 +++
 tools/perf/util/build-id.h                         |   3 +
 tools/perf/util/evlist.c                           |   2 +
 tools/perf/util/evlist.h                           |   1 +
 tools/perf/util/evsel.c                            |   2 +
 tools/perf/util/evsel.h                            |   4 +
 tools/perf/util/header.c                           |   1 +
 tools/perf/util/header.h                           |   4 +-
 tools/perf/util/hist.h                             |   4 +-
 tools/perf/util/session.c                          |   2 +-
Quoted 8 lines
 tools/perf/util/symbol.c                           |   4 +-
 tools/perf/util/symbol.h                           |   4 +-
 tools/perf/util/util.c                             |  57 +---
 tools/perf/util/util.h                             |   2 +-
 29 files changed, 433 insertions(+), 102 deletions(-)
 create mode 100644 tools/perf/scripts/python/bin/compaction-times-record
 create mode 100644 tools/perf/scripts/python/bin/compaction-times-report
 create mode 100644 tools/perf/scripts/python/compaction-times.py

Pulled, thanks a lot Arnaldo!

Ingo