All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Brice Goglin <Brice.Goglin@inria.fr>,
	David Ahern <dsahern@gmail.com>, Jiri Olsa <jolsa@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	Wang Nan <wangnan0@huawei.com>
Subject: [PATCH 32/37] perf tools: Use normal error reporting when processing PERF_RECORD_READ events
Date: Mon, 24 Oct 2016 13:20:52 -0300	[thread overview]
Message-ID: <1477326057-24080-33-git-send-email-acme@kernel.org> (raw)
In-Reply-To: <1477326057-24080-1-git-send-email-acme@kernel.org>

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

We already have handling for errors when processing PERF_RECORD_ events,
so instead of calling die() when not being able to alloc, propagate the
error, so that the normal UI exit sequence can take place, the user be
warned and possibly the terminal be properly reset to a sane mode.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Brice Goglin <Brice.Goglin@inria.fr>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-r90je3c009a125dvs3525yge@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-report.c | 12 +++++--
 tools/perf/util/values.c    | 81 +++++++++++++++++++++++++++++++++------------
 tools/perf/util/values.h    |  4 +--
 3 files changed, 70 insertions(+), 27 deletions(-)

diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 6e88460cd13d..8064de8ceedc 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -207,11 +207,14 @@ static int process_read_event(struct perf_tool *tool,
 
 	if (rep->show_threads) {
 		const char *name = evsel ? perf_evsel__name(evsel) : "unknown";
-		perf_read_values_add_value(&rep->show_threads_values,
+		int err = perf_read_values_add_value(&rep->show_threads_values,
 					   event->read.pid, event->read.tid,
 					   event->read.id,
 					   name,
 					   event->read.value);
+
+		if (err)
+			return err;
 	}
 
 	dump_printf(": %d %d %s %" PRIu64 "\n", event->read.pid, event->read.tid,
@@ -539,8 +542,11 @@ static int __cmd_report(struct report *rep)
 		}
 	}
 
-	if (rep->show_threads)
-		perf_read_values_init(&rep->show_threads_values);
+	if (rep->show_threads) {
+		ret = perf_read_values_init(&rep->show_threads_values);
+		if (ret)
+			return ret;
+	}
 
 	ret = report__setup_sample_type(rep);
 	if (ret) {
diff --git a/tools/perf/util/values.c b/tools/perf/util/values.c
index 0fb3c1fcd3e6..5074be4ed467 100644
--- a/tools/perf/util/values.c
+++ b/tools/perf/util/values.c
@@ -2,15 +2,18 @@
 
 #include "util.h"
 #include "values.h"
+#include "debug.h"
 
-void perf_read_values_init(struct perf_read_values *values)
+int perf_read_values_init(struct perf_read_values *values)
 {
 	values->threads_max = 16;
 	values->pid = malloc(values->threads_max * sizeof(*values->pid));
 	values->tid = malloc(values->threads_max * sizeof(*values->tid));
 	values->value = malloc(values->threads_max * sizeof(*values->value));
-	if (!values->pid || !values->tid || !values->value)
-		die("failed to allocate read_values threads arrays");
+	if (!values->pid || !values->tid || !values->value) {
+		pr_debug("failed to allocate read_values threads arrays");
+		goto out_free_pid;
+	}
 	values->threads = 0;
 
 	values->counters_max = 16;
@@ -18,9 +21,22 @@ void perf_read_values_init(struct perf_read_values *values)
 				      * sizeof(*values->counterrawid));
 	values->countername = malloc(values->counters_max
 				     * sizeof(*values->countername));
-	if (!values->counterrawid || !values->countername)
-		die("failed to allocate read_values counters arrays");
+	if (!values->counterrawid || !values->countername) {
+		pr_debug("failed to allocate read_values counters arrays");
+		goto out_free_counter;
+	}
 	values->counters = 0;
+
+	return 0;
+
+out_free_counter:
+	zfree(&values->counterrawid);
+	zfree(&values->countername);
+out_free_pid:
+	zfree(&values->pid);
+	zfree(&values->tid);
+	zfree(&values->value);
+	return -ENOMEM;
 }
 
 void perf_read_values_destroy(struct perf_read_values *values)
@@ -41,17 +57,27 @@ void perf_read_values_destroy(struct perf_read_values *values)
 	zfree(&values->countername);
 }
 
-static void perf_read_values__enlarge_threads(struct perf_read_values *values)
+static int perf_read_values__enlarge_threads(struct perf_read_values *values)
 {
-	values->threads_max *= 2;
-	values->pid = realloc(values->pid,
-			      values->threads_max * sizeof(*values->pid));
-	values->tid = realloc(values->tid,
-			      values->threads_max * sizeof(*values->tid));
-	values->value = realloc(values->value,
-				values->threads_max * sizeof(*values->value));
-	if (!values->pid || !values->tid || !values->value)
-		die("failed to enlarge read_values threads arrays");
+	int nthreads_max = values->threads_max * 2;
+	void *npid = realloc(values->pid, nthreads_max * sizeof(*values->pid)),
+	     *ntid = realloc(values->tid, nthreads_max * sizeof(*values->tid)),
+	     *nvalue = realloc(values->value, nthreads_max * sizeof(*values->value));
+
+	if (!npid || !ntid || !nvalue)
+		goto out_err;
+
+	values->threads_max = nthreads_max;
+	values->pid = npid;
+	values->tid = ntid;
+	values->value = nvalue;
+	return 0;
+out_err:
+	free(npid);
+	free(ntid);
+	free(nvalue);
+	pr_debug("failed to enlarge read_values threads arrays");
+	return -ENOMEM;
 }
 
 static int perf_read_values__findnew_thread(struct perf_read_values *values,
@@ -63,15 +89,21 @@ static int perf_read_values__findnew_thread(struct perf_read_values *values,
 		if (values->pid[i] == pid && values->tid[i] == tid)
 			return i;
 
-	if (values->threads == values->threads_max)
-		perf_read_values__enlarge_threads(values);
+	if (values->threads == values->threads_max) {
+		i = perf_read_values__enlarge_threads(values);
+		if (i < 0)
+			return i;
+	}
 
-	i = values->threads++;
+	i = values->threads + 1;
+	values->value[i] = malloc(values->counters_max * sizeof(**values->value));
+	if (!values->value[i]) {
+		pr_debug("failed to allocate read_values counters array");
+		return -ENOMEM;
+	}
 	values->pid[i] = pid;
 	values->tid[i] = tid;
-	values->value[i] = malloc(values->counters_max * sizeof(**values->value));
-	if (!values->value[i])
-		die("failed to allocate read_values counters array");
+	values->threads = i;
 
 	return i;
 }
@@ -115,16 +147,21 @@ static int perf_read_values__findnew_counter(struct perf_read_values *values,
 	return i;
 }
 
-void perf_read_values_add_value(struct perf_read_values *values,
+int perf_read_values_add_value(struct perf_read_values *values,
 				u32 pid, u32 tid,
 				u64 rawid, const char *name, u64 value)
 {
 	int tindex, cindex;
 
 	tindex = perf_read_values__findnew_thread(values, pid, tid);
+	if (tindex < 0)
+		return tindex;
 	cindex = perf_read_values__findnew_counter(values, rawid, name);
+	if (cindex < 0)
+		return cindex;
 
 	values->value[tindex][cindex] = value;
+	return 0;
 }
 
 static void perf_read_values__display_pretty(FILE *fp,
diff --git a/tools/perf/util/values.h b/tools/perf/util/values.h
index b21a80c6cf8d..808ff9c73bf5 100644
--- a/tools/perf/util/values.h
+++ b/tools/perf/util/values.h
@@ -14,10 +14,10 @@ struct perf_read_values {
 	u64 **value;
 };
 
-void perf_read_values_init(struct perf_read_values *values);
+int perf_read_values_init(struct perf_read_values *values);
 void perf_read_values_destroy(struct perf_read_values *values);
 
-void perf_read_values_add_value(struct perf_read_values *values,
+int perf_read_values_add_value(struct perf_read_values *values,
 				u32 pid, u32 tid,
 				u64 rawid, const char *name, u64 value);
 
-- 
2.7.4

  parent reply	other threads:[~2016-10-24 16:22 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-24 16:20 [GIT PULL 00/37] perf/core improvements and fixes Arnaldo Carvalho de Melo
2016-10-24 16:20 ` [PATCH 01/37] perf intel-pt/bts: Tidy instruction buffer size usage Arnaldo Carvalho de Melo
2016-10-24 16:20 ` [PATCH 02/37] perf intel-pt/bts: Report instruction bytes and length in sample Arnaldo Carvalho de Melo
2016-10-24 16:20 ` [PATCH 03/37] perf script: Support insn and insnlen Arnaldo Carvalho de Melo
2016-10-24 16:20 ` [PATCH 04/37] perf tools: Sync copy of x86's syscall table Arnaldo Carvalho de Melo
2016-10-24 16:20 ` [PATCH 05/37] tools lib traceevent: Add install_headers target Arnaldo Carvalho de Melo
2016-10-24 16:20 ` [PATCH 06/37] tools lib traceevent: Add do_install_mkdir Makefile function Arnaldo Carvalho de Melo
2016-10-24 16:20 ` [PATCH 07/37] tools lib traceevent: Rename LIB_FILE to LIB_TARGET Arnaldo Carvalho de Melo
2016-10-24 16:20 ` [PATCH 08/37] tools lib traceevent: Add version for traceevent shared object Arnaldo Carvalho de Melo
2016-10-24 16:20 ` [PATCH 09/37] tools lib: Add for_each_clear_bit macro Arnaldo Carvalho de Melo
2016-10-24 16:20 ` [PATCH 10/37] perf report: Move captured info to generic header info Arnaldo Carvalho de Melo
2016-10-24 16:20 ` [PATCH 11/37] perf header: Display missing features Arnaldo Carvalho de Melo
2016-10-24 16:20 ` [PATCH 12/37] perf header: Display feature name on write failure Arnaldo Carvalho de Melo
2016-10-24 16:20 ` [PATCH 13/37] perf record: Improve documentation of event parameters Arnaldo Carvalho de Melo
2016-10-24 16:20 ` [PATCH 14/37] perf tools: Implement branch_type event parameter Arnaldo Carvalho de Melo
2016-10-24 16:20 ` [PATCH 15/37] perf jit: Avoid returning garbage for a ret variable Arnaldo Carvalho de Melo
2016-10-24 16:20 ` [PATCH 16/37] perf jit: Add NT_GNU_BUILD_ID definition for older distros Arnaldo Carvalho de Melo
2016-10-24 16:20 ` [PATCH 17/37] perf jit: Improve error messages from JVMTI Arnaldo Carvalho de Melo
2016-10-24 16:20 ` [PATCH 18/37] perf jit: Enable jitdump support without dwarf Arnaldo Carvalho de Melo
2016-10-24 16:20 ` [PATCH 19/37] perf jit: Remove unecessary padding in jitdump file Arnaldo Carvalho de Melo
2016-10-24 16:20 ` [PATCH 20/37] perf jit: Make perf skip unknown records Arnaldo Carvalho de Melo
2016-10-24 16:20 ` [PATCH 21/37] perf jit: Do not assume pgoff is zero Arnaldo Carvalho de Melo
2016-10-24 16:20 ` [PATCH 22/37] perf jit: Add unwinding support Arnaldo Carvalho de Melo
2016-10-24 16:20 ` [PATCH 23/37] perf jit: Generate .eh_frame/.eh_frame_hdr in DSO Arnaldo Carvalho de Melo
2016-10-24 16:20 ` [PATCH 24/37] perf jit: Check JITHEADER_VERSION Arnaldo Carvalho de Melo
2016-10-24 16:20 ` [PATCH 25/37] perf jit: Add jitdump format specification document Arnaldo Carvalho de Melo
2016-10-24 16:20 ` [PATCH 26/37] perf pmu: Only print Using CPUID message once Arnaldo Carvalho de Melo
2016-10-24 16:20 ` [PATCH 27/37] perf tools: Fix typo "No enough" to "Not enough" Arnaldo Carvalho de Melo
2016-10-24 16:20 ` [PATCH 28/37] perf hists browser: Dynamically change verbosity level Arnaldo Carvalho de Melo
2016-10-24 16:20 ` [PATCH 29/37] perf trace: Implement --delay Arnaldo Carvalho de Melo
2016-10-24 16:20 ` [PATCH 30/37] perf bench mem: Move boilerplate memory allocation to the infrastructure Arnaldo Carvalho de Melo
2016-10-24 16:20 ` [PATCH 31/37] perf tools: Normalize sq_quote_argv() error reporting Arnaldo Carvalho de Melo
2016-10-24 16:20 ` Arnaldo Carvalho de Melo [this message]
2016-10-24 16:20 ` [PATCH 33/37] perf bench futex: Cache align the worker struct Arnaldo Carvalho de Melo
2016-10-24 18:50   ` Davidlohr Bueso
2016-10-24 18:53     ` Arnaldo Carvalho de Melo
2016-10-24 16:20 ` [PATCH 34/37] perf trace: Remove thread_trace->exit_time Arnaldo Carvalho de Melo
2016-10-24 16:20 ` [PATCH 35/37] perf trace: Use the syscall raw_syscalls:sys_enter timestamp Arnaldo Carvalho de Melo
2016-10-24 16:20 ` [PATCH 36/37] perf list: Make vendor event matching case insensitive Arnaldo Carvalho de Melo
2016-10-24 16:20 ` [PATCH 37/37] perf coresight: Removing miscellaneous debug output Arnaldo Carvalho de Melo
2016-10-24 16:20   ` Arnaldo Carvalho de Melo
2016-10-24 18:44 ` [GIT PULL 00/37] perf/core improvements and fixes Ingo Molnar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1477326057-24080-33-git-send-email-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=Brice.Goglin@inria.fr \
    --cc=acme@redhat.com \
    --cc=adrian.hunter@intel.com \
    --cc=dsahern@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=wangnan0@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.