builtin-probe.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. /*
  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. #include <sys/utsname.h>
  24. #include <sys/types.h>
  25. #include <sys/stat.h>
  26. #include <fcntl.h>
  27. #include <errno.h>
  28. #include <stdio.h>
  29. #include <unistd.h>
  30. #include <stdlib.h>
  31. #include <string.h>
  32. #include "perf.h"
  33. #include "builtin.h"
  34. #include "util/util.h"
  35. #include "util/strlist.h"
  36. #include "util/strfilter.h"
  37. #include "util/symbol.h"
  38. #include "util/debug.h"
  39. #include <subcmd/parse-options.h>
  40. #include "util/probe-finder.h"
  41. #include "util/probe-event.h"
  42. #include "util/probe-file.h"
  43. #define DEFAULT_VAR_FILTER "!__k???tab_* & !__crc_*"
  44. #define DEFAULT_FUNC_FILTER "!_*"
  45. #define DEFAULT_LIST_FILTER "*"
  46. /* Session management structure */
  47. static struct {
  48. int command; /* Command short_name */
  49. bool list_events;
  50. bool uprobes;
  51. bool quiet;
  52. bool target_used;
  53. int nevents;
  54. struct perf_probe_event events[MAX_PROBES];
  55. struct line_range line_range;
  56. char *target;
  57. struct strfilter *filter;
  58. } params;
  59. /* Parse an event definition. Note that any error must die. */
  60. static int parse_probe_event(const char *str)
  61. {
  62. struct perf_probe_event *pev = &params.events[params.nevents];
  63. int ret;
  64. pr_debug("probe-definition(%d): %s\n", params.nevents, str);
  65. if (++params.nevents == MAX_PROBES) {
  66. pr_err("Too many probes (> %d) were specified.", MAX_PROBES);
  67. return -1;
  68. }
  69. pev->uprobes = params.uprobes;
  70. if (params.target) {
  71. pev->target = strdup(params.target);
  72. if (!pev->target)
  73. return -ENOMEM;
  74. params.target_used = true;
  75. }
  76. /* Parse a perf-probe command into event */
  77. ret = parse_perf_probe_command(str, pev);
  78. pr_debug("%d arguments\n", pev->nargs);
  79. return ret;
  80. }
  81. static int params_add_filter(const char *str)
  82. {
  83. const char *err = NULL;
  84. int ret = 0;
  85. pr_debug2("Add filter: %s\n", str);
  86. if (!params.filter) {
  87. params.filter = strfilter__new(str, &err);
  88. if (!params.filter)
  89. ret = err ? -EINVAL : -ENOMEM;
  90. } else
  91. ret = strfilter__or(params.filter, str, &err);
  92. if (ret == -EINVAL) {
  93. pr_err("Filter parse error at %td.\n", err - str + 1);
  94. pr_err("Source: \"%s\"\n", str);
  95. pr_err(" %*c\n", (int)(err - str + 1), '^');
  96. }
  97. return ret;
  98. }
  99. static int set_target(const char *ptr)
  100. {
  101. int found = 0;
  102. const char *buf;
  103. /*
  104. * The first argument after options can be an absolute path
  105. * to an executable / library or kernel module.
  106. *
  107. * TODO: Support relative path, and $PATH, $LD_LIBRARY_PATH,
  108. * short module name.
  109. */
  110. if (!params.target && ptr && *ptr == '/') {
  111. params.target = strdup(ptr);
  112. if (!params.target)
  113. return -ENOMEM;
  114. params.target_used = false;
  115. found = 1;
  116. buf = ptr + (strlen(ptr) - 3);
  117. if (strcmp(buf, ".ko"))
  118. params.uprobes = true;
  119. }
  120. return found;
  121. }
  122. static int parse_probe_event_argv(int argc, const char **argv)
  123. {
  124. int i, len, ret, found_target;
  125. char *buf;
  126. found_target = set_target(argv[0]);
  127. if (found_target < 0)
  128. return found_target;
  129. if (found_target && argc == 1)
  130. return 0;
  131. /* Bind up rest arguments */
  132. len = 0;
  133. for (i = 0; i < argc; i++) {
  134. if (i == 0 && found_target)
  135. continue;
  136. len += strlen(argv[i]) + 1;
  137. }
  138. buf = zalloc(len + 1);
  139. if (buf == NULL)
  140. return -ENOMEM;
  141. len = 0;
  142. for (i = 0; i < argc; i++) {
  143. if (i == 0 && found_target)
  144. continue;
  145. len += sprintf(&buf[len], "%s ", argv[i]);
  146. }
  147. ret = parse_probe_event(buf);
  148. free(buf);
  149. return ret;
  150. }
  151. static int opt_set_target(const struct option *opt, const char *str,
  152. int unset __maybe_unused)
  153. {
  154. int ret = -ENOENT;
  155. char *tmp;
  156. if (str) {
  157. if (!strcmp(opt->long_name, "exec"))
  158. params.uprobes = true;
  159. else if (!strcmp(opt->long_name, "module"))
  160. params.uprobes = false;
  161. else
  162. return ret;
  163. /* Expand given path to absolute path, except for modulename */
  164. if (params.uprobes || strchr(str, '/')) {
  165. tmp = realpath(str, NULL);
  166. if (!tmp) {
  167. pr_warning("Failed to get the absolute path of %s: %m\n", str);
  168. return ret;
  169. }
  170. } else {
  171. tmp = strdup(str);
  172. if (!tmp)
  173. return -ENOMEM;
  174. }
  175. free(params.target);
  176. params.target = tmp;
  177. params.target_used = false;
  178. ret = 0;
  179. }
  180. return ret;
  181. }
  182. /* Command option callbacks */
  183. #ifdef HAVE_DWARF_SUPPORT
  184. static int opt_show_lines(const struct option *opt,
  185. const char *str, int unset __maybe_unused)
  186. {
  187. int ret = 0;
  188. if (!str)
  189. return 0;
  190. if (params.command == 'L') {
  191. pr_warning("Warning: more than one --line options are"
  192. " detected. Only the first one is valid.\n");
  193. return 0;
  194. }
  195. params.command = opt->short_name;
  196. ret = parse_line_range_desc(str, &params.line_range);
  197. return ret;
  198. }
  199. static int opt_show_vars(const struct option *opt,
  200. const char *str, int unset __maybe_unused)
  201. {
  202. struct perf_probe_event *pev = &params.events[params.nevents];
  203. int ret;
  204. if (!str)
  205. return 0;
  206. ret = parse_probe_event(str);
  207. if (!ret && pev->nargs != 0) {
  208. pr_err(" Error: '--vars' doesn't accept arguments.\n");
  209. return -EINVAL;
  210. }
  211. params.command = opt->short_name;
  212. return ret;
  213. }
  214. #else
  215. # define opt_show_lines NULL
  216. # define opt_show_vars NULL
  217. #endif
  218. static int opt_add_probe_event(const struct option *opt,
  219. const char *str, int unset __maybe_unused)
  220. {
  221. if (str) {
  222. params.command = opt->short_name;
  223. return parse_probe_event(str);
  224. }
  225. return 0;
  226. }
  227. static int opt_set_filter_with_command(const struct option *opt,
  228. const char *str, int unset)
  229. {
  230. if (!unset)
  231. params.command = opt->short_name;
  232. if (str)
  233. return params_add_filter(str);
  234. return 0;
  235. }
  236. static int opt_set_filter(const struct option *opt __maybe_unused,
  237. const char *str, int unset __maybe_unused)
  238. {
  239. if (str)
  240. return params_add_filter(str);
  241. return 0;
  242. }
  243. static int init_params(void)
  244. {
  245. return line_range__init(&params.line_range);
  246. }
  247. static void cleanup_params(void)
  248. {
  249. int i;
  250. for (i = 0; i < params.nevents; i++)
  251. clear_perf_probe_event(params.events + i);
  252. line_range__clear(&params.line_range);
  253. free(params.target);
  254. strfilter__delete(params.filter);
  255. memset(&params, 0, sizeof(params));
  256. }
  257. static void pr_err_with_code(const char *msg, int err)
  258. {
  259. char sbuf[STRERR_BUFSIZE];
  260. pr_err("%s", msg);
  261. pr_debug(" Reason: %s (Code: %d)",
  262. str_error_r(-err, sbuf, sizeof(sbuf)), err);
  263. pr_err("\n");
  264. }
  265. static int perf_add_probe_events(struct perf_probe_event *pevs, int npevs)
  266. {
  267. int ret;
  268. int i, k;
  269. const char *event = NULL, *group = NULL;
  270. ret = init_probe_symbol_maps(pevs->uprobes);
  271. if (ret < 0)
  272. return ret;
  273. ret = convert_perf_probe_events(pevs, npevs);
  274. if (ret < 0)
  275. goto out_cleanup;
  276. ret = apply_perf_probe_events(pevs, npevs);
  277. if (ret < 0)
  278. goto out_cleanup;
  279. for (i = k = 0; i < npevs; i++)
  280. k += pevs[i].ntevs;
  281. pr_info("Added new event%s\n", (k > 1) ? "s:" : ":");
  282. for (i = 0; i < npevs; i++) {
  283. struct perf_probe_event *pev = &pevs[i];
  284. for (k = 0; k < pev->ntevs; k++) {
  285. struct probe_trace_event *tev = &pev->tevs[k];
  286. /* We use tev's name for showing new events */
  287. show_perf_probe_event(tev->group, tev->event, pev,
  288. tev->point.module, false);
  289. /* Save the last valid name */
  290. event = tev->event;
  291. group = tev->group;
  292. }
  293. }
  294. /* Note that it is possible to skip all events because of blacklist */
  295. if (event) {
  296. /* Show how to use the event. */
  297. pr_info("\nYou can now use it in all perf tools, such as:\n\n");
  298. pr_info("\tperf record -e %s:%s -aR sleep 1\n\n", group, event);
  299. }
  300. out_cleanup:
  301. cleanup_perf_probe_events(pevs, npevs);
  302. exit_probe_symbol_maps();
  303. return ret;
  304. }
  305. static int del_perf_probe_caches(struct strfilter *filter)
  306. {
  307. struct probe_cache *cache;
  308. struct strlist *bidlist;
  309. struct str_node *nd;
  310. int ret;
  311. bidlist = build_id_cache__list_all(false);
  312. if (!bidlist) {
  313. ret = -errno;
  314. pr_debug("Failed to get buildids: %d\n", ret);
  315. return ret ?: -ENOMEM;
  316. }
  317. strlist__for_each_entry(nd, bidlist) {
  318. cache = probe_cache__new(nd->s);
  319. if (!cache)
  320. continue;
  321. if (probe_cache__filter_purge(cache, filter) < 0 ||
  322. probe_cache__commit(cache) < 0)
  323. pr_warning("Failed to remove entries for %s\n", nd->s);
  324. probe_cache__delete(cache);
  325. }
  326. return 0;
  327. }
  328. static int perf_del_probe_events(struct strfilter *filter)
  329. {
  330. int ret, ret2, ufd = -1, kfd = -1;
  331. char *str = strfilter__string(filter);
  332. struct strlist *klist = NULL, *ulist = NULL;
  333. struct str_node *ent;
  334. if (!str)
  335. return -EINVAL;
  336. pr_debug("Delete filter: \'%s\'\n", str);
  337. if (probe_conf.cache)
  338. return del_perf_probe_caches(filter);
  339. /* Get current event names */
  340. ret = probe_file__open_both(&kfd, &ufd, PF_FL_RW);
  341. if (ret < 0)
  342. goto out;
  343. klist = strlist__new(NULL, NULL);
  344. ulist = strlist__new(NULL, NULL);
  345. if (!klist || !ulist) {
  346. ret = -ENOMEM;
  347. goto out;
  348. }
  349. ret = probe_file__get_events(kfd, filter, klist);
  350. if (ret == 0) {
  351. strlist__for_each_entry(ent, klist)
  352. pr_info("Removed event: %s\n", ent->s);
  353. ret = probe_file__del_strlist(kfd, klist);
  354. if (ret < 0)
  355. goto error;
  356. }
  357. ret2 = probe_file__get_events(ufd, filter, ulist);
  358. if (ret2 == 0) {
  359. strlist__for_each_entry(ent, ulist)
  360. pr_info("Removed event: %s\n", ent->s);
  361. ret2 = probe_file__del_strlist(ufd, ulist);
  362. if (ret2 < 0)
  363. goto error;
  364. }
  365. if (ret == -ENOENT && ret2 == -ENOENT)
  366. pr_debug("\"%s\" does not hit any event.\n", str);
  367. /* Note that this is silently ignored */
  368. ret = 0;
  369. error:
  370. if (kfd >= 0)
  371. close(kfd);
  372. if (ufd >= 0)
  373. close(ufd);
  374. out:
  375. strlist__delete(klist);
  376. strlist__delete(ulist);
  377. free(str);
  378. return ret;
  379. }
  380. static int
  381. __cmd_probe(int argc, const char **argv, const char *prefix __maybe_unused)
  382. {
  383. const char * const probe_usage[] = {
  384. "perf probe [<options>] 'PROBEDEF' ['PROBEDEF' ...]",
  385. "perf probe [<options>] --add 'PROBEDEF' [--add 'PROBEDEF' ...]",
  386. "perf probe [<options>] --del '[GROUP:]EVENT' ...",
  387. "perf probe --list [GROUP:]EVENT ...",
  388. #ifdef HAVE_DWARF_SUPPORT
  389. "perf probe [<options>] --line 'LINEDESC'",
  390. "perf probe [<options>] --vars 'PROBEPOINT'",
  391. #endif
  392. "perf probe [<options>] --funcs",
  393. NULL
  394. };
  395. struct option options[] = {
  396. OPT_INCR('v', "verbose", &verbose,
  397. "be more verbose (show parsed arguments, etc)"),
  398. OPT_BOOLEAN('q', "quiet", &params.quiet,
  399. "be quiet (do not show any mesages)"),
  400. OPT_CALLBACK_DEFAULT('l', "list", NULL, "[GROUP:]EVENT",
  401. "list up probe events",
  402. opt_set_filter_with_command, DEFAULT_LIST_FILTER),
  403. OPT_CALLBACK('d', "del", NULL, "[GROUP:]EVENT", "delete a probe event.",
  404. opt_set_filter_with_command),
  405. OPT_CALLBACK('a', "add", NULL,
  406. #ifdef HAVE_DWARF_SUPPORT
  407. "[EVENT=]FUNC[@SRC][+OFF|%return|:RL|;PT]|SRC:AL|SRC;PT"
  408. " [[NAME=]ARG ...]",
  409. #else
  410. "[EVENT=]FUNC[+OFF|%return] [[NAME=]ARG ...]",
  411. #endif
  412. "probe point definition, where\n"
  413. "\t\tGROUP:\tGroup name (optional)\n"
  414. "\t\tEVENT:\tEvent name\n"
  415. "\t\tFUNC:\tFunction name\n"
  416. "\t\tOFF:\tOffset from function entry (in byte)\n"
  417. "\t\t%return:\tPut the probe at function return\n"
  418. #ifdef HAVE_DWARF_SUPPORT
  419. "\t\tSRC:\tSource code path\n"
  420. "\t\tRL:\tRelative line number from function entry.\n"
  421. "\t\tAL:\tAbsolute line number in file.\n"
  422. "\t\tPT:\tLazy expression of line code.\n"
  423. "\t\tARG:\tProbe argument (local variable name or\n"
  424. "\t\t\tkprobe-tracer argument format.)\n",
  425. #else
  426. "\t\tARG:\tProbe argument (kprobe-tracer argument format.)\n",
  427. #endif
  428. opt_add_probe_event),
  429. OPT_BOOLEAN('f', "force", &probe_conf.force_add, "forcibly add events"
  430. " with existing name"),
  431. OPT_CALLBACK('L', "line", NULL,
  432. "FUNC[:RLN[+NUM|-RLN2]]|SRC:ALN[+NUM|-ALN2]",
  433. "Show source code lines.", opt_show_lines),
  434. OPT_CALLBACK('V', "vars", NULL,
  435. "FUNC[@SRC][+OFF|%return|:RL|;PT]|SRC:AL|SRC;PT",
  436. "Show accessible variables on PROBEDEF", opt_show_vars),
  437. OPT_BOOLEAN('\0', "externs", &probe_conf.show_ext_vars,
  438. "Show external variables too (with --vars only)"),
  439. OPT_BOOLEAN('\0', "range", &probe_conf.show_location_range,
  440. "Show variables location range in scope (with --vars only)"),
  441. OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,
  442. "file", "vmlinux pathname"),
  443. OPT_STRING('s', "source", &symbol_conf.source_prefix,
  444. "directory", "path to kernel source"),
  445. OPT_BOOLEAN('\0', "no-inlines", &probe_conf.no_inlines,
  446. "Don't search inlined functions"),
  447. OPT__DRY_RUN(&probe_event_dry_run),
  448. OPT_INTEGER('\0', "max-probes", &probe_conf.max_probes,
  449. "Set how many probe points can be found for a probe."),
  450. OPT_CALLBACK_DEFAULT('F', "funcs", NULL, "[FILTER]",
  451. "Show potential probe-able functions.",
  452. opt_set_filter_with_command, DEFAULT_FUNC_FILTER),
  453. OPT_CALLBACK('\0', "filter", NULL,
  454. "[!]FILTER", "Set a filter (with --vars/funcs only)\n"
  455. "\t\t\t(default: \"" DEFAULT_VAR_FILTER "\" for --vars,\n"
  456. "\t\t\t \"" DEFAULT_FUNC_FILTER "\" for --funcs)",
  457. opt_set_filter),
  458. OPT_CALLBACK('x', "exec", NULL, "executable|path",
  459. "target executable name or path", opt_set_target),
  460. OPT_CALLBACK('m', "module", NULL, "modname|path",
  461. "target module name (for online) or path (for offline)",
  462. opt_set_target),
  463. OPT_BOOLEAN(0, "demangle", &symbol_conf.demangle,
  464. "Enable symbol demangling"),
  465. OPT_BOOLEAN(0, "demangle-kernel", &symbol_conf.demangle_kernel,
  466. "Enable kernel symbol demangling"),
  467. OPT_BOOLEAN(0, "cache", &probe_conf.cache, "Manipulate probe cache"),
  468. OPT_END()
  469. };
  470. int ret;
  471. set_option_flag(options, 'a', "add", PARSE_OPT_EXCLUSIVE);
  472. set_option_flag(options, 'd', "del", PARSE_OPT_EXCLUSIVE);
  473. set_option_flag(options, 'l', "list", PARSE_OPT_EXCLUSIVE);
  474. #ifdef HAVE_DWARF_SUPPORT
  475. set_option_flag(options, 'L', "line", PARSE_OPT_EXCLUSIVE);
  476. set_option_flag(options, 'V', "vars", PARSE_OPT_EXCLUSIVE);
  477. #else
  478. # define set_nobuild(s, l, c) set_option_nobuild(options, s, l, "NO_DWARF=1", c)
  479. set_nobuild('L', "line", false);
  480. set_nobuild('V', "vars", false);
  481. set_nobuild('\0', "externs", false);
  482. set_nobuild('\0', "range", false);
  483. set_nobuild('k', "vmlinux", true);
  484. set_nobuild('s', "source", true);
  485. set_nobuild('\0', "no-inlines", true);
  486. # undef set_nobuild
  487. #endif
  488. set_option_flag(options, 'F', "funcs", PARSE_OPT_EXCLUSIVE);
  489. argc = parse_options(argc, argv, options, probe_usage,
  490. PARSE_OPT_STOP_AT_NON_OPTION);
  491. if (argc > 0) {
  492. if (strcmp(argv[0], "-") == 0) {
  493. usage_with_options_msg(probe_usage, options,
  494. "'-' is not supported.\n");
  495. }
  496. if (params.command && params.command != 'a') {
  497. usage_with_options_msg(probe_usage, options,
  498. "another command except --add is set.\n");
  499. }
  500. ret = parse_probe_event_argv(argc, argv);
  501. if (ret < 0) {
  502. pr_err_with_code(" Error: Command Parse Error.", ret);
  503. return ret;
  504. }
  505. params.command = 'a';
  506. }
  507. if (params.quiet) {
  508. if (verbose != 0) {
  509. pr_err(" Error: -v and -q are exclusive.\n");
  510. return -EINVAL;
  511. }
  512. verbose = -1;
  513. }
  514. if (probe_conf.max_probes == 0)
  515. probe_conf.max_probes = MAX_PROBES;
  516. /*
  517. * Only consider the user's kernel image path if given.
  518. */
  519. symbol_conf.try_vmlinux_path = (symbol_conf.vmlinux_name == NULL);
  520. switch (params.command) {
  521. case 'l':
  522. if (params.uprobes) {
  523. pr_err(" Error: Don't use --list with --exec.\n");
  524. parse_options_usage(probe_usage, options, "l", true);
  525. parse_options_usage(NULL, options, "x", true);
  526. return -EINVAL;
  527. }
  528. ret = show_perf_probe_events(params.filter);
  529. if (ret < 0)
  530. pr_err_with_code(" Error: Failed to show event list.", ret);
  531. return ret;
  532. case 'F':
  533. ret = show_available_funcs(params.target, params.filter,
  534. params.uprobes);
  535. if (ret < 0)
  536. pr_err_with_code(" Error: Failed to show functions.", ret);
  537. return ret;
  538. #ifdef HAVE_DWARF_SUPPORT
  539. case 'L':
  540. ret = show_line_range(&params.line_range, params.target,
  541. params.uprobes);
  542. if (ret < 0)
  543. pr_err_with_code(" Error: Failed to show lines.", ret);
  544. return ret;
  545. case 'V':
  546. if (!params.filter)
  547. params.filter = strfilter__new(DEFAULT_VAR_FILTER,
  548. NULL);
  549. ret = show_available_vars(params.events, params.nevents,
  550. params.filter);
  551. if (ret < 0)
  552. pr_err_with_code(" Error: Failed to show vars.", ret);
  553. return ret;
  554. #endif
  555. case 'd':
  556. ret = perf_del_probe_events(params.filter);
  557. if (ret < 0) {
  558. pr_err_with_code(" Error: Failed to delete events.", ret);
  559. return ret;
  560. }
  561. break;
  562. case 'a':
  563. /* Ensure the last given target is used */
  564. if (params.target && !params.target_used) {
  565. pr_err(" Error: -x/-m must follow the probe definitions.\n");
  566. parse_options_usage(probe_usage, options, "m", true);
  567. parse_options_usage(NULL, options, "x", true);
  568. return -EINVAL;
  569. }
  570. ret = perf_add_probe_events(params.events, params.nevents);
  571. if (ret < 0) {
  572. pr_err_with_code(" Error: Failed to add events.", ret);
  573. return ret;
  574. }
  575. break;
  576. default:
  577. usage_with_options(probe_usage, options);
  578. }
  579. return 0;
  580. }
  581. int cmd_probe(int argc, const char **argv, const char *prefix)
  582. {
  583. int ret;
  584. ret = init_params();
  585. if (!ret) {
  586. ret = __cmd_probe(argc, argv, prefix);
  587. cleanup_params();
  588. }
  589. return ret < 0 ? ret : 0;
  590. }