linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [GIT PULL 00/10] perf/core improvements and fixes
@ 2016-06-20 22:23 Arnaldo Carvalho de Melo
  2016-06-20 22:23 ` [PATCH 01/10] perf tools: Find vdso with the consider of cross-platform Arnaldo Carvalho de Melo
                   ` (10 more replies)
  0 siblings, 11 replies; 17+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-06-20 22:23 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Arnaldo Carvalho de Melo, Adrian Hunter,
	Alexander Shishkin, Alexei Starovoitov, Andi Kleen,
	Brendan Gregg, David Ahern, Ekaterina Tumanova, He Kuang,
	Jean Delvare, Jiri Olsa, Josh Poimboeuf, Kan Liang, linux-kbuild,
	Masami Hiramatsu, Michal Marek, Namhyung Kim, Paolo Bonzini,
	Pekka Enberg, Peter Zijlstra, pi3orama, Stephane Eranian,
	Sukadev Bhattiprolu, Wang Nan, Zefan Li,
	Arnaldo Carvalho de Melo

Hi Ingo,

	Please consider pulling,

- Arnaldo

The following changes since commit 02469a95096a549508c5adf61d84a1d72851c85b:

  Merge tag 'perf-core-for-mingo-20160615' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/core (2016-06-16 10:27:35 +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-20160620

for you to fetch changes up to 2a0a7c72702bac1b87cd4d49196a334483386fab:

  perf script: Add stackcollapse.py script (2016-06-20 17:50:39 -0300)

----------------------------------------------------------------
perf/core improvements and fixes:

New features:

. Add --dry-run option to 'perf record' to check if command line options can be
  parsed, but not doing any recording (Wang Nan)

. Allow dumping the object files generated by llvm when processing eBPF
  scriptlet events (Wang Nan)

- Add stackcollapse.py script to help generating flame graphs (Paolo Bonzini)

Documentation:

. Fix 'perf script'  documentation of '-f' when it should be '-F' (Adrian Hunter)

Infrastructure:

- Fix write_backwards fallback when using a new tool on older kernels
  without support for this feature (Arnaldo Carvalho de Melo)

- Find vdso file in cross-platform perf.data file processing scenarios (He Kuang)

- Remove some leftovers from the initial codebase copying from git
  (Arnaldo Carvalho de Melo)

- List libelf-devel as an alternative, as this is how the libelf
  development package is called on OpenSuSE (Jean Delvare)

- Rename __hists__add_entry to hists__add_entry (Jiri Olsa)

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

----------------------------------------------------------------
Adrian Hunter (1):
      perf script: Fix documentation of '-f' when it should be '-F'

Arnaldo Carvalho de Melo (3):
      perf tools: Remove some unused functions
      perf tools: Remove --perf-dir and --work-dir
      perf evsel: Fix write_backwards fallback

He Kuang (1):
      perf tools: Find vdso with the consider of cross-platform

Jean Delvare (1):
      kbuild: List libelf-devel as an alternative

Jiri Olsa (1):
      perf hists: Rename __hists__add_entry to hists__add_entry

Paolo Bonzini (1):
      perf script: Add stackcollapse.py script

Wang Nan (2):
      perf llvm: Allow dump llvm output object file using llvm.dump-obj
      perf record: Add --dry-run option to check cmdline options

 Makefile                                           |   2 +-
 tools/perf/Documentation/perf-record.txt           |   7 ++
 tools/perf/Documentation/perf-script.txt           |  20 ++--
 tools/perf/builtin-annotate.c                      |   2 +-
 tools/perf/builtin-diff.c                          |  12 +-
 tools/perf/builtin-record.c                        |   7 ++
 tools/perf/config/Makefile                         |   2 +-
 tools/perf/perf.c                                  |  36 ------
 tools/perf/scripts/python/bin/stackcollapse-record |   8 ++
 tools/perf/scripts/python/bin/stackcollapse-report |   3 +
 tools/perf/scripts/python/stackcollapse.py         | 127 +++++++++++++++++++++
 tools/perf/tests/hists_link.c                      |   4 +-
 tools/perf/util/cache.h                            |   9 --
 tools/perf/util/config.c                           |   2 +-
 tools/perf/util/evsel.c                            |  23 ++--
 tools/perf/util/hist.c                             |  34 +++---
 tools/perf/util/hist.h                             |  14 +--
 tools/perf/util/llvm-utils.c                       |  42 +++++++
 tools/perf/util/llvm-utils.h                       |   5 +
 tools/perf/util/path.c                             |  65 +----------
 tools/perf/util/vdso.c                             |  40 ++++++-
 21 files changed, 288 insertions(+), 176 deletions(-)
 create mode 100755 tools/perf/scripts/python/bin/stackcollapse-record
 create mode 100755 tools/perf/scripts/python/bin/stackcollapse-report
 create mode 100755 tools/perf/scripts/python/stackcollapse.py

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 01/10] perf tools: Find vdso with the consider of cross-platform
  2016-06-20 22:23 [GIT PULL 00/10] perf/core improvements and fixes Arnaldo Carvalho de Melo
@ 2016-06-20 22:23 ` Arnaldo Carvalho de Melo
  2016-06-20 22:23 ` [PATCH 02/10] kbuild: List libelf-devel as an alternative Arnaldo Carvalho de Melo
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 17+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-06-20 22:23 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, He Kuang, Alexander Shishkin, Andi Kleen,
	David Ahern, Ekaterina Tumanova, Jiri Olsa, Josh Poimboeuf,
	Kan Liang, Masami Hiramatsu, Namhyung Kim, Pekka Enberg,
	Peter Zijlstra, Stephane Eranian, Sukadev Bhattiprolu, Wang Nan,
	Arnaldo Carvalho de Melo

From: He Kuang <hekuang@huawei.com>

There's a problem in machine__findnew_vdso(), vdso buildid generated by a
32-bit machine stores it with the name 'vdso', but when processing buildid on a
64-bit machine with the same 'perf.data', perf will search for vdso named as
'vdso32' and get failed.

This patch tries to find the existing dsos in machine->dsos by thread dso_type.
64-bit thread tries to find vdso with name 'vdso', because all 64-bit vdso is
named as that. 32-bit thread first tries to find vdso with name 'vdso32' if
this thread was run on 64-bit machine, if failed, then it tries 'vdso' which
indicates that the thread was run on 32-bit machine when recording.

Committer note:

Additional explanation by Adrian Hunter:

We match maps to builds ids using the file name - consider
machine__findnew_[v]dso() called in map__new().  So in the context of a perf
data file, we consider the file name to be unique.

A vdso map does not have a file name - all we know is that it is vdso.  We look
at the thread to tell if it is 32-bit, 64-bit or x32.  Then we need to get the
build id which has been recorded using short name "[vdso]" or "[vdso32]" or
"[vdsox32]".

The problem is that on a 32-bit machine, we use the name "[vdso]".  If you take
a 32-bit perf data file to a 64-bit machine, it gets hard to figure out if
"[vdso]" is 32-bit or 64-bit.

This patch solves that problem.

Signed-off-by: He Kuang <hekuang@huawei.com>
Acked-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Ekaterina Tumanova <tumanova@linux.vnet.ibm.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Kan Liang <kan.liang@intel.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/r/1463475894-163531-1-git-send-email-hekuang@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/vdso.c | 40 +++++++++++++++++++++++++++++++++++++---
 1 file changed, 37 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/vdso.c b/tools/perf/util/vdso.c
index 44d440da15dc..8f81c415723d 100644
--- a/tools/perf/util/vdso.c
+++ b/tools/perf/util/vdso.c
@@ -134,8 +134,6 @@ static struct dso *__machine__addnew_vdso(struct machine *machine, const char *s
 	return dso;
 }
 
