Commit 7f42b950 authored by Namhyung Kim's avatar Namhyung Kim Committed by Arnaldo Carvalho de Melo

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: default avatarNamhyung 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.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 8755d5e2
...@@ -43,7 +43,6 @@ ...@@ -43,7 +43,6 @@
#define VERSION "0.5" #define VERSION "0.5"
static const char *output_file = "trace.info";
static int output_fd; static int output_fd;
...@@ -125,8 +124,10 @@ static int record_file(const char *file, ssize_t hdr_sz) ...@@ -125,8 +124,10 @@ static int record_file(const char *file, ssize_t hdr_sz)
int err = -EIO; int err = -EIO;
fd = open(file, O_RDONLY); fd = open(file, O_RDONLY);
if (fd < 0) if (fd < 0) {
die("Can't read '%s'", file); pr_debug("Can't read '%s'", file);
return -errno;
}
/* put in zeros for file size, then fill true size later */ /* put in zeros for file size, then fill true size later */
if (hdr_sz) { if (hdr_sz) {
...@@ -148,8 +149,10 @@ static int record_file(const char *file, ssize_t hdr_sz) ...@@ -148,8 +149,10 @@ static int record_file(const char *file, ssize_t hdr_sz)
if (bigendian()) if (bigendian())
sizep += sizeof(u64) - hdr_sz; sizep += sizeof(u64) - hdr_sz;
if (hdr_sz && pwrite(output_fd, sizep, hdr_sz, hdr_pos) < 0) if (hdr_sz && pwrite(output_fd, sizep, hdr_sz, hdr_pos) < 0) {
die("writing to %s", output_file); pr_debug("writing file size failed\n");
goto out;
}
err = 0; err = 0;
out: out:
...@@ -164,11 +167,15 @@ static int read_header_files(void) ...@@ -164,11 +167,15 @@ static int read_header_files(void)
int err = -EIO; int err = -EIO;
path = get_tracing_file("events/header_page"); path = get_tracing_file("events/header_page");
if (!path) if (!path) {
die("can't get tracing/events/header_page"); pr_debug("can't get tracing/events/header_page");
return -ENOMEM;
}
if (stat(path, &st) < 0) if (stat(path, &st) < 0) {
die("can't read '%s'", path); pr_debug("can't read '%s'", path);
goto out;
}
if (write(output_fd, "header_page", 12) != 12) { if (write(output_fd, "header_page", 12) != 12) {
pr_debug("can't write header_page\n"); pr_debug("can't write header_page\n");
...@@ -183,11 +190,16 @@ static int read_header_files(void) ...@@ -183,11 +190,16 @@ static int read_header_files(void)
put_tracing_file(path); put_tracing_file(path);
path = get_tracing_file("events/header_event"); path = get_tracing_file("events/header_event");
if (!path) if (!path) {
die("can't get tracing/events/header_event"); pr_debug("can't get tracing/events/header_event");
err = -ENOMEM;
goto out;
}
if (stat(path, &st) < 0) if (stat(path, &st) < 0) {
die("can't read '%s'", path); pr_debug("can't read '%s'", path);
goto out;
}
if (write(output_fd, "header_event", 13) != 13) { if (write(output_fd, "header_event", 13) != 13) {
pr_debug("can't write header_event\n"); 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,8 +239,10 @@ static int copy_event_system(const char *sys, struct tracepoint_path *tps)
int err; int err;
dir = opendir(sys); dir = opendir(sys);
if (!dir) if (!dir) {
die("can't read directory '%s'", sys); pr_debug("can't read directory '%s'", sys);
return -errno;
}
while ((dent = readdir(dir))) { while ((dent = readdir(dir))) {
if (dent->d_type != DT_DIR || if (dent->d_type != DT_DIR ||
...@@ -291,8 +305,10 @@ static int read_ftrace_files(struct tracepoint_path *tps) ...@@ -291,8 +305,10 @@ static int read_ftrace_files(struct tracepoint_path *tps)
int ret; int ret;
path = get_tracing_file("events/ftrace"); path = get_tracing_file("events/ftrace");
if (!path) if (!path) {
die("can't get tracing/events/ftrace"); pr_debug("can't get tracing/events/ftrace");
return -ENOMEM;
}
ret = copy_event_system(path, tps); ret = copy_event_system(path, tps);
...@@ -324,12 +340,17 @@ static int read_event_files(struct tracepoint_path *tps) ...@@ -324,12 +340,17 @@ static int read_event_files(struct tracepoint_path *tps)
int err; int err;
path = get_tracing_file("events"); path = get_tracing_file("events");
if (!path) if (!path) {
die("can't get tracing/events"); pr_debug("can't get tracing/events");
return -ENOMEM;
}
dir = opendir(path); dir = opendir(path);
if (!dir) if (!dir) {
die("can't read directory '%s'", path); err = -errno;
pr_debug("can't read directory '%s'", path);
goto out;
}
while ((dent = readdir(dir))) { while ((dent = readdir(dir))) {
if (dent->d_type != DT_DIR || if (dent->d_type != DT_DIR ||
...@@ -408,8 +429,10 @@ static int read_ftrace_printk(void) ...@@ -408,8 +429,10 @@ static int read_ftrace_printk(void)
int ret, err = 0; int ret, err = 0;
path = get_tracing_file("printk_formats"); path = get_tracing_file("printk_formats");
if (!path) if (!path) {
die("can't get tracing/printk_formats"); pr_debug("can't get tracing/printk_formats");
return -ENOMEM;
}
ret = stat(path, &st); ret = stat(path, &st);
if (ret < 0) { if (ret < 0) {
...@@ -426,6 +449,19 @@ static int read_ftrace_printk(void) ...@@ -426,6 +449,19 @@ static int read_ftrace_printk(void)
return err; return err;
} }
static void
put_tracepoints_path(struct tracepoint_path *tps)
{
while (tps) {
struct tracepoint_path *t = tps;
tps = tps->next;
free(t->name);
free(t->system);
free(t);
}
}
static struct tracepoint_path * static struct tracepoint_path *
get_tracepoints_path(struct list_head *pattrs) get_tracepoints_path(struct list_head *pattrs)
{ {
...@@ -438,27 +474,17 @@ get_tracepoints_path(struct list_head *pattrs) ...@@ -438,27 +474,17 @@ get_tracepoints_path(struct list_head *pattrs)
continue; continue;
++nr_tracepoints; ++nr_tracepoints;
ppath->next = tracepoint_id_to_path(pos->attr.config); ppath->next = tracepoint_id_to_path(pos->attr.config);
if (!ppath->next) if (!ppath->next) {
die("%s\n", "No memory to alloc tracepoints list"); pr_debug("No memory to alloc tracepoints list\n");
put_tracepoints_path(&path);
return NULL;
}
ppath = ppath->next; ppath = ppath->next;
} }
return nr_tracepoints > 0 ? path.next : NULL; return nr_tracepoints > 0 ? path.next : NULL;
} }
static void
put_tracepoints_path(struct tracepoint_path *tps)
{
while (tps) {
struct tracepoint_path *t = tps;
tps = tps->next;
free(t->name);
free(t->system);
free(t);
}
}
bool have_tracepoints(struct list_head *pattrs) bool have_tracepoints(struct list_head *pattrs)
{ {
struct perf_evsel *pos; struct perf_evsel *pos;
...@@ -536,12 +562,16 @@ struct tracing_data *tracing_data_get(struct list_head *pattrs, ...@@ -536,12 +562,16 @@ struct tracing_data *tracing_data_get(struct list_head *pattrs,
snprintf(tdata->temp_file, sizeof(tdata->temp_file), snprintf(tdata->temp_file, sizeof(tdata->temp_file),
"/tmp/perf-XXXXXX"); "/tmp/perf-XXXXXX");
if (!mkstemp(tdata->temp_file)) if (!mkstemp(tdata->temp_file)) {
die("Can't make temp file"); pr_debug("Can't make temp file");
return NULL;
}
temp_fd = open(tdata->temp_file, O_RDWR); temp_fd = open(tdata->temp_file, O_RDWR);
if (temp_fd < 0) if (temp_fd < 0) {
die("Can't read '%s'", tdata->temp_file); pr_debug("Can't read '%s'", tdata->temp_file);
return NULL;
}
/* /*
* Set the temp file the default output, so all the * Set the temp file the default output, so all the
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment