aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNamhyung Kim <namhyung.kim@lge.com>2013-03-21 03:18:47 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2013-03-21 12:30:10 -0400
commit7f42b9505aee3fa9cb465a670989e3d426a1f3f2 (patch)
tree98cfde92163a379506404e3f1f8450795740b5c6
parent8755d5e202c3ef62e33d75426c2f0005e3f70ca9 (diff)
perf tools: Get rid of die() calls from trace-event-info.c
Now remove all remaining die() calls and convert them to check return value and propagate it. Signed-off-by: Namhyung Kim <namhyung@kernel.org> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Steven Rostedt <rostedt@goodmis.org> Link: http://lkml.kernel.org/r/1363850332-25297-5-git-send-email-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/util/trace-event-info.c114
1 files changed, 72 insertions, 42 deletions
diff --git a/tools/perf/util/trace-event-info.c b/tools/perf/util/trace-event-info.c
index 090e80d743db..3917eb9a8479 100644
--- a/tools/perf/util/trace-event-info.c
+++ b/tools/perf/util/trace-event-info.c
@@ -43,7 +43,6 @@
43 43
44#define VERSION "0.5" 44#define VERSION "0.5"
45 45
46static const char *output_file = "trace.info";
47static int output_fd; 46static int output_fd;
48 47
49 48
@@ -125,8 +124,10 @@ static int record_file(const char *file, ssize_t hdr_sz)
125 int err = -EIO; 124 int err = -EIO;
126 125
127 fd = open(file, O_RDONLY); 126 fd = open(file, O_RDONLY);
128 if (fd < 0) 127 if (fd < 0) {
129 die("Can't read '%s'", file); 128 pr_debug("Can't read '%s'", file);
129 return -errno;
130 }
130 131
131 /* put in zeros for file size, then fill true size later */ 132 /* put in zeros for file size, then fill true size later */
132 if (hdr_sz) { 133 if (hdr_sz) {
@@ -148,8 +149,10 @@ static int record_file(const char *file, ssize_t hdr_sz)
148 if (bigendian()) 149 if (bigendian())
149 sizep += sizeof(u64) - hdr_sz; 150 sizep += sizeof(u64) - hdr_sz;
150 151
151 if (hdr_sz && pwrite(output_fd, sizep, hdr_sz, hdr_pos) < 0) 152 if (hdr_sz && pwrite(output_fd, sizep, hdr_sz, hdr_pos) < 0) {
152 die("writing to %s", output_file); 153 pr_debug("writing file size failed\n");
154 goto out;
155 }
153 156
154 err = 0; 157 err = 0;
155out: 158out:
@@ -164,11 +167,15 @@ static int read_header_files(void)
164 int err = -EIO; 167 int err = -EIO;
165 168
166 path = get_tracing_file("events/header_page"); 169 path = get_tracing_file("events/header_page");
167 if (!path) 170 if (!path) {
168 die("can't get tracing/events/header_page"); 171 pr_debug("can't get tracing/events/header_page");
172 return -ENOMEM;
173 }
169 174
170 if (stat(path, &st) < 0) 175 if (stat(path, &st) < 0) {
171 die("can't read '%s'", path); 176 pr_debug("can't read '%s'", path);
177 goto out;
178 }
172 179
173 if (write(output_fd, "header_page", 12) != 12) { 180 if (write(output_fd, "header_page", 12) != 12) {
174 pr_debug("can't write header_page\n"); 181 pr_debug("can't write header_page\n");
@@ -183,11 +190,16 @@ static int read_header_files(void)
183 put_tracing_file(path); 190 put_tracing_file(path);
184 191
185 path = get_tracing_file("events/header_event"); 192 path = get_tracing_file("events/header_event");
186 if (!path) 193 if (!path) {
187 die("can't get tracing/events/header_event"); 194 pr_debug("can't get tracing/events/header_event");
195 err = -ENOMEM;
196 goto out;
197 }
188 198
189 if (stat(path, &st) < 0) 199 if (stat(path, &st) < 0) {
190 die("can't read '%s'", path); 200 pr_debug("can't read '%s'", path);
201 goto out;
202 }
191 203
192 if (write(output_fd, "header_event", 13) != 13) { 204 if (write(output_fd, "header_event", 13) != 13) {
193 pr_debug("can't write header_event\n"); 205 pr_debug("can't write header_event\n");
@@ -227,8 +239,10 @@ static int copy_event_system(const char *sys, struct tracepoint_path *tps)
227 int err; 239 int err;
228 240
229 dir = opendir(sys); 241 dir = opendir(sys);
230 if (!dir) 242 if (!dir) {
231 die("can't read directory '%s'", sys); 243 pr_debug("can't read directory '%s'", sys);
244 return -errno;
245 }
232 246
233 while ((dent = readdir(dir))) { 247 while ((dent = readdir(dir))) {
234 if (dent->d_type != DT_DIR || 248 if (dent->d_type != DT_DIR ||
@@ -291,8 +305,10 @@ static int read_ftrace_files(struct tracepoint_path *tps)
291 int ret; 305 int ret;
292 306
293 path = get_tracing_file("events/ftrace"); 307 path = get_tracing_file("events/ftrace");
294 if (!path) 308 if (!path) {
295 die("can't get tracing/events/ftrace"); 309 pr_debug("can't get tracing/events/ftrace");
310 return -ENOMEM;
311 }
296 312
297 ret = copy_event_system(path, tps); 313 ret = copy_event_system(path, tps);
298 314
@@ -324,12 +340,17 @@ static int read_event_files(struct tracepoint_path *tps)
324 int err; 340 int err;
325 341
326 path = get_tracing_file("events"); 342 path = get_tracing_file("events");
327 if (!path) 343 if (!path) {
328 die("can't get tracing/events"); 344 pr_debug("can't get tracing/events");
345 return -ENOMEM;
346 }
329 347
330 dir = opendir(path); 348 dir = opendir(path);
331 if (!dir) 349 if (!dir) {
332 die("can't read directory '%s'", path); 350 err = -errno;
351 pr_debug("can't read directory '%s'", path);
352 goto out;
353 }
333 354
334 while ((dent = readdir(dir))) { 355 while ((dent = readdir(dir))) {
335 if (dent->d_type != DT_DIR || 356 if (dent->d_type != DT_DIR ||
@@ -408,8 +429,10 @@ static int read_ftrace_printk(void)
408 int ret, err = 0; 429 int ret, err = 0;
409 430
410 path = get_tracing_file("printk_formats"); 431 path = get_tracing_file("printk_formats");
411 if (!path) 432 if (!path) {
412 die("can't get tracing/printk_formats"); 433 pr_debug("can't get tracing/printk_formats");
434 return -ENOMEM;
435 }
413 436
414 ret = stat(path, &st); 437 ret = stat(path, &st);
415 if (ret < 0) { 438 if (ret < 0) {
@@ -426,6 +449,19 @@ out:
426 return err; 449 return err;
427} 450}
428 451
452static void
453put_tracepoints_path(struct tracepoint_path *tps)
454{
455 while (tps) {
456 struct tracepoint_path *t = tps;
457
458 tps = tps->next;
459 free(t->name);
460 free(t->system);
461 free(t);
462 }
463}
464
429static struct tracepoint_path * 465static struct tracepoint_path *
430get_tracepoints_path(struct list_head *pattrs) 466get_tracepoints_path(struct list_head *pattrs)
431{ 467{
@@ -438,27 +474,17 @@ get_tracepoints_path(struct list_head *pattrs)
438 continue; 474 continue;
439 ++nr_tracepoints; 475 ++nr_tracepoints;
440 ppath->next = tracepoint_id_to_path(pos->attr.config); 476 ppath->next = tracepoint_id_to_path(pos->attr.config);
441 if (!ppath->next) 477 if (!ppath->next) {
442 die("%s\n", "No memory to alloc tracepoints list"); 478 pr_debug("No memory to alloc tracepoints list\n");
479 put_tracepoints_path(&path);
480 return NULL;
481 }
443 ppath = ppath->next; 482 ppath = ppath->next;
444 } 483 }
445 484
446 return nr_tracepoints > 0 ? path.next : NULL; 485 return nr_tracepoints > 0 ? path.next : NULL;
447} 486}
448 487
449static void
450put_tracepoints_path(struct tracepoint_path *tps)
451{
452 while (tps) {
453 struct tracepoint_path *t = tps;
454
455 tps = tps->next;
456 free(t->name);
457 free(t->system);
458 free(t);
459 }
460}
461
462bool have_tracepoints(struct list_head *pattrs) 488bool have_tracepoints(struct list_head *pattrs)
463{ 489{
464 struct perf_evsel *pos; 490 struct perf_evsel *pos;
@@ -536,12 +562,16 @@ struct tracing_data *tracing_data_get(struct list_head *pattrs,
536 562
537 snprintf(tdata->temp_file, sizeof(tdata->temp_file), 563 snprintf(tdata->temp_file, sizeof(tdata->temp_file),
538 "/tmp/perf-XXXXXX"); 564 "/tmp/perf-XXXXXX");
539 if (!mkstemp(tdata->temp_file)) 565 if (!mkstemp(tdata->temp_file)) {
540 die("Can't make temp file"); 566 pr_debug("Can't make temp file");
567 return NULL;
568 }
541 569
542 temp_fd = open(tdata->temp_file, O_RDWR); 570 temp_fd = open(tdata->temp_file, O_RDWR);
543 if (temp_fd < 0) 571 if (temp_fd < 0) {
544 die("Can't read '%s'", tdata->temp_file); 572 pr_debug("Can't read '%s'", tdata->temp_file);
573 return NULL;
574 }
545 575
546 /* 576 /*
547 * Set the temp file the default output, so all the 577 * Set the temp file the default output, so all the