-#if BITS_PER_LONG == 64
-
 static enum dso_type machine__thread_dso_type(struct machine *machine,
 					      struct thread *thread)
 {
@@ -156,6 +154,8 @@ static enum dso_type machine__thread_dso_type(struct machine *machine,
 	return dso_type;
 }
 
+#if BITS_PER_LONG == 64
+
 static int vdso__do_copy_compat(FILE *f, int fd)
 {
 	char buf[4096];
@@ -283,8 +283,38 @@ static int __machine__findnew_vdso_compat(struct machine *machine,
 
 #endif
 
+static struct dso *machine__find_vdso(struct machine *machine,
+				      struct thread *thread)
+{
+	struct dso *dso = NULL;
+	enum dso_type dso_type;
+
+	dso_type = machine__thread_dso_type(machine, thread);
+	switch (dso_type) {
+	case DSO__TYPE_32BIT:
+		dso = __dsos__find(&machine->dsos, DSO__NAME_VDSO32, true);
+		if (!dso) {
+			dso = __dsos__find(&machine->dsos, DSO__NAME_VDSO,
+					   true);
+			if (dso_type != dso__type(dso, machine))
+				dso = NULL;
+		}
+		break;
+	case DSO__TYPE_X32BIT:
+		dso = __dsos__find(&machine->dsos, DSO__NAME_VDSOX32, true);
+		break;
+	case DSO__TYPE_64BIT:
+	case DSO__TYPE_UNKNOWN:
+	default:
+		dso = __dsos__find(&machine->dsos, DSO__NAME_VDSO, true);
+		break;
+	}
+
+	return dso;
+}
+
 struct dso *machine__findnew_vdso(struct machine *machine,
-				  struct thread *thread __maybe_unused)
+				  struct thread *thread)
 {
 	struct vdso_info *vdso_info;
 	struct dso *dso = NULL;
@@ -297,6 +327,10 @@ struct dso *machine__findnew_vdso(struct machine *machine,
 	if (!vdso_info)
 		goto out_unlock;
 
+	dso = machine__find_vdso(machine, thread);
+	if (dso)
+		goto out_unlock;
+
 #if BITS_PER_LONG == 64
 	if (__machine__findnew_vdso_compat(machine, thread, vdso_info, &dso))
 		goto out_unlock;
-- 
2.5.5

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 02/10] kbuild: List libelf-devel as an alternative
  2016-06-20 22:23 [GIT PULL 00/10] perf/core improvements and fixes Arnaldo Carvalho de Melo
  2016-06-20 22:23 ` [PATCH 01/10] perf tools: Find vdso with the consider of cross-platform Arnaldo Carvalho de Melo
@ 2016-06-20 22:23 ` Arnaldo Carvalho de Melo
  2016-06-20 22:23 ` [PATCH 03/10] perf script: Fix documentation of '-f' when it should be '-F' Arnaldo Carvalho de Melo
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 17+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-06-20 22:23 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Jean Delvare, Jiri Olsa, Michal Marek,
	Peter Zijlstra, linux-kbuild, Arnaldo Carvalho de Melo

From: Jean Delvare <jdelvare@suse.de>

On openSUSE, the libelf development files are in package libelf-devel.

Signed-off-by: Jean Delvare <jdelvare@suse.de>
Acked-by: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Michal Marek <mmarek@suse.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: linux-kbuild@vger.kernel.org
Link: http://lkml.kernel.org/n/tip-s8nyk3pyy2927sd7qp7u42oi@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 Makefile                   | 2 +-
 tools/perf/config/Makefile | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index b409076c7c18..4a1fe88d6839 100644
--- a/Makefile
+++ b/Makefile
@@ -1038,7 +1038,7 @@ ifdef CONFIG_STACK_VALIDATION
   ifeq ($(has_libelf),1)
     objtool_target := tools/objtool FORCE
   else
-    $(warning "Cannot use CONFIG_STACK_VALIDATION, please install libelf-dev or elfutils-libelf-devel")
+    $(warning "Cannot use CONFIG_STACK_VALIDATION, please install libelf-dev, libelf-devel or elfutils-libelf-devel")
     SKIP_STACK_VALIDATION := 1
     export SKIP_STACK_VALIDATION
   endif
diff --git a/tools/perf/config/Makefile b/tools/perf/config/Makefile
index 80018feb99c0..534c81176f6c 100644
--- a/tools/perf/config/Makefile
+++ b/tools/perf/config/Makefile
@@ -257,7 +257,7 @@ else
       LIBC_SUPPORT := 1
     endif
     ifeq ($(LIBC_SUPPORT),1)
-      msg := $(warning No libelf found, disables 'probe' tool and BPF support in 'perf record', please install elfutils-libelf-devel/libelf-dev);
+      msg := $(warning No libelf found, disables 'probe' tool and BPF support in 'perf record', please install libelf-dev, libelf-devel or elfutils-libelf-devel);
 
       NO_LIBELF := 1
       NO_DWARF := 1
-- 
2.5.5

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 03/10] perf script: Fix documentation of '-f' when it should be '-F'
  2016-06-20 22:23 [GIT PULL 00/10] perf/core improvements and fixes Arnaldo Carvalho de Melo
  2016-06-20 22:23 ` [PATCH 01/10] perf tools: Find vdso with the consider of cross-platform Arnaldo Carvalho de Melo
  2016-06-20 22:23 ` [PATCH 02/10] kbuild: List libelf-devel as an alternative Arnaldo Carvalho de Melo
@ 2016-06-20 22:23 ` Arnaldo Carvalho de Melo
  2016-06-20 22:23 ` [PATCH 04/10] perf hists: Rename __hists__add_entry to hists__add_entry Arnaldo Carvalho de Melo
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 17+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-06-20 22:23 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Adrian Hunter, Andi Kleen, Jiri Olsa,
	Arnaldo Carvalho de Melo

From: Adrian Hunter <adrian.hunter@intel.com>

The documentation for perf script mixes up '-f' and '-F'. Fix it.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Link: http://lkml.kernel.org/r/None
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Documentation/perf-script.txt | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt
index 4fc44c75263f..4f34379ebd77 100644
--- a/tools/perf/Documentation/perf-script.txt
+++ b/tools/perf/Documentation/perf-script.txt
@@ -119,13 +119,13 @@ OPTIONS
 	srcline, period, iregs, brstack, brstacksym, flags.
         Field list can be prepended with the type, trace, sw or hw,
         to indicate to which event type the field list applies.
-        e.g., -f sw:comm,tid,time,ip,sym  and -f trace:time,cpu,trace
+        e.g., -F sw:comm,tid,time,ip,sym  and -F trace:time,cpu,trace
 
-		perf script -f <fields>
+		perf script -F <fields>
 
 	is equivalent to:
 
-		perf script -f trace:<fields> -f sw:<fields> -f hw:<fields>
+		perf script -F trace:<fields> -F sw:<fields> -F hw:<fields>
 
 	i.e., the specified fields apply to all event types if the type string
 	is not given.
@@ -133,9 +133,9 @@ OPTIONS
 	The arguments are processed in the order received. A later usage can
 	reset a prior request. e.g.:
 
-		-f trace: -f comm,tid,time,ip,sym
+		-F trace: -F comm,tid,time,ip,sym
 
-	The first -f suppresses trace events (field list is ""), but then the
+	The first -F suppresses trace events (field list is ""), but then the
 	second invocation sets the fields to comm,tid,time,ip,sym. In this case a
 	warning is given to the user:
 
@@ -143,9 +143,9 @@ OPTIONS
 
 	Alternatively, consider the order:
 
-		-f comm,tid,time,ip,sym -f trace:
+		-F comm,tid,time,ip,sym -F trace:
 
-	The first -f sets the fields for all events and the second -f
+	The first -F sets the fields for all events and the second -F
 	suppresses trace events. The user is given a warning message about
 	the override, and the result of the above is that only S/W and H/W
 	events are displayed with the given fields.
@@ -154,14 +154,14 @@ OPTIONS
 	event type, a message is displayed to the user that the option is
 	ignored for that type. For example:
 
-		$ perf script -f comm,tid,trace
+		$ perf script -F comm,tid,trace
 		'trace' not valid for hardware events. Ignoring.
 		'trace' not valid for software events. Ignoring.
 
 	Alternatively, if the type is given an invalid field is specified it
 	is an error. For example:
 
-        perf script -v -f sw:comm,tid,trace
+        perf script -v -F sw:comm,tid,trace
         'trace' not valid for software events.
 
 	At this point usage is displayed, and perf-script exits.
@@ -173,7 +173,7 @@ OPTIONS
 	respectively.
 
 	Finally, a user may not set fields to none for all event types.
-	i.e., -f "" is not allowed.
+	i.e., -F "" is not allowed.
 
 	The brstack output includes branch related information with raw addresses using the
 	/v/v/v/v/ syntax in the following order:
-- 
2.5.5

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 04/10] perf hists: Rename __hists__add_entry to hists__add_entry
  2016-06-20 22:23 [GIT PULL 00/10] perf/core improvements and fixes Arnaldo Carvalho de Melo
                   ` (2 preceding siblings ...)
  2016-06-20 22:23 ` [PATCH 03/10] perf script: Fix documentation of '-f' when it should be '-F' Arnaldo Carvalho de Melo
@ 2016-06-20 22:23 ` Arnaldo Carvalho de Melo
  2016-06-20 22:23 ` [PATCH 05/10] perf tools: Remove some unused functions Arnaldo Carvalho de Melo
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 17+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-06-20 22:23 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Jiri Olsa, David Ahern, Namhyung Kim,
	Peter Zijlstra, Arnaldo Carvalho de Melo

From: Jiri Olsa <jolsa@kernel.org>

There's no reason we should suffer the '__' prefix for the base global
function.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1465928361-2442-12-git-send-email-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-annotate.c |  2 +-
 tools/perf/builtin-diff.c     | 12 +-----------
 tools/perf/tests/hists_link.c |  4 ++--
 tools/perf/util/hist.c        | 34 +++++++++++++++++-----------------
 tools/perf/util/hist.h        | 14 +++++++-------
 5 files changed, 28 insertions(+), 38 deletions(-)

diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index 25c81734a950..a2324e1892aa 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -75,7 +75,7 @@ static int perf_evsel__add_sample(struct perf_evsel *evsel,
 	sample->period = 1;
 	sample->weight = 1;
 
-	he = __hists__add_entry(hists, al, NULL, NULL, NULL, sample, true);
+	he = hists__add_entry(hists, al, NULL, NULL, NULL, sample, true);
 	if (he == NULL)
 		return -ENOMEM;
 
diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c
index 7f628f9c2fb4..8b6735f35179 100644
--- a/tools/perf/builtin-diff.c
+++ b/tools/perf/builtin-diff.c
@@ -310,16 +310,6 @@ static int formula_fprintf(struct hist_entry *he, struct hist_entry *pair,
 	return -1;
 }
 
-static int hists__add_entry(struct hists *hists,
-			    struct addr_location *al,
-			    struct perf_sample *sample)
-{
-	if (__hists__add_entry(hists, al, NULL, NULL, NULL,
-			       sample, true) != NULL)
-		return 0;
-	return -ENOMEM;
-}
-
 static int diff__process_sample_event(struct perf_tool *tool __maybe_unused,
 				      union perf_event *event,
 				      struct perf_sample *sample,
@@ -336,7 +326,7 @@ static int diff__process_sample_event(struct perf_tool *tool __maybe_unused,
 		return -1;
 	}
 
-	if (hists__add_entry(hists, &al, sample)) {
+	if (!hists__add_entry(hists, &al, NULL, NULL, NULL, sample, true)) {
 		pr_warning("problem incrementing symbol period, skipping event\n");
 		goto out_put;
 	}
diff --git a/tools/perf/tests/hists_link.c b/tools/perf/tests/hists_link.c
index acf5a1301c07..6f96ca4d4fc0 100644
--- a/tools/perf/tests/hists_link.c
+++ b/tools/perf/tests/hists_link.c
@@ -84,7 +84,7 @@ static int add_hist_entries(struct perf_evlist *evlist, struct machine *machine)
 			if (machine__resolve(machine, &al, &sample) < 0)
 				goto out;
 
-			he = __hists__add_entry(hists, &al, NULL,
+			he = hists__add_entry(hists, &al, NULL,
 						NULL, NULL, &sample, true);
 			if (he == NULL) {
 				addr_location__put(&al);
@@ -103,7 +103,7 @@ static int add_hist_entries(struct perf_evlist *evlist, struct machine *machine)
 			if (machine__resolve(machine, &al, &sample) < 0)
 				goto out;
 
-			he = __hists__add_entry(hists, &al, NULL,
+			he = hists__add_entry(hists, &al, NULL,
 						NULL, NULL, &sample, true);
 			if (he == NULL) {
 				addr_location__put(&al);
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index 2515cfdb7365..d2647b1d82c0 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -531,13 +531,13 @@ out:
 	return he;
 }
 
-struct hist_entry *__hists__add_entry(struct hists *hists,
-				      struct addr_location *al,
-				      struct symbol *sym_parent,
-				      struct branch_info *bi,
-				      struct mem_info *mi,
-				      struct perf_sample *sample,
-				      bool sample_self)
+struct hist_entry *hists__add_entry(struct hists *hists,
+				    struct addr_location *al,
+				    struct symbol *sym_parent,
+				    struct branch_info *bi,
+				    struct mem_info *mi,
+				    struct perf_sample *sample,
+				    bool sample_self)
 {
 	struct hist_entry entry = {
 		.thread	= al->thread,
@@ -622,8 +622,8 @@ iter_add_single_mem_entry(struct hist_entry_iter *iter, struct addr_location *al
 	 */
 	sample->period = cost;
 
-	he = __hists__add_entry(hists, al, iter->parent, NULL, mi,
-				sample, true);
+	he = hists__add_entry(hists, al, iter->parent, NULL, mi,
+			      sample, true);
 	if (!he)
 		return -ENOMEM;
 
@@ -727,8 +727,8 @@ iter_add_next_branch_entry(struct hist_entry_iter *iter, struct addr_location *a
 	sample->period = 1;
 	sample->weight = bi->flags.cycles ? bi->flags.cycles : 1;
 
-	he = __hists__add_entry(hists, al, iter->parent, &bi[i], NULL,
-				sample, true);
+	he = hists__add_entry(hists, al, iter->parent, &bi[i], NULL,
+			      sample, true);
 	if (he == NULL)
 		return -ENOMEM;
 
@@ -764,8 +764,8 @@ iter_add_single_normal_entry(struct hist_entry_iter *iter, struct addr_location
 	struct perf_sample *sample = iter->sample;
 	struct hist_entry *he;
 
-	he = __hists__add_entry(evsel__hists(evsel), al, iter->parent, NULL, NULL,
-				sample, true);
+	he = hists__add_entry(evsel__hists(evsel), al, iter->parent, NULL, NULL,
+			      sample, true);
 	if (he == NULL)
 		return -ENOMEM;
 
@@ -825,8 +825,8 @@ iter_add_single_cumulative_entry(struct hist_entry_iter *iter,
 	struct hist_entry *he;
 	int err = 0;
 
-	he = __hists__add_entry(hists, al, iter->parent, NULL, NULL,
-				sample, true);
+	he = hists__add_entry(hists, al, iter->parent, NULL, NULL,
+			      sample, true);
 	if (he == NULL)
 		return -ENOMEM;
 
@@ -900,8 +900,8 @@ iter_add_next_cumulative_entry(struct hist_entry_iter *iter,
 		}
 	}
 
-	he = __hists__add_entry(evsel__hists(evsel), al, iter->parent, NULL, NULL,
-				sample, false);
+	he = hists__add_entry(evsel__hists(evsel), al, iter->parent, NULL, NULL,
+			      sample, false);
 	if (he == NULL)
 		return -ENOMEM;
 
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h
index a19112872ff9..0a03e08be503 100644
--- a/tools/perf/util/hist.h
+++ b/tools/perf/util/hist.h
@@ -120,13 +120,13 @@ extern const struct hist_iter_ops hist_iter_branch;
 extern const struct hist_iter_ops hist_iter_mem;
 extern const struct hist_iter_ops hist_iter_cumulative;
 
-struct hist_entry *__hists__add_entry(struct hists *hists,
-				      struct addr_location *al,
-				      struct symbol *parent,
-				      struct branch_info *bi,
-				      struct mem_info *mi,
-				      struct perf_sample *sample,
-				      bool sample_self);
+struct hist_entry *hists__add_entry(struct hists *hists,
+				    struct addr_location *al,
+				    struct symbol *parent,
+				    struct branch_info *bi,
+				    struct mem_info *mi,
+				    struct perf_sample *sample,
+				    bool sample_self);
 int hist_entry_iter__add(struct hist_entry_iter *iter, struct addr_location *al,
 			 int max_stack_depth, void *arg);
 
-- 
2.5.5

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 05/10] perf tools: Remove some unused functions
  2016-06-20 22:23 [GIT PULL 00/10] perf/core improvements and fixes Arnaldo Carvalho de Melo
                   ` (3 preceding siblings ...)
  2016-06-20 22:23 ` [PATCH 04/10] perf hists: Rename __hists__add_entry to hists__add_entry Arnaldo Carvalho de Melo
@ 2016-06-20 22:23 ` Arnaldo Carvalho de Melo
  2016-06-20 22:23 ` [PATCH 06/10] perf tools: Remove --perf-dir and --work-dir Arnaldo Carvalho de Melo
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 17+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-06-20 22:23 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Arnaldo Carvalho de Melo, Adrian Hunter,
	David Ahern, Jiri Olsa, Namhyung Kim, Wang Nan

From: Arnaldo Carvalho de Melo <acme@redhat.com>

Probably are there since the beginning, taken from git but never used.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-lr65jeefffjeaywoapps9a6i@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/cache.h  |  4 ---
 tools/perf/util/config.c |  2 +-
 tools/perf/util/path.c   | 65 +-----------------------------------------------
 3 files changed, 2 insertions(+), 69 deletions(-)

diff --git a/tools/perf/util/cache.h b/tools/perf/util/cache.h
index 0d814bb74661..f260040abc90 100644
--- a/tools/perf/util/cache.h
+++ b/tools/perf/util/cache.h
@@ -32,7 +32,6 @@ int perf_config_int(const char *, const char *);
 u64 perf_config_u64(const char *, const char *);
 int perf_config_bool(const char *, const char *);
 int config_error_nonbool(const char *);
-const char *perf_config_dirname(const char *, const char *);
 const char *perf_etc_perfconfig(void);
 
 char *alias_lookup(const char *alias);
@@ -45,9 +44,6 @@ static inline int is_absolute_path(const char *path)
 	return path[0] == '/';
 }
 
-char *strip_path_suffix(const char *path, const char *suffix);
-
 char *mkpath(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
-char *perf_path(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
 
 #endif /* __PERF_CACHE_H */
diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c
index 31e09a4e8862..d15c59267644 100644
--- a/tools/perf/util/config.c
+++ b/tools/perf/util/config.c
@@ -372,7 +372,7 @@ int perf_config_bool(const char *name, const char *value)
 	return !!perf_config_bool_or_int(name, value, &discard);
 }
 
-const char *perf_config_dirname(const char *name, const char *value)
+static const char *perf_config_dirname(const char *name, const char *value)
 {
 	if (!name)
 		return NULL;
diff --git a/tools/perf/util/path.c b/tools/perf/util/path.c
index 3bf6bf82ff2d..cff8bf0f87e8 100644
--- a/tools/perf/util/path.c
+++ b/tools/perf/util/path.c
@@ -14,14 +14,8 @@
 
 static char bad_path[] = "/bad-path/";
 /*
- * Two hacks:
+ * One hack:
  */
-
-static const char *get_perf_dir(void)
-{
-	return ".";
-}
-
 static char *get_pathname(void)
 {
 	static char pathname_array[4][PATH_MAX];
@@ -54,60 +48,3 @@ char *mkpath(const char *fmt, ...)
 		return bad_path;
 	return cleanup_path(pathname);
 }
-
-char *perf_path(const char *fmt, ...)
-{
-	const char *perf_dir = get_perf_dir();
-	char *pathname = get_pathname();
-	va_list args;
-	unsigned len;
-
-	len = strlen(perf_dir);
-	if (len > PATH_MAX-100)
-		return bad_path;
-	memcpy(pathname, perf_dir, len);
-	if (len && perf_dir[len-1] != '/')
-		pathname[len++] = '/';
-	va_start(args, fmt);
-	len += vsnprintf(pathname + len, PATH_MAX - len, fmt, args);
-	va_end(args);
-	if (len >= PATH_MAX)
-		return bad_path;
-	return cleanup_path(pathname);
-}
-
-/* strip arbitrary amount of directory separators at end of path */
-static inline int chomp_trailing_dir_sep(const char *path, int len)
-{
-	while (len && is_dir_sep(path[len - 1]))
-		len--;
-	return len;
-}
-
-/*
- * If path ends with suffix (complete path components), returns the
- * part before suffix (sans trailing directory separators).
- * Otherwise returns NULL.
- */
-char *strip_path_suffix(const char *path, const char *suffix)
-{
-	int path_len = strlen(path), suffix_len = strlen(suffix);
-
-	while (suffix_len) {
-		if (!path_len)
-			return NULL;
-
-		if (is_dir_sep(path[path_len - 1])) {
-			if (!is_dir_sep(suffix[suffix_len - 1]))
-				return NULL;
-			path_len = chomp_trailing_dir_sep(path, path_len);
-			suffix_len = chomp_trailing_dir_sep(suffix, suffix_len);
-		}
-		else if (path[--path_len] != suffix[--suffix_len])
-			return NULL;
-	}
-
-	if (path_len && !is_dir_sep(path[path_len - 1]))
-		return NULL;
-	return strndup(path, chomp_trailing_dir_sep(path, path_len));
-}
-- 
2.5.5

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 06/10] perf tools: Remove --perf-dir and --work-dir
  2016-06-20 22:23 [GIT PULL 00/10] perf/core improvements and fixes Arnaldo Carvalho de Melo
                   ` (4 preceding siblings ...)
  2016-06-20 22:23 ` [PATCH 05/10] perf tools: Remove some unused functions Arnaldo Carvalho de Melo
@ 2016-06-20 22:23 ` Arnaldo Carvalho de Melo
  2016-06-20 22:23 ` [PATCH 07/10] perf llvm: Allow dump llvm output object file using llvm.dump-obj Arnaldo Carvalho de Melo
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 17+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-06-20 22:23 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Arnaldo Carvalho de Melo, Adrian Hunter,
	David Ahern, Jiri Olsa, Namhyung Kim, Wang Nan

From: Arnaldo Carvalho de Melo <acme@redhat.com>

Completely unused in perf, carried along all this time from the initial
copy of git infrastructure, ditch'em.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-wtiln26gyqndprmkl0kdswvi@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/perf.c       | 36 ------------------------------------
 tools/perf/util/cache.h |  5 -----
 2 files changed, 41 deletions(-)

diff --git a/tools/perf/perf.c b/tools/perf/perf.c
index 15982cee5ef3..634bf7c6c477 100644
--- a/tools/perf/perf.c
+++ b/tools/perf/perf.c
@@ -139,8 +139,6 @@ struct option options[] = {
 	OPT_ARGUMENT("html-path", "html-path"),
 	OPT_ARGUMENT("paginate", "paginate"),
 	OPT_ARGUMENT("no-pager", "no-pager"),
-	OPT_ARGUMENT("perf-dir", "perf-dir"),
-	OPT_ARGUMENT("work-tree", "work-tree"),
 	OPT_ARGUMENT("debugfs-dir", "debugfs-dir"),
 	OPT_ARGUMENT("buildid-dir", "buildid-dir"),
 	OPT_ARGUMENT("list-cmds", "list-cmds"),
@@ -200,35 +198,6 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
 			use_pager = 0;
 			if (envchanged)
 				*envchanged = 1;
-		} else if (!strcmp(cmd, "--perf-dir")) {
-			if (*argc < 2) {
-				fprintf(stderr, "No directory given for --perf-dir.\n");
-				usage(perf_usage_string);
-			}
-			setenv(PERF_DIR_ENVIRONMENT, (*argv)[1], 1);
-			if (envchanged)
-				*envchanged = 1;
-			(*argv)++;
-			(*argc)--;
-			handled++;
-		} else if (!prefixcmp(cmd, CMD_PERF_DIR)) {
-			setenv(PERF_DIR_ENVIRONMENT, cmd + strlen(CMD_PERF_DIR), 1);
-			if (envchanged)
-				*envchanged = 1;
-		} else if (!strcmp(cmd, "--work-tree")) {
-			if (*argc < 2) {
-				fprintf(stderr, "No directory given for --work-tree.\n");
-				usage(perf_usage_string);
-			}
-			setenv(PERF_WORK_TREE_ENVIRONMENT, (*argv)[1], 1);
-			if (envchanged)
-				*envchanged = 1;
-			(*argv)++;
-			(*argc)--;
-		} else if (!prefixcmp(cmd, CMD_WORK_TREE)) {
-			setenv(PERF_WORK_TREE_ENVIRONMENT, cmd + strlen(CMD_WORK_TREE), 1);
-			if (envchanged)
-				*envchanged = 1;
 		} else if (!strcmp(cmd, "--debugfs-dir")) {
 			if (*argc < 2) {
 				fprintf(stderr, "No directory given for --debugfs-dir.\n");
@@ -363,11 +332,6 @@ const char perf_version_string[] = PERF_VERSION;
 
 #define RUN_SETUP	(1<<0)
 #define USE_PAGER	(1<<1)
-/*
- * require working tree to be present -- anything uses this needs
- * RUN_SETUP for reading from the configuration file.
- */
-#define NEED_WORK_TREE	(1<<2)
 
 static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
 {
diff --git a/tools/perf/util/cache.h b/tools/perf/util/cache.h
index f260040abc90..369f382eedb6 100644
--- a/tools/perf/util/cache.h
+++ b/tools/perf/util/cache.h
@@ -11,14 +11,9 @@
 #include <linux/string.h>
 
 #define CMD_EXEC_PATH "--exec-path"
-#define CMD_PERF_DIR "--perf-dir="
-#define CMD_WORK_TREE "--work-tree="
 #define CMD_DEBUGFS_DIR "--debugfs-dir="
 
-#define PERF_DIR_ENVIRONMENT "PERF_DIR"
-#define PERF_WORK_TREE_ENVIRONMENT "PERF_WORK_TREE"
 #define EXEC_PATH_ENVIRONMENT "PERF_EXEC_PATH"
-#define DEFAULT_PERF_DIR_ENVIRONMENT ".perf"
 #define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR"
 #define PERF_TRACEFS_ENVIRONMENT "PERF_TRACEFS_DIR"
 #define PERF_PAGER_ENVIRONMENT "PERF_PAGER"
-- 
2.5.5

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 07/10] perf llvm: Allow dump llvm output object file using llvm.dump-obj
  2016-06-20 22:23 [GIT PULL 00/10] perf/core improvements and fixes Arnaldo Carvalho de Melo
                   ` (5 preceding siblings ...)
  2016-06-20 22:23 ` [PATCH 06/10] perf tools: Remove --perf-dir and --work-dir Arnaldo Carvalho de Melo
@ 2016-06-20 22:23 ` Arnaldo Carvalho de Melo
  2016-06-20 22:23 ` [PATCH 08/10] perf record: Add --dry-run option to check cmdline options Arnaldo Carvalho de Melo
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 17+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-06-20 22:23 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Wang Nan, Alexei Starovoitov, Jiri Olsa, pi3orama,
	Arnaldo Carvalho de Melo

From: Wang Nan <wangnan0@huawei.com>

Add a 'llvm.dump-obj' config option to enable perf dump BPF object files
compiled by LLVM.

This option is useful when using BPF objects in embedded platforms.
LLVM compiler won't be deployed in these platforms, and currently we
don't support dynamic compiling library.

Before this patch users have to explicitly issue llvm commands to
compile BPF scripts, and can't use helpers (like include path detection
and default macros) in perf. With this option, user is allowed to use
perf to compile their BPF objects then copy them into their embedded
platforms.

Committer notice:

Testing it:

  # cat ~/.perfconfig
  [llvm]
	dump-obj = true
  #
  # ls -la filter.o
  ls: cannot access filter.o: No such file or directory
  # cat filter.c
  #include <uapi/linux/bpf.h>
  #define SEC(NAME) __attribute__((section(NAME), used))

  SEC("func=hrtimer_nanosleep rqtp->tv_nsec")
  int func(void *ctx, int err, long nsec)
  {
	return nsec > 1000;
  }
  char _license[] SEC("license") = "GPL";
  int _version SEC("version") = LINUX_VERSION_CODE;
  # trace -e nanosleep --event filter.c usleep 6
  LLVM: dumping filter.o
     0.007 ( 0.007 ms): usleep/13976 nanosleep(rqtp: 0x7ffc5847f640                                        ) ...
     0.007 (         ): perf_bpf_probe:func:(ffffffff811137d0) tv_nsec=6000)
     0.070 ( 0.070 ms): usleep/13976  ... [continued]: nanosleep()) = 0
  # ls -la filter.o
  -rw-r--r--. 1 root root 776 Jun 20 17:01 filter.o
  # readelf -SW filter.o
  There are 7 section headers, starting at offset 0x148:

  Section Headers:
   [Nr] Name        Type       Address          Off    Size   ES Flg Lk Inf Al
   [ 0]             NULL       0000000000000000 000000 000000 00      0   0  0
   [ 1] .strtab     STRTAB     0000000000000000 0000e8 00005a 00      0   0  1
   [ 2] .text       PROGBITS   0000000000000000 000040 000000 00  AX  0   0  4
   [ 3] func=hrtimer_nanosleep rqtp->tv_nsec PROGBITS 0000000000000000 000040 000028 00  AX  0   0  8
   [ 4] license     PROGBITS   0000000000000000 000068 000004 00  WA  0   0  1
   [ 5] version     PROGBITS   0000000000000000 00006c 000004 00  WA  0   0  4
   [ 6] .symtab     SYMTAB     0000000000000000 000070 000078 18      1   2  8
  Key to Flags:
   W (write), A (alloc), X (execute), M (merge), S (strings)
   I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)
   O (extra OS processing required) o (OS specific), p (processor specific)
   #

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/1466064161-48553-2-git-send-email-wangnan0@huawei.com
[ s/dumpping/dumping/g ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/llvm-utils.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 tools/perf/util/llvm-utils.h |  5 +++++
 2 files changed, 47 insertions(+)

diff --git a/tools/perf/util/llvm-utils.c b/tools/perf/util/llvm-utils.c
index 33071d6159bc..878a566763c3 100644
--- a/tools/perf/util/llvm-utils.c
+++ b/tools/perf/util/llvm-utils.c
@@ -42,6 +42,8 @@ int perf_llvm_config(const char *var, const char *value)
 		llvm_param.kbuild_dir = strdup(value);
 	else if (!strcmp(var, "kbuild-opts"))
 		llvm_param.kbuild_opts = strdup(value);
+	else if (!strcmp(var, "dump-obj"))
+		llvm_param.dump_obj = !!perf_config_bool(var, value);
 	else
 		return -1;
 	llvm_param.user_set_param = true;
@@ -326,6 +328,42 @@ get_kbuild_opts(char **kbuild_dir, char **kbuild_include_opts)
 	pr_debug("include option is set to %s\n", *kbuild_include_opts);
 }
 
+static void
+dump_obj(const char *path, void *obj_buf, size_t size)
+{
+	char *obj_path = strdup(path);
+	FILE *fp;
+	char *p;
+
+	if (!obj_path) {
+		pr_warning("WARNING: No enough memory, skip object dumping\n");
+		return;
+	}
+
+	p = strrchr(obj_path, '.');
+	if (!p || (strcmp(p, ".c") != 0)) {
+		pr_warning("WARNING: invalid llvm source path: '%s', skip object dumping\n",
+			   obj_path);
+		goto out;
+	}
+
+	p[1] = 'o';
+	fp = fopen(obj_path, "wb");
+	if (!fp) {
+		pr_warning("WARNING: failed to open '%s': %s, skip object dumping\n",
+			   obj_path, strerror(errno));
+		goto out;
+	}
+
+	pr_info("LLVM: dumping %s\n", obj_path);
+	if (fwrite(obj_buf, size, 1, fp) != 1)
+		pr_warning("WARNING: failed to write to file '%s': %s, skip object dumping\n",
+			   obj_path, strerror(errno));
+	fclose(fp);
+out:
+	free(obj_path);
+}
+
 int llvm__compile_bpf(const char *path, void **p_obj_buf,
 		      size_t *p_obj_buf_sz)
 {
@@ -411,6 +449,10 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf,
 
 	free(kbuild_dir);
 	free(kbuild_include_opts);
+
+	if (llvm_param.dump_obj)
+		dump_obj(path, obj_buf, obj_buf_sz);
+
 	if (!p_obj_buf)
 		free(obj_buf);
 	else
diff --git a/tools/perf/util/llvm-utils.h b/tools/perf/util/llvm-utils.h
index 23b9a743fe72..9f501cef06a1 100644
--- a/tools/perf/util/llvm-utils.h
+++ b/tools/perf/util/llvm-utils.h
@@ -30,6 +30,11 @@ struct llvm_param {
 	 */
 	const char *kbuild_opts;
 	/*
+	 * Default is false. If set to true, write compiling result
+	 * to object file.
+	 */
+	bool dump_obj;
+	/*
 	 * Default is false. If one of the above fields is set by user
 	 * explicitly then user_set_llvm is set to true. This is used
 	 * for perf test. If user doesn't set anything in .perfconfig
-- 
2.5.5

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 08/10] perf record: Add --dry-run option to check cmdline options
  2016-06-20 22:23 [GIT PULL 00/10] perf/core improvements and fixes Arnaldo Carvalho de Melo
                   ` (6 preceding siblings ...)
  2016-06-20 22:23 ` [PATCH 07/10] perf llvm: Allow dump llvm output object file using llvm.dump-obj Arnaldo Carvalho de Melo
@ 2016-06-20 22:23 ` Arnaldo Carvalho de Melo
  2016-06-20 22:23 ` [PATCH 09/10] perf evsel: Fix write_backwards fallback Arnaldo Carvalho de Melo
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 17+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-06-20 22:23 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Wang Nan, Alexei Starovoitov, Jiri Olsa, pi3orama,
	Arnaldo Carvalho de Melo

From: Wang Nan <wangnan0@huawei.com>

With '--dry-run', 'perf record' doesn't do reall recording. Combine with
llvm.dump-obj option, --dry-run can be used to help compile BPF objects
for embedded platform.

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/1466064161-48553-3-git-send-email-wangnan0@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Documentation/perf-record.txt | 7 +++++++
 tools/perf/builtin-record.c              | 7 +++++++
 2 files changed, 14 insertions(+)

diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt
index 8dbee832abd9..5b46b1d1a37c 100644
--- a/tools/perf/Documentation/perf-record.txt
+++ b/tools/perf/Documentation/perf-record.txt
@@ -360,6 +360,13 @@ particular perf.data snapshot should be kept or not.
 
 Implies --timestamp-filename, --no-buildid and --no-buildid-cache.
 
+--dry-run::
+Parse options then exit. --dry-run can be used to detect errors in cmdline
+options.
+
+'perf record --dry-run -e' can act as a BPF script compiler if llvm.dump-obj
+in config file is set to true.
+
 SEE ALSO
 --------
 linkperf:perf-stat[1], linkperf:perf-list[1]
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index d4cf1b0c88f9..b1304ebc8779 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -1274,6 +1274,8 @@ static struct record record = {
 const char record_callchain_help[] = CALLCHAIN_RECORD_HELP
 	"\n\t\t\t\tDefault: fp";
 
+static bool dry_run;
+
 /*
  * XXX Will stay a global variable till we fix builtin-script.c to stop messing
  * with it and switch to use the library functions in perf_evlist that came
@@ -1393,6 +1395,8 @@ struct option __record_options[] = {
 		    "append timestamp to output filename"),
 	OPT_BOOLEAN(0, "switch-output", &record.switch_output,
 		    "Switch output when receive SIGUSR2"),
+	OPT_BOOLEAN(0, "dry-run", &dry_run,
+		    "Parse options then exit"),
 	OPT_END()
 };
 
@@ -1462,6 +1466,9 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused)
 	if (err)
 		return err;
 
+	if (dry_run)
+		return 0;
+
 	err = bpf__setup_stdout(rec->evlist);
 	if (err) {
 		bpf__strerror_setup_stdout(rec->evlist, err, errbuf, sizeof(errbuf));
-- 
2.5.5

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 09/10] perf evsel: Fix write_backwards fallback
  2016-06-20 22:23 [GIT PULL 00/10] perf/core improvements and fixes Arnaldo Carvalho de Melo
                   ` (7 preceding siblings ...)
  2016-06-20 22:23 ` [PATCH 08/10] perf record: Add --dry-run option to check cmdline options Arnaldo Carvalho de Melo
@ 2016-06-20 22:23 ` Arnaldo Carvalho de Melo
  2016-06-20 22:23 ` [PATCH 10/10] perf script: Add stackcollapse.py script Arnaldo Carvalho de Melo
  2016-06-21  2:18 ` [GIT PULL 00/10] perf/core improvements and fixes Namhyung Kim
  10 siblings, 0 replies; 17+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-06-20 22:23 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Arnaldo Carvalho de Melo, He Kuang, Jiri Olsa,
	Masami Hiramatsu, Namhyung Kim, Zefan Li, pi3orama, Wang Nan,
	Arnaldo Carvalho de Melo

Commit b90dc17a5d14 "perf evsel: Add overwrite attribute and check
write_backward" misunderstood the 'order' should be obeyed in
__perf_evsel__open.

But the way this was done for attr.write_backwards was buggy, as we need
to check features in the inverse order of their introduction to the
kernel, so that a newer tool checks first the newest perf_event_attr
fields, detecting that the older kernel doesn't have support for them.

Also, we can avoid calling sys_perf_event_open() if we have already
detected the missing of write_backward.

Cc: He Kuang <hekuang@huawei.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Fixes: b90dc17a5d14 ("perf evsel: Add overwrite attribute and check write_backward")
Link: http://lkml.kernel.org/r/1466419645-75551-2-git-send-email-wangnan0@huawei.com
Link: http://lkml.kernel.org/r/20160616214724.GI13337@kernel.org
Signed-off-by: Wang Nan <wangnan0@huawei.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/evsel.c | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)

diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 9b2e3e624efe..1d8f2bbd38a7 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -1389,8 +1389,11 @@ fallback_missing_features:
 	if (perf_missing_features.lbr_flags)
 		evsel->attr.branch_sample_type &= ~(PERF_SAMPLE_BRANCH_NO_FLAGS |
 				     PERF_SAMPLE_BRANCH_NO_CYCLES);
-	if (perf_missing_features.write_backward)
+	if (perf_missing_features.write_backward) {
+		if (evsel->overwrite)
+			return -EINVAL;
 		evsel->attr.write_backward = false;
+	}
 retry_sample_id:
 	if (perf_missing_features.sample_id_all)
 		evsel->attr.sample_id_all = 0;
@@ -1453,12 +1456,6 @@ retry_open:
 				err = -EINVAL;
 				goto out_close;
 			}
-
-			if (evsel->overwrite &&
-			    perf_missing_features.write_backward) {
-				err = -EINVAL;
-				goto out_close;
-			}
 		}
 	}
 
