Skip to contentSkip to conversation

perf report: Show error message when processing sample fails

PATCH In review Namhyung Kim 3 participants 11 messages Nov 27, 2015 – Nov 29, 2015 perf events

lore
Share & tools
lore

Namhyung Kim

author maintainer
#0 lore raw

PATCH 1/3 perf report: Show error message when processing sample fails

Currently when perf fails to process samples for some reason, it doesn't show any message about the failure. This is very inconvenient for users especially on TUI as screen is reset after the failure.

---
 tools/perf/builtin-report.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
tools/perf/builtin-report.c +9 -3
index 8a9c6908f54e..af5db885ea9c 100644
@@ -513,20 +513,26 @@ static int __cmd_report(struct report *rep)
 	if (rep->cpu_list) {
 		ret = perf_session__cpu_bitmap(session, rep->cpu_list,
 					       rep->cpu_bitmap);
-		if (ret)
+		if (ret) {
+			ui__error("failed to set cpu bitmap\n");
 			return ret;
+		}
 	}
 
 	if (rep->show_threads)
 		perf_read_values_init(&rep->show_threads_values);
 
 	ret = report__setup_sample_type(rep);
-	if (ret)
+	if (ret) {
+		/* report__setup_sample_type() already showed error message */
 		return ret;
+	}
 
 	ret = perf_session__process_events(session);
-	if (ret)
+	if (ret) {
+		ui__error("failed to process sample\n");
 		return ret;
+	}
 
 	report__warn_kptr_restrict(rep);
 
Signature · 1 line
2.6.2
author maintainer
#1 lore raw

PATCH 2/3 perf hist: Do not skip elided fields when processing samples

If user gives a filter, perf marks the corresponding column elided and omits the output. But it should process and aggregates samples using the field, otherwise samples will be aggregated as if the column was not there resulted in incorrect output.

For example, I'd like to set a filter on native_write_msr_safe. The original overhead of the function is negligible.

  $ perf report | grep native_write_msr_safe
      0.00%  swapper  [kernel.vmlinux]  native_write_msr_safe
      0.00%  perf     [kernel.vmlinux]  native_write_msr_safe

However adding -S option gives different output.

  $ perf report -S native_write_msr_safe --percentage absolute | \
Quoted 1 line

grep -e swapper -e perf

     51.47%  swapper  [kernel.vmlinux]
      4.14%  perf     [kernel.vmlinux]

Since it aggregated samples using comm and dso only. In fact, the above values are same when it sorts with -s comm,dso.

  $ perf report -s comm,dso | grep -e swapper -e perf
     51.47%  swapper  [kernel.vmlinux]
      4.14%  perf     [kernel.vmlinux]

This resulted in TUI failure with -ERANGE since it tries to increase sample hit count for annotation with wrong symbols due to incorrect aggregation.

This patch fixes it not to skip elided fields when comparing samples in order to insert them to the hists.

---
 tools/perf/util/hist.c | 6 ------
 1 file changed, 6 deletions(-)
