Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --output option to perf-top #307

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion tools/perf/builtin-top.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ 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);

Expand Down Expand Up @@ -295,7 +296,7 @@ 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)
Expand Down Expand Up @@ -1213,6 +1214,7 @@ 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[] = {
Expand Down Expand Up @@ -1337,7 +1339,9 @@ 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);
Expand Down
1 change: 1 addition & 0 deletions tools/perf/ui/stdio/hist.c
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ 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) fprintf(stdout, "%s\n", bf); /* if fp is a file, print also to stdout */

if (symbol_conf.use_callchain)
ret += hist_entry_callchain__fprintf(he, total_period, 0, fp);
Expand Down
3 changes: 3 additions & 0 deletions tools/perf/util/top.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "tool.h"
#include <linux/types.h>
#include <stddef.h>
#include <stdio.h>
#include <stdbool.h>
#include <termios.h>

Expand Down Expand Up @@ -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 ""
Expand Down