From: Franck HOUSSEN <fghoussen@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: Franck HOUSSEN <fghoussen@gmail.com>
Subject: [PATCH] Add --output option to perf-top. Motivation: symmetry with other perf tools.
Date: Mon, 25 Jul 2016 15:17:20 +0200 [thread overview]
Message-ID: <1469452640-28335-1-git-send-email-fghoussen@gmail.com> (raw)
Signed-off-by: Franck HOUSSEN <fghoussen@gmail.com>
---
tools/perf/builtin-top.c | 10 +++++++++-
tools/perf/ui/stdio/hist.c | 2 ++
tools/perf/util/top.h | 3 +++
3 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 2a6cc25..a81a1ef 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -260,6 +260,8 @@ static void perf_top__print_sym_table(struct perf_top *top)
perf_top__header_snprintf(top, bf, sizeof(bf));
printf("%s\n", bf);
+ if (top && top->output_log)
+ fprintf(top->output_log, "\n%s\n", bf);
perf_top__reset_sample_counters(top);
@@ -295,7 +297,8 @@ static void perf_top__print_sym_table(struct perf_top *top)
hists__output_recalc_col_len(hists, top->print_entries - printed);
putchar('\n');
hists__fprintf(hists, false, top->print_entries - printed, win_width,
- top->min_percent, stdout);
+ top->min_percent,
+ top->output_log ? top->output_log : stdout);
}
static void prompt_integer(int *target, const char *msg)
@@ -1213,6 +1216,8 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused)
"Show raw trace event output (do not use print fmt or plugins)"),
OPT_BOOLEAN(0, "hierarchy", &symbol_conf.report_hierarchy,
"Show entries in a hierarchy"),
+ OPT_STRING('o', "output", &top.output_name, "log",
+ "Output to a file (tee-like way)"),
OPT_END()
};
const char * const top_usage[] = {
@@ -1337,7 +1342,10 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused)
sigaction(SIGWINCH, &act, NULL);
}
+ top.output_log = top.output_name ? fopen(top.output_name, "w") : NULL;
status = __cmd_top(&top);
+ if (top.output_log)
+ fclose(top.output_log);
out_delete_evlist:
perf_evlist__delete(top.evlist);
diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c
index 560eb47..40ef246 100644
--- a/tools/perf/ui/stdio/hist.c
+++ b/tools/perf/ui/stdio/hist.c
@@ -511,6 +511,8 @@ static int hist_entry__fprintf(struct hist_entry *he, size_t size,
hist_entry__snprintf(he, &hpp);
ret = fprintf(fp, "%s\n", bf);
+ if (fp != stdout) /* if fp is a file, print also to stdout */
+ fprintf(stdout, "%s\n", bf);
if (symbol_conf.use_callchain)
ret += hist_entry_callchain__fprintf(he, total_period, 0, fp);
diff --git a/tools/perf/util/top.h b/tools/perf/util/top.h
index b2940c8..4035a58 100644
--- a/tools/perf/util/top.h
+++ b/tools/perf/util/top.h
@@ -4,6 +4,7 @@
#include "tool.h"
#include <linux/types.h>
#include <stddef.h>
+#include <stdio.h>
#include <stdbool.h>
#include <termios.h>
@@ -37,6 +38,8 @@ struct perf_top {
int sym_pcnt_filter;
const char *sym_filter;
float min_percent;
+ const char *output_name;
+ FILE *output_log;
};
#define CONSOLE_CLEAR "^[[H^[[2J"
--
2.8.1
reply other threads:[~2016-07-25 13:17 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=1469452640-28335-1-git-send-email-fghoussen@gmail.com \
--to=fghoussen@gmail.com \
--cc=linux-kernel@vger.kernel.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®