diff options
| author | Jiri Olsa <jolsa@kernel.org> | 2019-02-20 07:27:57 -0500 |
|---|---|---|
| committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2019-02-20 14:15:35 -0500 |
| commit | 6ef362fd3cf3af5d8143a07b4ea20499bf2a9eec (patch) | |
| tree | 7298e3ac3146176b3a9378b4c95cd713b28393c2 | |
| parent | 6e7e8b9fec45f7bef11a5d9d2dd9febe439d4047 (diff) | |
perf script: Allow +- operator for type specific fields option
Add support to add/remove fields for specific event types in -F option.
It's now possible to use '+-' after event type, like:
# cat > test.c
#include <stdio.h>
int main(void)
{
printf("Hello world\n");
while(1) {}
}
^D
# gcc -g -o test test.c
# perf probe -x test 'test.c:5'
# perf record -e '{cpu/cpu-cycles,period=10000/,probe_test:main}:S' ./test
...
# perf script -Ftrace:+period,-cpu
test 3859 396291.117343: 10275 cpu/cpu-cycles,period=10000/: 7f..
test 3859 396291.118234: 11041 cpu/cpu-cycles,period=10000/: ffffff..
test 3859 396291.118234: 1 probe_test:main:
test 3859 396291.118248: 8668 cpu/cpu-cycles,period=10000/: ffffff..
test 3859 396291.118263: 10139 cpu/cpu-cycles,period=10000/: ffffff..
Committer testing:
Couldn't make the test above work, but tested it with:
# perf probe -x hello main
Added new event:
probe_hello:main (on main in /home/acme/c/hello)
You can now use it in all perf tools, such as:
perf record -e probe_hello:main -aR sleep 1
# perf record -e probe_hello:main ./hello
hello, world
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.025 MB perf.data (1 samples) ]
# perf script
hello 21454 [002] 254116.874005: probe_hello:main: (401126)
#
# perf script -Ftrace:+period,-cpu
hello 21454 254116.874005: 1 probe_hello:main: (401126)
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20190220122800.864-4-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
| -rw-r--r-- | tools/perf/Documentation/perf-script.txt | 6 | ||||
| -rw-r--r-- | tools/perf/builtin-script.c | 8 |
2 files changed, 14 insertions, 0 deletions
diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt index 9e4def08d569..2e19fd7ffe35 100644 --- a/tools/perf/Documentation/perf-script.txt +++ b/tools/perf/Documentation/perf-script.txt | |||
| @@ -159,6 +159,12 @@ OPTIONS | |||
| 159 | the override, and the result of the above is that only S/W and H/W | 159 | the override, and the result of the above is that only S/W and H/W |
| 160 | events are displayed with the given fields. | 160 | events are displayed with the given fields. |
| 161 | 161 | ||
| 162 | It's possible tp add/remove fields only for specific event type: | ||
| 163 | |||
| 164 | -Fsw:-cpu,-period | ||
| 165 | |||
| 166 | removes cpu and period from software events. | ||
| 167 | |||
| 162 | For the 'wildcard' option if a user selected field is invalid for an | 168 | For the 'wildcard' option if a user selected field is invalid for an |
| 163 | event type, a message is displayed to the user that the option is | 169 | event type, a message is displayed to the user that the option is |
| 164 | ignored for that type. For example: | 170 | ignored for that type. For example: |
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 8d5fe092525c..373ea151dc60 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c | |||
| @@ -2560,6 +2560,10 @@ static int parse_output_fields(const struct option *opt __maybe_unused, | |||
| 2560 | pr_warning("Overriding previous field request for %s events.\n", | 2560 | pr_warning("Overriding previous field request for %s events.\n", |
| 2561 | event_type(type)); | 2561 | event_type(type)); |
| 2562 | 2562 | ||
| 2563 | /* Don't override defaults for +- */ | ||
| 2564 | if (strchr(tok, '+') || strchr(tok, '-')) | ||
| 2565 | goto parse; | ||
| 2566 | |||
| 2563 | output[type].fields = 0; | 2567 | output[type].fields = 0; |
| 2564 | output[type].user_set = true; | 2568 | output[type].user_set = true; |
| 2565 | output[type].wildcard_set = false; | 2569 | output[type].wildcard_set = false; |
| @@ -2644,6 +2648,10 @@ parse: | |||
| 2644 | rc = -EINVAL; | 2648 | rc = -EINVAL; |
| 2645 | goto out; | 2649 | goto out; |
| 2646 | } | 2650 | } |
| 2651 | if (change == REMOVE) | ||
| 2652 | output[type].fields &= ~all_output_options[i].field; | ||
| 2653 | else | ||
| 2654 | output[type].fields |= all_output_options[i].field; | ||
| 2647 | output[type].user_set = true; | 2655 | output[type].user_set = true; |
| 2648 | output[type].wildcard_set = true; | 2656 | output[type].wildcard_set = true; |
| 2649 | } | 2657 | } |
