提交 146a1439 编写于 作者: M Masami Hiramatsu 提交者: Arnaldo Carvalho de Melo

perf probe: Remove die() from probe-event code

Remove die() and DIE_IF() code from util/probe-event.c since
these 'sudden death' in utility functions make reusing it from
other code (especially tui/gui) difficult.

Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
LKML-Reference: <20100412171742.3790.33650.stgit@localhost6.localdomain6>
Signed-off-by: NMasami Hiramatsu <mhiramat@redhat.com>
Signed-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
上级 b55a87ad
...@@ -59,23 +59,25 @@ static struct { ...@@ -59,23 +59,25 @@ static struct {
/* Parse an event definition. Note that any error must die. */ /* Parse an event definition. Note that any error must die. */
static void parse_probe_event(const char *str) static int parse_probe_event(const char *str)
{ {
struct perf_probe_event *pev = &params.events[params.nevents]; struct perf_probe_event *pev = &params.events[params.nevents];
int ret;
pr_debug("probe-definition(%d): %s\n", params.nevents, str); pr_debug("probe-definition(%d): %s\n", params.nevents, str);
if (++params.nevents == MAX_PROBES) if (++params.nevents == MAX_PROBES)
die("Too many probes (> %d) are specified.", MAX_PROBES); die("Too many probes (> %d) are specified.", MAX_PROBES);
/* Parse a perf-probe command into event */ /* Parse a perf-probe command into event */
parse_perf_probe_command(str, pev); ret = parse_perf_probe_command(str, pev);
pr_debug("%d arguments\n", pev->nargs); pr_debug("%d arguments\n", pev->nargs);
return ret;
} }
static void parse_probe_event_argv(int argc, const char **argv) static int parse_probe_event_argv(int argc, const char **argv)
{ {
int i, len; int i, len, ret;
char *buf; char *buf;
/* Bind up rest arguments */ /* Bind up rest arguments */
...@@ -86,16 +88,18 @@ static void parse_probe_event_argv(int argc, const char **argv) ...@@ -86,16 +88,18 @@ static void parse_probe_event_argv(int argc, const char **argv)
len = 0; len = 0;
for (i = 0; i < argc; i++) for (i = 0; i < argc; i++)
len += sprintf(&buf[len], "%s ", argv[i]); len += sprintf(&buf[len], "%s ", argv[i]);
parse_probe_event(buf); ret = parse_probe_event(buf);
free(buf); free(buf);
return ret;
} }
static int opt_add_probe_event(const struct option *opt __used, static int opt_add_probe_event(const struct option *opt __used,
const char *str, int unset __used) const char *str, int unset __used)
{ {
if (str) if (str)
parse_probe_event(str); return parse_probe_event(str);
return 0; else
return 0;
} }
static int opt_del_probe_event(const struct option *opt __used, static int opt_del_probe_event(const struct option *opt __used,
...@@ -113,11 +117,14 @@ static int opt_del_probe_event(const struct option *opt __used, ...@@ -113,11 +117,14 @@ static int opt_del_probe_event(const struct option *opt __used,
static int opt_show_lines(const struct option *opt __used, static int opt_show_lines(const struct option *opt __used,
const char *str, int unset __used) const char *str, int unset __used)
{ {
int ret = 0;
if (str) if (str)
parse_line_range_desc(str, &params.line_range); ret = parse_line_range_desc(str, &params.line_range);
INIT_LIST_HEAD(&params.line_range.line_list); INIT_LIST_HEAD(&params.line_range.line_list);
params.show_lines = true; params.show_lines = true;
return 0;
return ret;
} }
#endif #endif
...@@ -178,6 +185,8 @@ static const struct option options[] = { ...@@ -178,6 +185,8 @@ static const struct option options[] = {
int cmd_probe(int argc, const char **argv, const char *prefix __used) int cmd_probe(int argc, const char **argv, const char *prefix __used)
{ {
int ret;
argc = parse_options(argc, argv, options, probe_usage, argc = parse_options(argc, argv, options, probe_usage,
PARSE_OPT_STOP_AT_NON_OPTION); PARSE_OPT_STOP_AT_NON_OPTION);
if (argc > 0) { if (argc > 0) {
...@@ -185,7 +194,11 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used) ...@@ -185,7 +194,11 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used)
pr_warning(" Error: '-' is not supported.\n"); pr_warning(" Error: '-' is not supported.\n");
usage_with_options(probe_usage, options); usage_with_options(probe_usage, options);
} }
parse_probe_event_argv(argc, argv); ret = parse_probe_event_argv(argc, argv);
if (ret < 0) {
pr_err(" Error: Parse Error. (%d)\n", ret);
return ret;
}
} }
if ((!params.nevents && !params.dellist && !params.list_events && if ((!params.nevents && !params.dellist && !params.list_events &&
...@@ -197,16 +210,18 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used) ...@@ -197,16 +210,18 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used)
if (params.list_events) { if (params.list_events) {
if (params.nevents != 0 || params.dellist) { if (params.nevents != 0 || params.dellist) {
pr_warning(" Error: Don't use --list with" pr_err(" Error: Don't use --list with --add/--del.\n");
" --add/--del.\n");
usage_with_options(probe_usage, options); usage_with_options(probe_usage, options);
} }
if (params.show_lines) { if (params.show_lines) {
pr_warning(" Error: Don't use --list with --line.\n"); pr_err(" Error: Don't use --list with --line.\n");
usage_with_options(probe_usage, options); usage_with_options(probe_usage, options);
} }
show_perf_probe_events(); ret = show_perf_probe_events();
return 0; if (ret < 0)
pr_err(" Error: Failed to show event list. (%d)\n",
ret);
return ret;
} }
#ifdef DWARF_SUPPORT #ifdef DWARF_SUPPORT
...@@ -217,19 +232,30 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used) ...@@ -217,19 +232,30 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used)
usage_with_options(probe_usage, options); usage_with_options(probe_usage, options);
} }
show_line_range(&params.line_range); ret = show_line_range(&params.line_range);
return 0; if (ret < 0)
pr_err(" Error: Failed to show lines. (%d)\n", ret);
return ret;
} }
#endif #endif
if (params.dellist) { if (params.dellist) {
del_perf_probe_events(params.dellist); ret = del_perf_probe_events(params.dellist);
strlist__delete(params.dellist); strlist__delete(params.dellist);
if (params.nevents == 0) if (ret < 0) {
return 0; pr_err(" Error: Failed to delete events. (%d)\n", ret);
return ret;
}
} }
add_perf_probe_events(params.events, params.nevents, params.force_add); if (params.nevents) {
ret = add_perf_probe_events(params.events, params.nevents,
params.force_add);
if (ret < 0) {
pr_err(" Error: Failed to add events. (%d)\n", ret);
return ret;
}
}
return 0; return 0;
} }
此差异已折叠。
...@@ -89,10 +89,10 @@ struct line_range { ...@@ -89,10 +89,10 @@ struct line_range {
}; };
/* Command string to events */ /* Command string to events */
extern void parse_perf_probe_command(const char *cmd, extern int parse_perf_probe_command(const char *cmd,
struct perf_probe_event *pev); struct perf_probe_event *pev);
extern void parse_kprobe_trace_command(const char *cmd, extern int parse_kprobe_trace_command(const char *cmd,
struct kprobe_trace_event *tev); struct kprobe_trace_event *tev);
/* Events to command string */ /* Events to command string */
extern char *synthesize_perf_probe_command(struct perf_probe_event *pev); extern char *synthesize_perf_probe_command(struct perf_probe_event *pev);
...@@ -104,22 +104,22 @@ extern int synthesize_perf_probe_arg(struct perf_probe_arg *pa, char *buf, ...@@ -104,22 +104,22 @@ extern int synthesize_perf_probe_arg(struct perf_probe_arg *pa, char *buf,
extern bool perf_probe_event_need_dwarf(struct perf_probe_event *pev); extern bool perf_probe_event_need_dwarf(struct perf_probe_event *pev);
/* Convert from kprobe_trace_event to perf_probe_event */ /* Convert from kprobe_trace_event to perf_probe_event */
extern void convert_to_perf_probe_event(struct kprobe_trace_event *tev, extern int convert_to_perf_probe_event(struct kprobe_trace_event *tev,
struct perf_probe_event *pev); struct perf_probe_event *pev);
/* Release event contents */ /* Release event contents */
extern void clear_perf_probe_event(struct perf_probe_event *pev); extern void clear_perf_probe_event(struct perf_probe_event *pev);
extern void clear_kprobe_trace_event(struct kprobe_trace_event *tev); extern void clear_kprobe_trace_event(struct kprobe_trace_event *tev);
/* Command string to line-range */ /* Command string to line-range */
extern void parse_line_range_desc(const char *cmd, struct line_range *lr); extern int parse_line_range_desc(const char *cmd, struct line_range *lr);
extern void add_perf_probe_events(struct perf_probe_event *pevs, int ntevs, extern int add_perf_probe_events(struct perf_probe_event *pevs, int ntevs,
bool force_add); bool force_add);
extern void del_perf_probe_events(struct strlist *dellist); extern int del_perf_probe_events(struct strlist *dellist);
extern void show_perf_probe_events(void); extern int show_perf_probe_events(void);
extern void show_line_range(struct line_range *lr); extern int show_line_range(struct line_range *lr);
/* Maximum index number of event-name postfix */ /* Maximum index number of event-name postfix */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册