@@ -1496,7 +1493,10 @@ try_fallback:
 	 * Must probe features in the order they were added to the
 	 * perf_event_attr interface.
 	 */
-	if (!perf_missing_features.clockid_wrong && evsel->attr.use_clockid) {
+	if (!perf_missing_features.write_backward && evsel->attr.write_backward) {
+		perf_missing_features.write_backward = true;
+		goto fallback_missing_features;
+	} else if (!perf_missing_features.clockid_wrong && evsel->attr.use_clockid) {
 		perf_missing_features.clockid_wrong = true;
 		goto fallback_missing_features;
 	} else if (!perf_missing_features.clockid && evsel->attr.use_clockid) {
@@ -1521,12 +1521,7 @@ try_fallback:
 			  PERF_SAMPLE_BRANCH_NO_FLAGS))) {
 		perf_missing_features.lbr_flags = true;
 		goto fallback_missing_features;
-	} else if (!perf_missing_features.write_backward &&
-			evsel->attr.write_backward) {
-		perf_missing_features.write_backward = true;
-		goto fallback_missing_features;
 	}
-
 out_close:
 	do {
 		while (--thread >= 0) {
@@ -2409,6 +2404,8 @@ int perf_evsel__open_strerror(struct perf_evsel *evsel, struct target *target,
 	"We found oprofile daemon running, please stop it and try again.");
 		break;
 	case EINVAL:
+		if (evsel->overwrite && perf_missing_features.write_backward)
+			return scnprintf(msg, size, "Reading from overwrite event is not supported by this kernel.");
 		if (perf_missing_features.clockid)
 			return scnprintf(msg, size, "clockid feature not supported.");
 		if (perf_missing_features.clockid_wrong)
-- 
2.5.5

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 10/10] perf script: Add stackcollapse.py script
  2016-06-20 22:23 [GIT PULL 00/10] perf/core improvements and fixes Arnaldo Carvalho de Melo
                   ` (8 preceding siblings ...)
  2016-06-20 22:23 ` [PATCH 09/10] perf evsel: Fix write_backwards fallback Arnaldo Carvalho de Melo
@ 2016-06-20 22:23 ` Arnaldo Carvalho de Melo
  2016-06-21 18:36   ` Brendan Gregg
  2016-06-21  2:18 ` [GIT PULL 00/10] perf/core improvements and fixes Namhyung Kim
  10 siblings, 1 reply; 17+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-06-20 22:23 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Paolo Bonzini, Brendan Gregg, Arnaldo Carvalho de Melo

From: Paolo Bonzini <pbonzini@redhat.com>

Add stackcollapse.py script as an example of parsing call chains, and
also of using optparse to access command line options.

The flame graph tools include a set of scripts that parse output from
various tools (including "perf script"), remove the offsets in the
function and collapse each stack to a single line.  The website also
says "perf report could have a report style [...] that output folded
stacks directly, obviating the need for stackcollapse-perf.pl", so here
it is.

This script is a Python rewrite of stackcollapse-perf.pl, using the perf
scripting interface to access the perf data directly from Python.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Brendan Gregg <bgregg@netflix.com>
Link: http://lkml.kernel.org/r/1460467573-22989-1-git-send-email-pbonzini@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/scripts/python/bin/stackcollapse-record |   8 ++
 tools/perf/scripts/python/bin/stackcollapse-report |   3 +
 tools/perf/scripts/python/stackcollapse.py         | 127 +++++++++++++++++++++
 3 files changed, 138 insertions(+)
 create mode 100755 tools/perf/scripts/python/bin/stackcollapse-record
 create mode 100755 tools/perf/scripts/python/bin/stackcollapse-report
 create mode 100755 tools/perf/scripts/python/stackcollapse.py

diff --git a/tools/perf/scripts/python/bin/stackcollapse-record b/tools/perf/scripts/python/bin/stackcollapse-record
new file mode 100755
index 000000000000..9d8f9f0f3a17
--- /dev/null
+++ b/tools/perf/scripts/python/bin/stackcollapse-record
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+#
+# stackcollapse.py can cover all type of perf samples including
+# the tracepoints, so no special record requirements, just record what
+# you want to analyze.
+#
+perf record "$@"
diff --git a/tools/perf/scripts/python/bin/stackcollapse-report b/tools/perf/scripts/python/bin/stackcollapse-report
new file mode 100755
index 000000000000..356b9656393d
--- /dev/null
+++ b/tools/perf/scripts/python/bin/stackcollapse-report
@@ -0,0 +1,3 @@
+#!/bin/sh
+# description: produce callgraphs in short form for scripting use
+perf script -s "$PERF_EXEC_PATH"/scripts/python/stackcollapse.py -- "$@"
diff --git a/tools/perf/scripts/python/stackcollapse.py b/tools/perf/scripts/python/stackcollapse.py
new file mode 100755
index 000000000000..a2dfcda41ae6
--- /dev/null
+++ b/tools/perf/scripts/python/stackcollapse.py
@@ -0,0 +1,127 @@
+#!/usr/bin/perl -w
+#
+# stackcollapse.py - format perf samples with one line per distinct call stack
+#
+# This script's output has two space-separated fields.  The first is a semicolon
+# separated stack including the program name (from the "comm" field) and the
+# function names from the call stack.  The second is a count:
+#
+#  swapper;start_kernel;rest_init;cpu_idle;default_idle;native_safe_halt 2
+#
+# The file is sorted according to the first field.
+#
+# Input may be created and processed using:
+#
+#  perf record -a -g -F 99 sleep 60
+#  perf script report stackcollapse > out.stacks-folded
+#
+# (perf script record stackcollapse works too).
+#
+# Written by Paolo Bonzini <pbonzini@redhat.com>
+# Based on Brendan Gregg's stackcollapse-perf.pl script.
+
+import os
+import sys
+from collections import defaultdict
+from optparse import OptionParser, make_option
+
+sys.path.append(os.environ['PERF_EXEC_PATH'] + \
+                '/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
+
+from perf_trace_context import *
+from Core import *
+from EventClass import *
+
+# command line parsing
+
+option_list = [
+    # formatting options for the bottom entry of the stack
+    make_option("--include-tid", dest="include_tid",
+                 action="store_true", default=False,
+                 help="include thread id in stack"),
+    make_option("--include-pid", dest="include_pid",
+                 action="store_true", default=False,
+                 help="include process id in stack"),
+    make_option("--no-comm", dest="include_comm",
+                 action="store_false", default=True,
+                 help="do not separate stacks according to comm"),
+    make_option("--tidy-java", dest="tidy_java",
+                 action="store_true", default=False,
+                 help="beautify Java signatures"),
+    make_option("--kernel", dest="annotate_kernel",
+                 action="store_true", default=False,
+                 help="annotate kernel functions with _[k]")
+]
+
+parser = OptionParser(option_list=option_list)
+(opts, args) = parser.parse_args()
+
+if len(args) != 0:
+    parser.error("unexpected command line argument")
+if opts.include_tid and not opts.include_comm:
+    parser.error("requesting tid but not comm is invalid")
+if opts.include_pid and not opts.include_comm:
+    parser.error("requesting pid but not comm is invalid")
+
+# event handlers
+
+lines = defaultdict(lambda: 0)
+
+def process_event(param_dict):
+    def tidy_function_name(sym, dso):
+        if sym is None:
+            sym = '[unknown]'
+
+        sym = sym.replace(';', ':')
+        if opts.tidy_java:
+            # the original stackcollapse-perf.pl script gives the
+            # example of converting this:
+            #    Lorg/mozilla/javascript/MemberBox;.<init>(Ljava/lang/reflect/Method;)V
+            # to this:
+            #    org/mozilla/javascript/MemberBox:.init
+            sym = sym.replace('<', '')
+            sym = sym.replace('>', '')
+            if sym[0] == 'L' and sym.find('/'):
+                sym = sym[1:]
+            try:
+                sym = sym[:sym.index('(')]
+            except ValueError:
+                pass
+
+        if opts.annotate_kernel and dso == '[kernel.kallsyms]':
+            return sym + '_[k]'
+        else:
+            return sym
+
+    stack = list()
+    if 'callchain' in param_dict:
+        for entry in param_dict['callchain']:
+            entry.setdefault('sym', dict())
+            entry['sym'].setdefault('name', None)
+            entry.setdefault('dso', None)
+            stack.append(tidy_function_name(entry['sym']['name'],
+                                            entry['dso']))
+    else:
+        param_dict.setdefault('symbol', None)
+        param_dict.setdefault('dso', None)
+        stack.append(tidy_function_name(param_dict['symbol'],
+                                        param_dict['dso']))
+
+    if opts.include_comm:
+        comm = param_dict["comm"].replace(' ', '_')
+        sep = "-"
+        if opts.include_pid:
+            comm = comm + sep + str(param_dict['sample']['pid'])
+            sep = "/"
+        if opts.include_tid:
+            comm = comm + sep + str(param_dict['sample']['tid'])
+        stack.append(comm)
+
+    stack_string = ';'.join(reversed(stack))
+    lines[stack_string] = lines[stack_string] + 1
+
+def trace_end():
+    list = lines.keys()
+    list.sort()
+    for stack in list:
+        print "%s %d" % (stack, lines[stack])
-- 
2.5.5

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [GIT PULL 00/10] perf/core improvements and fixes
  2016-06-20 22:23 [GIT PULL 00/10] perf/core improvements and fixes Arnaldo Carvalho de Melo
                   ` (9 preceding siblings ...)
  2016-06-20 22:23 ` [PATCH 10/10] perf script: Add stackcollapse.py script Arnaldo Carvalho de Melo
@ 2016-06-21  2:18 ` Namhyung Kim
  2016-06-21  3:11   ` Brendan Gregg
  10 siblings, 1 reply; 17+ messages in thread
From: Namhyung Kim @ 2016-06-21  2:18 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Ingo Molnar, linux-kernel, Adrian Hunter, Alexander Shishkin,
	Alexei Starovoitov, Andi Kleen, Brendan Gregg, David Ahern,
	Ekaterina Tumanova, He Kuang, Jean Delvare, Jiri Olsa,
	Josh Poimboeuf, Kan Liang, linux-kbuild, Masami Hiramatsu,
	Michal Marek, Paolo Bonzini, Pekka Enberg, Peter Zijlstra,
	pi3orama, Stephane Eranian, Sukadev Bhattiprolu, Wang Nan,
	Zefan Li, Arnaldo Carvalho de Melo

Hi Arnaldo,

On Mon, Jun 20, 2016 at 07:23:20PM -0300, Arnaldo Carvalho de Melo wrote:
> Hi Ingo,
> 
> 	Please consider pulling,
> 
> - Arnaldo
> 
> The following changes since commit 02469a95096a549508c5adf61d84a1d72851c85b:
> 
>   Merge tag 'perf-core-for-mingo-20160615' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/core (2016-06-16 10:27:35 +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-20160620
> 
> for you to fetch changes up to 2a0a7c72702bac1b87cd4d49196a334483386fab:
> 
>   perf script: Add stackcollapse.py script (2016-06-20 17:50:39 -0300)
> 
> ----------------------------------------------------------------
> perf/core improvements and fixes:
> 
> New features:
> 
> . Add --dry-run option to 'perf record' to check if command line options can be
>   parsed, but not doing any recording (Wang Nan)
> 
> . Allow dumping the object files generated by llvm when processing eBPF
>   scriptlet events (Wang Nan)
> 
> - Add stackcollapse.py script to help generating flame graphs (Paolo Bonzini)

I think this is already done by '-g folded'.  Please see:

  http://www.brendangregg.com/blog/2016-04-30/linux-perf-folded.html

Thanks,
Namhyung


> 
> Documentation:
> 
> . Fix 'perf script'  documentation of '-f' when it should be '-F' (Adrian Hunter)
> 
> Infrastructure:
> 
> - Fix write_backwards fallback when using a new tool on older kernels
>   without support for this feature (Arnaldo Carvalho de Melo)
> 
> - Find vdso file in cross-platform perf.data file processing scenarios (He Kuang)
> 
> - Remove some leftovers from the initial codebase copying from git
>   (Arnaldo Carvalho de Melo)
> 
> - List libelf-devel as an alternative, as this is how the libelf
>   development package is called on OpenSuSE (Jean Delvare)
> 
> - Rename __hists__add_entry to hists__add_entry (Jiri Olsa)
> 
> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
> 
> ----------------------------------------------------------------
> Adrian Hunter (1):
>       perf script: Fix documentation of '-f' when it should be '-F'
> 
> Arnaldo Carvalho de Melo (3):
>       perf tools: Remove some unused functions
>       perf tools: Remove --perf-dir and --work-dir
>       perf evsel: Fix write_backwards fallback
> 
> He Kuang (1):
>       perf tools: Find vdso with the consider of cross-platform
> 
> Jean Delvare (1):
>       kbuild: List libelf-devel as an alternative
> 
> Jiri Olsa (1):
>       perf hists: Rename __hists__add_entry to hists__add_entry
> 
> Paolo Bonzini (1):
>       perf script: Add stackcollapse.py script
> 
> Wang Nan (2):
>       perf llvm: Allow dump llvm output object file using llvm.dump-obj
>       perf record: Add --dry-run option to check cmdline options
> 
>  Makefile                                           |   2 +-
>  tools/perf/Documentation/perf-record.txt           |   7 ++
>  tools/perf/Documentation/perf-script.txt           |  20 ++--
>  tools/perf/builtin-annotate.c                      |   2 +-
>  tools/perf/builtin-diff.c                          |  12 +-
>  tools/perf/builtin-record.c                        |   7 ++
>  tools/perf/config/Makefile                         |   2 +-
>  tools/perf/perf.c                                  |  36 ------
>  tools/perf/scripts/python/bin/stackcollapse-record |   8 ++
>  tools/perf/scripts/python/bin/stackcollapse-report |   3 +
>  tools/perf/scripts/python/stackcollapse.py         | 127 +++++++++++++++++++++
>  tools/perf/tests/hists_link.c                      |   4 +-
>  tools/perf/util/cache.h                            |   9 --
>  tools/perf/util/config.c                           |   2 +-
>  tools/perf/util/evsel.c                            |  23 ++--
>  tools/perf/util/hist.c                             |  34 +++---
>  tools/perf/util/hist.h                             |  14 +--
>  tools/perf/util/llvm-utils.c                       |  42 +++++++
>  tools/perf/util/llvm-utils.h                       |   5 +
>  tools/perf/util/path.c                             |  65 +----------
>  tools/perf/util/vdso.c                             |  40 ++++++-
>  21 files changed, 288 insertions(+), 176 deletions(-)
>  create mode 100755 tools/perf/scripts/python/bin/stackcollapse-record
>  create mode 100755 tools/perf/scripts/python/bin/stackcollapse-report
>  create mode 100755 tools/perf/scripts/python/stackcollapse.py

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [GIT PULL 00/10] perf/core improvements and fixes
  2016-06-21  2:18 ` [GIT PULL 00/10] perf/core improvements and fixes Namhyung Kim
@ 2016-06-21  3:11   ` Brendan Gregg
  2016-06-21 10:08     ` Paolo Bonzini
  0 siblings, 1 reply; 17+ messages in thread
From: Brendan Gregg @ 2016-06-21  3:11 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Arnaldo Carvalho de Melo, Ingo Molnar, linux-kernel,
	Adrian Hunter, Alexander Shishkin, Alexei Starovoitov,
	Andi Kleen, David Ahern, Ekaterina Tumanova, He Kuang,
	Jean Delvare, Jiri Olsa, Josh Poimboeuf, Kan Liang, linux-kbuild,
	Masami Hiramatsu, Michal Marek, Paolo Bonzini, Pekka Enberg,
	Peter Zijlstra, pi3orama, Stephane Eranian, Sukadev Bhattiprolu,
	Wang Nan, Zefan Li, Arnaldo Carvalho de Melo

On Mon, Jun 20, 2016 at 7:18 PM, Namhyung Kim <namhyung@kernel.org> wrote:
>
> Hi Arnaldo,
>
> On Mon, Jun 20, 2016 at 07:23:20PM -0300, Arnaldo Carvalho de Melo wrote:
> > Hi Ingo,
> >
> >       Please consider pulling,
> >
> > - Arnaldo
> >
> > The following changes since commit 02469a95096a549508c5adf61d84a1d72851c85b:
> >
> >   Merge tag 'perf-core-for-mingo-20160615' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/core (2016-06-16 10:27:35 +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-20160620
> >
> > for you to fetch changes up to 2a0a7c72702bac1b87cd4d49196a334483386fab:
> >
> >   perf script: Add stackcollapse.py script (2016-06-20 17:50:39 -0300)
> >
> > ----------------------------------------------------------------
> > perf/core improvements and fixes:
> >
> > New features:
> >
> > . Add --dry-run option to 'perf record' to check if command line options can be
> >   parsed, but not doing any recording (Wang Nan)
> >
> > . Allow dumping the object files generated by llvm when processing eBPF
> >   scriptlet events (Wang Nan)
> >
> > - Add stackcollapse.py script to help generating flame graphs (Paolo Bonzini)
>
> I think this is already done by '-g folded'.  Please see:
>
>   http://www.brendangregg.com/blog/2016-04-30/linux-perf-folded.html
>

Pretty much. Two similar solutions were developed around the same
time. Although I have to use some awk to get "perf -g folded" in the
exact right format, and stackcollapse-perf.py does that directly.

Brendan

Brendan Gregg, Senior Performance Architect, Netflix

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [GIT PULL 00/10] perf/core improvements and fixes
  2016-06-21  3:11   ` Brendan Gregg
@ 2016-06-21 10:08     ` Paolo Bonzini
  2016-06-21 16:14       ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 17+ messages in thread
From: Paolo Bonzini @ 2016-06-21 10:08 UTC (permalink / raw)
  To: Brendan Gregg, Namhyung Kim
  Cc: Arnaldo Carvalho de Melo, Ingo Molnar, linux-kernel,
	Adrian Hunter, Alexander Shishkin, Alexei Starovoitov,
	Andi Kleen, David Ahern, Ekaterina Tumanova, He Kuang,
	Jean Delvare, Jiri Olsa, Josh Poimboeuf, Kan Liang, linux-kbuild,
	Masami Hiramatsu, Michal Marek, Pekka Enberg, Peter Zijlstra,
	pi3orama, Stephane Eranian, Sukadev Bhattiprolu, Wang Nan,
	Zefan Li, Arnaldo Carvalho de Melo



On 21/06/2016 05:11, Brendan Gregg wrote:
>>> > > - Add stackcollapse.py script to help generating flame graphs (Paolo Bonzini)
>> >
>> > I think this is already done by '-g folded'.  Please see:
>> >
>> >   http://www.brendangregg.com/blog/2016-04-30/linux-perf-folded.html
>> >
> Pretty much. Two similar solutions were developed around the same
> time. Although I have to use some awk to get "perf -g folded" in the
> exact right format, and stackcollapse-perf.py does that directly.

Yes, the idea for stackcollapse-perf.py was:

- to do everything directly and emit "the right" format for the
flamegraph tools.  This however is a very minimal output, and it's not
necessarily the best for perf in general.

- to provide an example of visiting callgraphs from the scripting
interface, since it's not really documented.  From the commit message:
"Add stackcollapse.py script as an example of parsing call chains, and
also of using optparse to access command line options".

Paolo

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [GIT PULL 00/10] perf/core improvements and fixes
  2016-06-21 10:08     ` Paolo Bonzini
@ 2016-06-21 16:14       ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 17+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-06-21 16:14 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Brendan Gregg, Namhyung Kim, Arnaldo Carvalho de Melo,
	Ingo Molnar, linux-kernel, Adrian Hunter, Alexander Shishkin,
	Alexei Starovoitov, Andi Kleen, David Ahern, Ekaterina Tumanova,
	He Kuang, Jean Delvare, Jiri Olsa, Josh Poimboeuf, Kan Liang,
	linux-kbuild, Masami Hiramatsu, Michal Marek, Pekka Enberg,
	Peter Zijlstra, pi3orama, Stephane Eranian, Sukadev Bhattiprolu,
	Wang Nan, Zefan Li

Em Tue, Jun 21, 2016 at 12:08:47PM +0200, Paolo Bonzini escreveu:
> On 21/06/2016 05:11, Brendan Gregg wrote:
> >>> > > - Add stackcollapse.py script to help generating flame graphs (Paolo Bonzini)
> >> >
> >> > I think this is already done by '-g folded'.  Please see:
> >> >
> >> >   http://www.brendangregg.com/blog/2016-04-30/linux-perf-folded.html
> >> >
> > Pretty much. Two similar solutions were developed around the same
> > time. Although I have to use some awk to get "perf -g folded" in the
> > exact right format, and stackcollapse-perf.py does that directly.
> 
> Yes, the idea for stackcollapse-perf.py was:
> 
> - to do everything directly and emit "the right" format for the
> flamegraph tools.  This however is a very minimal output, and it's not
> necessarily the best for perf in general.
> 
> - to provide an example of visiting callgraphs from the scripting
> interface, since it's not really documented.  From the commit message:
> "Add stackcollapse.py script as an example of parsing call chains, and
> also of using optparse to access command line options".

Yeah, agreed, its short, and it provides the output ready to be used, no
need for extra processing, up to the user to decide if one or the other
is more suitable to their needs.

As a bonus, it documents callgraphs in scripts, good deal :-)

- Arnaldo

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 10/10] perf script: Add stackcollapse.py script
  2016-06-20 22:23 ` [PATCH 10/10] perf script: Add stackcollapse.py script Arnaldo Carvalho de Melo
@ 2016-06-21 18:36   ` Brendan Gregg
  2016-06-21 20:19     ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 17+ messages in thread
From: Brendan Gregg @ 2016-06-21 18:36 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Ingo Molnar, LKML, Paolo Bonzini, Brendan Gregg,
	Arnaldo Carvalho de Melo

On Mon, Jun 20, 2016 at 3:23 PM, Arnaldo Carvalho de Melo
<acme@kernel.org> wrote:
> From: Paolo Bonzini <pbonzini@redhat.com>
>
> Add stackcollapse.py script as an example of parsing call chains, and
> also of using optparse to access command line options.
>
> The flame graph tools include a set of scripts that parse output from
> various tools (including "perf script"), remove the offsets in the
> function and collapse each stack to a single line.  The website also
> says "perf report could have a report style [...] that output folded
> stacks directly, obviating the need for stackcollapse-perf.pl", so here
> it is.
>
> This script is a Python rewrite of stackcollapse-perf.pl, using the perf
> scripting interface to access the perf data directly from Python.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> Acked-by: Jiri Olsa <jolsa@kernel.org>
> Cc: Brendan Gregg <bgregg@netflix.com>
> Link: http://lkml.kernel.org/r/1460467573-22989-1-git-send-email-pbonzini@redhat.com
> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
> ---
>  tools/perf/scripts/python/bin/stackcollapse-record |   8 ++
>  tools/perf/scripts/python/bin/stackcollapse-report |   3 +
>  tools/perf/scripts/python/stackcollapse.py         | 127 +++++++++++++++++++++
>  3 files changed, 138 insertions(+)
>  create mode 100755 tools/perf/scripts/python/bin/stackcollapse-record
>  create mode 100755 tools/perf/scripts/python/bin/stackcollapse-report
>  create mode 100755 tools/perf/scripts/python/stackcollapse.py
>
> diff --git a/tools/perf/scripts/python/bin/stackcollapse-record b/tools/perf/scripts/python/bin/stackcollapse-record
> new file mode 100755
> index 000000000000..9d8f9f0f3a17
> --- /dev/null
> +++ b/tools/perf/scripts/python/bin/stackcollapse-record
> @@ -0,0 +1,8 @@
> +#!/bin/sh
> +
> +#
> +# stackcollapse.py can cover all type of perf samples including
> +# the tracepoints, so no special record requirements, just record what
> +# you want to analyze.
> +#
> +perf record "$@"
> diff --git a/tools/perf/scripts/python/bin/stackcollapse-report b/tools/perf/scripts/python/bin/stackcollapse-report
> new file mode 100755
> index 000000000000..356b9656393d
> --- /dev/null
> +++ b/tools/perf/scripts/python/bin/stackcollapse-report
> @@ -0,0 +1,3 @@
> +#!/bin/sh
> +# description: produce callgraphs in short form for scripting use
> +perf script -s "$PERF_EXEC_PATH"/scripts/python/stackcollapse.py -- "$@"
> diff --git a/tools/perf/scripts/python/stackcollapse.py b/tools/perf/scripts/python/stackcollapse.py
> new file mode 100755
> index 000000000000..a2dfcda41ae6
> --- /dev/null
> +++ b/tools/perf/scripts/python/stackcollapse.py
> @@ -0,0 +1,127 @@
> +#!/usr/bin/perl -w

Perl? I guess this line is ignored when invoked.

Rest looks good. Glad it supports tidy_java code, and kernel annotations.

Brendan

> +#
> +# stackcollapse.py - format perf samples with one line per distinct call stack
> +#
> +# This script's output has two space-separated fields.  The first is a semicolon
> +# separated stack including the program name (from the "comm" field) and the
> +# function names from the call stack.  The second is a count:
> +#
> +#  swapper;start_kernel;rest_init;cpu_idle;default_idle;native_safe_halt 2
> +#
> +# The file is sorted according to the first field.
> +#
> +# Input may be created and processed using:
> +#
> +#  perf record -a -g -F 99 sleep 60
> +#  perf script report stackcollapse > out.stacks-folded
> +#
> +# (perf script record stackcollapse works too).
> +#
> +# Written by Paolo Bonzini <pbonzini@redhat.com>
> +# Based on Brendan Gregg's stackcollapse-perf.pl script.
> +
> +import os
> +import sys
> +from collections import defaultdict
> +from optparse import OptionParser, make_option
> +
> +sys.path.append(os.environ['PERF_EXEC_PATH'] + \
> +                '/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
> +
> +from perf_trace_context import *
> +from Core import *
> +from EventClass import *
> +
> +# command line parsing
> +
> +option_list = [
> +    # formatting options for the bottom entry of the stack
> +    make_option("--include-tid", dest="include_tid",
> +                 action="store_true", default=False,
> +                 help="include thread id in stack"),
> +    make_option("--include-pid", dest="include_pid",
> +                 action="store_true", default=False,
> +                 help="include process id in stack"),
> +    make_option("--no-comm", dest="include_comm",
> +                 action="store_false", default=True,
> +                 help="do not separate stacks according to comm"),
> +    make_option("--tidy-java", dest="tidy_java",
> +                 action="store_true", default=False,
> +                 help="beautify Java signatures"),
> +    make_option("--kernel", dest="annotate_kernel",
> +                 action="store_true", default=False,
> +                 help="annotate kernel functions with _[k]")
> +]
> +
> +parser = OptionParser(option_list=option_list)
> +(opts, args) = parser.parse_args()
> +
> +if len(args) != 0:
> +    parser.error("unexpected command line argument")
> +if opts.include_tid and not opts.include_comm:
> +    parser.error("requesting tid but not comm is invalid")
> +if opts.include_pid and not opts.include_comm:
> +    parser.error("requesting pid but not comm is invalid")
> +
> +# event handlers
> +
> +lines = defaultdict(lambda: 0)
> +
> +def process_event(param_dict):
> +    def tidy_function_name(sym, dso):
> +        if sym is None:
> +            sym = '[unknown]'
> +
> +        sym = sym.replace(';', ':')
> +        if opts.tidy_java:
> +            # the original stackcollapse-perf.pl script gives the
> +            # example of converting this:
> +            #    Lorg/mozilla/javascript/MemberBox;.<init>(Ljava/lang/reflect/Method;)V
> +            # to this:
> +            #    org/mozilla/javascript/MemberBox:.init
> +            sym = sym.replace('<', '')
> +            sym = sym.replace('>', '')
> +            if sym[0] == 'L' and sym.find('/'):
> +                sym = sym[1:]
> +            try:
> +                sym = sym[:sym.index('(')]
> +            except ValueError:
> +                pass
> +
> +        if opts.annotate_kernel and dso == '[kernel.kallsyms]':
> +            return sym + '_[k]'
> +        else:
> +            return sym
> +
> +    stack = list()
> +    if 'callchain' in param_dict:
> +        for entry in param_dict['callchain']:
> +            entry.setdefault('sym', dict())
> +            entry['sym'].setdefault('name', None)
> +            entry.setdefault('dso', None)
> +            stack.append(tidy_function_name(entry['sym']['name'],
> +                                            entry['dso']))
> +    else:
> +        param_dict.setdefault('symbol', None)
> +        param_dict.setdefault('dso', None)
> +        stack.append(tidy_function_name(param_dict['symbol'],
> +                                        param_dict['dso']))
> +
> +    if opts.include_comm:
> +        comm = param_dict["comm"].replace(' ', '_')
> +        sep = "-"
> +        if opts.include_pid:
> +            comm = comm + sep + str(param_dict['sample']['pid'])
> +            sep = "/"
> +        if opts.include_tid:
> +            comm = comm + sep + str(param_dict['sample']['tid'])
> +        stack.append(comm)
> +
> +    stack_string = ';'.join(reversed(stack))
> +    lines[stack_string] = lines[stack_string] + 1
> +
> +def trace_end():
> +    list = lines.keys()
> +    list.sort()
> +    for stack in list:
> +        print "%s %d" % (stack, lines[stack])

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 10/10] perf script: Add stackcollapse.py script
  2016-06-21 18:36   ` Brendan Gregg
@ 2016-06-21 20:19     ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 17+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-06-21 20:19 UTC (permalink / raw)
  To: Brendan Gregg
  Cc: Ingo Molnar, LKML, Paolo Bonzini, Brendan Gregg,
	Arnaldo Carvalho de Melo

Em Tue, Jun 21, 2016 at 11:36:10AM -0700, Brendan Gregg escreveu:
> On Mon, Jun 20, 2016 at 3:23 PM, Arnaldo Carvalho de Melo
> <acme@kernel.org> wrote:
> > From: Paolo Bonzini <pbonzini@redhat.com>
> >
> > Add stackcollapse.py script as an example of parsing call chains, and
> > also of using optparse to access command line options.
> >
> > The flame graph tools include a set of scripts that parse output from
> > various tools (including "perf script"), remove the offsets in the
> > function and collapse each stack to a single line.  The website also
> > says "perf report could have a report style [...] that output folded
> > stacks directly, obviating the need for stackcollapse-perf.pl", so here
> > it is.
> >
> > This script is a Python rewrite of stackcollapse-perf.pl, using the perf
> > scripting interface to access the perf data directly from Python.
> >
> > Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> > Acked-by: Jiri Olsa <jolsa@kernel.org>
> > Cc: Brendan Gregg <bgregg@netflix.com>
> > Link: http://lkml.kernel.org/r/1460467573-22989-1-git-send-email-pbonzini@redhat.com
> > Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
> > ---
> >  tools/perf/scripts/python/bin/stackcollapse-record |   8 ++
> >  tools/perf/scripts/python/bin/stackcollapse-report |   3 +
> >  tools/perf/scripts/python/stackcollapse.py         | 127 +++++++++++++++++++++
> >  3 files changed, 138 insertions(+)
> >  create mode 100755 tools/perf/scripts/python/bin/stackcollapse-record
> >  create mode 100755 tools/perf/scripts/python/bin/stackcollapse-report
> >  create mode 100755 tools/perf/scripts/python/stackcollapse.py
> >
> > diff --git a/tools/perf/scripts/python/bin/stackcollapse-record b/tools/perf/scripts/python/bin/stackcollapse-record
> > new file mode 100755
> > index 000000000000..9d8f9f0f3a17
> > --- /dev/null
> > +++ b/tools/perf/scripts/python/bin/stackcollapse-record
> > @@ -0,0 +1,8 @@
> > +#!/bin/sh
> > +
> > +#
> > +# stackcollapse.py can cover all type of perf samples including
> > +# the tracepoints, so no special record requirements, just record what
> > +# you want to analyze.
> > +#
> > +perf record "$@"
> > diff --git a/tools/perf/scripts/python/bin/stackcollapse-report b/tools/perf/scripts/python/bin/stackcollapse-report
> > new file mode 100755
> > index 000000000000..356b9656393d
> > --- /dev/null
> > +++ b/tools/perf/scripts/python/bin/stackcollapse-report
> > @@ -0,0 +1,3 @@
> > +#!/bin/sh
> > +# description: produce callgraphs in short form for scripting use
> > +perf script -s "$PERF_EXEC_PATH"/scripts/python/stackcollapse.py -- "$@"
> > diff --git a/tools/perf/scripts/python/stackcollapse.py b/tools/perf/scripts/python/stackcollapse.py
> > new file mode 100755
> > index 000000000000..a2dfcda41ae6
> > --- /dev/null
> > +++ b/tools/perf/scripts/python/stackcollapse.py
> > @@ -0,0 +1,127 @@
> > +#!/usr/bin/perl -w
> 
> Perl? I guess this line is ignored when invoked.

Bummer, will fix and add another check on my .git/hooks/pre-commit
 
> Rest looks good. Glad it supports tidy_java code, and kernel annotations.

Glad you liked it,

- Arnaldo
 
> Brendan
> 
> > +#
> > +# stackcollapse.py - format perf samples with one line per distinct call stack
> > +#
> > +# This script's output has two space-separated fields.  The first is a semicolon
> > +# separated stack including the program name (from the "comm" field) and the
> > +# function names from the call stack.  The second is a count:
> > +#
> > +#  swapper;start_kernel;rest_init;cpu_idle;default_idle;native_safe_halt 2
> > +#
> > +# The file is sorted according to the first field.
> > +#
> > +# Input may be created and processed using:
> > +#
> > +#  perf record -a -g -F 99 sleep 60
> > +#  perf script report stackcollapse > out.stacks-folded
> > +#
> > +# (perf script record stackcollapse works too).
> > +#
> > +# Written by Paolo Bonzini <pbonzini@redhat.com>
> > +# Based on Brendan Gregg's stackcollapse-perf.pl script.
> > +
> > +import os
> > +import sys
> > +from collections import defaultdict
> > +from optparse import OptionParser, make_option
> > +
> > +sys.path.append(os.environ['PERF_EXEC_PATH'] + \
> > +                '/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
> > +
> > +from perf_trace_context import *
> > +from Core import *
> > +from EventClass import *
> > +
> > +# command line parsing
> > +
> > +option_list = [
> > +    # formatting options for the bottom entry of the stack
> > +    make_option("--include-tid", dest="include_tid",
> > +                 action="store_true", default=False,
> > +                 help="include thread id in stack"),
> > +    make_option("--include-pid", dest="include_pid",
> > +                 action="store_true", default=False,
> > +                 help="include process id in stack"),
> > +    make_option("--no-comm", dest="include_comm",
> > +                 action="store_false", default=True,
> > +                 help="do not separate stacks according to comm"),
> > +    make_option("--tidy-java", dest="tidy_java",
> > +                 action="store_true", default=False,
> > +                 help="beautify Java signatures"),
> > +    make_option("--kernel", dest="annotate_kernel",
> > +                 action="store_true", default=False,
> > +                 help="annotate kernel functions with _[k]")
> > +]
> > +
> > +parser = OptionParser(option_list=option_list)
> > +(opts, args) = parser.parse_args()
> > +
> > +if len(args) != 0:
> > +    parser.error("unexpected command line argument")
> > +if opts.include_tid and not opts.include_comm:
> > +    parser.error("requesting tid but not comm is invalid")
> > +if opts.include_pid and not opts.include_comm:
> > +    parser.error("requesting pid but not comm is invalid")
> > +
> > +# event handlers
> > +
> > +lines = defaultdict(lambda: 0)
> > +
> > +def process_event(param_dict):
> > +    def tidy_function_name(sym, dso):
> > +        if sym is None:
> > +            sym = '[unknown]'
> > +
> > +        sym = sym.replace(';', ':')
> > +        if opts.tidy_java:
> > +            # the original stackcollapse-perf.pl script gives the
> > +            # example of converting this:
> > +            #    Lorg/mozilla/javascript/MemberBox;.<init>(Ljava/lang/reflect/Method;)V
> > +            # to this:
> > +            #    org/mozilla/javascript/MemberBox:.init
> > +            sym = sym.replace('<', '')
> > +            sym = sym.replace('>', '')
> > +            if sym[0] == 'L' and sym.find('/'):
> > +                sym = sym[1:]
> > +            try:
> > +                sym = sym[:sym.index('(')]
> > +            except ValueError:
> > +                pass
> > +
> > +        if opts.annotate_kernel and dso == '[kernel.kallsyms]':
> > +            return sym + '_[k]'
> > +        else:
> > +            return sym
> > +
> > +    stack = list()
> > +    if 'callchain' in param_dict:
> > +        for entry in param_dict['callchain']:
> > +            entry.setdefault('sym', dict())
> > +            entry['sym'].setdefault('name', None)
> > +            entry.setdefault('dso', None)
> > +            stack.append(tidy_function_name(entry['sym']['name'],
> > +                                            entry['dso']))
> > +    else:
> > +        param_dict.setdefault('symbol', None)
> > +        param_dict.setdefault('dso', None)
> > +        stack.append(tidy_function_name(param_dict['symbol'],
> > +                                        param_dict['dso']))
> > +
> > +    if opts.include_comm:
> > +        comm = param_dict["comm"].replace(' ', '_')
> > +        sep = "-"
> > +        if opts.include_pid:
> > +            comm = comm + sep + str(param_dict['sample']['pid'])
> > +            sep = "/"
> > +        if opts.include_tid:
> > +            comm = comm + sep + str(param_dict['sample']['tid'])
> > +        stack.append(comm)
> > +
> > +    stack_string = ';'.join(reversed(stack))
> > +    lines[stack_string] = lines[stack_string] + 1
> > +
> > +def trace_end():
> > +    list = lines.keys()
> > +    list.sort()
> > +    for stack in list:
> > +        print "%s %d" % (stack, lines[stack])

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2016-06-21 20:30 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-20 22:23 [GIT PULL 00/10] perf/core improvements and fixes Arnaldo Carvalho de Melo
2016-06-20 22:23 ` [PATCH 01/10] perf tools: Find vdso with the consider of cross-platform Arnaldo Carvalho de Melo
2016-06-20 22:23 ` [PATCH 02/10] kbuild: List libelf-devel as an alternative Arnaldo Carvalho de Melo
2016-06-20 22:23 ` [PATCH 03/10] perf script: Fix documentation of '-f' when it should be '-F' Arnaldo Carvalho de Melo
2016-06-20 22:23 ` [PATCH 04/10] perf hists: Rename __hists__add_entry to hists__add_entry Arnaldo Carvalho de Melo
2016-06-20 22:23 ` [PATCH 05/10] perf tools: Remove some unused functions Arnaldo Carvalho de Melo
2016-06-20 22:23 ` [PATCH 06/10] perf tools: Remove --perf-dir and --work-dir Arnaldo Carvalho de Melo
2016-06-20 22:23 ` [PATCH 07/10] perf llvm: Allow dump llvm output object file using llvm.dump-obj Arnaldo Carvalho de Melo
2016-06-20 22:23 ` [PATCH 08/10] perf record: Add --dry-run option to check cmdline options Arnaldo Carvalho de Melo
2016-06-20 22:23 ` [PATCH 09/10] perf evsel: Fix write_backwards fallback Arnaldo Carvalho de Melo
2016-06-20 22:23 ` [PATCH 10/10] perf script: Add stackcollapse.py script Arnaldo Carvalho de Melo
2016-06-21 18:36   ` Brendan Gregg
2016-06-21 20:19     ` Arnaldo Carvalho de Melo
2016-06-21  2:18 ` [GIT PULL 00/10] perf/core improvements and fixes Namhyung Kim
2016-06-21  3:11   ` Brendan Gregg
2016-06-21 10:08     ` Paolo Bonzini
2016-06-21 16:14       ` Arnaldo Carvalho de Melo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).