tools/perf/util/hist.c +0 -6
index 4fd37d6708cb..6e8e0ee9ec37 100644
@@ -924,9 +924,6 @@ hist_entry__cmp(struct hist_entry *left, struct hist_entry *right)
 	int64_t cmp = 0;
 
 	perf_hpp__for_each_sort_list(fmt) {
-		if (perf_hpp__should_skip(fmt))
-			continue;
-
 		cmp = fmt->cmp(fmt, left, right);
 		if (cmp)
 			break;
@@ -942,9 +939,6 @@ hist_entry__collapse(struct hist_entry *left, struct hist_entry *right)
 	int64_t cmp = 0;
 
 	perf_hpp__for_each_sort_list(fmt) {
-		if (perf_hpp__should_skip(fmt))
-			continue;
-
 		cmp = fmt->collapse(fmt, left, right);
 		if (cmp)
 			break;
Signature · 1 line
2.6.2
#2 lore raw

Re: [PATCH 2/3] perf hist: Do not skip elided fields when processing samples

Em Sat, Nov 28, 2015 at 02:32:38AM +0900, Namhyung Kim escreveu:

Quoted 4 lines

If user gives a filter, perf marks the corresponding column elided and omits the output. But it should process and aggregates samples using the field, otherwise samples will be aggregated as if the column was not there resulted in incorrect output.

Thanks, applied, I've tested it and it now seems to work in both the --stdio and --tui interfaces, good job!

- Arnaldo

#3 lore raw

[tip:perf/core] perf hists: Do not skip elided fields when processing samples

In reply to Namhyung Kim
perf hists: Do not skip elided fields when processing samples
Commit-ID:  e72655d97d24fff559b4ab59de791c3741a74c8c
Gitweb:     http://git.kernel.org/tip/e72655d97d24fff559b4ab59de791c3741a74c8c
Author:     Namhyung Kim <[email protected]>
AuthorDate: Sat, 28 Nov 2015 02:32:38 +0900
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Fri, 27 Nov 2015 21:42:13 -0300

perf hists: Do not skip elided fields when processing samples

If user gives a filter, perf marks the corresponding column elided and omits the output. But it should process and aggregates samples using the field, otherwise samples will be aggregated as if the column was not there resulted in incorrect output.

For example, I'd like to set a filter on native_write_msr_safe. The original overhead of the function is negligible.

  $ perf report | grep native_write_msr_safe
      0.00%  swapper  [kernel.vmlinux]  native_write_msr_safe
      0.00%  perf     [kernel.vmlinux]  native_write_msr_safe

However adding -S option gives different output.

  $ perf report -S native_write_msr_safe --percentage absolute | \
Quoted 1 line

grep -e swapper -e perf

     51.47%  swapper  [kernel.vmlinux]
      4.14%  perf     [kernel.vmlinux]

Since it aggregated samples using comm and dso only. In fact, the above values are same when it sorts with -s comm,dso.

  $ perf report -s comm,dso | grep -e swapper -e perf
     51.47%  swapper  [kernel.vmlinux]
      4.14%  perf     [kernel.vmlinux]

This resulted in TUI failure with -ERANGE since it tries to increase sample hit count for annotation with wrong symbols due to incorrect aggregation.

This patch fixes it not to skip elided fields when comparing samples in order to insert them to the hists.

Commiter note:

After the patch, with a different workloads:

  # perf report --show-total-period -S native_write_msr_safe --stdio
  #
  # symbol: native_write_msr_safe
  #
  # Samples: 455  of event 'cycles:pp'
  # Event count (approx.): 134787489
  #
  # Overhead Period Command         Shared Object
  # ........ ...... ............... ................
  #
       0.22% 293081 qemu-system-x86 [vmlinux]
       0.19% 255914 swapper         [vmlinux]
       0.00%   2054 Timer           [vmlinux]
       0.00%   1021 firefox         [vmlinux]
       0.00%      2 perf            [vmlinux]
  # perf report --show-total-period | grep native_write_msr_safe
  Failed to open /tmp/perf-14838.map, continuing without symbols
       0.22% 293081 qemu-system-x86 [vmlinux]  [k] native_write_msr_safe
       0.19% 255914 swapper         [vmlinux]  [k] native_write_msr_safe
       0.00%   2054 Timer           [vmlinux]  [k] native_write_msr_safe
       0.00%   1021 firefox         [vmlinux]  [k] native_write_msr_safe
       0.00%      2 perf            [vmlinux]  [k] native_write_msr_safe
  #
---
 tools/perf/util/hist.c | 6 ------
 1 file changed, 6 deletions(-)
tools/perf/util/hist.c +0 -6
index 4fd37d6..6e8e0ee 100644
@@ -924,9 +924,6 @@ hist_entry__cmp(struct hist_entry *left, struct hist_entry *right)
 	int64_t cmp = 0;
 
 	perf_hpp__for_each_sort_list(fmt) {
-		if (perf_hpp__should_skip(fmt))
-			continue;
-
 		cmp = fmt->cmp(fmt, left, right);
 		if (cmp)
 			break;
@@ -942,9 +939,6 @@ hist_entry__collapse(struct hist_entry *left, struct hist_entry *right)
 	int64_t cmp = 0;
 
 	perf_hpp__for_each_sort_list(fmt) {
-		if (perf_hpp__should_skip(fmt))
-			continue;
-
 		cmp = fmt->collapse(fmt, left, right);
 		if (cmp)
 			break;
author maintainer
#4 lore raw

PATCH 3/3 perf hists browser: Update nr entries regardless of min percent

In reply to Namhyung Kim

When perf report on TUI was called with -S symbol filter, it should update nr entries even if min_pcnt is 0. IIRC the reason was to update nr entries after applying minimum percent threshold. But if symbol filter was given on command line (with -S option), it should use hists->nr_non_filtered_entries instead of hists->nr_entries.

So this patch fixes a bug of navigating hists browser that the cursor goes beyond the number of entries when -S (or similar) option is used.

---
 tools/perf/ui/browsers/hists.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
tools/perf/ui/browsers/hists.c +2 -3
index a211b7b6a81e..dcdcbafb078b 100644
@@ -2055,10 +2055,9 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
 	SLang_reset_tty();
 	SLang_init_tty(0, 0, 0);
 
-	if (min_pcnt) {
+	if (min_pcnt)
 		browser->min_pcnt = min_pcnt;
-		hist_browser__update_nr_entries(browser);
-	}
+	hist_browser__update_nr_entries(browser);
 
 	browser->pstack = pstack__new(3);
 	if (browser->pstack == NULL)
Signature · 1 line
2.6.2
#5 lore raw

Re: [PATCH 3/3] perf hists browser: Update nr entries regardless of min percent

Em Sat, Nov 28, 2015 at 02:32:39AM +0900, Namhyung Kim escreveu:

Quoted 8 lines

When perf report on TUI was called with -S symbol filter, it should update nr entries even if min_pcnt is 0. IIRC the reason was to update nr entries after applying minimum percent threshold. But if symbol filter was given on command line (with -S option), it should use hists->nr_non_filtered_entries instead of hists->nr_entries.

So this patch fixes a bug of navigating hists browser that the cursor goes beyond the number of entries when -S (or similar) option is used.

Thanks, tested and applied.

- Arnaldo

#6 lore raw

[tip:perf/core] perf hists browser: Update nr entries regardless of min percent

In reply to Namhyung Kim
perf hists browser: Update nr entries regardless of min percent
Commit-ID:  039050482573e168690d365b8ea1d4f599ebbbd8
Gitweb:     http://git.kernel.org/tip/039050482573e168690d365b8ea1d4f599ebbbd8
Author:     Namhyung Kim <[email protected]>
AuthorDate: Sat, 28 Nov 2015 02:32:39 +0900
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Fri, 27 Nov 2015 21:53:33 -0300

perf hists browser: Update nr entries regardless of min percent

When perf report on TUI was called with -S symbol filter, it should update nr entries even if min_pcnt is 0. IIRC the reason was to update nr entries after applying minimum percent threshold. But if symbol filter was given on command line (with -S option), it should use hists->nr_non_filtered_entries instead of hists->nr_entries.

So this patch fixes a bug of navigating hists browser that the cursor goes beyond the number of entries when -S (or similar) option is used.

---
 tools/perf/ui/browsers/hists.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
tools/perf/ui/browsers/hists.c +2 -3
index a211b7b..dcdcbaf 100644
@@ -2055,10 +2055,9 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
 	SLang_reset_tty();
 	SLang_init_tty(0, 0, 0);
 
-	if (min_pcnt) {
+	if (min_pcnt)
 		browser->min_pcnt = min_pcnt;
-		hist_browser__update_nr_entries(browser);
-	}
+	hist_browser__update_nr_entries(browser);
 
 	browser->pstack = pstack__new(3);
 	if (browser->pstack == NULL)
#7 lore raw
In reply to Namhyung Kim

Em Sat, Nov 28, 2015 at 02:32:37AM +0900, Namhyung Kim escreveu:

Quoted 14 lines

Currently when perf fails to process samples for some reason, it doesn't show any message about the failure. This is very inconvenient for users especially on TUI as screen is reset after the failure.

---
 tools/perf/builtin-report.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
tools/perf/builtin-report.c +0 -0
index 8a9c6908f54e..af5db885ea9c 100644

tools/perf/builtin-report.c static int __cmd_report(struct report *rep) · line 517

Quoted 6 lines
tools/perf/builtin-report.c +2 -1
@@ -513,20 +513,26 @@ static int __cmd_report(struct report *rep)
 	if (rep->cpu_list) {
 		ret = perf_session__cpu_bitmap(session, rep->cpu_list,
 					       rep->cpu_bitmap);
-		if (ret)
+		if (ret) {
+			ui__error("failed to set cpu bitmap\n");

Why? See below.

Quoted 10 lines
tools/perf/builtin-report.c +2 -1
 			return ret;
+		}
 	}
 
 	if (rep->show_threads)
 		perf_read_values_init(&rep->show_threads_values);
 
 	ret = report__setup_sample_type(rep);
-	if (ret)
+	if (ret) {

tools/perf/builtin-report.c static int __cmd_report(struct report *rep) · line 535

Quoted 10 lines
tools/perf/builtin-report.c +5 -1
+		/* report__setup_sample_type() already showed error message */
 		return ret;
+	}
 
 	ret = perf_session__process_events(session);
-	if (ret)
+	if (ret) {
+		ui__error("failed to process sample\n");
 		return ret;
+	}

I'm applying this because it removes the potential flash, but would be good to have the reason for this failure shown to the user.

- Arnaldo

#8 lore raw

Em Fri, Nov 27, 2015 at 04:56:27PM -0300, Arnaldo Carvalho de Melo escreveu:

Quoted 6 lines

Em Sat, Nov 28, 2015 at 02:32:37AM +0900, Namhyung Kim escreveu:

Quoted 5 lines

Currently when perf fails to process samples for some reason, it doesn't show any message about the failure. This is very inconvenient for users especially on TUI as screen is reset after the failure.

Ah, I added a :

As this was due to those messages from Ingo, right?

- Arnaldo

Quoted 43 lines
Quoted 9 lines
---
 tools/perf/builtin-report.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
tools/perf/builtin-report.c +0 -0
index 8a9c6908f54e..af5db885ea9c 100644

tools/perf/builtin-report.c static int __cmd_report(struct report *rep) · line 517

Quoted 6 lines
tools/perf/builtin-report.c +2 -1
@@ -513,20 +513,26 @@ static int __cmd_report(struct report *rep)
 	if (rep->cpu_list) {
 		ret = perf_session__cpu_bitmap(session, rep->cpu_list,
 					       rep->cpu_bitmap);
-		if (ret)
+		if (ret) {
+			ui__error("failed to set cpu bitmap\n");

Why? See below.

Quoted 10 lines
tools/perf/builtin-report.c +2 -1
 			return ret;
+		}
 	}
 
 	if (rep->show_threads)
 		perf_read_values_init(&rep->show_threads_values);
 
 	ret = report__setup_sample_type(rep);
-	if (ret)
+	if (ret) {

tools/perf/builtin-report.c static int __cmd_report(struct report *rep) · line 535

Quoted 10 lines
tools/perf/builtin-report.c +5 -1
+		/* report__setup_sample_type() already showed error message */
 		return ret;
+	}
 
 	ret = perf_session__process_events(session);
-	if (ret)
+	if (ret) {
+		ui__error("failed to process sample\n");
 		return ret;
+	}

I'm applying this because it removes the potential flash, but would be good to have the reason for this failure shown to the user.

- Arnaldo

author maintainer
#9 lore raw

Hi Arnaldo,

Quoted 6 lines · Arnaldo Carvalho de Melo

Em Fri, Nov 27, 2015 at 04:56:27PM -0300, Arnaldo Carvalho de Melo escreveu:

Quoted 5 lines

Em Sat, Nov 28, 2015 at 02:32:37AM +0900, Namhyung Kim escreveu:

Quoted 4 lines

Currently when perf fails to process samples for some reason, it doesn't show any message about the failure. This is very inconvenient for users especially on TUI as screen is reset after the failure.

Quoted 7 lines
Quoted 1 line
Quoted 1 line

Ah, I added a :

As this was due to those messages from Ingo, right?

Right.

Quoted 33 lines
Quoted 33 lines
Quoted 10 lines
---
 tools/perf/builtin-report.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
tools/perf/builtin-report.c +0 -0
index 8a9c6908f54e..af5db885ea9c 100644

tools/perf/builtin-report.c static int __cmd_report(struct report *rep) · line 517

Quoted 6 lines
tools/perf/builtin-report.c +2 -1
@@ -513,20 +513,26 @@ static int __cmd_report(struct report *rep)
 	if (rep->cpu_list) {
 		ret = perf_session__cpu_bitmap(session, rep->cpu_list,
 					       rep->cpu_bitmap);
-		if (ret)
+		if (ret) {
+			ui__error("failed to set cpu bitmap\n");

Why? See below.

Quoted 14 lines
tools/perf/builtin-report.c +4 -1
 			return ret;
+		}
 	}
 
 	if (rep->show_threads)
 		perf_read_values_init(&rep->show_threads_values);
 
 	ret = report__setup_sample_type(rep);
-	if (ret)
+	if (ret) {
+		/* report__setup_sample_type() already showed error message */
 		return ret;
+	}
 
Quoted 9 lines
Quoted 9 lines

tools/perf/builtin-report.c static int __cmd_report(struct report *rep) · line 535

Quoted 6 lines
tools/perf/builtin-report.c +3 -1
 	ret = perf_session__process_events(session);
-	if (ret)
+	if (ret) {
+		ui__error("failed to process sample\n");
 		return ret;
+	}

I'm applying this because it removes the potential flash, but would be good to have the reason for this failure shown to the user.

Yes, but at least the last error/warning will be shown in the bottom.

Thanks,
Namhyung

#10 lore raw
In reply to Namhyung Kim
perf report: Show error message when processing sample fails
Commit-ID:  25b1606be1a910a63a23c3d1006581c9aad4e6e3
Gitweb:     http://git.kernel.org/tip/25b1606be1a910a63a23c3d1006581c9aad4e6e3
Author:     Namhyung Kim <[email protected]>
AuthorDate: Sat, 28 Nov 2015 02:32:37 +0900
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Fri, 27 Nov 2015 16:56:32 -0300

perf report: Show error message when processing sample fails

Currently when perf fails to process samples for some reason, it doesn't show any message about the failure. This is very inconvenient for users especially on TUI as screen is reset after the failure.

---
 tools/perf/builtin-report.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
tools/perf/builtin-report.c +9 -3
index 8a9c690..af5db88 100644
@@ -513,20 +513,26 @@ static int __cmd_report(struct report *rep)
 	if (rep->cpu_list) {
 		ret = perf_session__cpu_bitmap(session, rep->cpu_list,
 					       rep->cpu_bitmap);
-		if (ret)
+		if (ret) {
+			ui__error("failed to set cpu bitmap\n");
 			return ret;
+		}
 	}
 
 	if (rep->show_threads)
 		perf_read_values_init(&rep->show_threads_values);
 
 	ret = report__setup_sample_type(rep);
-	if (ret)
+	if (ret) {
+		/* report__setup_sample_type() already showed error message */
 		return ret;
+	}
 
 	ret = perf_session__process_events(session);
-	if (ret)
+	if (ret) {
+		ui__error("failed to process sample\n");
 		return ret;
+	}
 
 	report__warn_kptr_restrict(rep);