summaryrefslogtreecommitdiffstats
path: root/tools/perf/builtin-record.c
diff options
context:
space:
mode:
authorIngo Molnar <mingo@elte.hu>2010-04-15 09:13:26 +0200
committerIngo Molnar <mingo@elte.hu>2010-04-15 09:13:26 +0200
commit84b13fd596522db47f9545d5124c30cc00dfdf5a (patch)
treec1f51b8fe43a59fb56ea43a18da88c0d0812dd7d /tools/perf/builtin-record.c
parentf92128193094c288bc315db1694fafeaeb7ee1d0 (diff)
parenta0cccc2e8e9fb16cbed3a117b30e3fbac3092ee3 (diff)
downloadop-kernel-dev-84b13fd596522db47f9545d5124c30cc00dfdf5a.zip
op-kernel-dev-84b13fd596522db47f9545d5124c30cc00dfdf5a.tar.gz
Merge branch 'perf/live' into perf/core
Conflicts: tools/perf/builtin-record.c Merge reason: add the live tracing feature, resolve conflict. Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools/perf/builtin-record.c')
-rw-r--r--tools/perf/builtin-record.c68
1 files changed, 61 insertions, 7 deletions
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index ca2affc..a1b99ee 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -42,6 +42,7 @@ static unsigned int mmap_pages = 128;
static unsigned int user_freq = UINT_MAX;
static int freq = 1000;
static int output;
+static int pipe_output = 0;
static const char *output_name = "perf.data";
static int group = 0;
static unsigned int realtime_prio = 0;
@@ -109,6 +110,11 @@ static void mmap_write_tail(struct mmap_data *md, unsigned long tail)
pc->data_tail = tail;
}
+static void advance_output(size_t size)
+{
+ bytes_written += size;
+}
+
static void write_output(void *buf, size_t size)
{
while (size) {
@@ -435,10 +441,19 @@ static int process_buildids(void)
static void atexit_header(void)
{
- session->header.data_size += bytes_written;
+ if (!pipe_output) {
+ session->header.data_size += bytes_written;
- process_buildids();
- perf_header__write(&session->header, output, true);
+ process_buildids();
+ perf_header__write(&session->header, output, true);
+ } else {
+ int err;
+
+ err = event__synthesize_build_ids(process_synthesized_event,
+ session);
+ if (err < 0)
+ pr_err("Couldn't synthesize build ids.\n");
+ }
}
static int __cmd_record(int argc, const char **argv)
@@ -464,7 +479,9 @@ static int __cmd_record(int argc, const char **argv)
exit(-1);
}
- if (!stat(output_name, &st) && st.st_size) {
+ if (!strcmp(output_name, "-"))
+ pipe_output = 1;
+ else if (!stat(output_name, &st) && st.st_size) {
if (write_mode == WRITE_FORCE) {
char oldname[PATH_MAX];
snprintf(oldname, sizeof(oldname), "%s.old",
@@ -482,7 +499,10 @@ static int __cmd_record(int argc, const char **argv)
else
flags |= O_TRUNC;
- output = open(output_name, flags, S_IRUSR|S_IWUSR);
+ if (pipe_output)
+ output = STDOUT_FILENO;
+ else
+ output = open(output_name, flags, S_IRUSR | S_IWUSR);
if (output < 0) {
perror("failed to create output file");
exit(-1);
@@ -496,7 +516,7 @@ static int __cmd_record(int argc, const char **argv)
}
if (!file_new) {
- err = perf_header__read(&session->header, output);
+ err = perf_header__read(session, output);
if (err < 0)
return err;
}
@@ -522,6 +542,8 @@ static int __cmd_record(int argc, const char **argv)
}
if (!child_pid) {
+ if (pipe_output)
+ dup2(2, 1);
close(child_ready_pipe[0]);
close(go_pipe[1]);
fcntl(go_pipe[0], F_SETFD, FD_CLOEXEC);
@@ -573,7 +595,11 @@ static int __cmd_record(int argc, const char **argv)
open_counters(cpumap[i]);
}
- if (file_new) {
+ if (pipe_output) {
+ err = perf_header__write_pipe(output);
+ if (err < 0)
+ return err;
+ } else if (file_new) {
err = perf_header__write(&session->header, output, false);
if (err < 0)
return err;
@@ -581,6 +607,34 @@ static int __cmd_record(int argc, const char **argv)
post_processing_offset = lseek(output, 0, SEEK_CUR);
+ if (pipe_output) {
+ err = event__synthesize_attrs(&session->header,
+ process_synthesized_event,
+ session);
+ if (err < 0) {
+ pr_err("Couldn't synthesize attrs.\n");
+ return err;
+ }
+
+ err = event__synthesize_event_types(process_synthesized_event,
+ session);
+ if (err < 0) {
+ pr_err("Couldn't synthesize event_types.\n");
+ return err;
+ }
+
+ err = event__synthesize_tracing_data(output, attrs,
+ nr_counters,
+ process_synthesized_event,
+ session);
+ if (err <= 0) {
+ pr_err("Couldn't record tracing data.\n");
+ return err;
+ }
+
+ advance_output(err);
+ }
+
err = event__synthesize_kernel_mmap(process_synthesized_event,
session, "_text");
if (err < 0)
OpenPOWER on IntegriCloud