blob: 59d43abfbfec1ce22b44ac9c2db18cd29f0ce612 [file] [log] [blame]
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -04001/*
2 * builtin-probe.c
3 *
4 * Builtin probe command: Set up probe events by C expression
5 *
6 * Written by Masami Hiramatsu <mhiramat@redhat.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 *
22 */
23#define _GNU_SOURCE
24#include <sys/utsname.h>
25#include <sys/types.h>
26#include <sys/stat.h>
27#include <fcntl.h>
28#include <errno.h>
29#include <stdio.h>
30#include <unistd.h>
31#include <stdlib.h>
32#include <string.h>
33
34#undef _GNU_SOURCE
35#include "perf.h"
36#include "builtin.h"
37#include "util/util.h"
Masami Hiramatsufa282442009-12-08 17:03:23 -050038#include "util/strlist.h"
Masami Hiramatsubd09d7b2011-01-20 23:15:39 +090039#include "util/strfilter.h"
Masami Hiramatsue0faa8d2010-03-16 18:05:37 -040040#include "util/symbol.h"
Masami Hiramatsu89c69c02009-10-16 20:08:10 -040041#include "util/debug.h"
Masami Hiramatsu96c96612009-12-16 17:24:00 -050042#include "util/debugfs.h"
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -040043#include "util/parse-options.h"
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -040044#include "util/probe-finder.h"
Masami Hiramatsu50656ee2009-11-30 19:19:58 -050045#include "util/probe-event.h"
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -040046
Masami Hiramatsubd09d7b2011-01-20 23:15:39 +090047#define DEFAULT_VAR_FILTER "!__k???tab_* & !__crc_*"
Masami Hiramatsu3c422582011-01-20 23:15:45 +090048#define DEFAULT_FUNC_FILTER "!_*"
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -040049
50/* Session management structure */
51static struct {
Masami Hiramatsufac13fd2009-12-15 10:31:14 -050052 bool list_events;
Masami Hiramatsud761b082009-12-15 10:32:25 -050053 bool force_add;
Masami Hiramatsu631c9de2010-01-06 09:45:34 -050054 bool show_lines;
Masami Hiramatsucf6eb482010-10-21 19:13:23 +090055 bool show_vars;
Masami Hiramatsufb8c5a52010-10-21 19:13:35 +090056 bool show_ext_vars;
Masami Hiramatsue80711c2011-01-13 21:46:11 +090057 bool show_funcs;
Masami Hiramatsucf6eb482010-10-21 19:13:23 +090058 bool mod_events;
Masami Hiramatsu4235b042010-03-16 18:06:12 -040059 int nevents;
60 struct perf_probe_event events[MAX_PROBES];
Masami Hiramatsufa282442009-12-08 17:03:23 -050061 struct strlist *dellist;
Masami Hiramatsu631c9de2010-01-06 09:45:34 -050062 struct line_range line_range;
Masami Hiramatsu469b9b82010-10-21 19:13:41 +090063 const char *target_module;
Masami Hiramatsuef4a3562010-04-21 15:56:40 -040064 int max_probe_points;
Masami Hiramatsubd09d7b2011-01-20 23:15:39 +090065 struct strfilter *filter;
Masami Hiramatsu12a1fad2010-03-16 18:05:44 -040066} params;
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -040067
Masami Hiramatsu253977b2009-10-27 16:43:10 -040068/* Parse an event definition. Note that any error must die. */
Masami Hiramatsu146a1432010-04-12 13:17:42 -040069static int parse_probe_event(const char *str)
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -040070{
Masami Hiramatsu4235b042010-03-16 18:06:12 -040071 struct perf_probe_event *pev = &params.events[params.nevents];
Masami Hiramatsu146a1432010-04-12 13:17:42 -040072 int ret;
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -040073
Masami Hiramatsu4235b042010-03-16 18:06:12 -040074 pr_debug("probe-definition(%d): %s\n", params.nevents, str);
Arnaldo Carvalho de Melo8a7ddad2010-05-18 22:57:27 -030075 if (++params.nevents == MAX_PROBES) {
76 pr_err("Too many probes (> %d) were specified.", MAX_PROBES);
77 return -1;
78 }
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -040079
Masami Hiramatsu4235b042010-03-16 18:06:12 -040080 /* Parse a perf-probe command into event */
Masami Hiramatsu146a1432010-04-12 13:17:42 -040081 ret = parse_perf_probe_command(str, pev);
Masami Hiramatsu4235b042010-03-16 18:06:12 -040082 pr_debug("%d arguments\n", pev->nargs);
Masami Hiramatsu146a1432010-04-12 13:17:42 -040083
84 return ret;
Masami Hiramatsu46ab4922009-10-27 16:43:02 -040085}
86
Masami Hiramatsu146a1432010-04-12 13:17:42 -040087static int parse_probe_event_argv(int argc, const char **argv)
Masami Hiramatsud1bde3f2009-12-08 17:02:54 -050088{
Masami Hiramatsu146a1432010-04-12 13:17:42 -040089 int i, len, ret;
Masami Hiramatsud1bde3f2009-12-08 17:02:54 -050090 char *buf;
91
92 /* Bind up rest arguments */
93 len = 0;
94 for (i = 0; i < argc; i++)
95 len += strlen(argv[i]) + 1;
Arnaldo Carvalho de Melo8a7ddad2010-05-18 22:57:27 -030096 buf = zalloc(len + 1);
97 if (buf == NULL)
98 return -ENOMEM;
Masami Hiramatsud1bde3f2009-12-08 17:02:54 -050099 len = 0;
100 for (i = 0; i < argc; i++)
101 len += sprintf(&buf[len], "%s ", argv[i]);
Masami Hiramatsucf6eb482010-10-21 19:13:23 +0900102 params.mod_events = true;
Masami Hiramatsu146a1432010-04-12 13:17:42 -0400103 ret = parse_probe_event(buf);
Masami Hiramatsud1bde3f2009-12-08 17:02:54 -0500104 free(buf);
Masami Hiramatsu146a1432010-04-12 13:17:42 -0400105 return ret;
Masami Hiramatsud1bde3f2009-12-08 17:02:54 -0500106}
107
Masami Hiramatsu253977b2009-10-27 16:43:10 -0400108static int opt_add_probe_event(const struct option *opt __used,
Masami Hiramatsu46ab4922009-10-27 16:43:02 -0400109 const char *str, int unset __used)
110{
Masami Hiramatsucf6eb482010-10-21 19:13:23 +0900111 if (str) {
112 params.mod_events = true;
Masami Hiramatsu146a1432010-04-12 13:17:42 -0400113 return parse_probe_event(str);
Masami Hiramatsucf6eb482010-10-21 19:13:23 +0900114 } else
Masami Hiramatsu146a1432010-04-12 13:17:42 -0400115 return 0;
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400116}
117
Masami Hiramatsufa282442009-12-08 17:03:23 -0500118static int opt_del_probe_event(const struct option *opt __used,
119 const char *str, int unset __used)
120{
121 if (str) {
Masami Hiramatsucf6eb482010-10-21 19:13:23 +0900122 params.mod_events = true;
Masami Hiramatsu12a1fad2010-03-16 18:05:44 -0400123 if (!params.dellist)
124 params.dellist = strlist__new(true, NULL);
125 strlist__add(params.dellist, str);
Masami Hiramatsufa282442009-12-08 17:03:23 -0500126 }
127 return 0;
128}
129
Masami Hiramatsu4b4da7f2010-03-22 13:10:26 -0300130#ifdef DWARF_SUPPORT
Hitoshi Mitake0eda7382010-01-16 21:31:16 +0900131static int opt_show_lines(const struct option *opt __used,
132 const char *str, int unset __used)
133{
Masami Hiramatsu146a1432010-04-12 13:17:42 -0400134 int ret = 0;
135
Masami Hiramatsu13e27d72011-08-11 20:02:53 +0900136 if (!str)
137 return 0;
138
139 if (params.show_lines) {
140 pr_warning("Warning: more than one --line options are"
141 " detected. Only the first one is valid.\n");
142 return 0;
143 }
144
Masami Hiramatsu12a1fad2010-03-16 18:05:44 -0400145 params.show_lines = true;
Masami Hiramatsu13e27d72011-08-11 20:02:53 +0900146 ret = parse_line_range_desc(str, &params.line_range);
147 INIT_LIST_HEAD(&params.line_range.line_list);
Masami Hiramatsu146a1432010-04-12 13:17:42 -0400148
149 return ret;
Hitoshi Mitake0eda7382010-01-16 21:31:16 +0900150}
Masami Hiramatsucf6eb482010-10-21 19:13:23 +0900151
152static int opt_show_vars(const struct option *opt __used,
153 const char *str, int unset __used)
154{
155 struct perf_probe_event *pev = &params.events[params.nevents];
156 int ret;
157
158 if (!str)
159 return 0;
160
161 ret = parse_probe_event(str);
162 if (!ret && pev->nargs != 0) {
163 pr_err(" Error: '--vars' doesn't accept arguments.\n");
164 return -EINVAL;
165 }
166 params.show_vars = true;
167
168 return ret;
169}
Masami Hiramatsu3c422582011-01-20 23:15:45 +0900170#endif
Masami Hiramatsubd09d7b2011-01-20 23:15:39 +0900171
172static int opt_set_filter(const struct option *opt __used,
173 const char *str, int unset __used)
174{
175 const char *err;
176
177 if (str) {
178 pr_debug2("Set filter: %s\n", str);
179 if (params.filter)
180 strfilter__delete(params.filter);
181 params.filter = strfilter__new(str, &err);
182 if (!params.filter) {
Arnaldo Carvalho de Melo823c7162011-01-31 19:45:38 -0200183 pr_err("Filter parse error at %td.\n", err - str + 1);
Masami Hiramatsubd09d7b2011-01-20 23:15:39 +0900184 pr_err("Source: \"%s\"\n", str);
185 pr_err(" %*c\n", (int)(err - str + 1), '^');
186 return -EINVAL;
187 }
188 }
189
190 return 0;
191}
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400192
193static const char * const probe_usage[] = {
Masami Hiramatsu46ab4922009-10-27 16:43:02 -0400194 "perf probe [<options>] 'PROBEDEF' ['PROBEDEF' ...]",
195 "perf probe [<options>] --add 'PROBEDEF' [--add 'PROBEDEF' ...]",
Masami Hiramatsufa282442009-12-08 17:03:23 -0500196 "perf probe [<options>] --del '[GROUP:]EVENT' ...",
Masami Hiramatsu4de189f2009-11-30 19:20:17 -0500197 "perf probe --list",
Masami Hiramatsu4b4da7f2010-03-22 13:10:26 -0300198#ifdef DWARF_SUPPORT
Masami Hiramatsu469b9b82010-10-21 19:13:41 +0900199 "perf probe [<options>] --line 'LINEDESC'",
200 "perf probe [<options>] --vars 'PROBEPOINT'",
Masami Hiramatsuf3ab4812010-02-25 08:35:12 -0500201#endif
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400202 NULL
203};
204
205static const struct option options[] = {
Ian Munsiec0555642010-04-13 18:37:33 +1000206 OPT_INCR('v', "verbose", &verbose,
Masami Hiramatsu89c69c02009-10-16 20:08:10 -0400207 "be more verbose (show parsed arguments, etc)"),
Masami Hiramatsu12a1fad2010-03-16 18:05:44 -0400208 OPT_BOOLEAN('l', "list", &params.list_events,
Masami Hiramatsufac13fd2009-12-15 10:31:14 -0500209 "list up current probe events"),
Masami Hiramatsufa282442009-12-08 17:03:23 -0500210 OPT_CALLBACK('d', "del", NULL, "[GROUP:]EVENT", "delete a probe event.",
211 opt_del_probe_event),
Masami Hiramatsu46ab4922009-10-27 16:43:02 -0400212 OPT_CALLBACK('a', "add", NULL,
Masami Hiramatsu4b4da7f2010-03-22 13:10:26 -0300213#ifdef DWARF_SUPPORT
Masami Hiramatsu32cb0dd2010-03-03 22:38:43 -0500214 "[EVENT=]FUNC[@SRC][+OFF|%return|:RL|;PT]|SRC:AL|SRC;PT"
Masami Hiramatsu48481932010-04-12 13:16:53 -0400215 " [[NAME=]ARG ...]",
Masami Hiramatsu4b4da7f2010-03-22 13:10:26 -0300216#else
Masami Hiramatsu48481932010-04-12 13:16:53 -0400217 "[EVENT=]FUNC[+OFF|%return] [[NAME=]ARG ...]",
Masami Hiramatsu23e8ec02009-10-07 18:28:30 -0400218#endif
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400219 "probe point definition, where\n"
Masami Hiramatsuaf663d72009-12-15 10:32:18 -0500220 "\t\tGROUP:\tGroup name (optional)\n"
221 "\t\tEVENT:\tEvent name\n"
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400222 "\t\tFUNC:\tFunction name\n"
Masami Hiramatsu2a9c8c32010-02-25 08:36:12 -0500223 "\t\tOFF:\tOffset from function entry (in byte)\n"
Masami Hiramatsu253977b2009-10-27 16:43:10 -0400224 "\t\t%return:\tPut the probe at function return\n"
Masami Hiramatsu4b4da7f2010-03-22 13:10:26 -0300225#ifdef DWARF_SUPPORT
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400226 "\t\tSRC:\tSource code path\n"
Masami Hiramatsu2a9c8c32010-02-25 08:36:12 -0500227 "\t\tRL:\tRelative line number from function entry.\n"
228 "\t\tAL:\tAbsolute line number in file.\n"
229 "\t\tPT:\tLazy expression of line code.\n"
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400230 "\t\tARG:\tProbe argument (local variable name or\n"
Masami Hiramatsu50656ee2009-11-30 19:19:58 -0500231 "\t\t\tkprobe-tracer argument format.)\n",
Masami Hiramatsu4b4da7f2010-03-22 13:10:26 -0300232#else
233 "\t\tARG:\tProbe argument (kprobe-tracer argument format.)\n",
234#endif
Masami Hiramatsu253977b2009-10-27 16:43:10 -0400235 opt_add_probe_event),
Masami Hiramatsu12a1fad2010-03-16 18:05:44 -0400236 OPT_BOOLEAN('f', "force", &params.force_add, "forcibly add events"
Masami Hiramatsud761b082009-12-15 10:32:25 -0500237 " with existing name"),
Masami Hiramatsu4b4da7f2010-03-22 13:10:26 -0300238#ifdef DWARF_SUPPORT
Masami Hiramatsu631c9de2010-01-06 09:45:34 -0500239 OPT_CALLBACK('L', "line", NULL,
Masami Hiramatsu085ea732010-04-02 12:50:39 -0400240 "FUNC[:RLN[+NUM|-RLN2]]|SRC:ALN[+NUM|-ALN2]",
Masami Hiramatsu631c9de2010-01-06 09:45:34 -0500241 "Show source code lines.", opt_show_lines),
Masami Hiramatsucf6eb482010-10-21 19:13:23 +0900242 OPT_CALLBACK('V', "vars", NULL,
243 "FUNC[@SRC][+OFF|%return|:RL|;PT]|SRC:AL|SRC;PT",
244 "Show accessible variables on PROBEDEF", opt_show_vars),
Masami Hiramatsufb8c5a52010-10-21 19:13:35 +0900245 OPT_BOOLEAN('\0', "externs", &params.show_ext_vars,
246 "Show external variables too (with --vars only)"),
Masami Hiramatsu4b4da7f2010-03-22 13:10:26 -0300247 OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,
248 "file", "vmlinux pathname"),
Chase Douglas9ed7e1b2010-06-14 15:26:30 -0400249 OPT_STRING('s', "source", &symbol_conf.source_prefix,
250 "directory", "path to kernel source"),
Masami Hiramatsu469b9b82010-10-21 19:13:41 +0900251 OPT_STRING('m', "module", &params.target_module,
Masami Hiramatsu14a8fd72011-06-27 16:27:51 +0900252 "modname|path",
253 "target module name (for online) or path (for offline)"),
Masami Hiramatsu631c9de2010-01-06 09:45:34 -0500254#endif
Masami Hiramatsuf4d7da42010-03-16 18:06:05 -0400255 OPT__DRY_RUN(&probe_event_dry_run),
Masami Hiramatsuef4a3562010-04-21 15:56:40 -0400256 OPT_INTEGER('\0', "max-probes", &params.max_probe_points,
257 "Set how many probe points can be found for a probe."),
Masami Hiramatsue80711c2011-01-13 21:46:11 +0900258 OPT_BOOLEAN('F', "funcs", &params.show_funcs,
259 "Show potential probe-able functions."),
Masami Hiramatsu3c422582011-01-20 23:15:45 +0900260 OPT_CALLBACK('\0', "filter", NULL,
261 "[!]FILTER", "Set a filter (with --vars/funcs only)\n"
262 "\t\t\t(default: \"" DEFAULT_VAR_FILTER "\" for --vars,\n"
263 "\t\t\t \"" DEFAULT_FUNC_FILTER "\" for --funcs)",
264 opt_set_filter),
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400265 OPT_END()
266};
267
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400268int cmd_probe(int argc, const char **argv, const char *prefix __used)
269{
Masami Hiramatsu146a1432010-04-12 13:17:42 -0400270 int ret;
271
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400272 argc = parse_options(argc, argv, options, probe_usage,
Masami Hiramatsu46ab4922009-10-27 16:43:02 -0400273 PARSE_OPT_STOP_AT_NON_OPTION);
Masami Hiramatsuce11a602009-12-15 10:31:28 -0500274 if (argc > 0) {
275 if (strcmp(argv[0], "-") == 0) {
276 pr_warning(" Error: '-' is not supported.\n");
277 usage_with_options(probe_usage, options);
278 }
Masami Hiramatsu146a1432010-04-12 13:17:42 -0400279 ret = parse_probe_event_argv(argc, argv);
280 if (ret < 0) {
281 pr_err(" Error: Parse Error. (%d)\n", ret);
282 return ret;
283 }
Masami Hiramatsuce11a602009-12-15 10:31:28 -0500284 }
Masami Hiramatsu46ab4922009-10-27 16:43:02 -0400285
Masami Hiramatsuef4a3562010-04-21 15:56:40 -0400286 if (params.max_probe_points == 0)
287 params.max_probe_points = MAX_PROBES;
288
Masami Hiramatsu4235b042010-03-16 18:06:12 -0400289 if ((!params.nevents && !params.dellist && !params.list_events &&
Masami Hiramatsue80711c2011-01-13 21:46:11 +0900290 !params.show_lines && !params.show_funcs))
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400291 usage_with_options(probe_usage, options);
292
Franck Bui-Huufd930ff2010-12-10 14:06:03 +0100293 /*
294 * Only consider the user's kernel image path if given.
295 */
296 symbol_conf.try_vmlinux_path = (symbol_conf.vmlinux_name == NULL);
297
Masami Hiramatsu12a1fad2010-03-16 18:05:44 -0400298 if (params.list_events) {
Masami Hiramatsucf6eb482010-10-21 19:13:23 +0900299 if (params.mod_events) {
Masami Hiramatsu146a1432010-04-12 13:17:42 -0400300 pr_err(" Error: Don't use --list with --add/--del.\n");
Masami Hiramatsufa282442009-12-08 17:03:23 -0500301 usage_with_options(probe_usage, options);
302 }
Masami Hiramatsu12a1fad2010-03-16 18:05:44 -0400303 if (params.show_lines) {
Masami Hiramatsu146a1432010-04-12 13:17:42 -0400304 pr_err(" Error: Don't use --list with --line.\n");
Masami Hiramatsu631c9de2010-01-06 09:45:34 -0500305 usage_with_options(probe_usage, options);
306 }
Masami Hiramatsucf6eb482010-10-21 19:13:23 +0900307 if (params.show_vars) {
308 pr_err(" Error: Don't use --list with --vars.\n");
309 usage_with_options(probe_usage, options);
310 }
Masami Hiramatsue80711c2011-01-13 21:46:11 +0900311 if (params.show_funcs) {
312 pr_err(" Error: Don't use --list with --funcs.\n");
313 usage_with_options(probe_usage, options);
314 }
Masami Hiramatsu146a1432010-04-12 13:17:42 -0400315 ret = show_perf_probe_events();
316 if (ret < 0)
317 pr_err(" Error: Failed to show event list. (%d)\n",
318 ret);
319 return ret;
Masami Hiramatsu4de189f2009-11-30 19:20:17 -0500320 }
Masami Hiramatsue80711c2011-01-13 21:46:11 +0900321 if (params.show_funcs) {
322 if (params.nevents != 0 || params.dellist) {
323 pr_err(" Error: Don't use --funcs with"
324 " --add/--del.\n");
325 usage_with_options(probe_usage, options);
326 }
327 if (params.show_lines) {
328 pr_err(" Error: Don't use --funcs with --line.\n");
329 usage_with_options(probe_usage, options);
330 }
331 if (params.show_vars) {
332 pr_err(" Error: Don't use --funcs with --vars.\n");
333 usage_with_options(probe_usage, options);
334 }
Masami Hiramatsu3c422582011-01-20 23:15:45 +0900335 if (!params.filter)
336 params.filter = strfilter__new(DEFAULT_FUNC_FILTER,
337 NULL);
338 ret = show_available_funcs(params.target_module,
339 params.filter);
340 strfilter__delete(params.filter);
Masami Hiramatsue80711c2011-01-13 21:46:11 +0900341 if (ret < 0)
342 pr_err(" Error: Failed to show functions."
343 " (%d)\n", ret);
344 return ret;
345 }
Masami Hiramatsu4de189f2009-11-30 19:20:17 -0500346
Masami Hiramatsu4b4da7f2010-03-22 13:10:26 -0300347#ifdef DWARF_SUPPORT
Masami Hiramatsu12a1fad2010-03-16 18:05:44 -0400348 if (params.show_lines) {
Masami Hiramatsucf6eb482010-10-21 19:13:23 +0900349 if (params.mod_events) {
350 pr_err(" Error: Don't use --line with"
351 " --add/--del.\n");
352 usage_with_options(probe_usage, options);
353 }
354 if (params.show_vars) {
355 pr_err(" Error: Don't use --line with --vars.\n");
Masami Hiramatsu631c9de2010-01-06 09:45:34 -0500356 usage_with_options(probe_usage, options);
357 }
Masami Hiramatsue0faa8d2010-03-16 18:05:37 -0400358
Masami Hiramatsu469b9b82010-10-21 19:13:41 +0900359 ret = show_line_range(&params.line_range, params.target_module);
Masami Hiramatsu146a1432010-04-12 13:17:42 -0400360 if (ret < 0)
361 pr_err(" Error: Failed to show lines. (%d)\n", ret);
362 return ret;
Masami Hiramatsu631c9de2010-01-06 09:45:34 -0500363 }
Masami Hiramatsucf6eb482010-10-21 19:13:23 +0900364 if (params.show_vars) {
365 if (params.mod_events) {
366 pr_err(" Error: Don't use --vars with"
367 " --add/--del.\n");
368 usage_with_options(probe_usage, options);
369 }
Masami Hiramatsubd09d7b2011-01-20 23:15:39 +0900370 if (!params.filter)
371 params.filter = strfilter__new(DEFAULT_VAR_FILTER,
372 NULL);
373
Masami Hiramatsucf6eb482010-10-21 19:13:23 +0900374 ret = show_available_vars(params.events, params.nevents,
Masami Hiramatsufb8c5a52010-10-21 19:13:35 +0900375 params.max_probe_points,
Masami Hiramatsu469b9b82010-10-21 19:13:41 +0900376 params.target_module,
Masami Hiramatsubd09d7b2011-01-20 23:15:39 +0900377 params.filter,
Masami Hiramatsufb8c5a52010-10-21 19:13:35 +0900378 params.show_ext_vars);
Masami Hiramatsubd09d7b2011-01-20 23:15:39 +0900379 strfilter__delete(params.filter);
Masami Hiramatsucf6eb482010-10-21 19:13:23 +0900380 if (ret < 0)
381 pr_err(" Error: Failed to show vars. (%d)\n", ret);
382 return ret;
383 }
Masami Hiramatsu631c9de2010-01-06 09:45:34 -0500384#endif
385
Masami Hiramatsu12a1fad2010-03-16 18:05:44 -0400386 if (params.dellist) {
Masami Hiramatsu146a1432010-04-12 13:17:42 -0400387 ret = del_perf_probe_events(params.dellist);
Masami Hiramatsu12a1fad2010-03-16 18:05:44 -0400388 strlist__delete(params.dellist);
Masami Hiramatsu146a1432010-04-12 13:17:42 -0400389 if (ret < 0) {
390 pr_err(" Error: Failed to delete events. (%d)\n", ret);
391 return ret;
392 }
Masami Hiramatsufa282442009-12-08 17:03:23 -0500393 }
394
Masami Hiramatsu146a1432010-04-12 13:17:42 -0400395 if (params.nevents) {
396 ret = add_perf_probe_events(params.events, params.nevents,
Masami Hiramatsuc82ec0a2010-10-21 19:13:29 +0900397 params.max_probe_points,
Masami Hiramatsu469b9b82010-10-21 19:13:41 +0900398 params.target_module,
Masami Hiramatsuc82ec0a2010-10-21 19:13:29 +0900399 params.force_add);
Masami Hiramatsu146a1432010-04-12 13:17:42 -0400400 if (ret < 0) {
401 pr_err(" Error: Failed to add events. (%d)\n", ret);
402 return ret;
403 }
404 }
Masami Hiramatsu4ea42b12009-10-08 17:17:38 -0400405 return 0;
406}