From: tzanussi@gmail.com
To: linux-kernel@vger.kernel.org
Cc: acme@ghostprotocols.net, mingo@elte.hu, fweisbec@gmail.com
Subject: [PATCH 4/7] perf trace record: handle commands correctly
Date: Tue, 9 Nov 2010 15:18:19 -0600 [thread overview]
Message-ID: <1289337502-2492-5-git-send-email-tzanussi@gmail.com> (raw)
In-Reply-To: <1289337502-2492-1-git-send-email-tzanussi@gmail.com>
From: Tom Zanussi <tom.zanussi@linux.intel.com>
Because the perf-trace shell scripts hard-coded the use of the
perf-record system-wide param, a perf trace record session was always
system wide, even if it was given a command.
If given a command, perf trace record now only records the events for
the command, as users expect.
If no command is given, or if the '-a' option is used, the recorded
events are system-wide, as before.
root@tropicana:~# perf trace record syscall-counts ls -al
root@tropicana:~# perf trace
ls-23152 [000] 39984.890387: sys_enter: NR 12 (0, 0, 0, 0, 0, 0)
ls-23152 [000] 39984.890404: sys_enter: NR 9 (0, 0, 0, 0, 0, 0)
root@tropicana:~# perf trace record syscall-counts -a ls -al
root@tropicana:~# perf trace
npviewer.bin-22297 [000] 39831.102709: sys_enter: NR 168 (0, 0, 0, 0, 0, 0)
ls-23111 [000] 39831.107679: sys_enter: NR 59 (0, 0, 0, 0, 0, 0)
Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com>
---
tools/perf/builtin-trace.c | 32 ++++++++++++++++++++++++++++----
1 files changed, 28 insertions(+), 4 deletions(-)
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 368e624..0de7fcb 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -10,6 +10,7 @@
#include "util/symbol.h"
#include "util/thread.h"
#include "util/trace-event.h"
+#include "util/parse-options.h"
#include "util/util.h"
static char const *script_name;
@@ -17,6 +18,7 @@ static char const *generate_script_lang;
static bool debug_mode;
static u64 last_timestamp;
static u64 nr_unordered;
+extern const struct option record_options[];
static int default_start_script(const char *script __unused,
int argc __unused,
@@ -566,6 +568,20 @@ static const struct option options[] = {
OPT_END()
};
+static bool have_cmd(int argc, const char **argv)
+{
+ char **__argv = malloc(sizeof(const char *) * argc);
+
+ if (!__argv)
+ die("malloc");
+ memcpy(__argv, argv, sizeof(const char *) * argc);
+ argc = parse_options(argc, (const char **)__argv, record_options,
+ NULL, PARSE_OPT_STOP_AT_NON_OPTION);
+ free(__argv);
+
+ return argc != 0;
+}
+
int cmd_trace(int argc, const char **argv, const char *prefix __used)
{
struct perf_session *session;
@@ -663,21 +679,28 @@ int cmd_trace(int argc, const char **argv, const char *prefix __used)
}
if (suffix) {
+ bool system_wide = false;
+ int j = 0;
+
script_path = get_script_path(argv[2], suffix);
if (!script_path) {
fprintf(stderr, "script not found\n");
return -1;
}
+ if (!strcmp(suffix, RECORD_SUFFIX))
+ system_wide = !have_cmd(argc - 2, &argv[2]);
+
__argv = malloc((argc + 1) * sizeof(const char *));
if (!__argv)
die("malloc");
- __argv[0] = "/bin/sh";
- __argv[1] = script_path;
+ __argv[j++] = "/bin/sh";
+ __argv[j++] = script_path;
+ if (system_wide)
+ __argv[j++] = "-a";
for (i = 3; i < argc; i++)
- __argv[i - 1] = argv[i];
- __argv[argc - 1] = NULL;
+ __argv[j++] = argv[i];
+ __argv[j++] = NULL;
execvp("/bin/sh", (char **)__argv);
free(__argv);
--
Tom Zanussi, Intel Open Source Technology Center
next prev parent reply other threads:[~2010-11-09 21:19 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-09 21:18 [PATCH 0/7] perf trace command-line cleanup tzanussi
2010-11-09 21:18 ` [PATCH 1/7] perf trace scripting: fix some small memory leaks and missing error checks tzanussi
2010-11-09 21:18 ` [PATCH 2/7] perf trace scripting: remove system-wide param from shell scripts tzanussi
2010-11-09 21:18 ` [PATCH 3/7] perf record: make the record options available outside perf record tzanussi
2010-11-09 21:18 ` tzanussi [this message]
2010-11-09 21:18 ` [PATCH 5/7] perf trace: live-mode command-line cleanup tzanussi
2010-11-09 21:18 ` [PATCH 6/7] perf trace: update Documentation with new perf trace variants tzanussi
2010-11-09 21:18 ` [PATCH 7/7] perf trace: update usage tzanussi
2010-11-09 21:38 ` [PATCH 0/7] perf trace command-line cleanup Arnaldo Carvalho de Melo
2010-11-10 7:32 ` Ingo Molnar
2010-11-10 18:09 ` Tom Zanussi
2010-11-10 18:10 [PATCH 0/7] perf trace command-line cleanup, v2 tzanussi
2010-11-10 18:10 ` [PATCH 4/7] perf trace record: handle commands correctly tzanussi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1289337502-2492-5-git-send-email-tzanussi@gmail.com \
--to=tzanussi@gmail.com \
--cc=acme@ghostprotocols.net \
--cc=fweisbec@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome