aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tools/perf/builtin-trace.c32
1 files changed, 28 insertions, 4 deletions
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 368e6249290a..0de7fcb90965 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -10,6 +10,7 @@
10#include "util/symbol.h" 10#include "util/symbol.h"
11#include "util/thread.h" 11#include "util/thread.h"
12#include "util/trace-event.h" 12#include "util/trace-event.h"
13#include "util/parse-options.h"
13#include "util/util.h" 14#include "util/util.h"
14 15
15static char const *script_name; 16static char const *script_name;
@@ -17,6 +18,7 @@ static char const *generate_script_lang;
17static bool debug_mode; 18static bool debug_mode;
18static u64 last_timestamp; 19static u64 last_timestamp;
19static u64 nr_unordered; 20static u64 nr_unordered;
21extern const struct option record_options[];
20 22
21static int default_start_script(const char *script __unused, 23static int default_start_script(const char *script __unused,
22 int argc __unused, 24 int argc __unused,
@@ -566,6 +568,20 @@ static const struct option options[] = {
566 OPT_END() 568 OPT_END()
567}; 569};
568 570
571static bool have_cmd(int argc, const char **argv)
572{
573 char **__argv = malloc(sizeof(const char *) * argc);
574
575 if (!__argv)
576 die("malloc");
577 memcpy(__argv, argv, sizeof(const char *) * argc);
578 argc = parse_options(argc, (const char **)__argv, record_options,
579 NULL, PARSE_OPT_STOP_AT_NON_OPTION);
580 free(__argv);
581
582 return argc != 0;
583}
584
569int cmd_trace(int argc, const char **argv, const char *prefix __used) 585int cmd_trace(int argc, const char **argv, const char *prefix __used)
570{ 586{
571 struct perf_session *session; 587 struct perf_session *session;
@@ -663,20 +679,28 @@ int cmd_trace(int argc, const char **argv, const char *prefix __used)
663 } 679 }
664 680
665 if (suffix) { 681 if (suffix) {
682 bool system_wide = false;
683 int j = 0;
684
666 script_path = get_script_path(argv[2], suffix); 685 script_path = get_script_path(argv[2], suffix);
667 if (!script_path) { 686 if (!script_path) {
668 fprintf(stderr, "script not found\n"); 687 fprintf(stderr, "script not found\n");
669 return -1; 688 return -1;
670 } 689 }
671 690
691 if (!strcmp(suffix, RECORD_SUFFIX))
692 system_wide = !have_cmd(argc - 2, &argv[2]);
693
672 __argv = malloc((argc + 1) * sizeof(const char *)); 694 __argv = malloc((argc + 1) * sizeof(const char *));
673 if (!__argv) 695 if (!__argv)
674 die("malloc"); 696 die("malloc");
675 __argv[0] = "/bin/sh"; 697 __argv[j++] = "/bin/sh";
676 __argv[1] = script_path; 698 __argv[j++] = script_path;
699 if (system_wide)
700 __argv[j++] = "-a";
677 for (i = 3; i < argc; i++) 701 for (i = 3; i < argc; i++)
678 __argv[i - 1] = argv[i]; 702 __argv[j++] = argv[i];
679 __argv[argc - 1] = NULL; 703 __argv[j++] = NULL;
680 704
681 execvp("/bin/sh", (char **)__argv); 705 execvp("/bin/sh", (char **)__argv);
682 free(__argv); 706 free(__argv);