mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Akihiro Nagai <akihiro.nagai.hw@hitachi.com>
To: Arnaldo Carvalho de Melo <acme@infradead.org>,
	Ingo Molnar <mingo@elte.hu>,
	Peter Zijlstra <peterz@infradead.org>,
	Frederic Weisbecker <fweisbec@gmail.com>
Cc: linux-kernel@vger.kernel.org,
	Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>,
	2nddept-manager@sdl.hitachi.co.jp,
	Akihiro Nagai <akihiro.nagai.hw@hitachi.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Paul Mackerras <paulus@samba.org>, Ingo Molnar <mingo@elte.hu>,
	Arnaldo Carvalho de Melo <acme@infradead.org>
Subject: [PATCH -tip v3 1/6] perf: new subcommand perf branch record
Date: Thu, 24 Mar 2011 20:31:56 +0900	[thread overview]
Message-ID: <20110324113156.20235.65177.stgit@localhost6.localdomain6> (raw)
In-Reply-To: <20110324113137.20235.42265.stgit@localhost6.localdomain6>

Introduce the easy way to record the bts log, 'perf branch record'.
This command records the bts log while the specified command is executing,
and save to the file "perf.data"

Usage:
  perf branch record <tracee command>

Example:
  # perf branch record ls -l
    (ls -l outputs)
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 0.007 MB perf.data (~320 samples) ]
  # ls
    perf.data

Changes in V3:
 - rename to 'perf branch'

Changes in V2:
 - Update to the latest -tip tree
 - add bts explanation to the subcommand list

Signed-off-by: Akihiro Nagai <akihiro.nagai.hw@hitachi.com>
Reviewed-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Arnaldo Carvalho de Melo <acme@infradead.org>
---

 tools/perf/Documentation/perf-branch.txt |   25 ++++++++++++
 tools/perf/Makefile                      |    1 
 tools/perf/builtin-branch.c              |   62 ++++++++++++++++++++++++++++++
 tools/perf/builtin.h                     |    1 
 tools/perf/command-list.txt              |    1 
 tools/perf/perf.c                        |    1 
 6 files changed, 91 insertions(+), 0 deletions(-)
 create mode 100644 tools/perf/Documentation/perf-branch.txt
 create mode 100644 tools/perf/builtin-branch.c

diff --git a/tools/perf/Documentation/perf-branch.txt b/tools/perf/Documentation/perf-branch.txt
new file mode 100644
index 0000000..075cfce
--- /dev/null
+++ b/tools/perf/Documentation/perf-branch.txt
@@ -0,0 +1,25 @@
+perf-branch(1)
+==============
+
+NAME
+----
+perf-branch - Record branch-trace-store log
+
+SYNOPSIS
+--------
+[verse]
+'perf branch' record <command>
+
+DESCRIPTION
+-----------
+This command records a branch-trace-store log.
+Branch-trace-store is a facility of processors. It can record
+addresses of from/to which the execution of a program branches,
+at every branch instruction and interrupt.
+
+'perf branch record <command>' records branch-trace-store log while
+the specified command is executing. And, save to the file "perf.data".
+
+SEE ALSO
+--------
+linkperf:perf-record[1]
diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 158c30e..f50bd89 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -356,6 +356,7 @@ BUILTIN_OBJS += $(OUTPUT)builtin-lock.o
 BUILTIN_OBJS += $(OUTPUT)builtin-kvm.o
 BUILTIN_OBJS += $(OUTPUT)builtin-test.o
 BUILTIN_OBJS += $(OUTPUT)builtin-inject.o
+BUILTIN_OBJS += $(OUTPUT)builtin-branch.o
 
 PERFLIBS = $(LIB_FILE)
 
diff --git a/tools/perf/builtin-branch.c b/tools/perf/builtin-branch.c
new file mode 100644
index 0000000..f338f3a
--- /dev/null
+++ b/tools/perf/builtin-branch.c
@@ -0,0 +1,62 @@
+#include "builtin.h"
+#include "perf.h"
+#include "util/parse-options.h"
+
+static const char * const branch_usage[] = {
+	"perf branch record <command>",
+	NULL,
+};
+
+/* arguments to call 'perf record' */
+static const char * const record_args[] = {
+	"record",
+	"-f",
+	"-e", "branches:u",
+	"-c", "1",
+	"-d",
+};
+
+/* dummy struct option to call parse_options() */
+static const struct option branch_options[] = {
+	OPT_END()
+};
+
+static int __cmd_record(int argc, const char **argv)
+{
+	unsigned int rec_argc, i, j;
+	const char **rec_argv;
+	int rc;
+
+	/* prepare the arguments list to call 'perf record' */
+	rec_argc = ARRAY_SIZE(record_args) + argc - 1;
+	rec_argv = calloc(rec_argc + 1, sizeof(char *));
+
+	for (i = 0; i < ARRAY_SIZE(record_args); i++)
+		rec_argv[i] = record_args[i];
+
+	for (j = 1; j < (unsigned int)argc; j++, i++)
+		rec_argv[i] = argv[j];
+
+	BUG_ON(i != rec_argc);
+
+	/* call 'perf record' */
+	rc = cmd_record(i, rec_argv, NULL);
+
+	free(rec_argv);
+	return rc;
+}
+
+int cmd_branch(int argc, const char **argv, const char *prefix __used)
+{
+	argc = parse_options(argc, argv, branch_options, branch_usage,
+			     PARSE_OPT_STOP_AT_NON_OPTION);
+	if (!argc)
+		usage_with_options(branch_usage, branch_options);
+
+	if (!strcmp(argv[0], "record"))
+		return __cmd_record(argc, argv);
+	else
+		usage_with_options(branch_usage, branch_options);
+
+	return 0;
+}
diff --git a/tools/perf/builtin.h b/tools/perf/builtin.h
index 4702e24..89fefdc 100644
--- a/tools/perf/builtin.h
+++ b/tools/perf/builtin.h
@@ -36,5 +36,6 @@ extern int cmd_lock(int argc, const char **argv, const char *prefix);
 extern int cmd_kvm(int argc, const char **argv, const char *prefix);
 extern int cmd_test(int argc, const char **argv, const char *prefix);
 extern int cmd_inject(int argc, const char **argv, const char *prefix);
+extern int cmd_branch(int argc, const char **argv, const char *prefix);
 
 #endif
diff --git a/tools/perf/command-list.txt b/tools/perf/command-list.txt
index d695fe4..537f655 100644
--- a/tools/perf/command-list.txt
+++ b/tools/perf/command-list.txt
@@ -23,3 +23,4 @@ perf-kmem			mainporcelain common
 perf-lock			mainporcelain common
 perf-kvm			mainporcelain common
 perf-test			mainporcelain common
+perf-branch			mainporcelain common
diff --git a/tools/perf/perf.c b/tools/perf/perf.c
index ec635b7..cfd9318 100644
--- a/tools/perf/perf.c
+++ b/tools/perf/perf.c
@@ -332,6 +332,7 @@ static void handle_internal_command(int argc, const char **argv)
 		{ "kvm",	cmd_kvm,	0 },
 		{ "test",	cmd_test,	0 },
 		{ "inject",	cmd_inject,	0 },
+		{ "branch",	cmd_branch,	0 },
 	};
 	unsigned int i;
 	static const char ext[] = STRIP_EXTENSION;


  reply	other threads:[~2011-03-24 11:31 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-24 11:31 [PATCH -tip v3 0/6] perf: Introduce branch sub commands Akihiro Nagai
2011-03-24 11:31 ` Akihiro Nagai [this message]
2011-03-24 11:32 ` [PATCH -tip v3 2/6] perf branch: Introduce new sub command 'perf branch trace' Akihiro Nagai
2011-03-24 11:32 ` [PATCH -tip v3 3/6] perf branch trace: print pid and command Akihiro Nagai
2011-03-24 17:05   ` David Ahern
2011-03-25 10:14     ` Akihiro Nagai
2011-03-25 15:02       ` David Ahern
2011-03-28 10:34         ` Akihiro Nagai
2011-03-28 14:31           ` David Ahern
2011-04-01 15:13             ` Frederic Weisbecker
2011-04-01 15:15               ` Peter Zijlstra
2011-04-01 15:24                 ` Arnaldo Carvalho de Melo
2011-04-01 17:11               ` David Ahern
2011-04-01 20:20                 ` Peter Zijlstra
2011-04-06 12:15                 ` Frederic Weisbecker
2011-04-06 14:09                   ` Arnaldo Carvalho de Melo
2011-04-06 14:15                     ` Peter Zijlstra
2011-04-06 14:30                       ` Frederic Weisbecker
2011-04-06 14:34                         ` David Ahern
2011-04-06 14:43                           ` Frederic Weisbecker
2011-04-06 14:42                       ` Frederic Weisbecker
2011-04-06 14:55                     ` Frederic Weisbecker
2011-04-06 17:18                       ` Arnaldo Carvalho de Melo
2011-04-04 10:00               ` Akihiro Nagai
2011-04-06 12:52                 ` Frederic Weisbecker
2011-04-11  4:54                   ` Akihiro Nagai
2011-03-24 11:32 ` [PATCH -tip v3 4/6] perf branch trace: print file path of the executed elf Akihiro Nagai
2011-03-24 11:32 ` [PATCH -tip v3 5/6] perf branch trace: print function+offset Akihiro Nagai
2011-03-24 11:32 ` [PATCH -tip v3 6/6] perf branch trace: add print all option Akihiro Nagai
2011-03-30 14:46 ` [PATCH -tip v3 0/6] perf: Introduce branch sub commands Frederic Weisbecker
2011-04-01 10:57   ` Akihiro Nagai
2011-04-01 12:51     ` Frederic Weisbecker
2011-04-01 14:43 ` Frederic Weisbecker
2011-04-04 10:06   ` Akihiro Nagai

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=20110324113156.20235.65177.stgit@localhost6.localdomain6 \
    --to=akihiro.nagai.hw@hitachi.com \
    --cc=2nddept-manager@sdl.hitachi.co.jp \
    --cc=acme@infradead.org \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masami.hiramatsu.pt@hitachi.com \
    --cc=mingo@elte.hu \
    --cc=paulus@samba.org \
    --cc=peterz@infradead.org \
    /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

all inboxes | Powered by JetHome®