Commit 2f3f9bcf authored by Jiri Olsa's avatar Jiri Olsa Committed by Arnaldo Carvalho de Melo

perf tools: Add +field argument support for --field option

Adding support to add field(s) to default field order via using the '+'
prefix, like for report:

  $ perf report
  Samples: 10  of event 'cycles', Event count (approx.): 4463799
  Overhead  Command  Shared Object      Symbol
    32.40%  ls       [kernel.kallsyms]  [k] filemap_fault
    28.19%  ls       [kernel.kallsyms]  [k] get_page_from_freelist
    23.38%  ls       [kernel.kallsyms]  [k] enqueue_entity
    15.04%  ls       [kernel.kallsyms]  [k] mmap_region

  $ perf report -F +period,sample
  Samples: 10  of event 'cycles', Event count (approx.): 4463799
  Overhead        Period       Samples  Command  Shared Object      Symbol
    32.40%       1446493             1  ls       [kernel.kallsyms]  [k] filemap_fault
    28.19%       1258486             1  ls       [kernel.kallsyms]  [k] get_page_from_freelist
    23.38%       1043754             1  ls       [kernel.kallsyms]  [k] enqueue_entity
    15.04%        671160             1  ls       [kernel.kallsyms]  [k] mmap_region

Works in general for commands using --field option.
Signed-off-by: default avatarJiri Olsa <jolsa@kernel.org>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jean Pihet <jean.pihet@linaro.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1408715919-25990-2-git-send-email-jolsa@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 3969cc09
...@@ -452,7 +452,7 @@ void perf_hpp__init(void) ...@@ -452,7 +452,7 @@ void perf_hpp__init(void)
/* /*
* If user specified field order, no need to setup default fields. * If user specified field order, no need to setup default fields.
*/ */
if (field_order) if (is_strict_order(field_order))
return; return;
if (symbol_conf.cumulate_callchain) { if (symbol_conf.cumulate_callchain) {
...@@ -519,7 +519,7 @@ void perf_hpp__column_disable(unsigned col) ...@@ -519,7 +519,7 @@ void perf_hpp__column_disable(unsigned col)
void perf_hpp__cancel_cumulate(void) void perf_hpp__cancel_cumulate(void)
{ {
if (field_order) if (is_strict_order(field_order))
return; return;
perf_hpp__column_disable(PERF_HPP__OVERHEAD_ACC); perf_hpp__column_disable(PERF_HPP__OVERHEAD_ACC);
......
...@@ -1453,7 +1453,7 @@ static int __setup_sorting(void) ...@@ -1453,7 +1453,7 @@ static int __setup_sorting(void)
int ret = 0; int ret = 0;
if (sort_keys == NULL) { if (sort_keys == NULL) {
if (field_order) { if (is_strict_order(field_order)) {
/* /*
* If user specified field order but no sort order, * If user specified field order but no sort order,
* we'll honor it and not add default sort orders. * we'll honor it and not add default sort orders.
...@@ -1639,23 +1639,36 @@ static void reset_dimensions(void) ...@@ -1639,23 +1639,36 @@ static void reset_dimensions(void)
memory_sort_dimensions[i].taken = 0; memory_sort_dimensions[i].taken = 0;
} }
bool is_strict_order(const char *order)
{
return order && (*order != '+');
}
static int __setup_output_field(void) static int __setup_output_field(void)
{ {
char *tmp, *tok, *str; char *tmp, *tok, *str, *strp;
int ret = 0; int ret = -EINVAL;
if (field_order == NULL) if (field_order == NULL)
return 0; return 0;
reset_dimensions(); reset_dimensions();
str = strdup(field_order); strp = str = strdup(field_order);
if (str == NULL) { if (str == NULL) {
error("Not enough memory to setup output fields"); error("Not enough memory to setup output fields");
return -ENOMEM; return -ENOMEM;
} }
for (tok = strtok_r(str, ", ", &tmp); if (!is_strict_order(field_order))
strp++;
if (!strlen(strp)) {
error("Invalid --fields key: `+'");
goto out;
}
for (tok = strtok_r(strp, ", ", &tmp);
tok; tok = strtok_r(NULL, ", ", &tmp)) { tok; tok = strtok_r(NULL, ", ", &tmp)) {
ret = output_field_add(tok); ret = output_field_add(tok);
if (ret == -EINVAL) { if (ret == -EINVAL) {
...@@ -1667,6 +1680,7 @@ static int __setup_output_field(void) ...@@ -1667,6 +1680,7 @@ static int __setup_output_field(void)
} }
} }
out:
free(str); free(str);
return ret; return ret;
} }
......
...@@ -218,4 +218,5 @@ void perf_hpp__set_elide(int idx, bool elide); ...@@ -218,4 +218,5 @@ void perf_hpp__set_elide(int idx, bool elide);
int report_parse_ignore_callees_opt(const struct option *opt, const char *arg, int unset); int report_parse_ignore_callees_opt(const struct option *opt, const char *arg, int unset);
bool is_strict_order(const char *order);
#endif /* __PERF_SORT_H */ #endif /* __PERF_SORT_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment