linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/12] perf: Assorted fixes
@ 2018-01-07 16:03 Jiri Olsa
  2018-01-07 16:03 ` [PATCH 01/12] perf tools: Enable LIBBABELTRACE by default Jiri Olsa
                   ` (11 more replies)
  0 siblings, 12 replies; 44+ messages in thread
From: Jiri Olsa @ 2018-01-07 16:03 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Peter Zijlstra
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Andi Kleen,
	Alexander Shishkin

hi,
sending assorted general fixes that queued
up in my other branches.

Also available in here:
  https://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
  perf/fixes

thanks,
jirka

---
 include/uapi/linux/perf_event.h          |  10 +++++---
 kernel/events/callchain.c                |  15 ------------
 kernel/events/core.c                     |  54 +++++++++++++++++++++++++++++------------
 kernel/events/internal.h                 |   4 ----
 tools/perf/Documentation/perf-report.txt |   8 +++++++
 tools/perf/Documentation/perf-script.txt |  23 +++++++++++++++++-
 tools/perf/Makefile.config               |   2 +-
 tools/perf/Makefile.perf                 |   2 +-
 tools/perf/builtin-report.c              | 158 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 tools/perf/builtin-script.c              | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------
 tools/perf/util/event.c                  |   8 +++++++
 tools/perf/util/event.h                  |   1 +
 tools/perf/util/evsel.c                  |   2 ++
 tools/perf/util/session.c                |   6 +++--
 tools/perf/util/tool.h                   |   1 +
 15 files changed, 342 insertions(+), 54 deletions(-)

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

* [PATCH 01/12] perf tools: Enable LIBBABELTRACE by default
  2018-01-07 16:03 [PATCH 00/12] perf: Assorted fixes Jiri Olsa
@ 2018-01-07 16:03 ` Jiri Olsa
  2018-01-08 15:17   ` Arnaldo Carvalho de Melo
  2018-01-11  6:24   ` [tip:perf/core] perf tools: Enable LIBBABELTRACE by default tip-bot for Jiri Olsa
  2018-01-07 16:03 ` [PATCH 02/12] perf tools: Display perf_event_attr::namespaces debug info Jiri Olsa
                   ` (10 subsequent siblings)
  11 siblings, 2 replies; 44+ messages in thread
From: Jiri Olsa @ 2018-01-07 16:03 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Peter Zijlstra
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Andi Kleen,
	Alexander Shishkin

There's no reason anymore to treat babel trace in a special way,
because a) we no longer display its state b) the needed babeltrace
library is now out and well adopted among distros.

Link: http://lkml.kernel.org/n/tip-n1c2a8hwtf6wlh8e0uiqn8in@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/Makefile.config | 2 +-
 tools/perf/Makefile.perf   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index f050f38d8fa3..12dec6ea5ed2 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -780,7 +780,7 @@ else
   NO_PERF_READ_VDSOX32 := 1
 endif
 
-ifdef LIBBABELTRACE
+ifndef NO_LIBBABELTRACE
   $(call feature_check,libbabeltrace)
   ifeq ($(feature-libbabeltrace), 1)
     CFLAGS += -DHAVE_LIBBABELTRACE_SUPPORT $(LIBBABELTRACE_CFLAGS)
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 68cf1360a3f3..9fdefd748e2e 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -77,7 +77,7 @@ include ../scripts/utilities.mak
 #
 # Define NO_ZLIB if you do not want to support compressed kernel modules
 #
-# Define LIBBABELTRACE if you DO want libbabeltrace support
+# Define NO_LIBBABELTRACE if you do not want libbabeltrace support
 # for CTF data format.
 #
 # Define NO_LZMA if you do not want to support compressed (xz) kernel modules
-- 
2.13.6

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

* [PATCH 02/12] perf tools: Display perf_event_attr::namespaces debug info
  2018-01-07 16:03 [PATCH 00/12] perf: Assorted fixes Jiri Olsa
  2018-01-07 16:03 ` [PATCH 01/12] perf tools: Enable LIBBABELTRACE by default Jiri Olsa
@ 2018-01-07 16:03 ` Jiri Olsa
  2018-01-11  6:24   ` [tip:perf/core] " tip-bot for Jiri Olsa
  2018-01-07 16:03 ` [PATCH 03/12] perf: Allocate context task_ctx_data for child event Jiri Olsa
                   ` (9 subsequent siblings)
  11 siblings, 1 reply; 44+ messages in thread
From: Jiri Olsa @ 2018-01-07 16:03 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Peter Zijlstra
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Andi Kleen,
	Alexander Shishkin

Display namespaces bit in -vv debug display:

  $ perf record -vv --namespaces ...
  ...
  perf_event_attr:
    size                             112
    ...
    namespaces                       1

Link: http://lkml.kernel.org/n/tip-vbfkuxoiuo3tk27nvreqcq29@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/util/evsel.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index a4d256ea0dc4..c435b2444153 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -1577,6 +1577,7 @@ int perf_event_attr__fprintf(FILE *fp, struct perf_event_attr *attr,
 	PRINT_ATTRf(use_clockid, p_unsigned);
 	PRINT_ATTRf(context_switch, p_unsigned);
 	PRINT_ATTRf(write_backward, p_unsigned);
+	PRINT_ATTRf(namespaces, p_unsigned);
 
 	PRINT_ATTRn("{ wakeup_events, wakeup_watermark }", wakeup_events, p_unsigned);
 	PRINT_ATTRf(bp_type, p_unsigned);
-- 
2.13.6

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

* [PATCH 03/12] perf: Allocate context task_ctx_data for child event
  2018-01-07 16:03 [PATCH 00/12] perf: Assorted fixes Jiri Olsa
  2018-01-07 16:03 ` [PATCH 01/12] perf tools: Enable LIBBABELTRACE by default Jiri Olsa
  2018-01-07 16:03 ` [PATCH 02/12] perf tools: Display perf_event_attr::namespaces debug info Jiri Olsa
@ 2018-01-07 16:03 ` Jiri Olsa
  2018-01-08 12:14   ` Peter Zijlstra
  2018-01-11  6:24   ` [tip:perf/core] " tip-bot for Jiri Olsa
  2018-01-07 16:03 ` [PATCH 04/12] perf: Add sample_id to PERF_RECORD_ITRACE_START event comment Jiri Olsa
                   ` (8 subsequent siblings)
  11 siblings, 2 replies; 44+ messages in thread
From: Jiri Olsa @ 2018-01-07 16:03 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Peter Zijlstra
  Cc: Andi Kleen, lkml, Ingo Molnar, Namhyung Kim, David Ahern,
	Alexander Shishkin

Currently we use perf_event_context::task_ctx_data to save
and restore the LBR status when the task is scheduled out
and in.

We don't allocate it for child contexts, which results in
shorter task's LBR stack, because we don't save the history
from previous run and start over every time we schedule the
task in.

I made a test to generate samples with LBR call stack
and got higher numbers on bigger chain depths:

                            before:     after:
  LBR call chain: nr: 1       60561     498127
  LBR call chain: nr: 2           0          0
  LBR call chain: nr: 3      107030       2172
  LBR call chain: nr: 4      466685      62758
  LBR call chain: nr: 5     2307319     878046
  LBR call chain: nr: 6       48713     495218
  LBR call chain: nr: 7        1040       4551
  LBR call chain: nr: 8         481        172
  LBR call chain: nr: 9         878        120
  LBR call chain: nr: 10       2377       6698
  LBR call chain: nr: 11      28830     151487
  LBR call chain: nr: 12      29347     339867
  LBR call chain: nr: 13          4         22
  LBR call chain: nr: 14          3         53

Cc: Andi Kleen <ak@linux.intel.com>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 kernel/events/core.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 4df5b695bf0d..55fb648a32b0 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -10703,6 +10703,19 @@ inherit_event(struct perf_event *parent_event,
 	if (IS_ERR(child_event))
 		return child_event;
 
+
+	if ((child_event->attach_state & PERF_ATTACH_TASK_DATA) &&
+	    !child_ctx->task_ctx_data) {
+		struct pmu *pmu = child_event->pmu;
+
+		child_ctx->task_ctx_data = kzalloc(pmu->task_ctx_size,
+						   GFP_KERNEL);
+		if (!child_ctx->task_ctx_data) {
+			free_event(child_event);
+			return NULL;
+		}
+	}
+
 	/*
 	 * is_orphaned_event() and list_add_tail(&parent_event->child_list)
 	 * must be under the same lock in order to serialize against
@@ -10713,6 +10726,7 @@ inherit_event(struct perf_event *parent_event,
 	if (is_orphaned_event(parent_event) ||
 	    !atomic_long_inc_not_zero(&parent_event->refcount)) {
 		mutex_unlock(&parent_event->child_mutex);
+		/* task_ctx_data is freed with child_ctx */
 		free_event(child_event);
 		return NULL;
 	}
-- 
2.13.6

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

* [PATCH 04/12] perf: Add sample_id to PERF_RECORD_ITRACE_START event comment
  2018-01-07 16:03 [PATCH 00/12] perf: Assorted fixes Jiri Olsa
                   ` (2 preceding siblings ...)
  2018-01-07 16:03 ` [PATCH 03/12] perf: Allocate context task_ctx_data for child event Jiri Olsa
@ 2018-01-07 16:03 ` Jiri Olsa
  2018-01-11  6:25   ` [tip:perf/core] " tip-bot for Jiri Olsa
  2018-01-07 16:03 ` [PATCH 05/12] perf: Make perf_callchain function static Jiri Olsa
                   ` (7 subsequent siblings)
  11 siblings, 1 reply; 44+ messages in thread
From: Jiri Olsa @ 2018-01-07 16:03 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Peter Zijlstra
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Andi Kleen,
	Alexander Shishkin

Adding missing sample_id line into PERF_RECORD_ITRACE_START
event comment.

Link: http://lkml.kernel.org/n/tip-v3pua3unuiif07kvxkk3wbrx@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 include/uapi/linux/perf_event.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h
index b9a4953018ed..8bb66e8da945 100644
--- a/include/uapi/linux/perf_event.h
+++ b/include/uapi/linux/perf_event.h
@@ -864,6 +864,7 @@ enum perf_event_type {
 	 *	struct perf_event_header	header;
 	 *	u32				pid;
 	 *	u32				tid;
+	 *	struct sample_id		sample_id;
 	 * };
 	 */
 	PERF_RECORD_ITRACE_START		= 12,
-- 
2.13.6

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

* [PATCH 05/12] perf: Make perf_callchain function static
  2018-01-07 16:03 [PATCH 00/12] perf: Assorted fixes Jiri Olsa
                   ` (3 preceding siblings ...)
  2018-01-07 16:03 ` [PATCH 04/12] perf: Add sample_id to PERF_RECORD_ITRACE_START event comment Jiri Olsa
@ 2018-01-07 16:03 ` Jiri Olsa
  2018-01-11  6:25   ` [tip:perf/core] " tip-bot for Jiri Olsa
  2018-01-07 16:03 ` [PATCH 06/12] perf: Return empty callchain instead of NULL Jiri Olsa
                   ` (6 subsequent siblings)
  11 siblings, 1 reply; 44+ messages in thread
From: Jiri Olsa @ 2018-01-07 16:03 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Peter Zijlstra
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Andi Kleen,
	Alexander Shishkin

And moving it into core.c, because there's no caller
of this function other than the one in core.c

Link: http://lkml.kernel.org/n/tip-uqp7qd6aif47g39glnbu95yl@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 kernel/events/callchain.c | 15 ---------------
 kernel/events/core.c      | 16 ++++++++++++++++
 kernel/events/internal.h  |  4 ----
 3 files changed, 16 insertions(+), 19 deletions(-)

diff --git a/kernel/events/callchain.c b/kernel/events/callchain.c
index 1b2be63c8528..772a43fea825 100644
--- a/kernel/events/callchain.c
+++ b/kernel/events/callchain.c
@@ -179,21 +179,6 @@ put_callchain_entry(int rctx)
 }
 
 struct perf_callchain_entry *
-perf_callchain(struct perf_event *event, struct pt_regs *regs)
-{
-	bool kernel = !event->attr.exclude_callchain_kernel;
-	bool user   = !event->attr.exclude_callchain_user;
-	/* Disallow cross-task user callchains. */
-	bool crosstask = event->ctx->task && event->ctx->task != current;
-	const u32 max_stack = event->attr.sample_max_stack;
-
-	if (!kernel && !user)
-		return NULL;
-
-	return get_perf_callchain(regs, 0, kernel, user, max_stack, crosstask, true);
-}
-
-struct perf_callchain_entry *
 get_perf_callchain(struct pt_regs *regs, u32 init_nr, bool kernel, bool user,
 		   u32 max_stack, bool crosstask, bool add_mark)
 {
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 55fb648a32b0..5fc1ded4b450 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -5980,6 +5980,22 @@ static u64 perf_virt_to_phys(u64 virt)
 	return phys_addr;
 }
 
+static struct perf_callchain_entry *
+perf_callchain(struct perf_event *event, struct pt_regs *regs)
+{
+	bool kernel = !event->attr.exclude_callchain_kernel;
+	bool user   = !event->attr.exclude_callchain_user;
+	/* Disallow cross-task user callchains. */
+	bool crosstask = event->ctx->task && event->ctx->task != current;
+	const u32 max_stack = event->attr.sample_max_stack;
+
+	if (!kernel && !user)
+		return NULL;
+
+	return get_perf_callchain(regs, 0, kernel, user,
+				  max_stack, crosstask, true);
+}
+
 void perf_prepare_sample(struct perf_event_header *header,
 			 struct perf_sample_data *data,
 			 struct perf_event *event,
diff --git a/kernel/events/internal.h b/kernel/events/internal.h
index 09b1537ae06c..6dc725a7e7bc 100644
--- a/kernel/events/internal.h
+++ b/kernel/events/internal.h
@@ -201,10 +201,6 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
 
 DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
 
-/* Callchain handling */
-extern struct perf_callchain_entry *
-perf_callchain(struct perf_event *event, struct pt_regs *regs);
-
 static inline int get_recursion_context(int *recursion)
 {
 	int rctx;
-- 
2.13.6

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

* [PATCH 06/12] perf: Return empty callchain instead of NULL
  2018-01-07 16:03 [PATCH 00/12] perf: Assorted fixes Jiri Olsa
                   ` (4 preceding siblings ...)
  2018-01-07 16:03 ` [PATCH 05/12] perf: Make perf_callchain function static Jiri Olsa
@ 2018-01-07 16:03 ` Jiri Olsa
  2018-01-08 12:15   ` Peter Zijlstra
  2018-01-11  6:26   ` [tip:perf/core] " tip-bot for Jiri Olsa
  2018-01-07 16:03 ` [PATCH 07/12] perf: Update PERF_RECORD_MISC_* comment for perf_event_header::misc bit 13 Jiri Olsa
                   ` (5 subsequent siblings)
  11 siblings, 2 replies; 44+ messages in thread
From: Jiri Olsa @ 2018-01-07 16:03 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Peter Zijlstra
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Andi Kleen,
	Alexander Shishkin

It simplifies the code a bit, because we dump the callchain
even if it's empty. With 'empty' callchain we can remove
all the NULL-checking code paths.

