Skip to content

Commit

Permalink
perf report: Add -F option to specify output fields
Browse files Browse the repository at this point in the history
The -F/--fields option is to allow user setup output field in any
order.  It can receive any sort keys and following (hpp) fields:

  overhead, overhead_sys, overhead_us, sample and period

If guest profiling is enabled, overhead_guest_{sys,us} will be
available too.

The output fields also affect sort order unless you give -s/--sort
option.  And any keys specified on -s option, will also be added to
the output field list automatically.

  $ perf report -F sym,sample,overhead
  ...
  #                     Symbol       Samples  Overhead
  # ..........................  ............  ........
  #
    [.] __cxa_atexit                       2     2.50%
    [.] __libc_csu_init                    4     5.00%
    [.] __new_exitfn                       3     3.75%
    [.] _dl_check_map_versions             1     1.25%
    [.] _dl_name_match_p                   4     5.00%
    [.] _dl_setup_hash                     1     1.25%
    [.] _dl_sysdep_start                   1     1.25%
    [.] _init                              5     6.25%
    [.] _setjmp                            6     7.50%
    [.] a                                  8    10.00%
    [.] b                                  8    10.00%
    [.] brk                                1     1.25%
    [.] c                                  8    10.00%

Note that, the example output above is captured after applying next
patch which fixes sort/comparing behavior.

Requested-by: Ingo Molnar <[email protected]>
Signed-off-by: Namhyung Kim <[email protected]>
Acked-by: Ingo Molnar <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
  • Loading branch information
namhyung authored and olsajiri committed May 21, 2014
1 parent 22af969 commit a7d945b
Show file tree
Hide file tree
Showing 6 changed files with 282 additions and 17 deletions.
10 changes: 10 additions & 0 deletions tools/perf/Documentation/perf-report.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@ OPTIONS
And default sort keys are changed to comm, dso_from, symbol_from, dso_to
and symbol_to, see '--branch-stack'.

-F::
--fields=::
Specify output field - multiple keys can be specified in CSV format.
Following fields are available:
overhead, overhead_sys, overhead_us, sample and period.
Also it can contain any sort key(s).

By default, every sort keys not specified in -F will be appended
automatically.

-p::
--parent=<regex>::
A regex filter to identify parent. The parent is a caller of this
Expand Down
15 changes: 7 additions & 8 deletions tools/perf/builtin-report.c
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,8 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)
OPT_STRING('s', "sort", &sort_order, "key[,key2...]",
"sort by key(s): pid, comm, dso, symbol, parent, cpu, srcline, ..."
" Please refer the man page for the complete list."),
OPT_STRING('F', "fields", &field_order, "key[,keys...]",
"output field(s): overhead, period, sample plus all of sort keys"),
OPT_BOOLEAN(0, "showcpuutilization", &symbol_conf.show_cpu_utilization,
"Show sample percentage for different cpu modes"),
OPT_STRING('p', "parent", &parent_pattern, "regex",
Expand Down Expand Up @@ -814,17 +816,14 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)
}

if (setup_sorting() < 0) {
parse_options_usage(report_usage, options, "s", 1);
if (sort_order)
parse_options_usage(report_usage, options, "s", 1);
if (field_order)
parse_options_usage(sort_order ? NULL : report_usage,
options, "F", 1);
goto error;
}

if (parent_pattern != default_parent_pattern) {
if (sort_dimension__add("parent") < 0)
goto error;
}

perf_hpp__init();

/* Force tty output for header output. */
if (report.header || report.header_only)
use_browser = 0;
Expand Down
59 changes: 55 additions & 4 deletions tools/perf/ui/hist.c
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,12 @@ void perf_hpp__init(void)
INIT_LIST_HEAD(&fmt->sort_list);
}

/*
* If user specified field order, no need to setup default fields.
*/
if (field_order)
return;

perf_hpp__column_enable(PERF_HPP__OVERHEAD);

if (symbol_conf.show_cpu_utilization) {
Expand All @@ -377,8 +383,6 @@ void perf_hpp__init(void)
list = &perf_hpp__format[PERF_HPP__OVERHEAD].sort_list;
if (list_empty(list))
list_add(list, &perf_hpp__sort_list);

perf_hpp__setup_output_field();
}

void perf_hpp__column_register(struct perf_hpp_fmt *format)
Expand All @@ -403,8 +407,55 @@ void perf_hpp__setup_output_field(void)

/* append sort keys to output field */
perf_hpp__for_each_sort_list(fmt) {
if (list_empty(&fmt->list))
perf_hpp__column_register(fmt);
if (!list_empty(&fmt->list))
continue;

/*
* sort entry fields are dynamically created,
* so they can share a same sort key even though
* the list is empty.
*/
if (perf_hpp__is_sort_entry(fmt)) {
struct perf_hpp_fmt *pos;

perf_hpp__for_each_format(pos) {
if (perf_hpp__same_sort_entry(pos, fmt))
goto next;
}
}

perf_hpp__column_register(fmt);
next:
continue;
}
}

void perf_hpp__append_sort_keys(void)
{
struct perf_hpp_fmt *fmt;

/* append output fields to sort keys */
perf_hpp__for_each_format(fmt) {
if (!list_empty(&fmt->sort_list))
continue;

/*
* sort entry fields are dynamically created,
* so they can share a same sort key even though
* the list is empty.
*/
if (perf_hpp__is_sort_entry(fmt)) {
struct perf_hpp_fmt *pos;

perf_hpp__for_each_sort_list(pos) {
if (perf_hpp__same_sort_entry(pos, fmt))
goto next;
}
}

perf_hpp__register_sort_field(fmt);
next:
continue;
}
}

Expand Down
4 changes: 4 additions & 0 deletions tools/perf/util/hist.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ void perf_hpp__column_register(struct perf_hpp_fmt *format);
void perf_hpp__column_enable(unsigned col);
void perf_hpp__register_sort_field(struct perf_hpp_fmt *format);
void perf_hpp__setup_output_field(void);
void perf_hpp__append_sort_keys(void);

bool perf_hpp__is_sort_entry(struct perf_hpp_fmt *format);
bool perf_hpp__same_sort_entry(struct perf_hpp_fmt *a, struct perf_hpp_fmt *b);

typedef u64 (*hpp_field_fn)(struct hist_entry *he);
typedef int (*hpp_callback_fn)(struct perf_hpp *hpp, bool front);
Expand Down
Loading

0 comments on commit a7d945b

Please sign in to comment.