Skip to content

Commit 2f3f9bc

Browse files
olsajiriacmel
authored andcommitted
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: Jiri Olsa <[email protected]> Cc: Corey Ashford <[email protected]> Cc: David Ahern <[email protected]> Cc: Frederic Weisbecker <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jean Pihet <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Paul Mackerras <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 3969cc0 commit 2f3f9bc

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

tools/perf/ui/hist.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ void perf_hpp__init(void)
452452
/*
453453
* If user specified field order, no need to setup default fields.
454454
*/
455-
if (field_order)
455+
if (is_strict_order(field_order))
456456
return;
457457

458458
if (symbol_conf.cumulate_callchain) {
@@ -519,7 +519,7 @@ void perf_hpp__column_disable(unsigned col)
519519

520520
void perf_hpp__cancel_cumulate(void)
521521
{
522-
if (field_order)
522+
if (is_strict_order(field_order))
523523
return;
524524

525525
perf_hpp__column_disable(PERF_HPP__OVERHEAD_ACC);

tools/perf/util/sort.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,7 +1453,7 @@ static int __setup_sorting(void)
14531453
int ret = 0;
14541454

14551455
if (sort_keys == NULL) {
1456-
if (field_order) {
1456+
if (is_strict_order(field_order)) {
14571457
/*
14581458
* If user specified field order but no sort order,
14591459
* we'll honor it and not add default sort orders.
@@ -1639,23 +1639,36 @@ static void reset_dimensions(void)
16391639
memory_sort_dimensions[i].taken = 0;
16401640
}
16411641

1642+
bool is_strict_order(const char *order)
1643+
{
1644+
return order && (*order != '+');
1645+
}
1646+
16421647
static int __setup_output_field(void)
16431648
{
1644-
char *tmp, *tok, *str;
1645-
int ret = 0;
1649+
char *tmp, *tok, *str, *strp;
1650+
int ret = -EINVAL;
16461651

16471652
if (field_order == NULL)
16481653
return 0;
16491654

16501655
reset_dimensions();
16511656

1652-
str = strdup(field_order);
1657+
strp = str = strdup(field_order);
16531658
if (str == NULL) {
16541659
error("Not enough memory to setup output fields");
16551660
return -ENOMEM;
16561661
}
16571662

1658-
for (tok = strtok_r(str, ", ", &tmp);
1663+
if (!is_strict_order(field_order))
1664+
strp++;
1665+
1666+
if (!strlen(strp)) {
1667+
error("Invalid --fields key: `+'");
1668+
goto out;
1669+
}
1670+
1671+
for (tok = strtok_r(strp, ", ", &tmp);
16591672
tok; tok = strtok_r(NULL, ", ", &tmp)) {
16601673
ret = output_field_add(tok);
16611674
if (ret == -EINVAL) {
@@ -1667,6 +1680,7 @@ static int __setup_output_field(void)
16671680
}
16681681
}
16691682

1683+
out:
16701684
free(str);
16711685
return ret;
16721686
}

tools/perf/util/sort.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,4 +218,5 @@ void perf_hpp__set_elide(int idx, bool elide);
218218

219219
int report_parse_ignore_callees_opt(const struct option *opt, const char *arg, int unset);
220220

221+
bool is_strict_order(const char *order);
221222
#endif /* __PERF_SORT_H */

0 commit comments

Comments
 (0)