Original-patch-from: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/n/tip-n4t869o2qc1b31v4wwvmxznb@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 kernel/events/core.c | 30 ++++++++++++------------------
 1 file changed, 12 insertions(+), 18 deletions(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 5fc1ded4b450..4e1a1bf8d867 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -5815,19 +5815,11 @@ void perf_output_sample(struct perf_output_handle *handle,
 		perf_output_read(handle, event);
 
 	if (sample_type & PERF_SAMPLE_CALLCHAIN) {
-		if (data->callchain) {
-			int size = 1;
-
-			if (data->callchain)
-				size += data->callchain->nr;
-
-			size *= sizeof(u64);
+		int size = 1;
 
-			__output_copy(handle, data->callchain, size);
-		} else {
-			u64 nr = 0;
-			perf_output_put(handle, nr);
-		}
+		size += data->callchain->nr;
+		size *= sizeof(u64);
+		__output_copy(handle, data->callchain, size);
 	}
 
 	if (sample_type & PERF_SAMPLE_RAW) {
@@ -5980,6 +5972,8 @@ static u64 perf_virt_to_phys(u64 virt)
 	return phys_addr;
 }
 
+static struct perf_callchain_entry __empty_callchain = { .nr = 0, };
+
 static struct perf_callchain_entry *
 perf_callchain(struct perf_event *event, struct pt_regs *regs)
 {
@@ -5988,12 +5982,14 @@ perf_callchain(struct perf_event *event, struct pt_regs *regs)
 	/* Disallow cross-task user callchains. */
 	bool crosstask = event->ctx->task && event->ctx->task != current;
 	const u32 max_stack = event->attr.sample_max_stack;
+	struct perf_callchain_entry *callchain;
 
 	if (!kernel && !user)
-		return NULL;
+		return &__empty_callchain;
 
-	return get_perf_callchain(regs, 0, kernel, user,
-				  max_stack, crosstask, true);
+	callchain = get_perf_callchain(regs, 0, kernel, user,
+				       max_stack, crosstask, true);
+	return callchain ?: &__empty_callchain;
 }
 
 void perf_prepare_sample(struct perf_event_header *header,
@@ -6018,9 +6014,7 @@ void perf_prepare_sample(struct perf_event_header *header,
 		int size = 1;
 
 		data->callchain = perf_callchain(event, regs);
-
-		if (data->callchain)
-			size += data->callchain->nr;
+		size += data->callchain->nr;
 
 		header->size += size * sizeof(u64);
 	}
-- 
2.13.6

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

* [PATCH 07/12] perf: Update PERF_RECORD_MISC_* comment for perf_event_header::misc bit 13
  2018-01-07 16:03 [PATCH 00/12] perf: Assorted fixes Jiri Olsa
                   ` (5 preceding siblings ...)
  2018-01-07 16:03 ` [PATCH 06/12] perf: Return empty callchain instead of NULL Jiri Olsa
@ 2018-01-07 16:03 ` Jiri Olsa
  2018-01-11  6:26   ` [tip:perf/core] " tip-bot for Jiri Olsa
  2018-01-07 16:03 ` [PATCH 08/12] perf script: Add support to display sample misc field Jiri Olsa
                   ` (4 subsequent siblings)
  11 siblings, 1 reply; 44+ messages in thread
From: Jiri Olsa @ 2018-01-07 16:03 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Peter Zijlstra
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Andi Kleen,
	Alexander Shishkin

The perf_event_header::misc bit 13 is shared on different
events and next patch is adding yet another bit 13 user.
Updating the comment to make it more structured and clear
which events use bit 13.

Suggested-by: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/n/tip-yhpr7l42xo6ew4xye6a189ez@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 include/uapi/linux/perf_event.h | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h
index 8bb66e8da945..c77c9a2ebbbb 100644
--- a/include/uapi/linux/perf_event.h
+++ b/include/uapi/linux/perf_event.h
@@ -612,9 +612,12 @@ struct perf_event_mmap_page {
  */
 #define PERF_RECORD_MISC_PROC_MAP_PARSE_TIMEOUT	(1 << 12)
 /*
- * PERF_RECORD_MISC_MMAP_DATA and PERF_RECORD_MISC_COMM_EXEC are used on
- * different events so can reuse the same bit position.
- * Ditto PERF_RECORD_MISC_SWITCH_OUT.
+ * Following PERF_RECORD_MISC_* are used on different
+ * events, so can reuse the same bit position:
+ *
+ *   PERF_RECORD_MISC_MMAP_DATA  - PERF_RECORD_MMAP* events
+ *   PERF_RECORD_MISC_COMM_EXEC  - PERF_RECORD_COMM event
+ *   PERF_RECORD_MISC_SWITCH_OUT - PERF_RECORD_SWITCH* events
  */
 #define PERF_RECORD_MISC_MMAP_DATA		(1 << 13)
 #define PERF_RECORD_MISC_COMM_EXEC		(1 << 13)
-- 
2.13.6

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

* [PATCH 08/12] perf script: Add support to display sample misc field
  2018-01-07 16:03 [PATCH 00/12] perf: Assorted fixes Jiri Olsa
                   ` (6 preceding siblings ...)
  2018-01-07 16:03 ` [PATCH 07/12] perf: Update PERF_RECORD_MISC_* comment for perf_event_header::misc bit 13 Jiri Olsa
@ 2018-01-07 16:03 ` Jiri Olsa
  2018-01-11  6:27   ` [tip:perf/core] " tip-bot for Jiri Olsa
  2018-01-07 16:03 ` [PATCH 09/12] perf script: Add support to display lost events Jiri Olsa
                   ` (3 subsequent siblings)
  11 siblings, 1 reply; 44+ messages in thread
From: Jiri Olsa @ 2018-01-07 16:03 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Peter Zijlstra
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Andi Kleen,
	Alexander Shishkin

Adding support to display sample misc field in form
of letter for each bit:

  # perf script -F +misc ...
   sched-messaging  1414 K     28690.636582:       4590 cycles ...
   sched-messaging  1407 U     28690.636600:     325620 cycles ...
   sched-messaging  1414 K     28690.636608:      19473 cycles ...
  misc field  __________/

The misc bits are assigned to following letters:

  PERF_RECORD_MISC_KERNEL        K
  PERF_RECORD_MISC_USER          U
  PERF_RECORD_MISC_HYPERVISOR    H
  PERF_RECORD_MISC_GUEST_KERNEL  G
  PERF_RECORD_MISC_GUEST_USER    g
  PERF_RECORD_MISC_MMAP_DATA*    M
  PERF_RECORD_MISC_COMM_EXEC     E
  PERF_RECORD_MISC_SWITCH_OUT    S

Link: http://lkml.kernel.org/n/tip-hg29n6pqspsinz8axruskq1j@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/Documentation/perf-script.txt | 20 ++++++++-
 tools/perf/builtin-script.c              | 74 +++++++++++++++++++++++++++-----
 tools/perf/util/event.h                  |  1 +
 tools/perf/util/evsel.c                  |  1 +
 4 files changed, 84 insertions(+), 12 deletions(-)

diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt
index 974ceb12c7f3..e37b5ee2ac21 100644
--- a/tools/perf/Documentation/perf-script.txt
+++ b/tools/perf/Documentation/perf-script.txt
@@ -117,7 +117,7 @@ OPTIONS
         Comma separated list of fields to print. Options are:
         comm, tid, pid, time, cpu, event, trace, ip, sym, dso, addr, symoff,
         srcline, period, iregs, uregs, brstack, brstacksym, flags, bpf-output, brstackinsn,
-	brstackoff, callindent, insn, insnlen, synth, phys_addr, metric.
+        brstackoff, callindent, insn, insnlen, synth, phys_addr, metric, misc.
         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
@@ -225,6 +225,24 @@ OPTIONS
 	that the metric computed is averaged over the whole sampling
 	period, not just for the sample point.
 
+	For sample events it's possible to display misc field with -F +misc option,
+	following letters are displayed for each bit:
+
+	  PERF_RECORD_MISC_KERNEL        K
+	  PERF_RECORD_MISC_USER          U
+	  PERF_RECORD_MISC_HYPERVISOR    H
+	  PERF_RECORD_MISC_GUEST_KERNEL  G
+	  PERF_RECORD_MISC_GUEST_USER    g
+	  PERF_RECORD_MISC_MMAP_DATA*    M
+	  PERF_RECORD_MISC_COMM_EXEC     E
+	  PERF_RECORD_MISC_SWITCH_OUT    S
+
+	  $ perf script -F +misc ...
+	   sched-messaging  1414 K     28690.636582:       4590 cycles ...
+	   sched-messaging  1407 U     28690.636600:     325620 cycles ...
+	   sched-messaging  1414 K     28690.636608:      19473 cycles ...
+	  misc field ___________/
+
 -k::
 --vmlinux=<file>::
         vmlinux pathname
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 77e47cf39f2c..85bd6fe2458a 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -93,6 +93,7 @@ enum perf_output_field {
 	PERF_OUTPUT_PHYS_ADDR       = 1U << 26,
 	PERF_OUTPUT_UREGS	    = 1U << 27,
 	PERF_OUTPUT_METRIC	    = 1U << 28,
+	PERF_OUTPUT_MISC            = 1U << 29,
 };
 
 struct output_option {
@@ -128,6 +129,7 @@ struct output_option {
 	{.str = "synth", .field = PERF_OUTPUT_SYNTH},
 	{.str = "phys_addr", .field = PERF_OUTPUT_PHYS_ADDR},
 	{.str = "metric", .field = PERF_OUTPUT_METRIC},
+	{.str = "misc", .field = PERF_OUTPUT_MISC},
 };
 
 enum {
@@ -594,7 +596,8 @@ static int perf_sample__fprintf_uregs(struct perf_sample *sample,
 
 static int perf_sample__fprintf_start(struct perf_sample *sample,
 				      struct thread *thread,
-				      struct perf_evsel *evsel, FILE *fp)
+				      struct perf_evsel *evsel,
+				      u32 type, FILE *fp)
 {
 	struct perf_event_attr *attr = &evsel->attr;
 	unsigned long secs;
@@ -624,6 +627,47 @@ static int perf_sample__fprintf_start(struct perf_sample *sample,
 			printed += fprintf(fp, "[%03d] ", sample->cpu);
 	}
 
+	if (PRINT_FIELD(MISC)) {
+		int ret = 0;
+
+		#define has(m) \
+			(sample->misc & PERF_RECORD_MISC_##m) == PERF_RECORD_MISC_##m
+
+		if (has(KERNEL))
+			ret += fprintf(fp, "K");
+		if (has(USER))
+			ret += fprintf(fp, "U");
+		if (has(HYPERVISOR))
+			ret += fprintf(fp, "H");
+		if (has(GUEST_KERNEL))
+			ret += fprintf(fp, "G");
+		if (has(GUEST_USER))
+			ret += fprintf(fp, "g");
+
+		switch (type) {
+		case PERF_RECORD_MMAP:
+		case PERF_RECORD_MMAP2:
+			if (has(MMAP_DATA))
+				ret += fprintf(fp, "M");
+			break;
+		case PERF_RECORD_COMM:
+			if (has(COMM_EXEC))
+				ret += fprintf(fp, "E");
+			break;
+		case PERF_RECORD_SWITCH:
+		case PERF_RECORD_SWITCH_CPU_WIDE:
+			if (has(SWITCH_OUT))
+				ret += fprintf(fp, "S");
+		default:
+			break;
+		}
+
+		#undef has
+
+		ret += fprintf(fp, "%*s", 6 - ret, " ");
+		printed += ret;
+	}
+
 	if (PRINT_FIELD(TIME)) {
 		nsecs = sample->time;
 		secs = nsecs / NSEC_PER_SEC;
@@ -1499,7 +1543,7 @@ static void script_print_metric(void *ctx, const char *color,
 	if (!fmt)
 		return;
 	perf_sample__fprintf_start(mctx->sample, mctx->thread, mctx->evsel,
-				   mctx->fp);
+				   PERF_RECORD_SAMPLE, mctx->fp);
 	fputs("\tmetric: ", mctx->fp);
 	if (color)
 		color_fprintf(mctx->fp, color, fmt, val);
@@ -1513,7 +1557,7 @@ static void script_new_line(void *ctx)
 	struct metric_ctx *mctx = ctx;
 
 	perf_sample__fprintf_start(mctx->sample, mctx->thread, mctx->evsel,
-				   mctx->fp);
+				   PERF_RECORD_SAMPLE, mctx->fp);
 	fputs("\tmetric: ", mctx->fp);
 }
 
@@ -1581,7 +1625,8 @@ static void process_event(struct perf_script *script,
 
 	++es->samples;
 
-	perf_sample__fprintf_start(sample, thread, evsel, fp);
+	perf_sample__fprintf_start(sample, thread, evsel,
+				   PERF_RECORD_SAMPLE, fp);
 
 	if (PRINT_FIELD(PERIOD))
 		fprintf(fp, "%10" PRIu64 " ", sample->period);
@@ -1828,7 +1873,8 @@ static int process_comm_event(struct perf_tool *tool,
 		sample->tid = event->comm.tid;
 		sample->pid = event->comm.pid;
 	}
-	perf_sample__fprintf_start(sample, thread, evsel, stdout);
+	perf_sample__fprintf_start(sample, thread, evsel,
+				   PERF_RECORD_COMM, stdout);
 	perf_event__fprintf(event, stdout);
 	ret = 0;
 out:
@@ -1863,7 +1909,8 @@ static int process_namespaces_event(struct perf_tool *tool,
 		sample->tid = event->namespaces.tid;
 		sample->pid = event->namespaces.pid;
 	}
-	perf_sample__fprintf_start(sample, thread, evsel, stdout);
+	perf_sample__fprintf_start(sample, thread, evsel,
+				   PERF_RECORD_NAMESPACES, stdout);
 	perf_event__fprintf(event, stdout);
 	ret = 0;
 out:
@@ -1896,7 +1943,8 @@ static int process_fork_event(struct perf_tool *tool,
 		sample->tid = event->fork.tid;
 		sample->pid = event->fork.pid;
 	}
-	perf_sample__fprintf_start(sample, thread, evsel, stdout);
+	perf_sample__fprintf_start(sample, thread, evsel,
+				   PERF_RECORD_FORK, stdout);
 	perf_event__fprintf(event, stdout);
 	thread__put(thread);
 
@@ -1925,7 +1973,8 @@ static int process_exit_event(struct perf_tool *tool,
 		sample->tid = event->fork.tid;
 		sample->pid = event->fork.pid;
 	}
-	perf_sample__fprintf_start(sample, thread, evsel, stdout);
+	perf_sample__fprintf_start(sample, thread, evsel,
+				   PERF_RECORD_EXIT, stdout);
 	perf_event__fprintf(event, stdout);
 
 	if (perf_event__process_exit(tool, event, sample, machine) < 0)
@@ -1960,7 +2009,8 @@ static int process_mmap_event(struct perf_tool *tool,
 		sample->tid = event->mmap.tid;
 		sample->pid = event->mmap.pid;
 	}
-	perf_sample__fprintf_start(sample, thread, evsel, stdout);
+	perf_sample__fprintf_start(sample, thread, evsel,
+				   PERF_RECORD_MMAP, stdout);
 	perf_event__fprintf(event, stdout);
 	thread__put(thread);
 	return 0;
@@ -1991,7 +2041,8 @@ static int process_mmap2_event(struct perf_tool *tool,
 		sample->tid = event->mmap2.tid;
 		sample->pid = event->mmap2.pid;
 	}
-	perf_sample__fprintf_start(sample, thread, evsel, stdout);
+	perf_sample__fprintf_start(sample, thread, evsel,
+				   PERF_RECORD_MMAP2, stdout);
 	perf_event__fprintf(event, stdout);
 	thread__put(thread);
 	return 0;
@@ -2017,7 +2068,8 @@ static int process_switch_event(struct perf_tool *tool,
 		return -1;
 	}
 
-	perf_sample__fprintf_start(sample, thread, evsel, stdout);
+	perf_sample__fprintf_start(sample, thread, evsel,
+				   PERF_RECORD_SWITCH, stdout);
 	perf_event__fprintf(event, stdout);
 	thread__put(thread);
 	return 0;
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
index 1ae95efbfb95..e5fbd6dd1b01 100644
--- a/tools/perf/util/event.h
+++ b/tools/perf/util/event.h
@@ -205,6 +205,7 @@ struct perf_sample {
 	u32 flags;
 	u16 insn_len;
 	u8  cpumode;
+	u16 misc;
 	char insn[MAX_INSN];
 	void *raw_data;
 	struct ip_callchain *callchain;
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index c435b2444153..d934f04e3110 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -2042,6 +2042,7 @@ int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event,
 	data->stream_id = data->id = data->time = -1ULL;
 	data->period = evsel->attr.sample_period;
 	data->cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
+	data->misc    = event->header.misc;
 	data->id = -1ULL;
 	data->data_src = PERF_MEM_DATA_SRC_NONE;
 
-- 
2.13.6

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

* [PATCH 09/12] perf script: Add support to display lost events
  2018-01-07 16:03 [PATCH 00/12] perf: Assorted fixes Jiri Olsa
                   ` (7 preceding siblings ...)
  2018-01-07 16:03 ` [PATCH 08/12] perf script: Add support to display sample misc field Jiri Olsa
@ 2018-01-07 16:03 ` Jiri Olsa
  2018-01-10 15:40   ` Arnaldo Carvalho de Melo
  2018-01-11  6:27   ` [tip:perf/core] " tip-bot for Jiri Olsa
  2018-01-07 16:03 ` [PATCH 10/12] perf tools: Make the tool's warning messages optional Jiri Olsa
                   ` (2 subsequent siblings)
  11 siblings, 2 replies; 44+ messages in thread
From: Jiri Olsa @ 2018-01-07 16:03 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Peter Zijlstra
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Andi Kleen,
	Alexander Shishkin

Adding option to display lost events:

  $ perf script --show-lost-events ...
   mplayer 13810 [002] 468011.402396:        100 cycles:ppp:  ff..
   mplayer 13810 [002] 468011.402396: PERF_RECORD_LOST lost 3880
   mplayer 13810 [002] 468011.402397:        100 cycles:ppp:  ff..

Link: http://lkml.kernel.org/n/tip-6gwbhzhev8n603uxjo6vl871@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/Documentation/perf-script.txt |  3 +++
 tools/perf/builtin-script.c              | 28 ++++++++++++++++++++++++++++
 tools/perf/util/event.c                  |  8 ++++++++
 3 files changed, 39 insertions(+)

diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt
index e37b5ee2ac21..735bf3b930ca 100644
--- a/tools/perf/Documentation/perf-script.txt
+++ b/tools/perf/Documentation/perf-script.txt
@@ -300,6 +300,9 @@ OPTIONS
 	Display context switch events i.e. events of type PERF_RECORD_SWITCH or
 	PERF_RECORD_SWITCH_CPU_WIDE.
 
+--show-lost-events
+	Display lost events i.e. events of type PERF_RECORD_LOST.
+
 --demangle::
 	Demangle symbol names to human readable form. It's enabled by default,
 	disable with --no-demangle.
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 85bd6fe2458a..8b5987fd94fc 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -1487,6 +1487,7 @@ struct perf_script {
 	bool			show_mmap_events;
 	bool			show_switch_events;
 	bool			show_namespace_events;
+	bool			show_lost_events;
 	bool			allocated;
 	bool			per_event_dump;
 	struct cpu_map		*cpus;
@@ -2075,6 +2076,29 @@ static int process_switch_event(struct perf_tool *tool,
 	return 0;
 }
 
+static int
+process_lost_event(struct perf_tool *tool,
+		   union perf_event *event,
+		   struct perf_sample *sample,
+		   struct machine *machine)
+{
+	struct perf_script *script = container_of(tool, struct perf_script, tool);
+	struct perf_session *session = script->session;
+	struct perf_evsel *evsel = perf_evlist__id2evsel(session->evlist, sample->id);
+	struct thread *thread;
+
+	thread = machine__findnew_thread(machine, sample->pid,
+					 sample->tid);
+	if (thread == NULL)
+		return -1;
+
+	perf_sample__fprintf_start(sample, thread, evsel,
+				   PERF_RECORD_LOST, stdout);
+	perf_event__fprintf(event, stdout);
+	thread__put(thread);
+	return 0;
+}
+
 static void sig_handler(int sig __maybe_unused)
 {
 	session_done = 1;
@@ -2169,6 +2193,8 @@ static int __cmd_script(struct perf_script *script)
 		script->tool.context_switch = process_switch_event;
 	if (script->show_namespace_events)
 		script->tool.namespaces = process_namespaces_event;
+	if (script->show_lost_events)
+		script->tool.lost = process_lost_event;
 
 	if (perf_script__setup_per_event_dump(script)) {
 		pr_err("Couldn't create the per event dump files\n");
@@ -3105,6 +3131,8 @@ int cmd_script(int argc, const char **argv)
 		    "Show context switch events (if recorded)"),
 	OPT_BOOLEAN('\0', "show-namespace-events", &script.show_namespace_events,
 		    "Show namespace events (if recorded)"),
+	OPT_BOOLEAN('\0', "show-lost-events", &script.show_lost_events,
+		    "Show lost events (if recorded)"),
 	OPT_BOOLEAN('\0', "per-event-dump", &script.per_event_dump,
 		    "Dump trace output to files named by the monitored events"),
 	OPT_BOOLEAN('f', "force", &symbol_conf.force, "don't complain, do it"),
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index 97a8ef9980db..7c7a8090fb07 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -1435,6 +1435,11 @@ size_t perf_event__fprintf_switch(union perf_event *event, FILE *fp)
 		       event->context_switch.next_prev_tid);
 }
 
+static size_t perf_event__fprintf_lost(union perf_event *event, FILE *fp)
+{
+	return fprintf(fp, " lost %lu\n", event->lost.lost);
+}
+
 size_t perf_event__fprintf(union perf_event *event, FILE *fp)
 {
 	size_t ret = fprintf(fp, "PERF_RECORD_%s",
@@ -1467,6 +1472,9 @@ size_t perf_event__fprintf(union perf_event *event, FILE *fp)
 	case PERF_RECORD_SWITCH_CPU_WIDE:
 		ret += perf_event__fprintf_switch(event, fp);
 		break;
+	case PERF_RECORD_LOST:
+		ret += perf_event__fprintf_lost(event, fp);
+		break;
 	default:
 		ret += fprintf(fp, "\n");
 	}
-- 
2.13.6

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

* [PATCH 10/12] perf tools: Make the tool's warning messages optional
  2018-01-07 16:03 [PATCH 00/12] perf: Assorted fixes Jiri Olsa
                   ` (8 preceding siblings ...)
  2018-01-07 16:03 ` [PATCH 09/12] perf script: Add support to display lost events Jiri Olsa
@ 2018-01-07 16:03 ` Jiri Olsa
  2018-01-11  6:27   ` [tip:perf/core] " tip-bot for Jiri Olsa
  2018-01-07 16:03 ` [PATCH 11/12] perf report: Add --stat option to display quick data statistics Jiri Olsa
  2018-01-07 16:03 ` [PATCH 12/12] perf report: Add --task option to display monitored tasks Jiri Olsa
  11 siblings, 1 reply; 44+ messages in thread
From: Jiri Olsa @ 2018-01-07 16:03 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Peter Zijlstra
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Andi Kleen,
	Alexander Shishkin

I want to display the pure events status coming in the
next patch and the tool's warnings are superfluous in
the output. Making it optional, enabled by default.

Link: http://lkml.kernel.org/n/tip-j30qvpjvbljwdq9at90cj7r2@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/util/session.c | 6 ++++--
 tools/perf/util/tool.h    | 1 +
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 54e30f1bcbd7..8d0fa2f8da16 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -1773,7 +1773,8 @@ static int __perf_session__process_pipe_events(struct perf_session *session)
 	err = perf_session__flush_thread_stacks(session);
 out_err:
 	free(buf);
-	perf_session__warn_about_errors(session);
+	if (!tool->no_warn)
+		perf_session__warn_about_errors(session);
 	ordered_events__free(&session->ordered_events);
 	auxtrace__free_events(session);
 	return err;
@@ -1929,7 +1930,8 @@ static int __perf_session__process_events(struct perf_session *session,
 	err = perf_session__flush_thread_stacks(session);
 out_err:
 	ui_progress__finish();
-	perf_session__warn_about_errors(session);
+	if (!tool->no_warn)
+		perf_session__warn_about_errors(session);
 	/*
 	 * We may switching perf.data output, make ordered_events
 	 * reusable.
diff --git a/tools/perf/util/tool.h b/tools/perf/util/tool.h
index 2532b558099b..183c91453522 100644
--- a/tools/perf/util/tool.h
+++ b/tools/perf/util/tool.h
@@ -76,6 +76,7 @@ struct perf_tool {
 	bool		ordered_events;
 	bool		ordering_requires_timestamps;
 	bool		namespace_events;
+	bool		no_warn;
 	enum show_feature_header show_feat_hdr;
 };
 
-- 
2.13.6

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

* [PATCH 11/12] perf report: Add --stat option to display quick data statistics
  2018-01-07 16:03 [PATCH 00/12] perf: Assorted fixes Jiri Olsa
                   ` (9 preceding siblings ...)
  2018-01-07 16:03 ` [PATCH 10/12] perf tools: Make the tool's warning messages optional Jiri Olsa
@ 2018-01-07 16:03 ` Jiri Olsa
  2018-01-11  6:28   ` [tip:perf/core] perf report: Add --stats " tip-bot for Jiri Olsa
  2018-01-07 16:03 ` [PATCH 12/12] perf report: Add --task option to display monitored tasks Jiri Olsa
  11 siblings, 1 reply; 44+ messages in thread
From: Jiri Olsa @ 2018-01-07 16:03 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Peter Zijlstra
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Andi Kleen,
	Alexander Shishkin

Adding --stat option to display quick data statistics
of event numbers, without any further processing, like
the one at the end of the perf report -D command.

  $ perf report --stat

  Aggregated stats:
             TOTAL events:       4566
              MMAP events:        113
              LOST events:         19
              COMM events:          3
              FORK events:        400
            SAMPLE events:       3315
             MMAP2 events:         32
    FINISHED_ROUND events:        681
        THREAD_MAP events:          1
           CPU_MAP events:          1
         TIME_CONV events:          1

I found this useful when hunting lost events
for another change.

Link: http://lkml.kernel.org/n/tip-2guzsg9opn135yj86oothemv@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/Documentation/perf-report.txt |  4 ++++
 tools/perf/builtin-report.c              | 26 +++++++++++++++++++++++++-
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/tools/perf/Documentation/perf-report.txt b/tools/perf/Documentation/perf-report.txt
index ddde2b54af57..b0d70bf4ddfe 100644
--- a/tools/perf/Documentation/perf-report.txt
+++ b/tools/perf/Documentation/perf-report.txt
@@ -437,6 +437,10 @@ include::itrace.txt[]
 	will be printed. Each entry is function name or file/line. Enabled by
 	default, disable with --no-inline.
 
+--stat::
+	Display overall events statistics without any further processing.
+	(like the one at the end of the perf report -D command)
+
 include::callchain-overhead-calculation.txt[]
 
 SEE ALSO
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 07827cd51480..11d303494b0c 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -60,6 +60,7 @@ struct report {
 	bool			show_threads;
 	bool			inverted_callchain;
 	bool			mem_mode;
+	bool			stat_mode;
 	bool			header;
 	bool			header_only;
 	bool			nonany_branch_mode;
@@ -583,6 +584,20 @@ static void report__output_resort(struct report *rep)
 	ui_progress__finish();
 }
 
+static void stat_setup(struct report *rep)
+{
+	memset(&rep->tool, 0, sizeof(rep->tool));
+	rep->tool.no_warn = true;
+}
+
+static int stat_print(struct report *rep)
+{
+	struct perf_session *session = rep->session;
+
+	perf_session__fprintf_nr_events(session, stdout);
+	return 0;
+}
+
 static int __cmd_report(struct report *rep)
 {
 	int ret;
@@ -614,12 +629,18 @@ static int __cmd_report(struct report *rep)
 		return ret;
 	}
 
+	if (rep->stat_mode)
+		stat_setup(rep);
+
 	ret = perf_session__process_events(session);
 	if (ret) {
 		ui__error("failed to process sample\n");
 		return ret;
 	}
 
+	if (rep->stat_mode)
+		return stat_print(rep);
+
 	report__warn_kptr_restrict(rep);
 
 	evlist__for_each_entry(session->evlist, pos)
@@ -776,6 +797,7 @@ int cmd_report(int argc, const char **argv)
 	OPT_BOOLEAN('q', "quiet", &quiet, "Do not show any message"),
 	OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
 		    "dump raw trace in ASCII"),
+	OPT_BOOLEAN(0, "stat", &report.stat_mode, "Display event stats"),
 	OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,
 		   "file", "vmlinux pathname"),
 	OPT_STRING(0, "kallsyms", &symbol_conf.kallsyms_name,
@@ -1037,6 +1059,8 @@ int cmd_report(int argc, const char **argv)
 		report.tool.show_feat_hdr = SHOW_FEAT_HEADER;
 	if (report.show_full_info)
 		report.tool.show_feat_hdr = SHOW_FEAT_HEADER_FULL_INFO;
+	if (report.stat_mode)
+		use_browser = 0;
 
 	if (strcmp(input_name, "-") != 0)
 		setup_browser(true);
@@ -1059,7 +1083,7 @@ int cmd_report(int argc, const char **argv)
 			ret = 0;
 			goto error;
 		}
-	} else if (use_browser == 0 && !quiet) {
+	} else if (use_browser == 0 && !quiet && !report.stat_mode) {
 		fputs("# To display the perf.data header info, please use --header/--header-only options.\n#\n",
 		      stdout);
 	}
-- 
2.13.6

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

* [PATCH 12/12] perf report: Add --task option to display monitored tasks
  2018-01-07 16:03 [PATCH 00/12] perf: Assorted fixes Jiri Olsa
                   ` (10 preceding siblings ...)
  2018-01-07 16:03 ` [PATCH 11/12] perf report: Add --stat option to display quick data statistics Jiri Olsa
@ 2018-01-07 16:03 ` Jiri Olsa
  2018-01-08 15:55   ` Arnaldo Carvalho de Melo
                     ` (2 more replies)
  11 siblings, 3 replies; 44+ messages in thread
From: Jiri Olsa @ 2018-01-07 16:03 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Peter Zijlstra
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Andi Kleen,
	Alexander Shishkin

Adding --task option to display monitored tasks stored
in perf.data. Displaying pid/tid/ppid plus the command
string aligned to distinguish parent and child tasks.

  $ perf record -a
  ...
  $ perf report --task
  #     pid     tid    ppid  comm
          0       0      -1 |swapper
          2       2       0 | kthreadd
      14080   14080       2 |  kworker/u17:1
          4       4       2 |  kworker/0:0H
          6       6       2 |  mm_percpu_wq
  ...
          1       1       0 | systemd
      23242   23242       1 |  firefox
      23242   23298   23242 |   Cache2 I/O
      23242   23304   23242 |   GMPThread
  ...
       1195    1195       1 |  login
       1611    1611    1195 |   bash
       1639    1639    1611 |    startx
       1663    1663    1639 |     xinit
       1673    1673    1663 |      xmonad-x86_64-l
      23939   23939    1673 |       xterm
      23941   23941   23939 |        bash
      23963   23963   23941 |         mutt
      24954   24954   23963 |          offlineimap

Link: http://lkml.kernel.org/n/tip-ehvadnmg8b3kdhvgsbuesbr7@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/Documentation/perf-report.txt |   4 +
 tools/perf/builtin-report.c              | 136 ++++++++++++++++++++++++++++++-
 2 files changed, 138 insertions(+), 2 deletions(-)

diff --git a/tools/perf/Documentation/perf-report.txt b/tools/perf/Documentation/perf-report.txt
index b0d70bf4ddfe..dcf0d154918f 100644
--- a/tools/perf/Documentation/perf-report.txt
+++ b/tools/perf/Documentation/perf-report.txt
@@ -441,6 +441,10 @@ include::itrace.txt[]
 	Display overall events statistics without any further processing.
 	(like the one at the end of the perf report -D command)
 
+--task::
+	Display monitored tasks stored in perf data. Displaying pid/tid/ppid
+	plus the command string aligned to distinguish parent and child tasks.
+
 include::callchain-overhead-calculation.txt[]
 
 SEE ALSO
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 11d303494b0c..f2ca2cbe63c1 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -15,6 +15,7 @@
 #include "util/color.h"
 #include <linux/list.h>
 #include <linux/rbtree.h>
+#include <linux/err.h>
 #include "util/symbol.h"
 #include "util/callchain.h"
 #include "util/values.h"
@@ -61,6 +62,7 @@ struct report {
 	bool			inverted_callchain;
 	bool			mem_mode;
 	bool			stat_mode;
+	bool			task_mode;
 	bool			header;
 	bool			header_only;
 	bool			nonany_branch_mode;
@@ -598,6 +600,124 @@ static int stat_print(struct report *rep)
 	return 0;
 }
 
+static void task_setup(struct report *rep)
+{
+	memset(&rep->tool, 0, sizeof(rep->tool));
+	rep->tool.comm = perf_event__process_comm;
+	rep->tool.exit = perf_event__process_exit;
+	rep->tool.fork = perf_event__process_fork;
+	rep->tool.no_warn = true;
+}
+
+struct task {
+	struct thread		*thread;
+	struct list_head	 list;
+	struct list_head	 children;
+};
+
+static struct task *task_list(struct task *task, struct machine *machine)
+{
+	struct thread *parent_thread, *thread = task->thread;
+	struct task   *parent_task;
+
+	/* Already listed. */
+	if (!list_empty(&task->list))
+		return NULL;
+
+	/* Last one in the chain. */
+	if (thread->ppid == -1)
+		return task;
+
+	parent_thread = machine__findnew_thread(machine, -1, thread->ppid);
+	if (!parent_thread)
+		return ERR_PTR(-ENOMEM);
+
+	parent_task = thread__priv(parent_thread);
+	list_add_tail(&task->list, &parent_task->children);
+	return task_list(parent_task, machine);
+}
+
+static void task__print_level(struct task *task, FILE *fp, int level)
+{
+	struct thread *thread = task->thread;
+	struct task *child;
+
+	fprintf(fp, "  %8d %8d %8d |%*s%s\n",
+		thread->pid_, thread->tid, thread->ppid,
+		level, "", thread__comm_str(thread));
+
+	if (!list_empty(&task->children)) {
+		list_for_each_entry(child, &task->children, list)
+			task__print_level(child, fp, level + 1);
+	}
+}
+
+static int task_print(struct report *rep, FILE *fp)
+{
+	struct perf_session *session = rep->session;
+	struct machine      *machine = &session->machines.host;
+	struct task *tasks, *task;
+	unsigned int nr = 0, itask = 0, i;
+	struct rb_node *nd;
+	LIST_HEAD(list);
+
+	/*
+	 * No locking needed while accessing machine->threads,
+	 * because --task is single threaded command.
+	 */
+
+	/* Count all the threads. */
+	for (i = 0; i < THREADS__TABLE_SIZE; i++)
+		nr += machine->threads[i].nr;
+
+	tasks = malloc(sizeof(*tasks) * nr);
+	if (!tasks)
+		return -ENOMEM;
+
+	for (i = 0; i < THREADS__TABLE_SIZE; i++) {
+		struct threads *threads = &machine->threads[i];
+
+		for (nd = rb_first(&threads->entries); nd; nd = rb_next(nd)) {
+			task = tasks + itask++;
+
+			task->thread = rb_entry(nd, struct thread, rb_node);
+			INIT_LIST_HEAD(&task->children);
+			INIT_LIST_HEAD(&task->list);
+			thread__set_priv(task->thread, task);
+		}
+	}
+
+	/*
+	 * Iterate every task down to the unprocessed parent
+	 * and link all in task children list. Task with no
+	 * parent is added into 'list'.
+	 */
+	for (itask = 0; itask < nr; itask++) {
+		task = tasks + itask;
+
+		if (!list_empty(&task->list))
+			continue;
+
+		task = task_list(task, machine);
+		if (IS_ERR(task)) {
+			pr_err("Error: failed to process tasks\n");
+			free(tasks);
+			return -ENOMEM;
+		}
+
+		if (task)
+			list_add_tail(&task->list, &list);
+	}
+
+	fprintf(fp, "# %8s %8s %8s  %s\n", "pid", "tid", "ppid", "comm");
+
+	list_for_each_entry(task, &list, list)
+		task__print_level(task, fp, 0);
+
+	free(tasks);
+	return 0;
+}
+
 static int __cmd_report(struct report *rep)
 {
 	int ret;
@@ -632,6 +752,9 @@ static int __cmd_report(struct report *rep)
 	if (rep->stat_mode)
 		stat_setup(rep);
 
+	if (rep->task_mode)
+		task_setup(rep);
+
 	ret = perf_session__process_events(session);
 	if (ret) {
 		ui__error("failed to process sample\n");
@@ -641,6 +764,9 @@ static int __cmd_report(struct report *rep)
 	if (rep->stat_mode)
 		return stat_print(rep);
 
+	if (rep->task_mode)
+		return task_print(rep, stdout);
+
 	report__warn_kptr_restrict(rep);
 
 	evlist__for_each_entry(session->evlist, pos)
@@ -798,6 +924,7 @@ int cmd_report(int argc, const char **argv)
 	OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
 		    "dump raw trace in ASCII"),
 	OPT_BOOLEAN(0, "stat", &report.stat_mode, "Display event stats"),
+	OPT_BOOLEAN(0, "task", &report.task_mode, "Display recorded tasks"),
 	OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,
 		   "file", "vmlinux pathname"),
 	OPT_STRING(0, "kallsyms", &symbol_conf.kallsyms_name,
@@ -1059,8 +1186,12 @@ int cmd_report(int argc, const char **argv)
 		report.tool.show_feat_hdr = SHOW_FEAT_HEADER;
 	if (report.show_full_info)
 		report.tool.show_feat_hdr = SHOW_FEAT_HEADER_FULL_INFO;
-	if (report.stat_mode)
+	if (report.stat_mode || report.task_mode)
 		use_browser = 0;
+	if (report.stat_mode && report.task_mode) {
+		pr_err("Error: --task and --stat options cannot be used together\n");
+		goto error;
+	}
 
 	if (strcmp(input_name, "-") != 0)
 		setup_browser(true);
@@ -1083,7 +1214,8 @@ int cmd_report(int argc, const char **argv)
 			ret = 0;
 			goto error;
 		}
-	} else if (use_browser == 0 && !quiet && !report.stat_mode) {
+	} else if (use_browser == 0 && !quiet &&
+		   !report.stat_mode && !report.task_mode) {
 		fputs("# To display the perf.data header info, please use --header/--header-only options.\n#\n",
 		      stdout);
 	}
-- 
2.13.6

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

* Re: [PATCH 03/12] perf: Allocate context task_ctx_data for child event
  2018-01-07 16:03 ` [PATCH 03/12] perf: Allocate context task_ctx_data for child event Jiri Olsa
@ 2018-01-08 12:14   ` Peter Zijlstra
  2018-01-11  6:24   ` [tip:perf/core] " tip-bot for Jiri Olsa
  1 sibling, 0 replies; 44+ messages in thread
From: Peter Zijlstra @ 2018-01-08 12:14 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Arnaldo Carvalho de Melo, Andi Kleen, lkml, Ingo Molnar,
	Namhyung Kim, David Ahern, Alexander Shishkin

On Sun, Jan 07, 2018 at 05:03:47PM +0100, Jiri Olsa wrote:
> Currently we use perf_event_context::task_ctx_data to save
> and restore the LBR status when the task is scheduled out
> and in.
> 
> We don't allocate it for child contexts, which results in
> shorter task's LBR stack, because we don't save the history
> from previous run and start over every time we schedule the
> task in.
> 
> I made a test to generate samples with LBR call stack
> and got higher numbers on bigger chain depths:
> 
>                             before:     after:
>   LBR call chain: nr: 1       60561     498127
>   LBR call chain: nr: 2           0          0
>   LBR call chain: nr: 3      107030       2172
>   LBR call chain: nr: 4      466685      62758
>   LBR call chain: nr: 5     2307319     878046
>   LBR call chain: nr: 6       48713     495218
>   LBR call chain: nr: 7        1040       4551
>   LBR call chain: nr: 8         481        172
>   LBR call chain: nr: 9         878        120
>   LBR call chain: nr: 10       2377       6698
>   LBR call chain: nr: 11      28830     151487
>   LBR call chain: nr: 12      29347     339867
>   LBR call chain: nr: 13          4         22
>   LBR call chain: nr: 14          3         53

Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>

Fixes: 4af57ef28c2c ("perf: Add pmu specific data for perf task context")

> Cc: Andi Kleen <ak@linux.intel.com>
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> ---
>  kernel/events/core.c | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
> 
> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index 4df5b695bf0d..55fb648a32b0 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -10703,6 +10703,19 @@ inherit_event(struct perf_event *parent_event,
>  	if (IS_ERR(child_event))
>  		return child_event;
>  
> +
> +	if ((child_event->attach_state & PERF_ATTACH_TASK_DATA) &&
> +	    !child_ctx->task_ctx_data) {
> +		struct pmu *pmu = child_event->pmu;
> +
> +		child_ctx->task_ctx_data = kzalloc(pmu->task_ctx_size,
> +						   GFP_KERNEL);
> +		if (!child_ctx->task_ctx_data) {
> +			free_event(child_event);
> +			return NULL;
> +		}
> +	}
> +
>  	/*
>  	 * is_orphaned_event() and list_add_tail(&parent_event->child_list)
>  	 * must be under the same lock in order to serialize against
> @@ -10713,6 +10726,7 @@ inherit_event(struct perf_event *parent_event,
>  	if (is_orphaned_event(parent_event) ||
>  	    !atomic_long_inc_not_zero(&parent_event->refcount)) {
>  		mutex_unlock(&parent_event->child_mutex);
> +		/* task_ctx_data is freed with child_ctx */
>  		free_event(child_event);
>  		return NULL;
>  	}
> -- 
> 2.13.6
> 

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

* Re: [PATCH 06/12] perf: Return empty callchain instead of NULL
  2018-01-07 16:03 ` [PATCH 06/12] perf: Return empty callchain instead of NULL Jiri Olsa
@ 2018-01-08 12:15   ` Peter Zijlstra
  2018-01-11  6:26   ` [tip:perf/core] " tip-bot for Jiri Olsa
  1 sibling, 0 replies; 44+ messages in thread
From: Peter Zijlstra @ 2018-01-08 12:15 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Arnaldo Carvalho de Melo, lkml, Ingo Molnar, Namhyung Kim,
	David Ahern, Andi Kleen, Alexander Shishkin

On Sun, Jan 07, 2018 at 05:03:50PM +0100, Jiri Olsa wrote:
> It simplifies the code a bit, because we dump the callchain
> even if it's empty. With 'empty' callchain we can remove
> all the NULL-checking code paths.

Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>

> 
> Original-patch-from: Peter Zijlstra <peterz@infradead.org>
> Link: http://lkml.kernel.org/n/tip-n4t869o2qc1b31v4wwvmxznb@git.kernel.org
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> ---
>  kernel/events/core.c | 30 ++++++++++++------------------
>  1 file changed, 12 insertions(+), 18 deletions(-)
> 
> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index 5fc1ded4b450..4e1a1bf8d867 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -5815,19 +5815,11 @@ void perf_output_sample(struct perf_output_handle *handle,
>  		perf_output_read(handle, event);
>  
>  	if (sample_type & PERF_SAMPLE_CALLCHAIN) {
> -		if (data->callchain) {
> -			int size = 1;
> -
> -			if (data->callchain)
> -				size += data->callchain->nr;
> -
> -			size *= sizeof(u64);
> +		int size = 1;
>  
> -			__output_copy(handle, data->callchain, size);
> -		} else {
> -			u64 nr = 0;
> -			perf_output_put(handle, nr);
> -		}
> +		size += data->callchain->nr;
> +		size *= sizeof(u64);
> +		__output_copy(handle, data->callchain, size);
>  	}
>  
>  	if (sample_type & PERF_SAMPLE_RAW) {
> @@ -5980,6 +5972,8 @@ static u64 perf_virt_to_phys(u64 virt)
>  	return phys_addr;
>  }
>  
> +static struct perf_callchain_entry __empty_callchain = { .nr = 0, };
> +
>  static struct perf_callchain_entry *
>  perf_callchain(struct perf_event *event, struct pt_regs *regs)
>  {
> @@ -5988,12 +5982,14 @@ perf_callchain(struct perf_event *event, struct pt_regs *regs)
>  	/* Disallow cross-task user callchains. */
>  	bool crosstask = event->ctx->task && event->ctx->task != current;
>  	const u32 max_stack = event->attr.sample_max_stack;
> +	struct perf_callchain_entry *callchain;
>  
>  	if (!kernel && !user)
> -		return NULL;
> +		return &__empty_callchain;
>  
> -	return get_perf_callchain(regs, 0, kernel, user,
> -				  max_stack, crosstask, true);
> +	callchain = get_perf_callchain(regs, 0, kernel, user,
> +				       max_stack, crosstask, true);
> +	return callchain ?: &__empty_callchain;
>  }
>  
>  void perf_prepare_sample(struct perf_event_header *header,
> @@ -6018,9 +6014,7 @@ void perf_prepare_sample(struct perf_event_header *header,
>  		int size = 1;
>  
>  		data->callchain = perf_callchain(event, regs);
> -
> -		if (data->callchain)
> -			size += data->callchain->nr;
> +		size += data->callchain->nr;
>  
>  		header->size += size * sizeof(u64);
>  	}
> -- 
> 2.13.6
> 

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

* Re: [PATCH 01/12] perf tools: Enable LIBBABELTRACE by default
  2018-01-07 16:03 ` [PATCH 01/12] perf tools: Enable LIBBABELTRACE by default Jiri Olsa
@ 2018-01-08 15:17   ` Arnaldo Carvalho de Melo
  2018-01-08 15:20     ` Arnaldo Carvalho de Melo
  2018-01-11  6:24   ` [tip:perf/core] perf tools: Enable LIBBABELTRACE by default tip-bot for Jiri Olsa
  1 sibling, 1 reply; 44+ messages in thread
From: Arnaldo Carvalho de Melo @ 2018-01-08 15:17 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Peter Zijlstra, lkml, Ingo Molnar, Namhyung Kim, David Ahern,
	Andi Kleen, Alexander Shishkin

Em Sun, Jan 07, 2018 at 05:03:45PM +0100, Jiri Olsa escreveu:
> There's no reason anymore to treat babel trace in a special way,
> because a) we no longer display its state b) the needed babeltrace
> library is now out and well adopted among distros.

Humm, after I applied this I got:

[acme@jouet perf]$ perf
perf: error while loading shared libraries: libbabeltrace-ctf.so.2: cannot open shared object file: No such file or directory
[acme@jouet perf]$

So it detects it somehow, builds with it, then fails to find it in the
LD_LIBRARY_PATH somehow?

- Arnaldo
 
> Link: http://lkml.kernel.org/n/tip-n1c2a8hwtf6wlh8e0uiqn8in@git.kernel.org
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> ---
>  tools/perf/Makefile.config | 2 +-
>  tools/perf/Makefile.perf   | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
> index f050f38d8fa3..12dec6ea5ed2 100644
> --- a/tools/perf/Makefile.config
> +++ b/tools/perf/Makefile.config
> @@ -780,7 +780,7 @@ else
>    NO_PERF_READ_VDSOX32 := 1
>  endif
>  
> -ifdef LIBBABELTRACE
> +ifndef NO_LIBBABELTRACE
>    $(call feature_check,libbabeltrace)
>    ifeq ($(feature-libbabeltrace), 1)
>      CFLAGS += -DHAVE_LIBBABELTRACE_SUPPORT $(LIBBABELTRACE_CFLAGS)
> diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
> index 68cf1360a3f3..9fdefd748e2e 100644
> --- a/tools/perf/Makefile.perf
> +++ b/tools/perf/Makefile.perf
> @@ -77,7 +77,7 @@ include ../scripts/utilities.mak
>  #
>  # Define NO_ZLIB if you do not want to support compressed kernel modules
>  #
> -# Define LIBBABELTRACE if you DO want libbabeltrace support
> +# Define NO_LIBBABELTRACE if you do not want libbabeltrace support
>  # for CTF data format.
>  #
>  # Define NO_LZMA if you do not want to support compressed (xz) kernel modules
> -- 
> 2.13.6

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

* Re: [PATCH 01/12] perf tools: Enable LIBBABELTRACE by default
  2018-01-08 15:17   ` Arnaldo Carvalho de Melo
@ 2018-01-08 15:20     ` Arnaldo Carvalho de Melo
  2018-01-08 15:24       ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 44+ messages in thread
From: Arnaldo Carvalho de Melo @ 2018-01-08 15:20 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Peter Zijlstra, lkml, Ingo Molnar, Namhyung Kim, David Ahern,
	Andi Kleen, Alexander Shishkin

Em Mon, Jan 08, 2018 at 12:17:09PM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Sun, Jan 07, 2018 at 05:03:45PM +0100, Jiri Olsa escreveu:
> > There's no reason anymore to treat babel trace in a special way,
> > because a) we no longer display its state b) the needed babeltrace
> > library is now out and well adopted among distros.
> 
> Humm, after I applied this I got:
> 
> [acme@jouet perf]$ perf
> perf: error while loading shared libraries: libbabeltrace-ctf.so.2: cannot open shared object file: No such file or directory
> [acme@jouet perf]$
> 
> So it detects it somehow, builds with it, then fails to find it in the
> LD_LIBRARY_PATH somehow?

[acme@jouet perf]$ ldd ~/bin/perf | grep babel
	libbabeltrace-ctf.so.2 => not found
[acme@jouet perf]$

[acme@jouet perf]$ tail -5 /tmp/build/perf/feature/test-libbabeltrace.d 
 /usr/local/include/babeltrace/ctf-ir/visitor.h \
 /usr/local/include/babeltrace/values.h \
 /usr/local/include/babeltrace/ref.h \
 /usr/local/include/babeltrace/graph/notification.h \
 /usr/local/include/babeltrace/ctf-ir/stream-class.h
[acme@jouet perf]$

so I don't have it in LD_LIBRARY_PATH:

[acme@jouet perf]$ export LD_LIBRARY_PATH=/usr/local/lib/
[acme@jouet perf]$ ldd ~/bin/perf | grep babel
	libbabeltrace-ctf.so.2 => /usr/local/lib/libbabeltrace-ctf.so.2 (0x00007f6322e83000)
[acme@jouet perf]$ perf stat -e cycles sleep 1

 Performance counter stats for 'sleep 1':

           384,636      cycles:u                                                    

       1.001294682 seconds time elapsed

[acme@jouet perf]$ 

Will try removing this local install and use what is in fedora27
instead...
 
> - Arnaldo
>  
> > Link: http://lkml.kernel.org/n/tip-n1c2a8hwtf6wlh8e0uiqn8in@git.kernel.org
> > Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> > ---
> >  tools/perf/Makefile.config | 2 +-
> >  tools/perf/Makefile.perf   | 2 +-
> >  2 files changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
> > index f050f38d8fa3..12dec6ea5ed2 100644
> > --- a/tools/perf/Makefile.config
> > +++ b/tools/perf/Makefile.config
> > @@ -780,7 +780,7 @@ else
> >    NO_PERF_READ_VDSOX32 := 1
> >  endif
> >  
> > -ifdef LIBBABELTRACE
> > +ifndef NO_LIBBABELTRACE
> >    $(call feature_check,libbabeltrace)
> >    ifeq ($(feature-libbabeltrace), 1)
> >      CFLAGS += -DHAVE_LIBBABELTRACE_SUPPORT $(LIBBABELTRACE_CFLAGS)
> > diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
> > index 68cf1360a3f3..9fdefd748e2e 100644
> > --- a/tools/perf/Makefile.perf
> > +++ b/tools/perf/Makefile.perf
> > @@ -77,7 +77,7 @@ include ../scripts/utilities.mak
> >  #
> >  # Define NO_ZLIB if you do not want to support compressed kernel modules
> >  #
> > -# Define LIBBABELTRACE if you DO want libbabeltrace support
> > +# Define NO_LIBBABELTRACE if you do not want libbabeltrace support
> >  # for CTF data format.
> >  #
> >  # Define NO_LZMA if you do not want to support compressed (xz) kernel modules
> > -- 
> > 2.13.6

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

* Re: [PATCH 01/12] perf tools: Enable LIBBABELTRACE by default
  2018-01-08 15:20     ` Arnaldo Carvalho de Melo
@ 2018-01-08 15:24       ` Arnaldo Carvalho de Melo
  2018-01-08 17:11         ` Jiri Olsa
  0 siblings, 1 reply; 44+ messages in thread
From: Arnaldo Carvalho de Melo @ 2018-01-08 15:24 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Peter Zijlstra, lkml, Ingo Molnar, Namhyung Kim, David Ahern,
	Andi Kleen, Alexander Shishkin

Em Mon, Jan 08, 2018 at 12:20:37PM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Mon, Jan 08, 2018 at 12:17:09PM -0300, Arnaldo Carvalho de Melo escreveu:
> > Em Sun, Jan 07, 2018 at 05:03:45PM +0100, Jiri Olsa escreveu:
> > > There's no reason anymore to treat babel trace in a special way,
> > > because a) we no longer display its state b) the needed babeltrace
> > > library is now out and well adopted among distros.
> > 
> > Humm, after I applied this I got:
> > 
> > [acme@jouet perf]$ perf
> > perf: error while loading shared libraries: libbabeltrace-ctf.so.2: cannot open shared object file: No such file or directory
> > [acme@jouet perf]$
> > 
> > So it detects it somehow, builds with it, then fails to find it in the
> > LD_LIBRARY_PATH somehow?
> 
> [acme@jouet perf]$ ldd ~/bin/perf | grep babel
> 	libbabeltrace-ctf.so.2 => not found
> [acme@jouet perf]$
> 
> [acme@jouet perf]$ tail -5 /tmp/build/perf/feature/test-libbabeltrace.d 
>  /usr/local/include/babeltrace/ctf-ir/visitor.h \
>  /usr/local/include/babeltrace/values.h \
>  /usr/local/include/babeltrace/ref.h \
>  /usr/local/include/babeltrace/graph/notification.h \
>  /usr/local/include/babeltrace/ctf-ir/stream-class.h
> [acme@jouet perf]$
> 
> so I don't have it in LD_LIBRARY_PATH:
> 
> [acme@jouet perf]$ export LD_LIBRARY_PATH=/usr/local/lib/
> [acme@jouet perf]$ ldd ~/bin/perf | grep babel
> 	libbabeltrace-ctf.so.2 => /usr/local/lib/libbabeltrace-ctf.so.2 (0x00007f6322e83000)
> [acme@jouet perf]$ perf stat -e cycles sleep 1
> 
>  Performance counter stats for 'sleep 1':
> 
>            384,636      cycles:u                                                    
> 
>        1.001294682 seconds time elapsed
> 
> [acme@jouet perf]$ 
> 
> Will try removing this local install and use what is in fedora27
> instead...

Works:

[acme@jouet perf]$ ldd ~/bin/perf | grep babel
	libbabeltrace-ctf.so.1 => /lib64/libbabeltrace-ctf.so.1 (0x00007fcb688d0000)
	libbabeltrace.so.1 => /lib64/libbabeltrace.so.1 (0x00007fcb67e92000)
[acme@jouet perf]$ rpm -q libbabeltrace-devel
libbabeltrace-devel-1.5.3-1.fc27.x86_64
[acme@jouet perf]$

But then, if we show:

Auto-detecting system features:
...                         dwarf: [ on  ]
...            dwarf_getlocations: [ on  ]
...                         glibc: [ on  ]
...                          gtk2: [ on  ]
...                      libaudit: [ on  ]
...                        libbfd: [ on  ]
...                        libelf: [ on  ]
...                       libnuma: [ on  ]
...        numa_num_possible_cpus: [ on  ]
...                       libperl: [ on  ]
...                     libpython: [ on  ]
...                      libslang: [ on  ]
...                     libcrypto: [ on  ]
...                     libunwind: [ on  ]
...            libdw-dwarf-unwind: [ on  ]
...                          zlib: [ on  ]
...                          lzma: [ on  ]
...                     get_cpuid: [ on  ]
...                           bpf: [ on  ]

Shoudln't we tell the user that babeltrace was linked too?

- Arnaldo

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

* Re: [PATCH 12/12] perf report: Add --task option to display monitored tasks
  2018-01-07 16:03 ` [PATCH 12/12] perf report: Add --task option to display monitored tasks Jiri Olsa
@ 2018-01-08 15:55   ` Arnaldo Carvalho de Melo
  2018-01-08 16:03     ` Arnaldo Carvalho de Melo
  2018-01-09  1:56   ` Namhyung Kim
  2018-01-11  6:29   ` [tip:perf/core] perf report: Add --tasks " tip-bot for Jiri Olsa
  2 siblings, 1 reply; 44+ messages in thread
From: Arnaldo Carvalho de Melo @ 2018-01-08 15:55 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Peter Zijlstra, lkml, Ingo Molnar, Namhyung Kim, David Ahern,
	Andi Kleen, Alexander Shishkin

Em Sun, Jan 07, 2018 at 05:03:56PM +0100, Jiri Olsa escreveu:
> Adding --task option to display monitored tasks stored
> in perf.data. Displaying pid/tid/ppid plus the command
> string aligned to distinguish parent and child tasks.

I'm making this --tasks, plural, but then you can also use --task :-)

- Arnaldo
 
>   $ perf record -a
>   ...
>   $ perf report --task
>   #     pid     tid    ppid  comm
>           0       0      -1 |swapper
>           2       2       0 | kthreadd
>       14080   14080       2 |  kworker/u17:1
>           4       4       2 |  kworker/0:0H
>           6       6       2 |  mm_percpu_wq
>   ...
>           1       1       0 | systemd
>       23242   23242       1 |  firefox
>       23242   23298   23242 |   Cache2 I/O
>       23242   23304   23242 |   GMPThread
>   ...
>        1195    1195       1 |  login
>        1611    1611    1195 |   bash
>        1639    1639    1611 |    startx
>        1663    1663    1639 |     xinit
>        1673    1673    1663 |      xmonad-x86_64-l
>       23939   23939    1673 |       xterm
>       23941   23941   23939 |        bash
>       23963   23963   23941 |         mutt
>       24954   24954   23963 |          offlineimap
> 
> Link: http://lkml.kernel.org/n/tip-ehvadnmg8b3kdhvgsbuesbr7@git.kernel.org
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> ---
>  tools/perf/Documentation/perf-report.txt |   4 +
>  tools/perf/builtin-report.c              | 136 ++++++++++++++++++++++++++++++-
>  2 files changed, 138 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/perf/Documentation/perf-report.txt b/tools/perf/Documentation/perf-report.txt
> index b0d70bf4ddfe..dcf0d154918f 100644
> --- a/tools/perf/Documentation/perf-report.txt
> +++ b/tools/perf/Documentation/perf-report.txt
> @@ -441,6 +441,10 @@ include::itrace.txt[]
>  	Display overall events statistics without any further processing.
>  	(like the one at the end of the perf report -D command)
>  
> +--task::
> +	Display monitored tasks stored in perf data. Displaying pid/tid/ppid
> +	plus the command string aligned to distinguish parent and child tasks.
> +
>  include::callchain-overhead-calculation.txt[]
>  
>  SEE ALSO
> diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
> index 11d303494b0c..f2ca2cbe63c1 100644
> --- a/tools/perf/builtin-report.c
> +++ b/tools/perf/builtin-report.c
> @@ -15,6 +15,7 @@
>  #include "util/color.h"
>  #include <linux/list.h>
>  #include <linux/rbtree.h>
> +#include <linux/err.h>
>  #include "util/symbol.h"
>  #include "util/callchain.h"
>  #include "util/values.h"
> @@ -61,6 +62,7 @@ struct report {
>  	bool			inverted_callchain;
>  	bool			mem_mode;
>  	bool			stat_mode;
> +	bool			task_mode;
>  	bool			header;
>  	bool			header_only;
>  	bool			nonany_branch_mode;
> @@ -598,6 +600,124 @@ static int stat_print(struct report *rep)
>  	return 0;
>  }
>  
> +static void task_setup(struct report *rep)
> +{
> +	memset(&rep->tool, 0, sizeof(rep->tool));
> +	rep->tool.comm = perf_event__process_comm;
> +	rep->tool.exit = perf_event__process_exit;
> +	rep->tool.fork = perf_event__process_fork;
> +	rep->tool.no_warn = true;
> +}
> +
> +struct task {
> +	struct thread		*thread;
> +	struct list_head	 list;
> +	struct list_head	 children;
> +};
> +
> +static struct task *task_list(struct task *task, struct machine *machine)
> +{
> +	struct thread *parent_thread, *thread = task->thread;
> +	struct task   *parent_task;
> +
> +	/* Already listed. */
> +	if (!list_empty(&task->list))
> +		return NULL;
> +
> +	/* Last one in the chain. */
> +	if (thread->ppid == -1)
> +		return task;
> +
> +	parent_thread = machine__findnew_thread(machine, -1, thread->ppid);
> +	if (!parent_thread)
> +		return ERR_PTR(-ENOMEM);
> +
> +	parent_task = thread__priv(parent_thread);
> +	list_add_tail(&task->list, &parent_task->children);
> +	return task_list(parent_task, machine);
> +}
> +
> +static void task__print_level(struct task *task, FILE *fp, int level)
> +{
> +	struct thread *thread = task->thread;
> +	struct task *child;
> +
> +	fprintf(fp, "  %8d %8d %8d |%*s%s\n",
> +		thread->pid_, thread->tid, thread->ppid,
> +		level, "", thread__comm_str(thread));
> +
> +	if (!list_empty(&task->children)) {
> +		list_for_each_entry(child, &task->children, list)
> +			task__print_level(child, fp, level + 1);
> +	}
> +}
> +
> +static int task_print(struct report *rep, FILE *fp)
> +{
> +	struct perf_session *session = rep->session;
> +	struct machine      *machine = &session->machines.host;
> +	struct task *tasks, *task;
> +	unsigned int nr = 0, itask = 0, i;
> +	struct rb_node *nd;
> +	LIST_HEAD(list);
> +
> +	/*
> +	 * No locking needed while accessing machine->threads,
> +	 * because --task is single threaded command.
> +	 */
> +
> +	/* Count all the threads. */
> +	for (i = 0; i < THREADS__TABLE_SIZE; i++)
> +		nr += machine->threads[i].nr;
> +
> +	tasks = malloc(sizeof(*tasks) * nr);
> +	if (!tasks)
> +		return -ENOMEM;
> +
> +	for (i = 0; i < THREADS__TABLE_SIZE; i++) {
> +		struct threads *threads = &machine->threads[i];
> +
> +		for (nd = rb_first(&threads->entries); nd; nd = rb_next(nd)) {
> +			task = tasks + itask++;
> +
> +			task->thread = rb_entry(nd, struct thread, rb_node);
> +			INIT_LIST_HEAD(&task->children);
> +			INIT_LIST_HEAD(&task->list);
> +			thread__set_priv(task->thread, task);
> +		}
> +	}
> +
> +	/*
> +	 * Iterate every task down to the unprocessed parent
> +	 * and link all in task children list. Task with no
> +	 * parent is added into 'list'.
> +	 */
> +	for (itask = 0; itask < nr; itask++) {
> +		task = tasks + itask;
> +
> +		if (!list_empty(&task->list))
> +			continue;
> +
> +		task = task_list(task, machine);
> +		if (IS_ERR(task)) {
> +			pr_err("Error: failed to process tasks\n");
> +			free(tasks);
> +			return -ENOMEM;
> +		}
> +
> +		if (task)
> +			list_add_tail(&task->list, &list);
> +	}
> +
> +	fprintf(fp, "# %8s %8s %8s  %s\n", "pid", "tid", "ppid", "comm");
> +
> +	list_for_each_entry(task, &list, list)
> +		task__print_level(task, fp, 0);
> +
> +	free(tasks);
> +	return 0;
> +}
> +
>  static int __cmd_report(struct report *rep)
>  {
>  	int ret;
> @@ -632,6 +752,9 @@ static int __cmd_report(struct report *rep)
>  	if (rep->stat_mode)
>  		stat_setup(rep);
>  
> +	if (rep->task_mode)
> +		task_setup(rep);
> +
>  	ret = perf_session__process_events(session);
>  	if (ret) {
>  		ui__error("failed to process sample\n");
> @@ -641,6 +764,9 @@ static int __cmd_report(struct report *rep)
>  	if (rep->stat_mode)
>  		return stat_print(rep);
>  
> +	if (rep->task_mode)
> +		return task_print(rep, stdout);
> +
>  	report__warn_kptr_restrict(rep);
>  
>  	evlist__for_each_entry(session->evlist, pos)
> @@ -798,6 +924,7 @@ int cmd_report(int argc, const char **argv)
>  	OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
>  		    "dump raw trace in ASCII"),
>  	OPT_BOOLEAN(0, "stat", &report.stat_mode, "Display event stats"),
> +	OPT_BOOLEAN(0, "task", &report.task_mode, "Display recorded tasks"),
>  	OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,
>  		   "file", "vmlinux pathname"),
>  	OPT_STRING(0, "kallsyms", &symbol_conf.kallsyms_name,
> @@ -1059,8 +1186,12 @@ int cmd_report(int argc, const char **argv)
>  		report.tool.show_feat_hdr = SHOW_FEAT_HEADER;
>  	if (report.show_full_info)
>  		report.tool.show_feat_hdr = SHOW_FEAT_HEADER_FULL_INFO;
> -	if (report.stat_mode)
> +	if (report.stat_mode || report.task_mode)
>  		use_browser = 0;
> +	if (report.stat_mode && report.task_mode) {
> +		pr_err("Error: --task and --stat options cannot be used together\n");
> +		goto error;
> +	}
>  
>  	if (strcmp(input_name, "-") != 0)
>  		setup_browser(true);
> @@ -1083,7 +1214,8 @@ int cmd_report(int argc, const char **argv)
>  			ret = 0;
>  			goto error;
>  		}
> -	} else if (use_browser == 0 && !quiet && !report.stat_mode) {
> +	} else if (use_browser == 0 && !quiet &&
> +		   !report.stat_mode && !report.task_mode) {
>  		fputs("# To display the perf.data header info, please use --header/--header-only options.\n#\n",
>  		      stdout);
>  	}
> -- 
> 2.13.6

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

* Re: [PATCH 12/12] perf report: Add --task option to display monitored tasks
  2018-01-08 15:55   ` Arnaldo Carvalho de Melo
@ 2018-01-08 16:03     ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 44+ messages in thread
From: Arnaldo Carvalho de Melo @ 2018-01-08 16:03 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Peter Zijlstra, lkml, Ingo Molnar, Namhyung Kim, David Ahern,
	Andi Kleen, Alexander Shishkin

Em Mon, Jan 08, 2018 at 12:55:34PM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Sun, Jan 07, 2018 at 05:03:56PM +0100, Jiri Olsa escreveu:
> > Adding --task option to display monitored tasks stored
> > in perf.data. Displaying pid/tid/ppid plus the command
> > string aligned to distinguish parent and child tasks.
> 
> I'm making this --tasks, plural, but then you can also use --task :-)

And tested it, nice new feature! :-)

- Arnaldo
 
> - Arnaldo
>  
> >   $ perf record -a
> >   ...
> >   $ perf report --task
> >   #     pid     tid    ppid  comm
> >           0       0      -1 |swapper
> >           2       2       0 | kthreadd
> >       14080   14080       2 |  kworker/u17:1
> >           4       4       2 |  kworker/0:0H
> >           6       6       2 |  mm_percpu_wq
> >   ...
> >           1       1       0 | systemd
> >       23242   23242       1 |  firefox
> >       23242   23298   23242 |   Cache2 I/O
> >       23242   23304   23242 |   GMPThread
> >   ...
> >        1195    1195       1 |  login
> >        1611    1611    1195 |   bash
> >        1639    1639    1611 |    startx
> >        1663    1663    1639 |     xinit
> >        1673    1673    1663 |      xmonad-x86_64-l
> >       23939   23939    1673 |       xterm
> >       23941   23941   23939 |        bash
> >       23963   23963   23941 |         mutt
> >       24954   24954   23963 |          offlineimap
> > 
> > Link: http://lkml.kernel.org/n/tip-ehvadnmg8b3kdhvgsbuesbr7@git.kernel.org
> > Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> > ---
> >  tools/perf/Documentation/perf-report.txt |   4 +
> >  tools/perf/builtin-report.c              | 136 ++++++++++++++++++++++++++++++-
> >  2 files changed, 138 insertions(+), 2 deletions(-)
> > 
> > diff --git a/tools/perf/Documentation/perf-report.txt b/tools/perf/Documentation/perf-report.txt
> > index b0d70bf4ddfe..dcf0d154918f 100644
> > --- a/tools/perf/Documentation/perf-report.txt
> > +++ b/tools/perf/Documentation/perf-report.txt
> > @@ -441,6 +441,10 @@ include::itrace.txt[]
> >  	Display overall events statistics without any further processing.
> >  	(like the one at the end of the perf report -D command)
> >  
> > +--task::
> > +	Display monitored tasks stored in perf data. Displaying pid/tid/ppid
> > +	plus the command string aligned to distinguish parent and child tasks.
> > +
> >  include::callchain-overhead-calculation.txt[]
> >  
> >  SEE ALSO
> > diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
> > index 11d303494b0c..f2ca2cbe63c1 100644
> > --- a/tools/perf/builtin-report.c
> > +++ b/tools/perf/builtin-report.c
> > @@ -15,6 +15,7 @@
> >  #include "util/color.h"
> >  #include <linux/list.h>
> >  #include <linux/rbtree.h>
> > +#include <linux/err.h>
> >  #include "util/symbol.h"
> >  #include "util/callchain.h"
> >  #include "util/values.h"
> > @@ -61,6 +62,7 @@ struct report {
> >  	bool			inverted_callchain;
> >  	bool			mem_mode;
> >  	bool			stat_mode;
> > +	bool			task_mode;
> >  	bool			header;
> >  	bool			header_only;
> >  	bool			nonany_branch_mode;
> > @@ -598,6 +600,124 @@ static int stat_print(struct report *rep)
> >  	return 0;
> >  }
> >  
> > +static void task_setup(struct report *rep)
> > +{
> > +	memset(&rep->tool, 0, sizeof(rep->tool));
> > +	rep->tool.comm = perf_event__process_comm;
> > +	rep->tool.exit = perf_event__process_exit;
> > +	rep->tool.fork = perf_event__process_fork;
> > +	rep->tool.no_warn = true;
> > +}
> > +
> > +struct task {
> > +	struct thread		*thread;
> > +	struct list_head	 list;
> > +	struct list_head	 children;
> > +};
> > +
> > +static struct task *task_list(struct task *task, struct machine *machine)
> > +{
> > +	struct thread *parent_thread, *thread = task->thread;
> > +	struct task   *parent_task;
> > +
> > +	/* Already listed. */
> > +	if (!list_empty(&task->list))
> > +		return NULL;
> > +
> > +	/* Last one in the chain. */
> > +	if (thread->ppid == -1)
> > +		return task;
> > +
> > +	parent_thread = machine__findnew_thread(machine, -1, thread->ppid);
> > +	if (!parent_thread)
> > +		return ERR_PTR(-ENOMEM);
> > +
> > +	parent_task = thread__priv(parent_thread);
> > +	list_add_tail(&task->list, &parent_task->children);
> > +	return task_list(parent_task, machine);
> > +}
> > +
> > +static void task__print_level(struct task *task, FILE *fp, int level)
> > +{
> > +	struct thread *thread = task->thread;
> > +	struct task *child;
> > +
> > +	fprintf(fp, "  %8d %8d %8d |%*s%s\n",
> > +		thread->pid_, thread->tid, thread->ppid,
> > +		level, "", thread__comm_str(thread));
> > +
> > +	if (!list_empty(&task->children)) {
> > +		list_for_each_entry(child, &task->children, list)
> > +			task__print_level(child, fp, level + 1);
> > +	}
> > +}
> > +
> > +static int task_print(struct report *rep, FILE *fp)
> > +{
> > +	struct perf_session *session = rep->session;
> > +	struct machine      *machine = &session->machines.host;
> > +	struct task *tasks, *task;
> > +	unsigned int nr = 0, itask = 0, i;
> > +	struct rb_node *nd;
> > +	LIST_HEAD(list);
> > +
> > +	/*
> > +	 * No locking needed while accessing machine->threads,
> > +	 * because --task is single threaded command.
> > +	 */
> > +
> > +	/* Count all the threads. */
> > +	for (i = 0; i < THREADS__TABLE_SIZE; i++)
> > +		nr += machine->threads[i].nr;
> > +
> > +	tasks = malloc(sizeof(*tasks) * nr);
> > +	if (!tasks)
> > +		return -ENOMEM;
> > +
> > +	for (i = 0; i < THREADS__TABLE_SIZE; i++) {
> > +		struct threads *threads = &machine->threads[i];
> > +
> > +		for (nd = rb_first(&threads->entries); nd; nd = rb_next(nd)) {
> > +			task = tasks + itask++;
> > +
> > +			task->thread = rb_entry(nd, struct thread, rb_node);
> > +			INIT_LIST_HEAD(&task->children);
> > +			INIT_LIST_HEAD(&task->list);
> > +			thread__set_priv(task->thread, task);
> > +		}
> > +	}
> > +
> > +	/*
> > +	 * Iterate every task down to the unprocessed parent
> > +	 * and link all in task children list. Task with no
> > +	 * parent is added into 'list'.
> > +	 */
> > +	for (itask = 0; itask < nr; itask++) {
> > +		task = tasks + itask;
> > +
> > +		if (!list_empty(&task->list))
> > +			continue;
> > +
> > +		task = task_list(task, machine);
> > +		if (IS_ERR(task)) {
> > +			pr_err("Error: failed to process tasks\n");
> > +			free(tasks);
> > +			return -ENOMEM;
> > +		}
> > +
> > +		if (task)
> > +			list_add_tail(&task->list, &list);
> > +	}
> > +
> > +	fprintf(fp, "# %8s %8s %8s  %s\n", "pid", "tid", "ppid", "comm");
> > +
> > +	list_for_each_entry(task, &list, list)
> > +		task__print_level(task, fp, 0);
> > +
> > +	free(tasks);
> > +	return 0;
> > +}
> > +
> >  static int __cmd_report(struct report *rep)
> >  {
> >  	int ret;
> > @@ -632,6 +752,9 @@ static int __cmd_report(struct report *rep)
> >  	if (rep->stat_mode)
> >  		stat_setup(rep);
> >  
> > +	if (rep->task_mode)
> > +		task_setup(rep);
> > +
> >  	ret = perf_session__process_events(session);
> >  	if (ret) {
> >  		ui__error("failed to process sample\n");
> > @@ -641,6 +764,9 @@ static int __cmd_report(struct report *rep)
> >  	if (rep->stat_mode)
> >  		return stat_print(rep);
> >  
> > +	if (rep->task_mode)
> > +		return task_print(rep, stdout);
> > +
> >  	report__warn_kptr_restrict(rep);
> >  
> >  	evlist__for_each_entry(session->evlist, pos)
> > @@ -798,6 +924,7 @@ int cmd_report(int argc, const char **argv)
> >  	OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
> >  		    "dump raw trace in ASCII"),
> >  	OPT_BOOLEAN(0, "stat", &report.stat_mode, "Display event stats"),
> > +	OPT_BOOLEAN(0, "task", &report.task_mode, "Display recorded tasks"),
> >  	OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,
> >  		   "file", "vmlinux pathname"),
> >  	OPT_STRING(0, "kallsyms", &symbol_conf.kallsyms_name,
> > @@ -1059,8 +1186,12 @@ int cmd_report(int argc, const char **argv)
> >  		report.tool.show_feat_hdr = SHOW_FEAT_HEADER;
> >  	if (report.show_full_info)
> >  		report.tool.show_feat_hdr = SHOW_FEAT_HEADER_FULL_INFO;
> > -	if (report.stat_mode)
> > +	if (report.stat_mode || report.task_mode)
> >  		use_browser = 0;
> > +	if (report.stat_mode && report.task_mode) {
> > +		pr_err("Error: --task and --stat options cannot be used together\n");
> > +		goto error;
> > +	}
> >  
> >  	if (strcmp(input_name, "-") != 0)
> >  		setup_browser(true);
> > @@ -1083,7 +1214,8 @@ int cmd_report(int argc, const char **argv)
> >  			ret = 0;
> >  			goto error;
> >  		}
> > -	} else if (use_browser == 0 && !quiet && !report.stat_mode) {
> > +	} else if (use_browser == 0 && !quiet &&
> > +		   !report.stat_mode && !report.task_mode) {
> >  		fputs("# To display the perf.data header info, please use --header/--header-only options.\n#\n",
> >  		      stdout);
> >  	}
> > -- 
> > 2.13.6

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

* Re: [PATCH 01/12] perf tools: Enable LIBBABELTRACE by default
  2018-01-08 15:24       ` Arnaldo Carvalho de Melo
@ 2018-01-08 17:11         ` Jiri Olsa
  2018-01-08 17:16           ` Jiri Olsa
  0 siblings, 1 reply; 44+ messages in thread
From: Jiri Olsa @ 2018-01-08 17:11 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Jiri Olsa, Peter Zijlstra, lkml, Ingo Molnar, Namhyung Kim,
	David Ahern, Andi Kleen, Alexander Shishkin

On Mon, Jan 08, 2018 at 12:24:33PM -0300, Arnaldo Carvalho de Melo wrote:

SNIP

> 
> Works:
> 
> [acme@jouet perf]$ ldd ~/bin/perf | grep babel
> 	libbabeltrace-ctf.so.1 => /lib64/libbabeltrace-ctf.so.1 (0x00007fcb688d0000)
> 	libbabeltrace.so.1 => /lib64/libbabeltrace.so.1 (0x00007fcb67e92000)
> [acme@jouet perf]$ rpm -q libbabeltrace-devel
> libbabeltrace-devel-1.5.3-1.fc27.x86_64
> [acme@jouet perf]$
> 
> But then, if we show:
> 
> Auto-detecting system features:
> ...                         dwarf: [ on  ]
> ...            dwarf_getlocations: [ on  ]
> ...                         glibc: [ on  ]
> ...                          gtk2: [ on  ]
> ...                      libaudit: [ on  ]
> ...                        libbfd: [ on  ]
> ...                        libelf: [ on  ]
> ...                       libnuma: [ on  ]
> ...        numa_num_possible_cpus: [ on  ]
> ...                       libperl: [ on  ]
> ...                     libpython: [ on  ]
> ...                      libslang: [ on  ]
> ...                     libcrypto: [ on  ]
> ...                     libunwind: [ on  ]
> ...            libdw-dwarf-unwind: [ on  ]
> ...                          zlib: [ on  ]
> ...                          lzma: [ on  ]
> ...                     get_cpuid: [ on  ]
> ...                           bpf: [ on  ]
> 
> Shoudln't we tell the user that babeltrace was linked too?

the logic is just to simply display the state of features
which we provide in FEATURE_DISPLAY variable, which is
believed to be common and important enough to display
status about

maybe we could display it with 'make VF=1' output?

jirka

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

* Re: [PATCH 01/12] perf tools: Enable LIBBABELTRACE by default
  2018-01-08 17:11         ` Jiri Olsa
@ 2018-01-08 17:16           ` Jiri Olsa
  2018-01-09  9:26             ` [PATCH] perf build: Display EXTRA features for VF=1 build Jiri Olsa
  0 siblings, 1 reply; 44+ messages in thread
From: Jiri Olsa @ 2018-01-08 17:16 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Jiri Olsa, Peter Zijlstra, lkml, Ingo Molnar, Namhyung Kim,
	David Ahern, Andi Kleen, Alexander Shishkin

On Mon, Jan 08, 2018 at 06:11:22PM +0100, Jiri Olsa wrote:
> On Mon, Jan 08, 2018 at 12:24:33PM -0300, Arnaldo Carvalho de Melo wrote:
> 
> SNIP
> 
> > 
> > Works:
> > 
> > [acme@jouet perf]$ ldd ~/bin/perf | grep babel
> > 	libbabeltrace-ctf.so.1 => /lib64/libbabeltrace-ctf.so.1 (0x00007fcb688d0000)
> > 	libbabeltrace.so.1 => /lib64/libbabeltrace.so.1 (0x00007fcb67e92000)
> > [acme@jouet perf]$ rpm -q libbabeltrace-devel
> > libbabeltrace-devel-1.5.3-1.fc27.x86_64
> > [acme@jouet perf]$
> > 
> > But then, if we show:
> > 
> > Auto-detecting system features:
> > ...                         dwarf: [ on  ]
> > ...            dwarf_getlocations: [ on  ]
> > ...                         glibc: [ on  ]
> > ...                          gtk2: [ on  ]
> > ...                      libaudit: [ on  ]
> > ...                        libbfd: [ on  ]
> > ...                        libelf: [ on  ]
> > ...                       libnuma: [ on  ]
> > ...        numa_num_possible_cpus: [ on  ]
> > ...                       libperl: [ on  ]
> > ...                     libpython: [ on  ]
> > ...                      libslang: [ on  ]
> > ...                     libcrypto: [ on  ]
> > ...                     libunwind: [ on  ]
> > ...            libdw-dwarf-unwind: [ on  ]
> > ...                          zlib: [ on  ]
> > ...                          lzma: [ on  ]
> > ...                     get_cpuid: [ on  ]
> > ...                           bpf: [ on  ]
> > 
> > Shoudln't we tell the user that babeltrace was linked too?
> 
> the logic is just to simply display the state of features
> which we provide in FEATURE_DISPLAY variable, which is
> believed to be common and important enough to display
> status about
> 
> maybe we could display it with 'make VF=1' output?

like in patch attached ;-)

	[jolsa@krava perf]$ make VF=1
	  BUILD:   Doing 'make -j4' parallel build
	Warning: Kernel ABI header at 'tools/include/uapi/linux/perf_event.h' differs from latest version at 'include/uapi/linux/perf_event.h'

	Auto-detecting system features:
	...                         dwarf: [ on  ]
	...            dwarf_getlocations: [ on  ]
	...                         glibc: [ on  ]
	...                          gtk2: [ on  ]
	...                      libaudit: [ on  ]
	...                        libbfd: [ on  ]
	...                        libelf: [ on  ]
	...                       libnuma: [ on  ]
	...        numa_num_possible_cpus: [ on  ]
	...                       libperl: [ on  ]
	...                     libpython: [ on  ]
	...                      libslang: [ on  ]
	...                     libcrypto: [ on  ]
	...                     libunwind: [ OFF ]
	...            libdw-dwarf-unwind: [ on  ]
	...                          zlib: [ on  ]
	...                          lzma: [ on  ]
	...                     get_cpuid: [ on  ]
	...                           bpf: [ on  ]
	...                     backtrace: [ on  ]
	...                fortify-source: [ on  ]
	...         sync-compare-and-swap: [ on  ]
	...                  gtk2-infobar: [ on  ]
	...             libelf-getphdrnum: [ on  ]
	...           libelf-gelf_getnote: [ on  ]
	...          libelf-getshdrstrndx: [ on  ]
	...                   libelf-mmap: [ on  ]
	...             libpython-version: [ on  ]
	...                 libunwind-x86: [ OFF ]
	...              libunwind-x86_64: [ OFF ]
	...                 libunwind-arm: [ OFF ]
	...             libunwind-aarch64: [ OFF ]
	...   pthread-attr-setaffinity-np: [ on  ]
	...               pthread-barrier: [ on  ]
	...            stackprotector-all: [ on  ]
	...                       timerfd: [ on  ]
	...                  sched_getcpu: [ on  ]
	...                           sdt: [ on  ]
	...                         setns: [ on  ]

	Makefile.config:459: No libunwind found. Please install libunwind-dev[el] >= 1.1 and/or set LIBUNWIND_DIR
	...                        bionic: [ OFF ]
	...                    compile-32: [ on  ]
	...                   compile-x32: [ OFF ]
	...                cplus-demangle: [ on  ]
	...                         hello: [ OFF ]
	...                 libbabeltrace: [ on  ]
	...                       liberty: [ on  ]
	...                     liberty-z: [ on  ]
	...         libunwind-debug-frame: [ OFF ]
	...     libunwind-debug-frame-arm: [ OFF ]
	... libunwind-debug-frame-aarch64: [ OFF ]
	...                        prefix: /home/jolsa
	...                        bindir: /home/jolsa/bin
	...                        libdir: /home/jolsa/lib64
	...                    sysconfdir: /home/jolsa/etc
	...                 LIBUNWIND_DIR: 
	...                     LIBDW_DIR: 
	...                          JDIR: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.151-1.b12.fc26.x86_64
	...     DWARF post unwind library: libdw


jirka

---
diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index 12dec6ea5ed2..92265b32dddd 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -947,6 +947,10 @@ define print_var_code
 endef
 
 ifeq ($(VF),1)
+  # Display EXTRA features which are detected manualy
+  # from here with feature_check call and thus cannot
+  # be partof global state output.
+  $(foreach feat,$(FEATURE_TESTS_EXTRA),$(call feature_print_status,$(feat),))
   $(call print_var,prefix)
   $(call print_var,bindir)
   $(call print_var,libdir)

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

* Re: [PATCH 12/12] perf report: Add --task option to display monitored tasks
  2018-01-07 16:03 ` [PATCH 12/12] perf report: Add --task option to display monitored tasks Jiri Olsa
  2018-01-08 15:55   ` Arnaldo Carvalho de Melo
@ 2018-01-09  1:56   ` Namhyung Kim
  2018-01-09  9:15     ` Jiri Olsa
  2018-01-11  6:29   ` [tip:perf/core] perf report: Add --tasks " tip-bot for Jiri Olsa
  2 siblings, 1 reply; 44+ messages in thread
From: Namhyung Kim @ 2018-01-09  1:56 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Arnaldo Carvalho de Melo, Peter Zijlstra, lkml, Ingo Molnar,
	David Ahern, Andi Kleen, Alexander Shishkin, kernel-team

Hi Jiri,

On Sun, Jan 07, 2018 at 05:03:56PM +0100, Jiri Olsa wrote:
> Adding --task option to display monitored tasks stored
> in perf.data. Displaying pid/tid/ppid plus the command
> string aligned to distinguish parent and child tasks.
> 
>   $ perf record -a
>   ...
>   $ perf report --task
>   #     pid     tid    ppid  comm
>           0       0      -1 |swapper
>           2       2       0 | kthreadd
>       14080   14080       2 |  kworker/u17:1
>           4       4       2 |  kworker/0:0H
>           6       6       2 |  mm_percpu_wq
>   ...
>           1       1       0 | systemd
>       23242   23242       1 |  firefox
>       23242   23298   23242 |   Cache2 I/O
>       23242   23304   23242 |   GMPThread
>   ...
>        1195    1195       1 |  login
>        1611    1611    1195 |   bash
>        1639    1639    1611 |    startx
>        1663    1663    1639 |     xinit
>        1673    1673    1663 |      xmonad-x86_64-l
>       23939   23939    1673 |       xterm
>       23941   23941   23939 |        bash
>       23963   23963   23941 |         mutt
>       24954   24954   23963 |          offlineimap

Nice! :)


> 
> Link: http://lkml.kernel.org/n/tip-ehvadnmg8b3kdhvgsbuesbr7@git.kernel.org
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> ---
>  tools/perf/Documentation/perf-report.txt |   4 +
>  tools/perf/builtin-report.c              | 136 ++++++++++++++++++++++++++++++-
>  2 files changed, 138 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/perf/Documentation/perf-report.txt b/tools/perf/Documentation/perf-report.txt
> index b0d70bf4ddfe..dcf0d154918f 100644
> --- a/tools/perf/Documentation/perf-report.txt
> +++ b/tools/perf/Documentation/perf-report.txt
> @@ -441,6 +441,10 @@ include::itrace.txt[]
>  	Display overall events statistics without any further processing.
>  	(like the one at the end of the perf report -D command)
>  
> +--task::
> +	Display monitored tasks stored in perf data. Displaying pid/tid/ppid
> +	plus the command string aligned to distinguish parent and child tasks.
> +
>  include::callchain-overhead-calculation.txt[]
>  
>  SEE ALSO
> diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
> index 11d303494b0c..f2ca2cbe63c1 100644
> --- a/tools/perf/builtin-report.c
> +++ b/tools/perf/builtin-report.c
> @@ -15,6 +15,7 @@
>  #include "util/color.h"
>  #include <linux/list.h>
>  #include <linux/rbtree.h>
> +#include <linux/err.h>
>  #include "util/symbol.h"
>  #include "util/callchain.h"
>  #include "util/values.h"
> @@ -61,6 +62,7 @@ struct report {
>  	bool			inverted_callchain;
>  	bool			mem_mode;
>  	bool			stat_mode;
> +	bool			task_mode;
>  	bool			header;
>  	bool			header_only;
>  	bool			nonany_branch_mode;
> @@ -598,6 +600,124 @@ static int stat_print(struct report *rep)
>  	return 0;
>  }
>  
> +static void task_setup(struct report *rep)
> +{
> +	memset(&rep->tool, 0, sizeof(rep->tool));
> +	rep->tool.comm = perf_event__process_comm;
> +	rep->tool.exit = perf_event__process_exit;
> +	rep->tool.fork = perf_event__process_fork;
> +	rep->tool.no_warn = true;
> +}
> +
> +struct task {
> +	struct thread		*thread;
> +	struct list_head	 list;
> +	struct list_head	 children;
> +};
> +
> +static struct task *task_list(struct task *task, struct machine *machine)
> +{
> +	struct thread *parent_thread, *thread = task->thread;
> +	struct task   *parent_task;
> +
> +	/* Already listed. */
> +	if (!list_empty(&task->list))
> +		return NULL;
> +
> +	/* Last one in the chain. */
> +	if (thread->ppid == -1)
> +		return task;
> +
> +	parent_thread = machine__findnew_thread(machine, -1, thread->ppid);

I think it should be machine__find_thread() since creating a new
thread at this stage would lack thread->priv anyway.

Thanks,
Namhyung


> +	if (!parent_thread)
> +		return ERR_PTR(-ENOMEM);
> +
> +	parent_task = thread__priv(parent_thread);
> +	list_add_tail(&task->list, &parent_task->children);
> +	return task_list(parent_task, machine);
> +}

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

* Re: [PATCH 12/12] perf report: Add --task option to display monitored tasks
  2018-01-09  1:56   ` Namhyung Kim
@ 2018-01-09  9:15     ` Jiri Olsa
  2018-01-09 13:05       ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 44+ messages in thread
From: Jiri Olsa @ 2018-01-09  9:15 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Jiri Olsa, Arnaldo Carvalho de Melo, Peter Zijlstra, lkml,
	Ingo Molnar, David Ahern, Andi Kleen, Alexander Shishkin,
	kernel-team

On Tue, Jan 09, 2018 at 10:56:07AM +0900, Namhyung Kim wrote:

SNIP

> > +static struct task *task_list(struct task *task, struct machine *machine)
> > +{
> > +	struct thread *parent_thread, *thread = task->thread;
> > +	struct task   *parent_task;
> > +
> > +	/* Already listed. */
> > +	if (!list_empty(&task->list))
> > +		return NULL;
> > +
> > +	/* Last one in the chain. */
> > +	if (thread->ppid == -1)
> > +		return task;
> > +
> > +	parent_thread = machine__findnew_thread(machine, -1, thread->ppid);
> 
> I think it should be machine__find_thread() since creating a new
> thread at this stage would lack thread->priv anyway.

ugh, that's right.. I tried to stay safe, but the NULL
in priv would bring it down anyway

Arnaldo,
I already see changed version on top of your branch,
please let me know if you make also this change or
I should send v2

thanks,
jirka

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

* [PATCH] perf build: Display EXTRA features for VF=1 build
  2018-01-08 17:16           ` Jiri Olsa
@ 2018-01-09  9:26             ` Jiri Olsa
  2018-01-19 10:15               ` Jiri Olsa
  2018-01-24 11:23               ` [tip:perf/core] " tip-bot for Jiri Olsa
  0 siblings, 2 replies; 44+ messages in thread
From: Jiri Olsa @ 2018-01-09  9:26 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Jiri Olsa, Peter Zijlstra, lkml, Ingo Molnar, Namhyung Kim,
	David Ahern, Andi Kleen, Alexander Shishkin

On Mon, Jan 08, 2018 at 06:16:49PM +0100, Jiri Olsa wrote:
> On Mon, Jan 08, 2018 at 06:11:22PM +0100, Jiri Olsa wrote:
> > On Mon, Jan 08, 2018 at 12:24:33PM -0300, Arnaldo Carvalho de Melo wrote:
> > 
> > SNIP
> > 
> > > 
> > > Works:
> > > 
> > > [acme@jouet perf]$ ldd ~/bin/perf | grep babel
> > > 	libbabeltrace-ctf.so.1 => /lib64/libbabeltrace-ctf.so.1 (0x00007fcb688d0000)
> > > 	libbabeltrace.so.1 => /lib64/libbabeltrace.so.1 (0x00007fcb67e92000)
> > > [acme@jouet perf]$ rpm -q libbabeltrace-devel
> > > libbabeltrace-devel-1.5.3-1.fc27.x86_64
> > > [acme@jouet perf]$
> > > 
> > > But then, if we show:
> > > 
> > > Auto-detecting system features:
> > > ...                         dwarf: [ on  ]
> > > ...            dwarf_getlocations: [ on  ]
> > > ...                         glibc: [ on  ]
> > > ...                          gtk2: [ on  ]
> > > ...                      libaudit: [ on  ]
> > > ...                        libbfd: [ on  ]
> > > ...                        libelf: [ on  ]
> > > ...                       libnuma: [ on  ]
> > > ...        numa_num_possible_cpus: [ on  ]
> > > ...                       libperl: [ on  ]
> > > ...                     libpython: [ on  ]
> > > ...                      libslang: [ on  ]
> > > ...                     libcrypto: [ on  ]
> > > ...                     libunwind: [ on  ]
> > > ...            libdw-dwarf-unwind: [ on  ]
> > > ...                          zlib: [ on  ]
> > > ...                          lzma: [ on  ]
> > > ...                     get_cpuid: [ on  ]
> > > ...                           bpf: [ on  ]
> > > 
> > > Shoudln't we tell the user that babeltrace was linked too?
> > 
> > the logic is just to simply display the state of features
> > which we provide in FEATURE_DISPLAY variable, which is
> > believed to be common and important enough to display
> > status about
> > 
> > maybe we could display it with 'make VF=1' output?
> 
> like in patch attached ;-)

with changelog

thanks,
jirka


---
Display state of the rest of the features (FEATURE_TESTS_EXTRA)
for 'make VF=1' build. These features are detected manually by
perf's Makefile.config so they can't be displayed with the
main list, but only after we're done in Makefile.config.

  $ make VF=1
    BUILD:   Doing 'make -j4' parallel build

  Auto-detecting system features:
  ...                         dwarf: [ on  ]
  ...            dwarf_getlocations: [ on  ]
  ...                         glibc: [ on  ]
  ...                          gtk2: [ on  ]

SNIP

  ...                       timerfd: [ on  ]
  ...                  sched_getcpu: [ on  ]
  ...                           sdt: [ on  ]
  ...                         setns: [ on  ]

extra features:
  ...                        bionic: [ OFF ]
  ...                    compile-32: [ on  ]
  ...                   compile-x32: [ OFF ]
  ...                cplus-demangle: [ on  ]
  ...                         hello: [ OFF ]
  ...                 libbabeltrace: [ on  ]
  ...                       liberty: [ on  ]
  ...                     liberty-z: [ on  ]
  ...         libunwind-debug-frame: [ OFF ]
  ...     libunwind-debug-frame-arm: [ OFF ]
  ... libunwind-debug-frame-aarch64: [ OFF ]

SNIP

Link: http://lkml.kernel.org/n/tip-q4r73p2c6wfag2s38fpsim8v@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/Makefile.config | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index 12dec6ea5ed2..92265b32dddd 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -947,6 +947,10 @@ define print_var_code
 endef
 
 ifeq ($(VF),1)
+  # Display EXTRA features which are detected manualy
+  # from here with feature_check call and thus cannot
+  # be partof global state output.
+  $(foreach feat,$(FEATURE_TESTS_EXTRA),$(call feature_print_status,$(feat),))
   $(call print_var,prefix)
   $(call print_var,bindir)
   $(call print_var,libdir)
-- 
2.13.6

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

* Re: [PATCH 12/12] perf report: Add --task option to display monitored tasks
  2018-01-09  9:15     ` Jiri Olsa
@ 2018-01-09 13:05       ` Arnaldo Carvalho de Melo
  2018-01-09 13:27         ` Jiri Olsa
  0 siblings, 1 reply; 44+ messages in thread
From: Arnaldo Carvalho de Melo @ 2018-01-09 13:05 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Namhyung Kim, Jiri Olsa, Peter Zijlstra, lkml, Ingo Molnar,
	David Ahern, Andi Kleen, Alexander Shishkin, kernel-team

Em Tue, Jan 09, 2018 at 10:15:51AM +0100, Jiri Olsa escreveu:
> On Tue, Jan 09, 2018 at 10:56:07AM +0900, Namhyung Kim wrote:
> 
> SNIP
> 
> > > +static struct task *task_list(struct task *task, struct machine *machine)
> > > +{
> > > +	struct thread *parent_thread, *thread = task->thread;
> > > +	struct task   *parent_task;
> > > +
> > > +	/* Already listed. */
> > > +	if (!list_empty(&task->list))
> > > +		return NULL;
> > > +
> > > +	/* Last one in the chain. */
> > > +	if (thread->ppid == -1)
> > > +		return task;
> > > +
> > > +	parent_thread = machine__findnew_thread(machine, -1, thread->ppid);
> > 
> > I think it should be machine__find_thread() since creating a new
> > thread at this stage would lack thread->priv anyway.
> 
> ugh, that's right.. I tried to stay safe, but the NULL
> in priv would bring it down anyway
> 
> Arnaldo,
> I already see changed version on top of your branch,
> please let me know if you make also this change or
> I should send v2

I can make the change, thanks!

Just to make sure we're on the same page, just this, right?

diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 3685ac101b16..e60709fe31ed 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -633,9 +633,9 @@ static struct task *tasks_list(struct task *task, struct machine *machine)
 	if (thread->ppid == -1)
 		return task;
 
-	parent_thread = machine__findnew_thread(machine, -1, thread->ppid);
+	parent_thread = machine__find_thread(machine, -1, thread->ppid);
 	if (!parent_thread)
-		return ERR_PTR(-ENOMEM);
+		return ERR_PTR(-ENOENT);
 
 	parent_task = thread__priv(parent_thread);
 	list_add_tail(&task->list, &parent_task->children);

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

* Re: [PATCH 12/12] perf report: Add --task option to display monitored tasks
  2018-01-09 13:05       ` Arnaldo Carvalho de Melo
@ 2018-01-09 13:27         ` Jiri Olsa
  0 siblings, 0 replies; 44+ messages in thread
From: Jiri Olsa @ 2018-01-09 13:27 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Namhyung Kim, Jiri Olsa, Peter Zijlstra, lkml, Ingo Molnar,
	David Ahern, Andi Kleen, Alexander Shishkin, kernel-team

On Tue, Jan 09, 2018 at 10:05:24AM -0300, Arnaldo Carvalho de Melo wrote:
> Em Tue, Jan 09, 2018 at 10:15:51AM +0100, Jiri Olsa escreveu:
> > On Tue, Jan 09, 2018 at 10:56:07AM +0900, Namhyung Kim wrote:
> > 
> > SNIP
> > 
> > > > +static struct task *task_list(struct task *task, struct machine *machine)
> > > > +{
> > > > +	struct thread *parent_thread, *thread = task->thread;
> > > > +	struct task   *parent_task;
> > > > +
> > > > +	/* Already listed. */
> > > > +	if (!list_empty(&task->list))
> > > > +		return NULL;
> > > > +
> > > > +	/* Last one in the chain. */
> > > > +	if (thread->ppid == -1)
> > > > +		return task;
> > > > +
> > > > +	parent_thread = machine__findnew_thread(machine, -1, thread->ppid);
> > > 
> > > I think it should be machine__find_thread() since creating a new
> > > thread at this stage would lack thread->priv anyway.
> > 
> > ugh, that's right.. I tried to stay safe, but the NULL
> > in priv would bring it down anyway
> > 
> > Arnaldo,
> > I already see changed version on top of your branch,
> > please let me know if you make also this change or
> > I should send v2
> 
> I can make the change, thanks!
> 
> Just to make sure we're on the same page, just this, right?
> 
> diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
> index 3685ac101b16..e60709fe31ed 100644
> --- a/tools/perf/builtin-report.c
> +++ b/tools/perf/builtin-report.c
> @@ -633,9 +633,9 @@ static struct task *tasks_list(struct task *task, struct machine *machine)
>  	if (thread->ppid == -1)
>  		return task;
>  
> -	parent_thread = machine__findnew_thread(machine, -1, thread->ppid);
> +	parent_thread = machine__find_thread(machine, -1, thread->ppid);

yes

>  	if (!parent_thread)
> -		return ERR_PTR(-ENOMEM);
> +		return ERR_PTR(-ENOENT);

right, I haven't noticed this one.. then we should
also do in the attached change

thanks,
jirka


---
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index f7338b594844..67c74d6dab24 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -710,7 +710,7 @@ static int tasks_print(struct report *rep, FILE *fp)
 		if (IS_ERR(task)) {
 			pr_err("Error: failed to process tasks\n");
 			free(tasks);
-			return -ENOMEM;
+			return PTR_ERR(task);
 		}
 
 		if (task)

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

* Re: [PATCH 09/12] perf script: Add support to display lost events
  2018-01-07 16:03 ` [PATCH 09/12] perf script: Add support to display lost events Jiri Olsa
@ 2018-01-10 15:40   ` Arnaldo Carvalho de Melo
  2018-01-10 15:44     ` Jiri Olsa
  2018-01-11  6:27   ` [tip:perf/core] " tip-bot for Jiri Olsa
  1 sibling, 1 reply; 44+ messages in thread
From: Arnaldo Carvalho de Melo @ 2018-01-10 15:40 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Peter Zijlstra, lkml, Ingo Molnar, Namhyung Kim, David Ahern,
	Andi Kleen, Alexander Shishkin

Em Sun, Jan 07, 2018 at 05:03:53PM +0100, Jiri Olsa escreveu:
> +++ b/tools/perf/util/event.c
> +static size_t perf_event__fprintf_lost(union perf_event *event, FILE *fp)
> +{
> +	return fprintf(fp, " lost %lu\n", event->lost.lost);
> +}

Had to make this:

	return fprintf(fp, " lost %" PRIu64 "\n", event->lost.lost);

To fix this:

  CC       /tmp/build/perf/util/event.o
util/event.c: In function 'perf_event__fprintf_lost':
util/event.c:1440:21: error: format '%lu' expects argument of type 'long unsigned int', but argument 3 has type 'u64 {aka long long unsigned int}' [-Werror=format=]
  return fprintf(fp, " lost %lu\n", event->lost.lost);
                     ^
  CC       /tmp/build/perf/builtin-script.o
  CC       /tmp/build/perf/builtin-kmem.o
cc1: all warnings being treated as errors

 on these systems:

  17 debian:experimental-x-mips  : FAIL mips-linux-gnu-gcc (Debian 7.2.0-11) 7.2.0
  19 debian:experimental-x-mipsel: FAIL mipsel-linux-gnu-gcc (Debian 7.2.0-11) 7.2.0
  25 fedora:24-x-ARC-uClibc      : FAIL arc-linux-gcc (ARCompact ISA Linux uClibc toolchain 2017.09-rc2) 7.1.1 20170710
  43 ubuntu:16.04-x-arm          : FAIL arm-linux-gnueabihf-gcc (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
  45 ubuntu:16.04-x-powerpc      : FAIL powerpc-linux-gnu-gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609

- Arnaldo

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

* Re: [PATCH 09/12] perf script: Add support to display lost events
  2018-01-10 15:40   ` Arnaldo Carvalho de Melo
@ 2018-01-10 15:44     ` Jiri Olsa
  0 siblings, 0 replies; 44+ messages in thread
From: Jiri Olsa @ 2018-01-10 15:44 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Jiri Olsa, Peter Zijlstra, lkml, Ingo Molnar, Namhyung Kim,
	David Ahern, Andi Kleen, Alexander Shishkin

On Wed, Jan 10, 2018 at 12:40:50PM -0300, Arnaldo Carvalho de Melo wrote:
> Em Sun, Jan 07, 2018 at 05:03:53PM +0100, Jiri Olsa escreveu:
> > +++ b/tools/perf/util/event.c
> > +static size_t perf_event__fprintf_lost(union perf_event *event, FILE *fp)
> > +{
> > +	return fprintf(fp, " lost %lu\n", event->lost.lost);
> > +}
> 
> Had to make this:
> 
> 	return fprintf(fp, " lost %" PRIu64 "\n", event->lost.lost);

right, thanks

jirka

> 
> To fix this:
> 
>   CC       /tmp/build/perf/util/event.o
> util/event.c: In function 'perf_event__fprintf_lost':
> util/event.c:1440:21: error: format '%lu' expects argument of type 'long unsigned int', but argument 3 has type 'u64 {aka long long unsigned int}' [-Werror=format=]
>   return fprintf(fp, " lost %lu\n", event->lost.lost);
>                      ^
>   CC       /tmp/build/perf/builtin-script.o
>   CC       /tmp/build/perf/builtin-kmem.o
> cc1: all warnings being treated as errors
> 
>  on these systems:
> 
>   17 debian:experimental-x-mips  : FAIL mips-linux-gnu-gcc (Debian 7.2.0-11) 7.2.0
>   19 debian:experimental-x-mipsel: FAIL mipsel-linux-gnu-gcc (Debian 7.2.0-11) 7.2.0
>   25 fedora:24-x-ARC-uClibc      : FAIL arc-linux-gcc (ARCompact ISA Linux uClibc toolchain 2017.09-rc2) 7.1.1 20170710
>   43 ubuntu:16.04-x-arm          : FAIL arm-linux-gnueabihf-gcc (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
>   45 ubuntu:16.04-x-powerpc      : FAIL powerpc-linux-gnu-gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
> 
> - Arnaldo

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

* [tip:perf/core] perf tools: Enable LIBBABELTRACE by default
  2018-01-07 16:03 ` [PATCH 01/12] perf tools: Enable LIBBABELTRACE by default Jiri Olsa
  2018-01-08 15:17   ` Arnaldo Carvalho de Melo
@ 2018-01-11  6:24   ` tip-bot for Jiri Olsa
  1 sibling, 0 replies; 44+ messages in thread
From: tip-bot for Jiri Olsa @ 2018-01-11  6:24 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: alexander.shishkin, acme, hpa, tglx, mingo, ak, dsahern, jolsa,
	linux-kernel, namhyung, peterz

Commit-ID:  24787afbcd0127859394eb9230659ee6d5dc4644
Gitweb:     https://git.kernel.org/tip/24787afbcd0127859394eb9230659ee6d5dc4644
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Sun, 7 Jan 2018 17:03:45 +0100
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 8 Jan 2018 12:10:21 -0300

perf tools: Enable LIBBABELTRACE by default

There's no reason anymore to treat babel trace in a special way, because
a) we no longer display its state b) the needed babeltrace library is
now out and well adopted among distros.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20180107160356.28203-2-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Makefile.config | 2 +-
 tools/perf/Makefile.perf   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index f050f38..12dec6e 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -780,7 +780,7 @@ else
   NO_PERF_READ_VDSOX32 := 1
 endif
 
-ifdef LIBBABELTRACE
+ifndef NO_LIBBABELTRACE
   $(call feature_check,libbabeltrace)
   ifeq ($(feature-libbabeltrace), 1)
     CFLAGS += -DHAVE_LIBBABELTRACE_SUPPORT $(LIBBABELTRACE_CFLAGS)
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 68cf136..9fdefd7 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -77,7 +77,7 @@ include ../scripts/utilities.mak
 #
 # Define NO_ZLIB if you do not want to support compressed kernel modules
 #
-# Define LIBBABELTRACE if you DO want libbabeltrace support
+# Define NO_LIBBABELTRACE if you do not want libbabeltrace support
 # for CTF data format.
 #
 # Define NO_LZMA if you do not want to support compressed (xz) kernel modules

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

* [tip:perf/core] perf tools: Display perf_event_attr::namespaces debug info
  2018-01-07 16:03 ` [PATCH 02/12] perf tools: Display perf_event_attr::namespaces debug info Jiri Olsa
@ 2018-01-11  6:24   ` tip-bot for Jiri Olsa
  0 siblings, 0 replies; 44+ messages in thread
From: tip-bot for Jiri Olsa @ 2018-01-11  6:24 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: dsahern, mingo, acme, jolsa, hpa, namhyung, peterz,
	alexander.shishkin, tglx, linux-kernel, ak

Commit-ID:  db9fc765e8f4d0144d13cdfa4be32d81eae01710
Gitweb:     https://git.kernel.org/tip/db9fc765e8f4d0144d13cdfa4be32d81eae01710
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Sun, 7 Jan 2018 17:03:46 +0100
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 8 Jan 2018 12:15:19 -0300

perf tools: Display perf_event_attr::namespaces debug info

Display namespaces bit in -vv debug display:

  $ perf record -vv --namespaces ...
  ...
  perf_event_attr:
    size                             112
    ...
    namespaces                       1

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20180107160356.28203-3-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/evsel.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index a4d256e..c435b24 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -1577,6 +1577,7 @@ int perf_event_attr__fprintf(FILE *fp, struct perf_event_attr *attr,
 	PRINT_ATTRf(use_clockid, p_unsigned);
 	PRINT_ATTRf(context_switch, p_unsigned);
 	PRINT_ATTRf(write_backward, p_unsigned);
+	PRINT_ATTRf(namespaces, p_unsigned);
 
 	PRINT_ATTRn("{ wakeup_events, wakeup_watermark }", wakeup_events, p_unsigned);
 	PRINT_ATTRf(bp_type, p_unsigned);

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

* [tip:perf/core] perf: Allocate context task_ctx_data for child event
  2018-01-07 16:03 ` [PATCH 03/12] perf: Allocate context task_ctx_data for child event Jiri Olsa
  2018-01-08 12:14   ` Peter Zijlstra
@ 2018-01-11  6:24   ` tip-bot for Jiri Olsa
  1 sibling, 0 replies; 44+ messages in thread
From: tip-bot for Jiri Olsa @ 2018-01-11  6:24 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: alexander.shishkin, ak, dsahern, peterz, hpa, linux-kernel, tglx,
	mingo, namhyung, acme, jolsa

Commit-ID:  313ccb96159489eabdbdcf4deb34e7fbac17557d
Gitweb:     https://git.kernel.org/tip/313ccb96159489eabdbdcf4deb34e7fbac17557d
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Sun, 7 Jan 2018 17:03:47 +0100
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 8 Jan 2018 12:26:46 -0300

perf: Allocate context task_ctx_data for child event

Currently we use perf_event_context::task_ctx_data to save and restore
the LBR status when the task is scheduled out and in.

We don't allocate it for child contexts, which results in shorter task's
LBR stack, because we don't save the history from previous run and start
over every time we schedule the task in.

I made a test to generate samples with LBR call stack and got higher
numbers on bigger chain depths:

                            before:     after:
  LBR call chain: nr: 1       60561     498127
  LBR call chain: nr: 2           0          0
  LBR call chain: nr: 3      107030       2172
  LBR call chain: nr: 4      466685      62758
  LBR call chain: nr: 5     2307319     878046
  LBR call chain: nr: 6       48713     495218
  LBR call chain: nr: 7        1040       4551
  LBR call chain: nr: 8         481        172
  LBR call chain: nr: 9         878        120
  LBR call chain: nr: 10       2377       6698
  LBR call chain: nr: 11      28830     151487
  LBR call chain: nr: 12      29347     339867
  LBR call chain: nr: 13          4         22
  LBR call chain: nr: 14          3         53

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Fixes: 4af57ef28c2c ("perf: Add pmu specific data for perf task context")
Link: http://lkml.kernel.org/r/20180107160356.28203-4-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 kernel/events/core.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 4df5b69..55fb648 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -10703,6 +10703,19 @@ inherit_event(struct perf_event *parent_event,
 	if (IS_ERR(child_event))
 		return child_event;
 
+
+	if ((child_event->attach_state & PERF_ATTACH_TASK_DATA) &&
+	    !child_ctx->task_ctx_data) {
+		struct pmu *pmu = child_event->pmu;
+
+		child_ctx->task_ctx_data = kzalloc(pmu->task_ctx_size,
+						   GFP_KERNEL);
+		if (!child_ctx->task_ctx_data) {
+			free_event(child_event);
+			return NULL;
+		}
+	}
+
 	/*
 	 * is_orphaned_event() and list_add_tail(&parent_event->child_list)
 	 * must be under the same lock in order to serialize against
@@ -10713,6 +10726,7 @@ inherit_event(struct perf_event *parent_event,
 	if (is_orphaned_event(parent_event) ||
 	    !atomic_long_inc_not_zero(&parent_event->refcount)) {
 		mutex_unlock(&parent_event->child_mutex);
+		/* task_ctx_data is freed with child_ctx */
 		free_event(child_event);
 		return NULL;
 	}

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

* [tip:perf/core] perf: Add sample_id to PERF_RECORD_ITRACE_START event comment
  2018-01-07 16:03 ` [PATCH 04/12] perf: Add sample_id to PERF_RECORD_ITRACE_START event comment Jiri Olsa
@ 2018-01-11  6:25   ` tip-bot for Jiri Olsa
  0 siblings, 0 replies; 44+ messages in thread
From: tip-bot for Jiri Olsa @ 2018-01-11  6:25 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: jolsa, mingo, namhyung, ak, tglx, dsahern, hpa, peterz,
	linux-kernel, acme, alexander.shishkin

Commit-ID:  81df978c49379481716aef591de77313c286d747
Gitweb:     https://git.kernel.org/tip/81df978c49379481716aef591de77313c286d747
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Sun, 7 Jan 2018 17:03:48 +0100
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 8 Jan 2018 12:32:25 -0300

perf: Add sample_id to PERF_RECORD_ITRACE_START event comment

Adding missing sample_id line into PERF_RECORD_ITRACE_START
event comment.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20180107160356.28203-5-jolsa@kernel.org
[ Update the tools/include/uapi/linux copy ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 include/uapi/linux/perf_event.h       | 1 +
 tools/include/uapi/linux/perf_event.h | 1 +
 2 files changed, 2 insertions(+)

diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h
index b9a4953..8bb66e8 100644
--- a/include/uapi/linux/perf_event.h
+++ b/include/uapi/linux/perf_event.h
@@ -864,6 +864,7 @@ enum perf_event_type {
 	 *	struct perf_event_header	header;
 	 *	u32				pid;
 	 *	u32				tid;
+	 *	struct sample_id		sample_id;
 	 * };
 	 */
 	PERF_RECORD_ITRACE_START		= 12,
diff --git a/tools/include/uapi/linux/perf_event.h b/tools/include/uapi/linux/perf_event.h
index b9a4953..8bb66e8 100644
--- a/tools/include/uapi/linux/perf_event.h
+++ b/tools/include/uapi/linux/perf_event.h
@@ -864,6 +864,7 @@ enum perf_event_type {
 	 *	struct perf_event_header	header;
 	 *	u32				pid;
 	 *	u32				tid;
+	 *	struct sample_id		sample_id;
 	 * };
 	 */
 	PERF_RECORD_ITRACE_START		= 12,

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

* [tip:perf/core] perf: Make perf_callchain function static
  2018-01-07 16:03 ` [PATCH 05/12] perf: Make perf_callchain function static Jiri Olsa
@ 2018-01-11  6:25   ` tip-bot for Jiri Olsa
  0 siblings, 0 replies; 44+ messages in thread
From: tip-bot for Jiri Olsa @ 2018-01-11  6:25 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: tglx, peterz, namhyung, hpa, jolsa, dsahern, acme, ak, mingo,
	alexander.shishkin, linux-kernel

Commit-ID:  8cf7e0e22414f5acf85ecb7cd0d4482e6c9696ae
Gitweb:     https://git.kernel.org/tip/8cf7e0e22414f5acf85ecb7cd0d4482e6c9696ae
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Sun, 7 Jan 2018 17:03:49 +0100
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 8 Jan 2018 12:33:01 -0300

perf: Make perf_callchain function static

And move it to core.c, because there's no caller of this function other
than the one in core.c

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20180107160356.28203-6-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 kernel/events/callchain.c | 15 ---------------
 kernel/events/core.c      | 16 ++++++++++++++++
 kernel/events/internal.h  |  4 ----
 3 files changed, 16 insertions(+), 19 deletions(-)

diff --git a/kernel/events/callchain.c b/kernel/events/callchain.c
index 1b2be63..772a43f 100644
--- a/kernel/events/callchain.c
+++ b/kernel/events/callchain.c
@@ -179,21 +179,6 @@ put_callchain_entry(int rctx)
 }
 
 struct perf_callchain_entry *
-perf_callchain(struct perf_event *event, struct pt_regs *regs)
-{
-	bool kernel = !event->attr.exclude_callchain_kernel;
-	bool user   = !event->attr.exclude_callchain_user;
-	/* Disallow cross-task user callchains. */
-	bool crosstask = event->ctx->task && event->ctx->task != current;
-	const u32 max_stack = event->attr.sample_max_stack;
-
-	if (!kernel && !user)
-		return NULL;
-
-	return get_perf_callchain(regs, 0, kernel, user, max_stack, crosstask, true);
-}
-
-struct perf_callchain_entry *
 get_perf_callchain(struct pt_regs *regs, u32 init_nr, bool kernel, bool user,
 		   u32 max_stack, bool crosstask, bool add_mark)
 {
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 55fb648..5fc1ded 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -5980,6 +5980,22 @@ static u64 perf_virt_to_phys(u64 virt)
 	return phys_addr;
 }
 
+static struct perf_callchain_entry *
+perf_callchain(struct perf_event *event, struct pt_regs *regs)
+{
+	bool kernel = !event->attr.exclude_callchain_kernel;
+	bool user   = !event->attr.exclude_callchain_user;
+	/* Disallow cross-task user callchains. */
+	bool crosstask = event->ctx->task && event->ctx->task != current;
+	const u32 max_stack = event->attr.sample_max_stack;
+
+	if (!kernel && !user)
+		return NULL;
+
+	return get_perf_callchain(regs, 0, kernel, user,
+				  max_stack, crosstask, true);
+}
+
 void perf_prepare_sample(struct perf_event_header *header,
 			 struct perf_sample_data *data,
 			 struct perf_event *event,
diff --git a/kernel/events/internal.h b/kernel/events/internal.h
index 09b1537..6dc725a 100644
--- a/kernel/events/internal.h
+++ b/kernel/events/internal.h
@@ -201,10 +201,6 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
 
 DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
 
-/* Callchain handling */
-extern struct perf_callchain_entry *
-perf_callchain(struct perf_event *event, struct pt_regs *regs);
-
 static inline int get_recursion_context(int *recursion)
 {
 	int rctx;

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

* [tip:perf/core] perf: Return empty callchain instead of NULL
  2018-01-07 16:03 ` [PATCH 06/12] perf: Return empty callchain instead of NULL Jiri Olsa
  2018-01-08 12:15   ` Peter Zijlstra
@ 2018-01-11  6:26   ` tip-bot for Jiri Olsa
  1 sibling, 0 replies; 44+ messages in thread
From: tip-bot for Jiri Olsa @ 2018-01-11  6:26 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: peterz, mingo, ak, jolsa, tglx, acme, hpa, namhyung, dsahern,
	linux-kernel, alexander.shishkin

Commit-ID:  99e818cc88889a2fa2f483b91b372c47b94b7c98
Gitweb:     https://git.kernel.org/tip/99e818cc88889a2fa2f483b91b372c47b94b7c98
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Sun, 7 Jan 2018 17:03:50 +0100
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 8 Jan 2018 12:35:01 -0300

perf: Return empty callchain instead of NULL

It simplifies the code a bit, because we dump the callchain
Link: http://lkml.kernel.org/n/tip-uqp7qd6aif47g39glnbu95yl@git.kernel.org
even if it's empty. With 'empty' callchain we can remove
all the NULL-checking code paths.

Original-patch-from: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: http://lkml.kernel.org/r/20180107160356.28203-7-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 kernel/events/core.c | 30 ++++++++++++------------------
 1 file changed, 12 insertions(+), 18 deletions(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 5fc1ded..4e1a1bf 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -5815,19 +5815,11 @@ void perf_output_sample(struct perf_output_handle *handle,
 		perf_output_read(handle, event);
 
 	if (sample_type & PERF_SAMPLE_CALLCHAIN) {
-		if (data->callchain) {
-			int size = 1;
-
-			if (data->callchain)
-				size += data->callchain->nr;
-
-			size *= sizeof(u64);
+		int size = 1;
 
-			__output_copy(handle, data->callchain, size);
-		} else {
-			u64 nr = 0;
-			perf_output_put(handle, nr);
-		}
+		size += data->callchain->nr;
+		size *= sizeof(u64);
+		__output_copy(handle, data->callchain, size);
 	}
 
 	if (sample_type & PERF_SAMPLE_RAW) {
@@ -5980,6 +5972,8 @@ static u64 perf_virt_to_phys(u64 virt)
 	return phys_addr;
 }
 
+static struct perf_callchain_entry __empty_callchain = { .nr = 0, };
+
 static struct perf_callchain_entry *
 perf_callchain(struct perf_event *event, struct pt_regs *regs)
 {
@@ -5988,12 +5982,14 @@ perf_callchain(struct perf_event *event, struct pt_regs *regs)
 	/* Disallow cross-task user callchains. */
 	bool crosstask = event->ctx->task && event->ctx->task != current;
 	const u32 max_stack = event->attr.sample_max_stack;
+	struct perf_callchain_entry *callchain;
 
 	if (!kernel && !user)
-		return NULL;
+		return &__empty_callchain;
 
-	return get_perf_callchain(regs, 0, kernel, user,
-				  max_stack, crosstask, true);
+	callchain = get_perf_callchain(regs, 0, kernel, user,
+				       max_stack, crosstask, true);
+	return callchain ?: &__empty_callchain;
 }
 
 void perf_prepare_sample(struct perf_event_header *header,
@@ -6018,9 +6014,7 @@ void perf_prepare_sample(struct perf_event_header *header,
 		int size = 1;
 
 		data->callchain = perf_callchain(event, regs);
-
-		if (data->callchain)
-			size += data->callchain->nr;
+		size += data->callchain->nr;
 
 		header->size += size * sizeof(u64);
 	}

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

* [tip:perf/core] perf: Update PERF_RECORD_MISC_* comment for perf_event_header::misc bit 13
  2018-01-07 16:03 ` [PATCH 07/12] perf: Update PERF_RECORD_MISC_* comment for perf_event_header::misc bit 13 Jiri Olsa
@ 2018-01-11  6:26   ` tip-bot for Jiri Olsa
  0 siblings, 0 replies; 44+ messages in thread
From: tip-bot for Jiri Olsa @ 2018-01-11  6:26 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: mingo, linux-kernel, ak, tglx, acme, dsahern, alexander.shishkin,
	jolsa, peterz, hpa, namhyung

Commit-ID:  972c14884728bf5f69ec69cfb1beeec1a9cd29ee
Gitweb:     https://git.kernel.org/tip/972c14884728bf5f69ec69cfb1beeec1a9cd29ee
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Sun, 7 Jan 2018 17:03:51 +0100
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 8 Jan 2018 12:37:54 -0300

perf: Update PERF_RECORD_MISC_* comment for perf_event_header::misc bit 13

The perf_event_header::misc bit 13 is shared on different events and
next patch is adding yet another bit 13 user.  Updating the comment to
make it more structured and clear which events use bit 13.

Suggested-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: http://lkml.kernel.org/r/20180107160356.28203-8-jolsa@kernel.org
[ Update the tools/include/uapi/linux copy ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 include/uapi/linux/perf_event.h       | 9 ++++++---
 tools/include/uapi/linux/perf_event.h | 9 ++++++---
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h
index 8bb66e8..c77c9a2 100644
--- a/include/uapi/linux/perf_event.h
+++ b/include/uapi/linux/perf_event.h
@@ -612,9 +612,12 @@ struct perf_event_mmap_page {
  */
 #define PERF_RECORD_MISC_PROC_MAP_PARSE_TIMEOUT	(1 << 12)
 /*
- * PERF_RECORD_MISC_MMAP_DATA and PERF_RECORD_MISC_COMM_EXEC are used on
- * different events so can reuse the same bit position.
- * Ditto PERF_RECORD_MISC_SWITCH_OUT.
+ * Following PERF_RECORD_MISC_* are used on different
+ * events, so can reuse the same bit position:
+ *
+ *   PERF_RECORD_MISC_MMAP_DATA  - PERF_RECORD_MMAP* events
+ *   PERF_RECORD_MISC_COMM_EXEC  - PERF_RECORD_COMM event
+ *   PERF_RECORD_MISC_SWITCH_OUT - PERF_RECORD_SWITCH* events
  */
 #define PERF_RECORD_MISC_MMAP_DATA		(1 << 13)
 #define PERF_RECORD_MISC_COMM_EXEC		(1 << 13)
diff --git a/tools/include/uapi/linux/perf_event.h b/tools/include/uapi/linux/perf_event.h
index 8bb66e8..c77c9a2 100644
--- a/tools/include/uapi/linux/perf_event.h
+++ b/tools/include/uapi/linux/perf_event.h
@@ -612,9 +612,12 @@ struct perf_event_mmap_page {
  */
 #define PERF_RECORD_MISC_PROC_MAP_PARSE_TIMEOUT	(1 << 12)
 /*
- * PERF_RECORD_MISC_MMAP_DATA and PERF_RECORD_MISC_COMM_EXEC are used on
- * different events so can reuse the same bit position.
- * Ditto PERF_RECORD_MISC_SWITCH_OUT.
+ * Following PERF_RECORD_MISC_* are used on different
+ * events, so can reuse the same bit position:
+ *
+ *   PERF_RECORD_MISC_MMAP_DATA  - PERF_RECORD_MMAP* events
+ *   PERF_RECORD_MISC_COMM_EXEC  - PERF_RECORD_COMM event
+ *   PERF_RECORD_MISC_SWITCH_OUT - PERF_RECORD_SWITCH* events
  */
 #define PERF_RECORD_MISC_MMAP_DATA		(1 << 13)
 #define PERF_RECORD_MISC_COMM_EXEC		(1 << 13)

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

* [tip:perf/core] perf script: Add support to display sample misc field
  2018-01-07 16:03 ` [PATCH 08/12] perf script: Add support to display sample misc field Jiri Olsa
@ 2018-01-11  6:27   ` tip-bot for Jiri Olsa
  0 siblings, 0 replies; 44+ messages in thread
From: tip-bot for Jiri Olsa @ 2018-01-11  6:27 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: namhyung, peterz, hpa, alexander.shishkin, ak, tglx, acme,
	linux-kernel, dsahern, jolsa, mingo

Commit-ID:  28a0b39877f5ed64ae9fadf95dddb90999309dee
Gitweb:     https://git.kernel.org/tip/28a0b39877f5ed64ae9fadf95dddb90999309dee
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Sun, 7 Jan 2018 17:03:52 +0100
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 8 Jan 2018 12:39:50 -0300

perf script: Add support to display sample misc field

Adding support to display sample misc field in form
of letter for each bit:

  # perf script -F +misc ...
   sched-messaging  1414 K     28690.636582:       4590 cycles ...
   sched-messaging  1407 U     28690.636600:     325620 cycles ...
   sched-messaging  1414 K     28690.636608:      19473 cycles ...
  misc field  __________/

The misc bits are assigned to following letters:

  PERF_RECORD_MISC_KERNEL        K
  PERF_RECORD_MISC_USER          U
  PERF_RECORD_MISC_HYPERVISOR    H
  PERF_RECORD_MISC_GUEST_KERNEL  G
  PERF_RECORD_MISC_GUEST_USER    g
  PERF_RECORD_MISC_MMAP_DATA*    M
  PERF_RECORD_MISC_COMM_EXEC     E
  PERF_RECORD_MISC_SWITCH_OUT    S

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20180107160356.28203-9-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Documentation/perf-script.txt | 20 ++++++++-
 tools/perf/builtin-script.c              | 74 +++++++++++++++++++++++++++-----
 tools/perf/util/event.h                  |  1 +
 tools/perf/util/evsel.c                  |  1 +
 4 files changed, 84 insertions(+), 12 deletions(-)

diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt
index 7b622a8..93ae8d6 100644
--- a/tools/perf/Documentation/perf-script.txt
+++ b/tools/perf/Documentation/perf-script.txt
@@ -117,7 +117,7 @@ OPTIONS
         Comma separated list of fields to print. Options are:
         comm, tid, pid, time, cpu, event, trace, ip, sym, dso, addr, symoff,
         srcline, period, iregs, uregs, brstack, brstacksym, flags, bpf-output, brstackinsn,
-	brstackoff, callindent, insn, insnlen, synth, phys_addr, metric.
+        brstackoff, callindent, insn, insnlen, synth, phys_addr, metric, misc.
         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
@@ -225,6 +225,24 @@ OPTIONS
 	that the metric computed is averaged over the whole sampling
 	period, not just for the sample point.
 
+	For sample events it's possible to display misc field with -F +misc option,
+	following letters are displayed for each bit:
+
+	  PERF_RECORD_MISC_KERNEL        K
+	  PERF_RECORD_MISC_USER          U
+	  PERF_RECORD_MISC_HYPERVISOR    H
+	  PERF_RECORD_MISC_GUEST_KERNEL  G
+	  PERF_RECORD_MISC_GUEST_USER    g
+	  PERF_RECORD_MISC_MMAP_DATA*    M
+	  PERF_RECORD_MISC_COMM_EXEC     E
+	  PERF_RECORD_MISC_SWITCH_OUT    S
+
+	  $ perf script -F +misc ...
+	   sched-messaging  1414 K     28690.636582:       4590 cycles ...
+	   sched-messaging  1407 U     28690.636600:     325620 cycles ...
+	   sched-messaging  1414 K     28690.636608:      19473 cycles ...
+	  misc field ___________/
+
 -k::
 --vmlinux=<file>::
         vmlinux pathname
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 330dcd9..bb60349 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -93,6 +93,7 @@ enum perf_output_field {
 	PERF_OUTPUT_PHYS_ADDR       = 1U << 26,
 	PERF_OUTPUT_UREGS	    = 1U << 27,
 	PERF_OUTPUT_METRIC	    = 1U << 28,
+	PERF_OUTPUT_MISC            = 1U << 29,
 };
 
 struct output_option {
@@ -128,6 +129,7 @@ struct output_option {
 	{.str = "synth", .field = PERF_OUTPUT_SYNTH},
 	{.str = "phys_addr", .field = PERF_OUTPUT_PHYS_ADDR},
 	{.str = "metric", .field = PERF_OUTPUT_METRIC},
+	{.str = "misc", .field = PERF_OUTPUT_MISC},
 };
 
 enum {
@@ -594,7 +596,8 @@ static int perf_sample__fprintf_uregs(struct perf_sample *sample,
 
 static int perf_sample__fprintf_start(struct perf_sample *sample,
 				      struct thread *thread,
-				      struct perf_evsel *evsel, FILE *fp)
+				      struct perf_evsel *evsel,
+				      u32 type, FILE *fp)
 {
 	struct perf_event_attr *attr = &evsel->attr;
 	unsigned long secs;
@@ -624,6 +627,47 @@ static int perf_sample__fprintf_start(struct perf_sample *sample,
 			printed += fprintf(fp, "[%03d] ", sample->cpu);
 	}
 
+	if (PRINT_FIELD(MISC)) {
+		int ret = 0;
+
+		#define has(m) \
+			(sample->misc & PERF_RECORD_MISC_##m) == PERF_RECORD_MISC_##m
+
+		if (has(KERNEL))
+			ret += fprintf(fp, "K");
+		if (has(USER))
+			ret += fprintf(fp, "U");
+		if (has(HYPERVISOR))
+			ret += fprintf(fp, "H");
+		if (has(GUEST_KERNEL))
+			ret += fprintf(fp, "G");
+		if (has(GUEST_USER))
+			ret += fprintf(fp, "g");
+
+		switch (type) {
+		case PERF_RECORD_MMAP:
+		case PERF_RECORD_MMAP2:
+			if (has(MMAP_DATA))
+				ret += fprintf(fp, "M");
+			break;
+		case PERF_RECORD_COMM:
+			if (has(COMM_EXEC))
+				ret += fprintf(fp, "E");
+			break;
+		case PERF_RECORD_SWITCH:
+		case PERF_RECORD_SWITCH_CPU_WIDE:
+			if (has(SWITCH_OUT))
+				ret += fprintf(fp, "S");
+		default:
+			break;
+		}
+
+		#undef has
+
+		ret += fprintf(fp, "%*s", 6 - ret, " ");
+		printed += ret;
+	}
+
 	if (PRINT_FIELD(TIME)) {
 		nsecs = sample->time;
 		secs = nsecs / NSEC_PER_SEC;
@@ -1502,7 +1546,7 @@ static void script_print_metric(void *ctx, const char *color,
 	if (!fmt)
 		return;
 	perf_sample__fprintf_start(mctx->sample, mctx->thread, mctx->evsel,
-				   mctx->fp);
+				   PERF_RECORD_SAMPLE, mctx->fp);
 	fputs("\tmetric: ", mctx->fp);
 	if (color)
 		color_fprintf(mctx->fp, color, fmt, val);
@@ -1516,7 +1560,7 @@ static void script_new_line(void *ctx)
 	struct metric_ctx *mctx = ctx;
 
 	perf_sample__fprintf_start(mctx->sample, mctx->thread, mctx->evsel,
-				   mctx->fp);
+				   PERF_RECORD_SAMPLE, mctx->fp);
 	fputs("\tmetric: ", mctx->fp);
 }
 
@@ -1584,7 +1628,8 @@ static void process_event(struct perf_script *script,
 
 	++es->samples;
 
-	perf_sample__fprintf_start(sample, thread, evsel, fp);
+	perf_sample__fprintf_start(sample, thread, evsel,
+				   PERF_RECORD_SAMPLE, fp);
 
 	if (PRINT_FIELD(PERIOD))
 		fprintf(fp, "%10" PRIu64 " ", sample->period);
@@ -1833,7 +1878,8 @@ static int process_comm_event(struct perf_tool *tool,
 		sample->tid = event->comm.tid;
 		sample->pid = event->comm.pid;
 	}
-	perf_sample__fprintf_start(sample, thread, evsel, stdout);
+	perf_sample__fprintf_start(sample, thread, evsel,
+				   PERF_RECORD_COMM, stdout);
 	perf_event__fprintf(event, stdout);
 	ret = 0;
 out:
@@ -1868,7 +1914,8 @@ static int process_namespaces_event(struct perf_tool *tool,
 		sample->tid = event->namespaces.tid;
 		sample->pid = event->namespaces.pid;
 	}
-	perf_sample__fprintf_start(sample, thread, evsel, stdout);
+	perf_sample__fprintf_start(sample, thread, evsel,
+				   PERF_RECORD_NAMESPACES, stdout);
 	perf_event__fprintf(event, stdout);
 	ret = 0;
 out:
@@ -1901,7 +1948,8 @@ static int process_fork_event(struct perf_tool *tool,
 		sample->tid = event->fork.tid;
 		sample->pid = event->fork.pid;
 	}
-	perf_sample__fprintf_start(sample, thread, evsel, stdout);
+	perf_sample__fprintf_start(sample, thread, evsel,
+				   PERF_RECORD_FORK, stdout);
 	perf_event__fprintf(event, stdout);
 	thread__put(thread);
 
@@ -1930,7 +1978,8 @@ static int process_exit_event(struct perf_tool *tool,
 		sample->tid = event->fork.tid;
 		sample->pid = event->fork.pid;
 	}
-	perf_sample__fprintf_start(sample, thread, evsel, stdout);
+	perf_sample__fprintf_start(sample, thread, evsel,
+				   PERF_RECORD_EXIT, stdout);
 	perf_event__fprintf(event, stdout);
 
 	if (perf_event__process_exit(tool, event, sample, machine) < 0)
@@ -1965,7 +2014,8 @@ static int process_mmap_event(struct perf_tool *tool,
 		sample->tid = event->mmap.tid;
 		sample->pid = event->mmap.pid;
 	}
-	perf_sample__fprintf_start(sample, thread, evsel, stdout);
+	perf_sample__fprintf_start(sample, thread, evsel,
+				   PERF_RECORD_MMAP, stdout);
 	perf_event__fprintf(event, stdout);
 	thread__put(thread);
 	return 0;
@@ -1996,7 +2046,8 @@ static int process_mmap2_event(struct perf_tool *tool,
 		sample->tid = event->mmap2.tid;
 		sample->pid = event->mmap2.pid;
 	}
-	perf_sample__fprintf_start(sample, thread, evsel, stdout);
+	perf_sample__fprintf_start(sample, thread, evsel,
+				   PERF_RECORD_MMAP2, stdout);
 	perf_event__fprintf(event, stdout);
 	thread__put(thread);
 	return 0;
@@ -2022,7 +2073,8 @@ static int process_switch_event(struct perf_tool *tool,
 		return -1;
 	}
 
-	perf_sample__fprintf_start(sample, thread, evsel, stdout);
+	perf_sample__fprintf_start(sample, thread, evsel,
+				   PERF_RECORD_SWITCH, stdout);
 	perf_event__fprintf(event, stdout);
 	thread__put(thread);
 	return 0;
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
index 1ae95ef..e5fbd6d 100644
--- a/tools/perf/util/event.h
+++ b/tools/perf/util/event.h
@@ -205,6 +205,7 @@ struct perf_sample {
 	u32 flags;
 	u16 insn_len;
 	u8  cpumode;
+	u16 misc;
 	char insn[MAX_INSN];
 	void *raw_data;
 	struct ip_callchain *callchain;
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index c435b24..d934f04e3 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -2042,6 +2042,7 @@ int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event,
 	data->stream_id = data->id = data->time = -1ULL;
 	data->period = evsel->attr.sample_period;
 	data->cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
+	data->misc    = event->header.misc;
 	data->id = -1ULL;
 	data->data_src = PERF_MEM_DATA_SRC_NONE;
 

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

* [tip:perf/core] perf script: Add support to display lost events
  2018-01-07 16:03 ` [PATCH 09/12] perf script: Add support to display lost events Jiri Olsa
  2018-01-10 15:40   ` Arnaldo Carvalho de Melo
@ 2018-01-11  6:27   ` tip-bot for Jiri Olsa
  1 sibling, 0 replies; 44+ messages in thread
From: tip-bot for Jiri Olsa @ 2018-01-11  6:27 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: mingo, dsahern, hpa, alexander.shishkin, acme, jolsa, peterz, ak,
	tglx, namhyung, linux-kernel

Commit-ID:  3d7c27b6dbca4c90e7d921b45c2240e7c3cb92a2
Gitweb:     https://git.kernel.org/tip/3d7c27b6dbca4c90e7d921b45c2240e7c3cb92a2
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Sun, 7 Jan 2018 17:03:53 +0100
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 10 Jan 2018 12:00:39 -0300

perf script: Add support to display lost events

Adding option to display lost events:

  $ perf script --show-lost-events ...
   mplayer 13810 [002] 468011.402396:        100 cycles:ppp:  ff..
   mplayer 13810 [002] 468011.402396: PERF_RECORD_LOST lost 3880
   mplayer 13810 [002] 468011.402397:        100 cycles:ppp:  ff..

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20180107160356.28203-10-jolsa@kernel.org
[ Use PRIu64 when printing u64 values, fixing the build in some arches ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Documentation/perf-script.txt |  3 +++
 tools/perf/builtin-script.c              | 28 ++++++++++++++++++++++++++++
 tools/perf/util/event.c                  |  8 ++++++++
 3 files changed, 39 insertions(+)

diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt
index 93ae8d6..806ec63 100644
--- a/tools/perf/Documentation/perf-script.txt
+++ b/tools/perf/Documentation/perf-script.txt
@@ -300,6 +300,9 @@ OPTIONS
 	Display context switch events i.e. events of type PERF_RECORD_SWITCH or
 	PERF_RECORD_SWITCH_CPU_WIDE.
 
+--show-lost-events
+	Display lost events i.e. events of type PERF_RECORD_LOST.
+
 --demangle::
 	Demangle symbol names to human readable form. It's enabled by default,
 	disable with --no-demangle.
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index bb60349..c1cce47 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -1489,6 +1489,7 @@ struct perf_script {
 	bool			show_mmap_events;
 	bool			show_switch_events;
 	bool			show_namespace_events;
+	bool			show_lost_events;
 	bool			allocated;
 	bool			per_event_dump;
 	struct cpu_map		*cpus;
@@ -2080,6 +2081,29 @@ static int process_switch_event(struct perf_tool *tool,
 	return 0;
 }
 
+static int
+process_lost_event(struct perf_tool *tool,
+		   union perf_event *event,
+		   struct perf_sample *sample,
+		   struct machine *machine)
+{
+	struct perf_script *script = container_of(tool, struct perf_script, tool);
+	struct perf_session *session = script->session;
+	struct perf_evsel *evsel = perf_evlist__id2evsel(session->evlist, sample->id);
+	struct thread *thread;
+
+	thread = machine__findnew_thread(machine, sample->pid,
+					 sample->tid);
+	if (thread == NULL)
+		return -1;
+
+	perf_sample__fprintf_start(sample, thread, evsel,
+				   PERF_RECORD_LOST, stdout);
+	perf_event__fprintf(event, stdout);
+	thread__put(thread);
+	return 0;
+}
+
 static void sig_handler(int sig __maybe_unused)
 {
 	session_done = 1;
@@ -2174,6 +2198,8 @@ static int __cmd_script(struct perf_script *script)
 		script->tool.context_switch = process_switch_event;
 	if (script->show_namespace_events)
 		script->tool.namespaces = process_namespaces_event;
+	if (script->show_lost_events)
+		script->tool.lost = process_lost_event;
 
 	if (perf_script__setup_per_event_dump(script)) {
 		pr_err("Couldn't create the per event dump files\n");
@@ -3110,6 +3136,8 @@ int cmd_script(int argc, const char **argv)
 		    "Show context switch events (if recorded)"),
 	OPT_BOOLEAN('\0', "show-namespace-events", &script.show_namespace_events,
 		    "Show namespace events (if recorded)"),
+	OPT_BOOLEAN('\0', "show-lost-events", &script.show_lost_events,
+		    "Show lost events (if recorded)"),
 	OPT_BOOLEAN('\0', "per-event-dump", &script.per_event_dump,
 		    "Dump trace output to files named by the monitored events"),
 	OPT_BOOLEAN('f', "force", &symbol_conf.force, "don't complain, do it"),
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index 97a8ef9..44e603c 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -1435,6 +1435,11 @@ size_t perf_event__fprintf_switch(union perf_event *event, FILE *fp)
 		       event->context_switch.next_prev_tid);
 }
 
+static size_t perf_event__fprintf_lost(union perf_event *event, FILE *fp)
+{
+	return fprintf(fp, " lost %" PRIu64 "\n", event->lost.lost);
+}
+
 size_t perf_event__fprintf(union perf_event *event, FILE *fp)
 {
 	size_t ret = fprintf(fp, "PERF_RECORD_%s",
@@ -1467,6 +1472,9 @@ size_t perf_event__fprintf(union perf_event *event, FILE *fp)
 	case PERF_RECORD_SWITCH_CPU_WIDE:
 		ret += perf_event__fprintf_switch(event, fp);
 		break;
+	case PERF_RECORD_LOST:
+		ret += perf_event__fprintf_lost(event, fp);
+		break;
 	default:
 		ret += fprintf(fp, "\n");
 	}

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

* [tip:perf/core] perf tools: Make the tool's warning messages optional
  2018-01-07 16:03 ` [PATCH 10/12] perf tools: Make the tool's warning messages optional Jiri Olsa
@ 2018-01-11  6:27   ` tip-bot for Jiri Olsa
  0 siblings, 0 replies; 44+ messages in thread
From: tip-bot for Jiri Olsa @ 2018-01-11  6:27 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: ak, jolsa, dsahern, acme, hpa, peterz, alexander.shishkin,
	namhyung, mingo, tglx, linux-kernel

Commit-ID:  075ca1ebb25e798e4072a1e3a482b829bb51afb2
Gitweb:     https://git.kernel.org/tip/075ca1ebb25e798e4072a1e3a482b829bb51afb2
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Sun, 7 Jan 2018 17:03:54 +0100
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 10 Jan 2018 12:00:55 -0300

perf tools: Make the tool's warning messages optional

I want to display the pure events status coming in the next patch and
the tool's warnings are superfluous in the output. Making it optional,
enabled by default.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20180107160356.28203-11-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/session.c | 6 ++++--
 tools/perf/util/tool.h    | 1 +
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 54e30f1..8d0fa2f 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -1773,7 +1773,8 @@ done:
 	err = perf_session__flush_thread_stacks(session);
 out_err:
 	free(buf);
-	perf_session__warn_about_errors(session);
+	if (!tool->no_warn)
+		perf_session__warn_about_errors(session);
 	ordered_events__free(&session->ordered_events);
 	auxtrace__free_events(session);
 	return err;
@@ -1929,7 +1930,8 @@ out:
 	err = perf_session__flush_thread_stacks(session);
 out_err:
 	ui_progress__finish();
-	perf_session__warn_about_errors(session);
+	if (!tool->no_warn)
+		perf_session__warn_about_errors(session);
 	/*
 	 * We may switching perf.data output, make ordered_events
 	 * reusable.
diff --git a/tools/perf/util/tool.h b/tools/perf/util/tool.h
index 2532b55..183c914 100644
--- a/tools/perf/util/tool.h
+++ b/tools/perf/util/tool.h
@@ -76,6 +76,7 @@ struct perf_tool {
 	bool		ordered_events;
 	bool		ordering_requires_timestamps;
 	bool		namespace_events;
+	bool		no_warn;
 	enum show_feature_header show_feat_hdr;
 };
 

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

* [tip:perf/core] perf report: Add --stats option to display quick data statistics
  2018-01-07 16:03 ` [PATCH 11/12] perf report: Add --stat option to display quick data statistics Jiri Olsa
@ 2018-01-11  6:28   ` tip-bot for Jiri Olsa
  0 siblings, 0 replies; 44+ messages in thread
From: tip-bot for Jiri Olsa @ 2018-01-11  6:28 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: namhyung, hpa, dsahern, ak, tglx, jolsa, acme, linux-kernel,
	alexander.shishkin, mingo, peterz

Commit-ID:  a4a4d0a7a2b20f7880262de4f51685baaf693476
Gitweb:     https://git.kernel.org/tip/a4a4d0a7a2b20f7880262de4f51685baaf693476
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Sun, 7 Jan 2018 17:03:55 +0100
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 10 Jan 2018 12:00:56 -0300

perf report: Add --stats option to display quick data statistics

Add --stats option to display quick data statistics of event numbers,
without any further processing, like the one at the end of the perf
report -D command.

  $ perf report --stat

  Aggregated stats:
             TOTAL events:       4566
              MMAP events:        113
              LOST events:         19
              COMM events:          3
              FORK events:        400
            SAMPLE events:       3315
             MMAP2 events:         32
    FINISHED_ROUND events:        681
        THREAD_MAP events:          1
           CPU_MAP events:          1
         TIME_CONV events:          1

I found this useful when hunting lost events for another change.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20180107160356.28203-12-jolsa@kernel.org
[ Rename it to --stats, plural ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Documentation/perf-report.txt |  4 ++++
 tools/perf/builtin-report.c              | 26 +++++++++++++++++++++++++-
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/tools/perf/Documentation/perf-report.txt b/tools/perf/Documentation/perf-report.txt
index 1e02c4e..a7d11ef 100644
--- a/tools/perf/Documentation/perf-report.txt
+++ b/tools/perf/Documentation/perf-report.txt
@@ -457,6 +457,10 @@ include::itrace.txt[]
 	will be printed. Each entry is function name or file/line. Enabled by
 	default, disable with --no-inline.
 
+--stats::
+	Display overall events statistics without any further processing.
+	(like the one at the end of the perf report -D command)
+
 include::callchain-overhead-calculation.txt[]
 
 SEE ALSO
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 770bf8a..8e67a8c 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -62,6 +62,7 @@ struct report {
 	bool			show_threads;
 	bool			inverted_callchain;
 	bool			mem_mode;
+	bool			stats_mode;
 	bool			header;
 	bool			header_only;
 	bool			nonany_branch_mode;
@@ -588,6 +589,20 @@ static void report__output_resort(struct report *rep)
 	ui_progress__finish();
 }
 
+static void stats_setup(struct report *rep)
+{
+	memset(&rep->tool, 0, sizeof(rep->tool));
+	rep->tool.no_warn = true;
+}
+
+static int stats_print(struct report *rep)
+{
+	struct perf_session *session = rep->session;
+
+	perf_session__fprintf_nr_events(session, stdout);
+	return 0;
+}
+
 static int __cmd_report(struct report *rep)
 {
 	int ret;
@@ -619,12 +634,18 @@ static int __cmd_report(struct report *rep)
 		return ret;
 	}
 
+	if (rep->stats_mode)
+		stats_setup(rep);
+
 	ret = perf_session__process_events(session);
 	if (ret) {
 		ui__error("failed to process sample\n");
 		return ret;
 	}
 
+	if (rep->stats_mode)
+		return stats_print(rep);
+
 	report__warn_kptr_restrict(rep);
 
 	evlist__for_each_entry(session->evlist, pos)
@@ -781,6 +802,7 @@ int cmd_report(int argc, const char **argv)
 	OPT_BOOLEAN('q', "quiet", &quiet, "Do not show any message"),
 	OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
 		    "dump raw trace in ASCII"),
+	OPT_BOOLEAN(0, "stats", &report.stats_mode, "Display event stats"),
 	OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,
 		   "file", "vmlinux pathname"),
 	OPT_STRING(0, "kallsyms", &symbol_conf.kallsyms_name,
@@ -1042,6 +1064,8 @@ repeat:
 		report.tool.show_feat_hdr = SHOW_FEAT_HEADER;
 	if (report.show_full_info)
 		report.tool.show_feat_hdr = SHOW_FEAT_HEADER_FULL_INFO;
+	if (report.stats_mode)
+		use_browser = 0;
 
 	if (strcmp(input_name, "-") != 0)
 		setup_browser(true);
@@ -1064,7 +1088,7 @@ repeat:
 			ret = 0;
 			goto error;
 		}
-	} else if (use_browser == 0 && !quiet) {
+	} else if (use_browser == 0 && !quiet && !report.stats_mode) {
 		fputs("# To display the perf.data header info, please use --header/--header-only options.\n#\n",
 		      stdout);
 	}

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

* [tip:perf/core] perf report: Add --tasks option to display monitored tasks
  2018-01-07 16:03 ` [PATCH 12/12] perf report: Add --task option to display monitored tasks Jiri Olsa
  2018-01-08 15:55   ` Arnaldo Carvalho de Melo
  2018-01-09  1:56   ` Namhyung Kim
@ 2018-01-11  6:29   ` tip-bot for Jiri Olsa
  2 siblings, 0 replies; 44+ messages in thread
From: tip-bot for Jiri Olsa @ 2018-01-11  6:29 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: ak, peterz, mingo, alexander.shishkin, dsahern, namhyung, hpa,
	jolsa, linux-kernel, tglx, acme

Commit-ID:  930f8b3479444d264aa33e008c4b00b86e8c62cc
Gitweb:     https://git.kernel.org/tip/930f8b3479444d264aa33e008c4b00b86e8c62cc
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Sun, 7 Jan 2018 17:03:56 +0100
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 10 Jan 2018 12:00:56 -0300

perf report: Add --tasks option to display monitored tasks

Add --tasks option to display monitored tasks stored in perf.data.
Displaying pid/tid/ppid plus the command string aligned to distinguish
parent and child tasks.

  $ perf record -a
  ...
  $ perf report --tasks
  #     pid     tid    ppid  comm
          0       0      -1 |swapper
          2       2       0 | kthreadd
      14080   14080       2 |  kworker/u17:1
          4       4       2 |  kworker/0:0H
          6       6       2 |  mm_percpu_wq
  ...
          1       1       0 | systemd
      23242   23242       1 |  firefox
      23242   23298   23242 |   Cache2 I/O
      23242   23304   23242 |   GMPThread
  ...
       1195    1195       1 |  login
       1611    1611    1195 |   bash
       1639    1639    1611 |    startx
       1663    1663    1639 |     xinit
       1673    1673    1663 |      xmonad-x86_64-l
      23939   23939    1673 |       xterm
      23941   23941   23939 |        bash
      23963   23963   23941 |         mutt
      24954   24954   23963 |          offlineimap

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20180107160356.28203-13-jolsa@kernel.org
[ Make it --tasks, plural, --task works as well, as its unambiguous ]
[ Use machine__find_thread(), not findnew(), as pointed out by Namhyung ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Documentation/perf-report.txt |   4 +
 tools/perf/builtin-report.c              | 136 ++++++++++++++++++++++++++++++-
 2 files changed, 138 insertions(+), 2 deletions(-)

diff --git a/tools/perf/Documentation/perf-report.txt b/tools/perf/Documentation/perf-report.txt
index a7d11ef..856c3c7 100644
--- a/tools/perf/Documentation/perf-report.txt
+++ b/tools/perf/Documentation/perf-report.txt
@@ -461,6 +461,10 @@ include::itrace.txt[]
 	Display overall events statistics without any further processing.
 	(like the one at the end of the perf report -D command)
 
+--tasks::
+	Display monitored tasks stored in perf data. Displaying pid/tid/ppid
+	plus the command string aligned to distinguish parent and child tasks.
+
 include::callchain-overhead-calculation.txt[]
 
 SEE ALSO
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 8e67a8c..2c7bd85 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -15,6 +15,7 @@
 #include "util/color.h"
 #include <linux/list.h>
 #include <linux/rbtree.h>
+#include <linux/err.h>
 #include "util/symbol.h"
 #include "util/callchain.h"
 #include "util/values.h"
@@ -63,6 +64,7 @@ struct report {
 	bool			inverted_callchain;
 	bool			mem_mode;
 	bool			stats_mode;
+	bool			tasks_mode;
 	bool			header;
 	bool			header_only;
 	bool			nonany_branch_mode;
@@ -603,6 +605,124 @@ static int stats_print(struct report *rep)
 	return 0;
 }
 
+static void tasks_setup(struct report *rep)
+{
+	memset(&rep->tool, 0, sizeof(rep->tool));
+	rep->tool.comm = perf_event__process_comm;
+	rep->tool.exit = perf_event__process_exit;
+	rep->tool.fork = perf_event__process_fork;
+	rep->tool.no_warn = true;
+}
+
+struct task {
+	struct thread		*thread;
+	struct list_head	 list;
+	struct list_head	 children;
+};
+
+static struct task *tasks_list(struct task *task, struct machine *machine)
+{
+	struct thread *parent_thread, *thread = task->thread;
+	struct task   *parent_task;
+
+	/* Already listed. */
+	if (!list_empty(&task->list))
+		return NULL;
+
+	/* Last one in the chain. */
+	if (thread->ppid == -1)
+		return task;
+
+	parent_thread = machine__find_thread(machine, -1, thread->ppid);
+	if (!parent_thread)
+		return ERR_PTR(-ENOENT);
+
+	parent_task = thread__priv(parent_thread);
+	list_add_tail(&task->list, &parent_task->children);
+	return tasks_list(parent_task, machine);
+}
+
+static void task__print_level(struct task *task, FILE *fp, int level)
+{
+	struct thread *thread = task->thread;
+	struct task *child;
+
+	fprintf(fp, "  %8d %8d %8d |%*s%s\n",
+		thread->pid_, thread->tid, thread->ppid,
+		level, "", thread__comm_str(thread));
+
+	if (!list_empty(&task->children)) {
+		list_for_each_entry(child, &task->children, list)
+			task__print_level(child, fp, level + 1);
+	}
+}
+
+static int tasks_print(struct report *rep, FILE *fp)
+{
+	struct perf_session *session = rep->session;
+	struct machine      *machine = &session->machines.host;
+	struct task *tasks, *task;
+	unsigned int nr = 0, itask = 0, i;
+	struct rb_node *nd;
+	LIST_HEAD(list);
+
+	/*
+	 * No locking needed while accessing machine->threads,
+	 * because --tasks is single threaded command.
+	 */
+
+	/* Count all the threads. */
+	for (i = 0; i < THREADS__TABLE_SIZE; i++)
+		nr += machine->threads[i].nr;
+
+	tasks = malloc(sizeof(*tasks) * nr);
+	if (!tasks)
+		return -ENOMEM;
+
+	for (i = 0; i < THREADS__TABLE_SIZE; i++) {
+		struct threads *threads = &machine->threads[i];
+
+		for (nd = rb_first(&threads->entries); nd; nd = rb_next(nd)) {
+			task = tasks + itask++;
+
+			task->thread = rb_entry(nd, struct thread, rb_node);
+			INIT_LIST_HEAD(&task->children);
+			INIT_LIST_HEAD(&task->list);
+			thread__set_priv(task->thread, task);
+		}
+	}
+
+	/*
+	 * Iterate every task down to the unprocessed parent
+	 * and link all in task children list. Task with no
+	 * parent is added into 'list'.
+	 */
+	for (itask = 0; itask < nr; itask++) {
+		task = tasks + itask;
+
+		if (!list_empty(&task->list))
+			continue;
+
+		task = tasks_list(task, machine);
+		if (IS_ERR(task)) {
+			pr_err("Error: failed to process tasks\n");
+			free(tasks);
+			return PTR_ERR(task);
+		}
+
+		if (task)
+			list_add_tail(&task->list, &list);
+	}
+
+	fprintf(fp, "# %8s %8s %8s  %s\n", "pid", "tid", "ppid", "comm");
+
+	list_for_each_entry(task, &list, list)
+		task__print_level(task, fp, 0);
+
+	free(tasks);
+	return 0;
+}
+
 static int __cmd_report(struct report *rep)
 {
 	int ret;
@@ -637,6 +757,9 @@ static int __cmd_report(struct report *rep)
 	if (rep->stats_mode)
 		stats_setup(rep);
 
+	if (rep->tasks_mode)
+		tasks_setup(rep);
+
 	ret = perf_session__process_events(session);
 	if (ret) {
 		ui__error("failed to process sample\n");
@@ -646,6 +769,9 @@ static int __cmd_report(struct report *rep)
 	if (rep->stats_mode)
 		return stats_print(rep);
 
+	if (rep->tasks_mode)
+		return tasks_print(rep, stdout);
+
 	report__warn_kptr_restrict(rep);
 
 	evlist__for_each_entry(session->evlist, pos)
@@ -803,6 +929,7 @@ int cmd_report(int argc, const char **argv)
 	OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
 		    "dump raw trace in ASCII"),
 	OPT_BOOLEAN(0, "stats", &report.stats_mode, "Display event stats"),
+	OPT_BOOLEAN(0, "tasks", &report.tasks_mode, "Display recorded tasks"),
 	OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,
 		   "file", "vmlinux pathname"),
 	OPT_STRING(0, "kallsyms", &symbol_conf.kallsyms_name,
@@ -1064,8 +1191,12 @@ repeat:
 		report.tool.show_feat_hdr = SHOW_FEAT_HEADER;
 	if (report.show_full_info)
 		report.tool.show_feat_hdr = SHOW_FEAT_HEADER_FULL_INFO;
-	if (report.stats_mode)
+	if (report.stats_mode || report.tasks_mode)
 		use_browser = 0;
+	if (report.stats_mode && report.tasks_mode) {
+		pr_err("Error: --tasks and --stats options cannot be used together\n");
+		goto error;
+	}
 
 	if (strcmp(input_name, "-") != 0)
 		setup_browser(true);
@@ -1088,7 +1219,8 @@ repeat:
 			ret = 0;
 			goto error;
 		}
-	} else if (use_browser == 0 && !quiet && !report.stats_mode) {
+	} else if (use_browser == 0 && !quiet &&
+		   !report.stats_mode && !report.tasks_mode) {
 		fputs("# To display the perf.data header info, please use --header/--header-only options.\n#\n",
 		      stdout);
 	}

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

* Re: [PATCH] perf build: Display EXTRA features for VF=1 build
  2018-01-09  9:26             ` [PATCH] perf build: Display EXTRA features for VF=1 build Jiri Olsa
@ 2018-01-19 10:15               ` Jiri Olsa
  2018-01-19 12:43                 ` Arnaldo Carvalho de Melo
  2018-01-24 11:23               ` [tip:perf/core] " tip-bot for Jiri Olsa
  1 sibling, 1 reply; 44+ messages in thread
From: Jiri Olsa @ 2018-01-19 10:15 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Jiri Olsa, Peter Zijlstra, lkml, Ingo Molnar, Namhyung Kim,
	David Ahern, Andi Kleen, Alexander Shishkin

On Tue, Jan 09, 2018 at 10:26:46AM +0100, Jiri Olsa wrote:
> On Mon, Jan 08, 2018 at 06:16:49PM +0100, Jiri Olsa wrote:
> > On Mon, Jan 08, 2018 at 06:11:22PM +0100, Jiri Olsa wrote:
> > > On Mon, Jan 08, 2018 at 12:24:33PM -0300, Arnaldo Carvalho de Melo wrote:
> > > 
> > > SNIP
> > > 
> > > > 
> > > > Works:
> > > > 
> > > > [acme@jouet perf]$ ldd ~/bin/perf | grep babel
> > > > 	libbabeltrace-ctf.so.1 => /lib64/libbabeltrace-ctf.so.1 (0x00007fcb688d0000)
> > > > 	libbabeltrace.so.1 => /lib64/libbabeltrace.so.1 (0x00007fcb67e92000)
> > > > [acme@jouet perf]$ rpm -q libbabeltrace-devel
> > > > libbabeltrace-devel-1.5.3-1.fc27.x86_64
> > > > [acme@jouet perf]$
> > > > 
> > > > But then, if we show:
> > > > 
> > > > Auto-detecting system features:
> > > > ...                         dwarf: [ on  ]
> > > > ...            dwarf_getlocations: [ on  ]
> > > > ...                         glibc: [ on  ]
> > > > ...                          gtk2: [ on  ]
> > > > ...                      libaudit: [ on  ]
> > > > ...                        libbfd: [ on  ]
> > > > ...                        libelf: [ on  ]
> > > > ...                       libnuma: [ on  ]
> > > > ...        numa_num_possible_cpus: [ on  ]
> > > > ...                       libperl: [ on  ]
> > > > ...                     libpython: [ on  ]
> > > > ...                      libslang: [ on  ]
> > > > ...                     libcrypto: [ on  ]
> > > > ...                     libunwind: [ on  ]
> > > > ...            libdw-dwarf-unwind: [ on  ]
> > > > ...                          zlib: [ on  ]
> > > > ...                          lzma: [ on  ]
> > > > ...                     get_cpuid: [ on  ]
> > > > ...                           bpf: [ on  ]
> > > > 
> > > > Shoudln't we tell the user that babeltrace was linked too?
> > > 
> > > the logic is just to simply display the state of features
> > > which we provide in FEATURE_DISPLAY variable, which is
> > > believed to be common and important enough to display
> > > status about
> > > 
> > > maybe we could display it with 'make VF=1' output?
> > 
> > like in patch attached ;-)
> 
> with changelog
> 
> thanks,
> jirka

Arnaldo,
could you please check this one?

thanks,
jirka

> 
> 
> ---
> Display state of the rest of the features (FEATURE_TESTS_EXTRA)
> for 'make VF=1' build. These features are detected manually by
> perf's Makefile.config so they can't be displayed with the
> main list, but only after we're done in Makefile.config.
> 
>   $ make VF=1
>     BUILD:   Doing 'make -j4' parallel build
> 
>   Auto-detecting system features:
>   ...                         dwarf: [ on  ]
>   ...            dwarf_getlocations: [ on  ]
>   ...                         glibc: [ on  ]
>   ...                          gtk2: [ on  ]
> 
> SNIP
> 
>   ...                       timerfd: [ on  ]
>   ...                  sched_getcpu: [ on  ]
>   ...                           sdt: [ on  ]
>   ...                         setns: [ on  ]
> 
> extra features:
>   ...                        bionic: [ OFF ]
>   ...                    compile-32: [ on  ]
>   ...                   compile-x32: [ OFF ]
>   ...                cplus-demangle: [ on  ]
>   ...                         hello: [ OFF ]
>   ...                 libbabeltrace: [ on  ]
>   ...                       liberty: [ on  ]
>   ...                     liberty-z: [ on  ]
>   ...         libunwind-debug-frame: [ OFF ]
>   ...     libunwind-debug-frame-arm: [ OFF ]
>   ... libunwind-debug-frame-aarch64: [ OFF ]
> 
> SNIP
> 
> Link: http://lkml.kernel.org/n/tip-q4r73p2c6wfag2s38fpsim8v@git.kernel.org
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> ---
>  tools/perf/Makefile.config | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
> index 12dec6ea5ed2..92265b32dddd 100644
> --- a/tools/perf/Makefile.config
> +++ b/tools/perf/Makefile.config
> @@ -947,6 +947,10 @@ define print_var_code
>  endef
>  
>  ifeq ($(VF),1)
> +  # Display EXTRA features which are detected manualy
> +  # from here with feature_check call and thus cannot
> +  # be partof global state output.
> +  $(foreach feat,$(FEATURE_TESTS_EXTRA),$(call feature_print_status,$(feat),))
>    $(call print_var,prefix)
>    $(call print_var,bindir)
>    $(call print_var,libdir)
> -- 
> 2.13.6
> 

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

* Re: [PATCH] perf build: Display EXTRA features for VF=1 build
  2018-01-19 10:15               ` Jiri Olsa
@ 2018-01-19 12:43                 ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 44+ messages in thread
From: Arnaldo Carvalho de Melo @ 2018-01-19 12:43 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Jiri Olsa, Peter Zijlstra, lkml, Ingo Molnar, Namhyung Kim,
	David Ahern, Andi Kleen, Alexander Shishkin

Em Fri, Jan 19, 2018 at 11:15:24AM +0100, Jiri Olsa escreveu:
> On Tue, Jan 09, 2018 at 10:26:46AM +0100, Jiri Olsa wrote:
> > On Mon, Jan 08, 2018 at 06:16:49PM +0100, Jiri Olsa wrote:
> > > On Mon, Jan 08, 2018 at 06:11:22PM +0100, Jiri Olsa wrote:
> > > > On Mon, Jan 08, 2018 at 12:24:33PM -0300, Arnaldo Carvalho de Melo wrote:
> > > > > Shoudln't we tell the user that babeltrace was linked too?

> > > > the logic is just to simply display the state of features
> > > > which we provide in FEATURE_DISPLAY variable, which is
> > > > believed to be common and important enough to display
> > > > status about

> > > > maybe we could display it with 'make VF=1' output?

> > > like in patch attached ;-)

> > with changelog
> 
> Arnaldo,
> could you please check this one?

Applied.

- Arnaldo

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

* [tip:perf/core] perf build: Display EXTRA features for VF=1 build
  2018-01-09  9:26             ` [PATCH] perf build: Display EXTRA features for VF=1 build Jiri Olsa
  2018-01-19 10:15               ` Jiri Olsa
@ 2018-01-24 11:23               ` tip-bot for Jiri Olsa
  1 sibling, 0 replies; 44+ messages in thread
From: tip-bot for Jiri Olsa @ 2018-01-24 11:23 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: alexander.shishkin, acme, ak, namhyung, peterz, mathieu.poirier,
	tglx, hpa, dsahern, mingo, linux-kernel, jolsa, jolsa

Commit-ID:  99402e0683ecea11db44fd1c59a65b4eb3bd2672
Gitweb:     https://git.kernel.org/tip/99402e0683ecea11db44fd1c59a65b4eb3bd2672
Author:     Jiri Olsa <jolsa@redhat.com>
AuthorDate: Tue, 9 Jan 2018 10:26:46 +0100
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Tue, 23 Jan 2018 09:51:36 -0300

perf build: Display EXTRA features for VF=1 build

Display the state of the rest of the features (FEATURE_TESTS_EXTRA) on a
'make VF=1' build. These features are detected manually by perf's
Makefile.config so they can't be displayed with the main list, but only
after we're done in Makefile.config.

  $ make VF=1
    BUILD:   Doing 'make -j4' parallel build

  Auto-detecting system features:
  ...                         dwarf: [ on  ]
  ...            dwarf_getlocations: [ on  ]
  ...                         glibc: [ on  ]
  ...                          gtk2: [ on  ]

SNIP

  ...                       timerfd: [ on  ]
  ...                  sched_getcpu: [ on  ]
  ...                           sdt: [ on  ]
  ...                         setns: [ on  ]

extra features:
  ...                        bionic: [ OFF ]
  ...                    compile-32: [ on  ]
  ...                   compile-x32: [ OFF ]
  ...                cplus-demangle: [ on  ]
  ...                         hello: [ OFF ]
  ...                 libbabeltrace: [ on  ]
  ...                       liberty: [ on  ]
  ...                     liberty-z: [ on  ]
  ...         libunwind-debug-frame: [ OFF ]
  ...     libunwind-debug-frame-arm: [ OFF ]
  ... libunwind-debug-frame-aarch64: [ OFF ]

SNIP

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20180109092646.GB11520@krava
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Makefile.config | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index 12dec6e..92265b3 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -947,6 +947,10 @@ define print_var_code
 endef
 
 ifeq ($(VF),1)
+  # Display EXTRA features which are detected manualy
+  # from here with feature_check call and thus cannot
+  # be partof global state output.
+  $(foreach feat,$(FEATURE_TESTS_EXTRA),$(call feature_print_status,$(feat),))
   $(call print_var,prefix)
   $(call print_var,bindir)
   $(call print_var,libdir)

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

end of thread, other threads:[~2018-01-24 11:27 UTC | newest]

Thread overview: 44+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-07 16:03 [PATCH 00/12] perf: Assorted fixes Jiri Olsa
2018-01-07 16:03 ` [PATCH 01/12] perf tools: Enable LIBBABELTRACE by default Jiri Olsa
2018-01-08 15:17   ` Arnaldo Carvalho de Melo
2018-01-08 15:20     ` Arnaldo Carvalho de Melo
2018-01-08 15:24       ` Arnaldo Carvalho de Melo
2018-01-08 17:11         ` Jiri Olsa
2018-01-08 17:16           ` Jiri Olsa
2018-01-09  9:26             ` [PATCH] perf build: Display EXTRA features for VF=1 build Jiri Olsa
2018-01-19 10:15               ` Jiri Olsa
2018-01-19 12:43                 ` Arnaldo Carvalho de Melo
2018-01-24 11:23               ` [tip:perf/core] " tip-bot for Jiri Olsa
2018-01-11  6:24   ` [tip:perf/core] perf tools: Enable LIBBABELTRACE by default tip-bot for Jiri Olsa
2018-01-07 16:03 ` [PATCH 02/12] perf tools: Display perf_event_attr::namespaces debug info Jiri Olsa
2018-01-11  6:24   ` [tip:perf/core] " tip-bot for Jiri Olsa
2018-01-07 16:03 ` [PATCH 03/12] perf: Allocate context task_ctx_data for child event Jiri Olsa
2018-01-08 12:14   ` Peter Zijlstra
2018-01-11  6:24   ` [tip:perf/core] " tip-bot for Jiri Olsa
2018-01-07 16:03 ` [PATCH 04/12] perf: Add sample_id to PERF_RECORD_ITRACE_START event comment Jiri Olsa
2018-01-11  6:25   ` [tip:perf/core] " tip-bot for Jiri Olsa
2018-01-07 16:03 ` [PATCH 05/12] perf: Make perf_callchain function static Jiri Olsa
2018-01-11  6:25   ` [tip:perf/core] " tip-bot for Jiri Olsa
2018-01-07 16:03 ` [PATCH 06/12] perf: Return empty callchain instead of NULL Jiri Olsa
2018-01-08 12:15   ` Peter Zijlstra
2018-01-11  6:26   ` [tip:perf/core] " tip-bot for Jiri Olsa
2018-01-07 16:03 ` [PATCH 07/12] perf: Update PERF_RECORD_MISC_* comment for perf_event_header::misc bit 13 Jiri Olsa
2018-01-11  6:26   ` [tip:perf/core] " tip-bot for Jiri Olsa
2018-01-07 16:03 ` [PATCH 08/12] perf script: Add support to display sample misc field Jiri Olsa
2018-01-11  6:27   ` [tip:perf/core] " tip-bot for Jiri Olsa
2018-01-07 16:03 ` [PATCH 09/12] perf script: Add support to display lost events Jiri Olsa
2018-01-10 15:40   ` Arnaldo Carvalho de Melo
2018-01-10 15:44     ` Jiri Olsa
2018-01-11  6:27   ` [tip:perf/core] " tip-bot for Jiri Olsa
2018-01-07 16:03 ` [PATCH 10/12] perf tools: Make the tool's warning messages optional Jiri Olsa
2018-01-11  6:27   ` [tip:perf/core] " tip-bot for Jiri Olsa
2018-01-07 16:03 ` [PATCH 11/12] perf report: Add --stat option to display quick data statistics Jiri Olsa
2018-01-11  6:28   ` [tip:perf/core] perf report: Add --stats " tip-bot for Jiri Olsa
2018-01-07 16:03 ` [PATCH 12/12] perf report: Add --task option to display monitored tasks Jiri Olsa
2018-01-08 15:55   ` Arnaldo Carvalho de Melo
2018-01-08 16:03     ` Arnaldo Carvalho de Melo
2018-01-09  1:56   ` Namhyung Kim
2018-01-09  9:15     ` Jiri Olsa
2018-01-09 13:05       ` Arnaldo Carvalho de Melo
2018-01-09 13:27         ` Jiri Olsa
2018-01-11  6:29   ` [tip:perf/core] perf report: Add --tasks " tip-bot for Jiri Olsa

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).