Commit 146a1439 authored by Masami Hiramatsu's avatar Masami Hiramatsu Committed by 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: default avatarMasami Hiramatsu <mhiramat@redhat.com>
Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent b55a87ad
......@@ -59,23 +59,25 @@ static struct {
/* 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];
int ret;
pr_debug("probe-definition(%d): %s\n", params.nevents, str);
if (++params.nevents == MAX_PROBES)
die("Too many probes (> %d) are specified.", MAX_PROBES);
/* 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);
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;
/* Bind up rest arguments */
......@@ -86,16 +88,18 @@ static void parse_probe_event_argv(int argc, const char **argv)
len = 0;
for (i = 0; i < argc; i++)
len += sprintf(&buf[len], "%s ", argv[i]);
parse_probe_event(buf);
ret = parse_probe_event(buf);
free(buf);
return ret;
}
static int opt_add_probe_event(const struct option *opt __used,
const char *str, int unset __used)
{
if (str)
parse_probe_event(str);
return 0;
return parse_probe_event(str);
else
return 0;
}
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,
const char *str, int unset __used)
{
int ret = 0;
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);
params.show_lines = true;
return 0;
return ret;
}
#endif
......@@ -178,6 +185,8 @@ static const struct option options[] = {
int cmd_probe(int argc, const char **argv, const char *prefix __used)
{
int ret;
argc = parse_options(argc, argv, options, probe_usage,
PARSE_OPT_STOP_AT_NON_OPTION);
if (argc > 0) {
......@@ -185,7 +194,11 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used)
pr_warning(" Error: '-' is not supported.\n");
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 &&
......@@ -197,16 +210,18 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used)
if (params.list_events) {
if (params.nevents != 0 || params.dellist) {
pr_warning(" Error: Don't use --list with"
" --add/--del.\n");
pr_err(" Error: Don't use --list with --add/--del.\n");
usage_with_options(probe_usage, options);
}
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);
}
show_perf_probe_events();
return 0;
ret = show_perf_probe_events();
if (ret < 0)
pr_err(" Error: Failed to show event list. (%d)\n",
ret);
return ret;
}
#ifdef DWARF_SUPPORT
......@@ -217,19 +232,30 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used)
usage_with_options(probe_usage, options);
}
show_line_range(&params.line_range);
return 0;
ret = show_line_range(&params.line_range);
if (ret < 0)
pr_err(" Error: Failed to show lines. (%d)\n", ret);
return ret;
}
#endif
if (params.dellist) {
del_perf_probe_events(params.dellist);
ret = del_perf_probe_events(params.dellist);
strlist__delete(params.dellist);
if (params.nevents == 0)
return 0;
if (ret < 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;
}
This diff is collapsed.
......@@ -89,10 +89,10 @@ struct line_range {
};
/* Command string to events */
extern void parse_perf_probe_command(const char *cmd,
struct perf_probe_event *pev);
extern void parse_kprobe_trace_command(const char *cmd,
struct kprobe_trace_event *tev);
extern int parse_perf_probe_command(const char *cmd,
struct perf_probe_event *pev);
extern int parse_kprobe_trace_command(const char *cmd,
struct kprobe_trace_event *tev);
/* Events to command string */
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,
extern bool perf_probe_event_need_dwarf(struct perf_probe_event *pev);
/* Convert from kprobe_trace_event to perf_probe_event */
extern void convert_to_perf_probe_event(struct kprobe_trace_event *tev,
struct perf_probe_event *pev);
extern int convert_to_perf_probe_event(struct kprobe_trace_event *tev,
struct perf_probe_event *pev);
/* Release event contents */
extern void clear_perf_probe_event(struct perf_probe_event *pev);
extern void clear_kprobe_trace_event(struct kprobe_trace_event *tev);
/* 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,
bool force_add);
extern void del_perf_probe_events(struct strlist *dellist);
extern void show_perf_probe_events(void);
extern void show_line_range(struct line_range *lr);
extern int add_perf_probe_events(struct perf_probe_event *pevs, int ntevs,
bool force_add);
extern int del_perf_probe_events(struct strlist *dellist);
extern int show_perf_probe_events(void);
extern int show_line_range(struct line_range *lr);
/* Maximum index number of event-name postfix */
......
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