perf record: collect user registers set jointly with dwarf stacks
PATCH v3 1/1 perf record: collect user registers set jointly with dwarf stacks
When dwarf stacks are collected jointly with user specified register set using --user-regs option like below the full register context is still captured on a sample:
$ perf record -g --call-graph dwarf,1024 --user-regs=IP,SP,BP -- matrix.gcc.g.O3
188143843893585 0x6b48 [0x4f8]: PERF_RECORD_SAMPLE(IP, 0x4002): 23828/23828: 0x401236 period: 1363819 addr: 0x7ffedbdd51ac ... FP chain: nr:0
... user regs: mask 0xff0fff ABI 64-bit
.... AX 0x53b .... BX 0x7ffedbdd3cc0 .... CX 0xffffffff .... DX 0x33d3a .... SI 0x7f09b74c38d0 .... DI 0x0 .... BP 0x401260 .... SP 0x7ffedbdd3cc0 .... IP 0x401236 .... FLAGS 0x20a .... CS 0x33 .... SS 0x2b .... R8 0x7f09b74c3800 .... R9 0x7f09b74c2da0 .... R10 0xfffffffffffff3ce .... R11 0x246 .... R12 0x401070 .... R13 0x7ffedbdd5db0 .... R14 0x0 .... R15 0x0
... ustack: size 1024, offset 0xe0
. data_src: 0x5080021
... thread: stack_test2.g.O:23828
...... dso: /root/abudanko/stacks/stack_test2.g.O3
After applying the change suggested in the patch the sample data contain only user specified register values:
$ perf record -g --call-graph dwarf,1024 --user-regs=BP -- matrix.gcc.g.03
188368474305373 0x5e40 [0x470]: PERF_RECORD_SAMPLE(IP, 0x4002): 23839/23839: 0x401236 period: 1260507 addr: 0x7ffd3d85e96c ... FP chain: nr:0
... user regs: mask 0x1c0 ABI 64-bit
.... BP 0x401260 .... SP 0x7ffd3d85cc20 .... IP 0x401236
... ustack: size 1024, offset 0x58
. data_src: 0x5080021
... thread: stack_test2.g.O:23839
...... dso: /root/abudanko/stacks/stack_test2.g.O3
IP and SP registers (dwarf_regs) are collected anayways regardless of the --user-regs option value provided from the command line:
-g call-graph dwarf,K full_regs -g call-graph dwarf,K --user-regs=user_regs user_regs | dwarf_regs --user-regs=user_regs user_regs
---
Changes in v3:
- avoid changes in platform specific header files
Changes in v2:
- implemented dwarf register set to avoid corrupted trace when --user-regs option value omits IP,SP
--- tools/perf/util/evsel.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
tools/perf/util/evsel.c +7 -1
@@ -669,6 +669,9 @@ int perf_evsel__group_desc(struct perf_evsel *evsel, char *buf, size_t size)return ret; } +#define DWARF_REGS_MASK ((1ULL << PERF_REG_IP) | \ + (1ULL << PERF_REG_SP)) +static void __perf_evsel__config_callchain (struct perf_evsel *evsel,struct record_opts *opts,struct callchain_param *param)
@@ -702,7 +705,10 @@ static void __perf_evsel__config_callchain(struct perf_evsel *evsel,if (!function) {perf_evsel__set_sample_bit (evsel,REGS_USER );perf_evsel__set_sample_bit (evsel,STACK_USER ); - attr->sample_regs_user |=PERF_REGS_MASK ; +if (opts->sample_user_regs) + attr->sample_regs_user |=DWARF_REGS_MASK ; +else + attr->sample_regs_user |=PERF_REGS_MASK ; attr->sample_stack_user = param->dump_size; attr->exclude_callchain_user =1 ; }else {
Signature · 1 line
2.20.1
Em Mon, Apr 22, 2019 at 05:37:52PM +0300, Alexey Budankov escreveu:
Quoted 46 lines
When dwarf stacks are collected jointly with user specified register set using --user-regs option like below the full register context is still captured on a sample:
$ perf record -g --call-graph dwarf,1024 --user-regs=IP,SP,BP -- matrix.gcc.g.O3188143843893585
0x6b48[0x4f8]:PERF_RECORD_SAMPLE(IP, 0x4002): 23828/23828:0x401236period: 1363819 addr:0x7ffedbdd51ac... FP chain: nr:0
... user regs: mask0xff0fffABI 64-bit.... AX 0x53b .... BX 0x7ffedbdd3cc0 .... CX 0xffffffff .... DX 0x33d3a .... SI 0x7f09b74c38d0 .... DI 0x0 .... BP 0x401260 .... SP 0x7ffedbdd3cc0 .... IP 0x401236 .... FLAGS 0x20a .... CS 0x33 .... SS 0x2b .... R8 0x7f09b74c3800 .... R9 0x7f09b74c2da0 .... R10 0xfffffffffffff3ce .... R11 0x246 .... R12 0x401070 .... R13 0x7ffedbdd5db0 .... R14 0x0 .... R15 0x0... ustack: size 1024, offset
0xe0
.data_src:0x5080021
... thread: stack_test2.g.O:23828
...... dso:/root/abudanko/stacks/stack_test2.g.O3After applying the change suggested in the patch the sample data contain only user specified register values:
$ perf record -g --call-graph dwarf,1024 --user-regs=BP -- matrix.gcc.g.03188368474305373
0x5e40[0x470]:PERF_RECORD_SAMPLE(IP, 0x4002): 23839/23839:0x401236period: 1260507 addr:0x7ffd3d85e96c... FP chain: nr:0
... user regs: mask0x1c0ABI 64-bit.... BP 0x401260 .... SP 0x7ffd3d85cc20 .... IP 0x401236
Quoted 7 lines
... ustack: size 1024, offset
0x58
.data_src:0x5080021
... thread: stack_test2.g.O:23839
...... dso:/root/abudanko/stacks/stack_test2.g.O3IP and SP registers (
dwarf_regs) are collected anayways regardless of the --user-regs option value provided from the command line:
So user asks for a, b and c and gets a, b, c + d and e? At the very least we should warn that those registers are being added to the mix, i.e. something like:
WARNING: specified --user-regs register set doesn't include registers needed by also specified --call-graph=dwarf, auto adding missing registers (list of missing registers auto-added).
- Arnaldo
P.S. Back from vacation, going thru backlog, hopefully will apply your perf.data compression patchkit after testing its patches one by one, sorry for the delay for that one (and this :))
Quoted 45 lines
-g call-graph dwarf,K full_regs -g call-graph dwarf,K --user-regs=user_regs user_regs | dwarf_regs --user-regs=user_regs user_regsSigned-off-by Alexey Budankov <[email protected]>---
Changes in v3:
- avoid changes in platform specific header filesChanges in v2:
- implemented dwarf register set to avoid corrupted trace when --user-regs option value omits IP,SP--- tools/perf/util/evsel.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)tools/perf/util/evsel.c +7
-1@@ -669,6 +669,9 @@ int perf_evsel__group_desc(struct perf_evsel *evsel, char *buf, size_t size)return ret; } +#define DWARF_REGS_MASK ((1ULL << PERF_REG_IP) | \ + (1ULL << PERF_REG_SP)) +static void __perf_evsel__config_callchain (struct perf_evsel *evsel,struct record_opts *opts,struct callchain_param *param)@@ -702,7 +705,10 @@ static void __perf_evsel__config_callchain(struct perf_evsel *evsel,if (!function) {perf_evsel__set_sample_bit (evsel,REGS_USER );perf_evsel__set_sample_bit (evsel,STACK_USER ); - attr->sample_regs_user |=PERF_REGS_MASK ; +if (opts->sample_user_regs) + attr->sample_regs_user |=DWARF_REGS_MASK ; +else + attr->sample_regs_user |=PERF_REGS_MASK ; attr->sample_stack_user = param->dump_size; attr->exclude_callchain_user =1 ; }else {Signature · 1 line
2.20.1
Signature · 1 line
- Arnaldo
Quoted 55 lines · Arnaldo Carvalho de Melo
Em Mon, Apr 22, 2019 at 05:37:52PM +0300, Alexey Budankov escreveu:
Quoted 46 lines
When dwarf stacks are collected jointly with user specified register set using --user-regs option like below the full register context is still captured on a sample:
$ perf record -g --call-graph dwarf,1024 --user-regs=IP,SP,BP -- matrix.gcc.g.O3188143843893585
0x6b48[0x4f8]:PERF_RECORD_SAMPLE(IP, 0x4002): 23828/23828:0x401236period: 1363819 addr:0x7ffedbdd51ac... FP chain: nr:0
... user regs: mask0xff0fffABI 64-bit.... AX 0x53b .... BX 0x7ffedbdd3cc0 .... CX 0xffffffff .... DX 0x33d3a .... SI 0x7f09b74c38d0 .... DI 0x0 .... BP 0x401260 .... SP 0x7ffedbdd3cc0 .... IP 0x401236 .... FLAGS 0x20a .... CS 0x33 .... SS 0x2b .... R8 0x7f09b74c3800 .... R9 0x7f09b74c2da0 .... R10 0xfffffffffffff3ce .... R11 0x246 .... R12 0x401070 .... R13 0x7ffedbdd5db0 .... R14 0x0 .... R15 0x0... ustack: size 1024, offset
0xe0
.data_src:0x5080021
... thread: stack_test2.g.O:23828
...... dso:/root/abudanko/stacks/stack_test2.g.O3After applying the change suggested in the patch the sample data contain only user specified register values:
$ perf record -g --call-graph dwarf,1024 --user-regs=BP -- matrix.gcc.g.03188368474305373
0x5e40[0x470]:PERF_RECORD_SAMPLE(IP, 0x4002): 23839/23839:0x401236period: 1260507 addr:0x7ffd3d85e96c... FP chain: nr:0
... user regs: mask0x1c0ABI 64-bit.... BP 0x401260 .... SP 0x7ffd3d85cc20 .... IP 0x401236Quoted 7 lines
... ustack: size 1024, offset
0x58
.data_src:0x5080021
... thread: stack_test2.g.O:23839
...... dso:/root/abudanko/stacks/stack_test2.g.O3IP and SP registers (
dwarf_regs) are collected anayways regardless of the --user-regs option value provided from the command line:
Quoted 7 lines
So user asks for a, b and c and gets a, b, c + d and e? At the very least we should warn that those registers are being added to the mix, i.e. something like:
WARNING: specified --user-regs register set doesn't include registers needed by also specified --call-graph=dwarf, auto adding missing registers (list of missing registers auto-added).
Well, let's have it like this.
~Alexey
Quoted 53 lines
- Arnaldo
P.S. Back from vacation, going thru backlog, hopefully will apply your perf.data compression patchkit after testing its patches one by one, sorry for the delay for that one (and this :))Quoted 45 lines
-g call-graph dwarf,K full_regs -g call-graph dwarf,K --user-regs=user_regs user_regs | dwarf_regs --user-regs=user_regs user_regsSigned-off-by Alexey Budankov <[email protected]>---
Changes in v3:
- avoid changes in platform specific header filesChanges in v2:
- implemented dwarf register set to avoid corrupted trace when --user-regs option value omits IP,SP--- tools/perf/util/evsel.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)tools/perf/util/evsel.c +7
-1@@ -669,6 +669,9 @@ int perf_evsel__group_desc(struct perf_evsel *evsel, char *buf, size_t size)return ret; } +#define DWARF_REGS_MASK ((1ULL << PERF_REG_IP) | \ + (1ULL << PERF_REG_SP)) +static void __perf_evsel__config_callchain (struct perf_evsel *evsel,struct record_opts *opts,struct callchain_param *param)@@ -702,7 +705,10 @@ static void __perf_evsel__config_callchain(struct perf_evsel *evsel,if (!function) {perf_evsel__set_sample_bit (evsel,REGS_USER );perf_evsel__set_sample_bit (evsel,STACK_USER ); - attr->sample_regs_user |=PERF_REGS_MASK ; +if (opts->sample_user_regs) + attr->sample_regs_user |=DWARF_REGS_MASK ; +else + attr->sample_regs_user |=PERF_REGS_MASK ; attr->sample_stack_user = param->dump_size; attr->exclude_callchain_user =1 ; }else {Signature · 1 line
2.20.1