summaryrefslogtreecommitdiff
path: root/tools/perf/builtin-probe.c
diff options
context:
space:
mode:
authorMasami Hiramatsu <mhiramat@redhat.com>2009-10-17 00:08:01 (GMT)
committerIngo Molnar <mingo@elte.hu>2009-10-17 07:54:00 (GMT)
commit074fc0e4b3f5d24306c2995f2f3b0bd4759e8aeb (patch)
tree485c1ac28a03ed0558eb443e1212eaf6ceee2c63 /tools/perf/builtin-probe.c
parent4c20194c2de151bca14224ae384b47abf7636a95 (diff)
downloadlinux-074fc0e4b3f5d24306c2995f2f3b0bd4759e8aeb.tar.xz
perf: Use die() for error cases in perf-probe
Use die() for exiting perf-probe with errors. This replaces perror_exit(), msg_exit() and fprintf()+exit() with die(), and uses die() in semantic_error(). This also renames 'die' local variables to 'dw_die' for avoiding name confliction. Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> LKML-Reference: <20091017000801.16556.46866.stgit@dhcp-100-2-132.bos.redhat.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools/perf/builtin-probe.c')
-rw-r--r--tools/perf/builtin-probe.c47
1 files changed, 14 insertions, 33 deletions
diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c
index 73c883b..a1467d1 100644
--- a/tools/perf/builtin-probe.c
+++ b/tools/perf/builtin-probe.c
@@ -49,6 +49,7 @@ const char *default_search_path[NR_SEARCH_PATH] = {
#define MAX_PATH_LEN 256
#define MAX_PROBES 128
+#define MAX_PROBE_ARGS 128
/* Session management structure */
static struct {
@@ -60,19 +61,7 @@ static struct {
char *events[MAX_PROBES];
} session;
-static void semantic_error(const char *msg)
-{
- fprintf(stderr, "Semantic error: %s\n", msg);
- exit(1);
-}
-
-static void perror_exit(const char *msg)
-{
- perror(msg);
- exit(1);
-}
-
-#define MAX_PROBE_ARGS 128
+#define semantic_error(msg ...) die("Semantic error :" msg)
static int parse_probepoint(const struct option *opt __used,
const char *str, int unset __used)
@@ -109,7 +98,7 @@ static int parse_probepoint(const struct option *opt __used,
/* Duplicate the argument */
argv[argc] = strndup(s, str - s);
if (argv[argc] == NULL)
- perror_exit("strndup");
+ die("strndup");
if (++argc == MAX_PROBE_ARGS)
semantic_error("Too many arguments");
debug("argv[%d]=%s\n", argc, argv[argc - 1]);
@@ -171,7 +160,7 @@ static int parse_probepoint(const struct option *opt __used,
if (pp->nr_args > 0) {
pp->args = (char **)malloc(sizeof(char *) * pp->nr_args);
if (!pp->args)
- perror_exit("malloc");
+ die("malloc");
memcpy(pp->args, &argv[2], sizeof(char *) * pp->nr_args);
}
@@ -260,7 +249,7 @@ static int write_new_event(int fd, const char *buf)
printf("Adding new event: %s\n", buf);
ret = write(fd, buf, strlen(buf));
if (ret <= 0)
- perror("Error: Failed to create event");
+ die("failed to create event.");
return ret;
}
@@ -273,7 +262,7 @@ static int synthesize_probepoint(struct probe_point *pp)
int i, len, ret;
pp->probes[0] = buf = (char *)calloc(MAX_CMDLEN, sizeof(char));
if (!buf)
- perror_exit("calloc");
+ die("calloc");
ret = snprintf(buf, MAX_CMDLEN, "%s+%d", pp->function, pp->offset);
if (ret <= 0 || ret >= MAX_CMDLEN)
goto error;
@@ -322,10 +311,8 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used)
ret = synthesize_probepoint(&session.probes[j]);
if (ret == -E2BIG)
semantic_error("probe point is too long.");
- else if (ret < 0) {
- perror("snprintf");
- return -1;
- }
+ else if (ret < 0)
+ die("snprintf");
}
#ifndef NO_LIBDWARF
@@ -336,10 +323,8 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used)
fd = open(session.vmlinux, O_RDONLY);
else
fd = open_default_vmlinux();
- if (fd < 0) {
- perror("vmlinux/module file open");
- return -1;
- }
+ if (fd < 0)
+ die("vmlinux/module file open");
/* Searching probe points */
for (j = 0; j < session.nr_probe; j++) {
@@ -349,10 +334,8 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used)
lseek(fd, SEEK_SET, 0);
ret = find_probepoint(fd, pp);
- if (ret <= 0) {
- fprintf(stderr, "Error: No probe point found.\n");
- return -1;
- }
+ if (ret <= 0)
+ die("No probe point found.\n");
debug("probe event %s found\n", session.events[j]);
}
close(fd);
@@ -363,10 +346,8 @@ setup_probes:
/* Settng up probe points */
snprintf(buf, MAX_CMDLEN, "%s/../kprobe_events", debugfs_path);
fd = open(buf, O_WRONLY, O_APPEND);
- if (fd < 0) {
- perror("kprobe_events open");
- return -1;
- }
+ if (fd < 0)
+ die("kprobe_events open");
for (j = 0; j < session.nr_probe; j++) {
pp = &session.probes[j];
if (pp->found == 1) {