aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2016-10-14 17:23:11 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2016-10-24 10:07:44 -0400
commit899735066a8d945b7ae56a34847298fd0dd2104b (patch)
treecda5f4c4311a99fd28db7722bd562e7e1f93e7d5 /tools/perf
parente7b32d12a287a79f2831c1246baf3de0aed95dcc (diff)
perf tools: Use normal error reporting when processing PERF_RECORD_READ events
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>
Diffstat (limited to 'tools/perf')
-rw-r--r--tools/perf/builtin-report.c12
-rw-r--r--tools/perf/util/values.c81
-rw-r--r--tools/perf/util/values.h4
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,
207 207
208 if (rep->show_threads) { 208 if (rep->show_threads) {
209 const char *name = evsel ? perf_evsel__name(evsel) : "unknown"; 209 const char *name = evsel ? perf_evsel__name(evsel) : "unknown";
210 perf_read_values_add_value(&rep->show_threads_values, 210 int err = perf_read_values_add_value(&rep->show_threads_values,
211 event->read.pid, event->read.tid, 211 event->read.pid, event->read.tid,
212 event->read.id, 212 event->read.id,
213 name, 213 name,
214 event->read.value); 214 event->read.value);
215
216 if (err)
217 return err;
215 } 218 }
216 219
217 dump_printf(": %d %d %s %" PRIu64 "\n", event->read.pid, event->read.tid, 220 dump_printf(": %d %d %s %" PRIu64 "\n", event->read.pid, event->read.tid,
@@ -539,8 +542,11 @@ static int __cmd_report(struct report *rep)
539 } 542 }
540 } 543 }
541 544
542 if (rep->show_threads) 545 if (rep->show_threads) {
543 perf_read_values_init(&rep->show_threads_values); 546 ret = perf_read_values_init(&rep->show_threads_values);
547 if (ret)
548 return ret;
549 }
544 550
545 ret = report__setup_sample_type(rep); 551 ret = report__setup_sample_type(rep);
546 if (ret) { 552 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 @@
2 2
3#include "util.h" 3#include "util.h"
4#include "values.h" 4#include "values.h"
5#include "debug.h"
5 6
6void perf_read_values_init(struct perf_read_values *values) 7int perf_read_values_init(struct perf_read_values *values)
7{ 8{
8 values->threads_max = 16; 9 values->threads_max = 16;
9 values->pid = malloc(values->threads_max * sizeof(*values->pid)); 10 values->pid = malloc(values->threads_max * sizeof(*values->pid));
10 values->tid = malloc(values->threads_max * sizeof(*values->tid)); 11 values->tid = malloc(values->threads_max * sizeof(*values->tid));
11 values->value = malloc(values->threads_max * sizeof(*values->value)); 12 values->value = malloc(values->threads_max * sizeof(*values->value));
12 if (!values->pid || !values->tid || !values->value) 13 if (!values->pid || !values->tid || !values->value) {
13 die("failed to allocate read_values threads arrays"); 14 pr_debug("failed to allocate read_values threads arrays");
15 goto out_free_pid;
16 }
14 values->threads = 0; 17 values->threads = 0;
15 18
16 values->counters_max = 16; 19 values->counters_max = 16;
@@ -18,9 +21,22 @@ void perf_read_values_init(struct perf_read_values *values)
18 * sizeof(*values->counterrawid)); 21 * sizeof(*values->counterrawid));
19 values->countername = malloc(values->counters_max 22 values->countername = malloc(values->counters_max
20 * sizeof(*values->countername)); 23 * sizeof(*values->countername));
21 if (!values->counterrawid || !values->countername) 24 if (!values->counterrawid || !values->countername) {
22 die("failed to allocate read_values counters arrays"); 25 pr_debug("failed to allocate read_values counters arrays");
26 goto out_free_counter;
27 }
23 values->counters = 0; 28 values->counters = 0;
29
30 return 0;
31
32out_free_counter:
33 zfree(&values->counterrawid);
34 zfree(&values->countername);
35out_free_pid:
36 zfree(&values->pid);
37 zfree(&values->tid);
38 zfree(&values->value);
39 return -ENOMEM;
24} 40}
25 41
26void perf_read_values_destroy(struct perf_read_values *values) 42void perf_read_values_destroy(struct perf_read_values *values)
@@ -41,17 +57,27 @@ void perf_read_values_destroy(struct perf_read_values *values)
41 zfree(&values->countername); 57 zfree(&values->countername);
42} 58}
43 59
44static void perf_read_values__enlarge_threads(struct perf_read_values *values) 60static int perf_read_values__enlarge_threads(struct perf_read_values *values)
45{ 61{
46 values->threads_max *= 2; 62 int nthreads_max = values->threads_max * 2;
47 values->pid = realloc(values->pid, 63 void *npid = realloc(values->pid, nthreads_max * sizeof(*values->pid)),
48 values->threads_max * sizeof(*values->pid)); 64 *ntid = realloc(values->tid, nthreads_max * sizeof(*values->tid)),
49 values->tid = realloc(values->tid, 65 *nvalue = realloc(values->value, nthreads_max * sizeof(*values->value));
50 values->threads_max * sizeof(*values->tid)); 66
51 values->value = realloc(values->value, 67 if (!npid || !ntid || !nvalue)
52 values->threads_max * sizeof(*values->value)); 68 goto out_err;
53 if (!values->pid || !values->tid || !values->value) 69
54 die("failed to enlarge read_values threads arrays"); 70 values->threads_max = nthreads_max;
71 values->pid = npid;
72 values->tid = ntid;
73 values->value = nvalue;
74 return 0;
75out_err:
76 free(npid);
77 free(ntid);
78 free(nvalue);
79 pr_debug("failed to enlarge read_values threads arrays");
80 return -ENOMEM;
55} 81}
56 82
57static int perf_read_values__findnew_thread(struct perf_read_values *values, 83static 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,
63 if (values->pid[i] == pid && values->tid[i] == tid) 89 if (values->pid[i] == pid && values->tid[i] == tid)
64 return i; 90 return i;
65 91
66 if (values->threads == values->threads_max) 92 if (values->threads == values->threads_max) {
67 perf_read_values__enlarge_threads(values); 93 i = perf_read_values__enlarge_threads(values);
94 if (i < 0)
95 return i;
96 }
68 97
69 i = values->threads++; 98 i = values->threads + 1;
99 values->value[i] = malloc(values->counters_max * sizeof(**values->value));
100 if (!values->value[i]) {
101 pr_debug("failed to allocate read_values counters array");
102 return -ENOMEM;
103 }
70 values->pid[i] = pid; 104 values->pid[i] = pid;
71 values->tid[i] = tid; 105 values->tid[i] = tid;
72 values->value[i] = malloc(values->counters_max * sizeof(**values->value)); 106 values->threads = i;
73 if (!values->value[i])
74 die("failed to allocate read_values counters array");
75 107
76 return i; 108 return i;
77} 109}
@@ -115,16 +147,21 @@ static int perf_read_values__findnew_counter(struct perf_read_values *values,
115 return i; 147 return i;
116} 148}
117 149
118void perf_read_values_add_value(struct perf_read_values *values, 150int perf_read_values_add_value(struct perf_read_values *values,
119 u32 pid, u32 tid, 151 u32 pid, u32 tid,
120 u64 rawid, const char *name, u64 value) 152 u64 rawid, const char *name, u64 value)
121{ 153{
122 int tindex, cindex; 154 int tindex, cindex;
123 155
124 tindex = perf_read_values__findnew_thread(values, pid, tid); 156 tindex = perf_read_values__findnew_thread(values, pid, tid);
157 if (tindex < 0)
158 return tindex;
125 cindex = perf_read_values__findnew_counter(values, rawid, name); 159 cindex = perf_read_values__findnew_counter(values, rawid, name);
160 if (cindex < 0)
161 return cindex;
126 162
127 values->value[tindex][cindex] = value; 163 values->value[tindex][cindex] = value;
164 return 0;
128} 165}
129 166
130static void perf_read_values__display_pretty(FILE *fp, 167static 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 {
14 u64 **value; 14 u64 **value;
15}; 15};
16 16
17void perf_read_values_init(struct perf_read_values *values); 17int perf_read_values_init(struct perf_read_values *values);
18void perf_read_values_destroy(struct perf_read_values *values); 18void perf_read_values_destroy(struct perf_read_values *values);
19 19
20void perf_read_values_add_value(struct perf_read_values *values, 20int perf_read_values_add_value(struct perf_read_values *values,
21 u32 pid, u32 tid, 21 u32 pid, u32 tid,
22 u64 rawid, const char *name, u64 value); 22 u64 rawid, const char *name, u64 value);
23 23