diff options
Diffstat (limited to 'tools/perf/util/values.c')
-rw-r--r-- | tools/perf/util/values.c | 63 |
1 files changed, 46 insertions, 17 deletions
diff --git a/tools/perf/util/values.c b/tools/perf/util/values.c index 5074be4ed467..5de2e15e2eda 100644 --- a/tools/perf/util/values.c +++ b/tools/perf/util/values.c | |||
@@ -1,4 +1,7 @@ | |||
1 | #include <inttypes.h> | ||
2 | #include <stdio.h> | ||
1 | #include <stdlib.h> | 3 | #include <stdlib.h> |
4 | #include <errno.h> | ||
2 | 5 | ||
3 | #include "util.h" | 6 | #include "util.h" |
4 | #include "values.h" | 7 | #include "values.h" |
@@ -108,24 +111,45 @@ static int perf_read_values__findnew_thread(struct perf_read_values *values, | |||
108 | return i; | 111 | return i; |
109 | } | 112 | } |
110 | 113 | ||
111 | static void perf_read_values__enlarge_counters(struct perf_read_values *values) | 114 | static int perf_read_values__enlarge_counters(struct perf_read_values *values) |
112 | { | 115 | { |
113 | int i; | 116 | char **countername; |
117 | int i, counters_max = values->counters_max * 2; | ||
118 | u64 *counterrawid = realloc(values->counterrawid, counters_max * sizeof(*values->counterrawid)); | ||
119 | |||
120 | if (!counterrawid) { | ||
121 | pr_debug("failed to enlarge read_values rawid array"); | ||
122 | goto out_enomem; | ||
123 | } | ||
114 | 124 | ||
115 | values->counters_max *= 2; | 125 | countername = realloc(values->countername, counters_max * sizeof(*values->countername)); |
116 | values->counterrawid = realloc(values->counterrawid, | 126 | if (!countername) { |
117 | values->counters_max * sizeof(*values->counterrawid)); | 127 | pr_debug("failed to enlarge read_values rawid array"); |
118 | values->countername = realloc(values->countername, | 128 | goto out_free_rawid; |
119 | values->counters_max * sizeof(*values->countername)); | 129 | } |
120 | if (!values->counterrawid || !values->countername) | ||
121 | die("failed to enlarge read_values counters arrays"); | ||
122 | 130 | ||
123 | for (i = 0; i < values->threads; i++) { | 131 | for (i = 0; i < values->threads; i++) { |
124 | values->value[i] = realloc(values->value[i], | 132 | u64 *value = realloc(values->value[i], counters_max * sizeof(**values->value)); |
125 | values->counters_max * sizeof(**values->value)); | 133 | |
126 | if (!values->value[i]) | 134 | if (value) { |
127 | die("failed to enlarge read_values counters arrays"); | 135 | pr_debug("failed to enlarge read_values ->values array"); |
136 | goto out_free_name; | ||
137 | } | ||
138 | |||
139 | values->value[i] = value; | ||
128 | } | 140 | } |
141 | |||
142 | values->counters_max = counters_max; | ||
143 | values->counterrawid = counterrawid; | ||
144 | values->countername = countername; | ||
145 | |||
146 | return 0; | ||
147 | out_free_name: | ||
148 | free(countername); | ||
149 | out_free_rawid: | ||
150 | free(counterrawid); | ||
151 | out_enomem: | ||
152 | return -ENOMEM; | ||
129 | } | 153 | } |
130 | 154 | ||
131 | static int perf_read_values__findnew_counter(struct perf_read_values *values, | 155 | static int perf_read_values__findnew_counter(struct perf_read_values *values, |
@@ -137,8 +161,11 @@ static int perf_read_values__findnew_counter(struct perf_read_values *values, | |||
137 | if (values->counterrawid[i] == rawid) | 161 | if (values->counterrawid[i] == rawid) |
138 | return i; | 162 | return i; |
139 | 163 | ||
140 | if (values->counters == values->counters_max) | 164 | if (values->counters == values->counters_max) { |
141 | perf_read_values__enlarge_counters(values); | 165 | i = perf_read_values__enlarge_counters(values); |
166 | if (i) | ||
167 | return i; | ||
168 | } | ||
142 | 169 | ||
143 | i = values->counters++; | 170 | i = values->counters++; |
144 | values->counterrawid[i] = rawid; | 171 | values->counterrawid[i] = rawid; |
@@ -172,8 +199,10 @@ static void perf_read_values__display_pretty(FILE *fp, | |||
172 | int *counterwidth; | 199 | int *counterwidth; |
173 | 200 | ||
174 | counterwidth = malloc(values->counters * sizeof(*counterwidth)); | 201 | counterwidth = malloc(values->counters * sizeof(*counterwidth)); |
175 | if (!counterwidth) | 202 | if (!counterwidth) { |
176 | die("failed to allocate counterwidth array"); | 203 | fprintf(fp, "INTERNAL ERROR: Failed to allocate counterwidth array\n"); |
204 | return; | ||
205 | } | ||
177 | tidwidth = 3; | 206 | tidwidth = 3; |
178 | pidwidth = 3; | 207 | pidwidth = 3; |
179 | for (j = 0; j < values->counters; j++) | 208 | for (j = 0; j < values->counters; j++) |