perf script: Fix PERF_SAMPLE_WEIGHT_STRUCT support
PATCH 1/2 perf script: Fix PERF_SAMPLE_WEIGHT_STRUCT support
From: Kan Liang <[email protected]>
-F weight in perf script is broken.
# ./perf mem record # ./perf script -F weight Samples for 'dummy:HG' event do not have WEIGHT attribute set. Cannot print 'weight' field.
The sample type, PERF_SAMPLE_WEIGHT_STRUCT, is an alternative of the PERF_SAMPLE_WEIGHT sample type. They share the same space, weight. The lower 32 bits are exactly the same for both sample type. The higher 32 bits may be different for different architecture. For a new kernel on x86, the PERF_SAMPLE_WEIGHT_STRUCT is used. For an old kernel or other ARCHs, the PERF_SAMPLE_WEIGHT is used.
With -F weight, current perf script will only check the input string "weight" with the PERF_SAMPLE_WEIGHT sample type. Because the commit ea8d0ed6eae3 ("perf tools: Support PERF_SAMPLE_WEIGHT_STRUCT") didn't update the PERF_SAMPLE_WEIGHT_STRUCT sample type for perf script. For a new kernel on x86, the check fails.
Use PERF_SAMPLE_WEIGHT_TYPE, which supports both sample types, to replace PERF_SAMPLE_WEIGHT.
--- tools/perf/builtin-script.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/builtin-script.c +1 -1
@@ -459,7 +459,7 @@ static int evsel__check_attr(struct evsel *evsel, struct perf_session *session)return -EINVAL ;if (PRINT_FIELD (WEIGHT ) && -evsel__check_stype (evsel,PERF_SAMPLE_WEIGHT ,"WEIGHT" ,PERF_OUTPUT_WEIGHT )) +evsel__check_stype (evsel,PERF_SAMPLE_WEIGHT_TYPE ,"WEIGHT" ,PERF_OUTPUT_WEIGHT ))return -EINVAL ; if (PRINT_FIELD(SYM) &&
Signature · 1 line
2.7.4
PATCH 2/2 perf script: Support instruction latency
From: Kan Liang <[email protected]>
The instruction latency information can be recorded on
some platforms, e.g., the Intel Sapphire Rapids server. With both memory latency (weight) and the new instruction latency information, users can easily locate the expensive load instructions, and also understand the time spent in different stages. The users can optimize their applications in different pipeline stages.
Add a new field "ins_lat" to filter the instruction latency information, which is available with sample type PERF_SAMPLE_WEIGHT_STRUCT.
--- tools/perf/Documentation/perf-script.txt | 2 +- tools/perf/builtin-script.c | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-)
tools/perf/Documentation/perf-script.txt +1 -1
@@ -130,7 +130,7 @@ OPTIONS comm, tid, pid, time, cpu, event, trace, ip, sym, dso, addr, symoff, srcline, period, iregs, uregs, brstack, brstacksym, flags, bpf-output, brstackinsn, brstackoff, callindent, insn, insnlen, synth, phys_addr, - metric, misc, srccode, ipc, data_page_size, code_page_size. + metric, misc, srccode, ipc, data_page_size, code_page_size, ins_lat. Field list can be prepended with the type, trace, sw or hw, to indicate to which event type the field list applies. e.g., -F sw:comm,tid,time,ip,sym and -F trace:time,cpu,trace
tools/perf/builtin-script.c +12 -2
@@ -122,6 +122,7 @@ enum perf_output_field {PERF_OUTPUT_TOD =1ULL <<32 ,PERF_OUTPUT_DATA_PAGE_SIZE =1ULL <<33 ,PERF_OUTPUT_CODE_PAGE_SIZE =1ULL <<34 , + PERF_OUTPUT_INS_LAT = 1ULL << 35, }; struct perf_script {
@@ -188,6 +189,7 @@ struct output_option { {.str = "tod", .field = PERF_OUTPUT_TOD}, {.str = "data_page_size", .field = PERF_OUTPUT_DATA_PAGE_SIZE}, {.str = "code_page_size", .field = PERF_OUTPUT_CODE_PAGE_SIZE}, + {.str = "ins_lat", .field = PERF_OUTPUT_INS_LAT}, }; enum {
@@ -262,7 +264,8 @@ static struct {PERF_OUTPUT_DSO |PERF_OUTPUT_PERIOD |PERF_OUTPUT_ADDR |PERF_OUTPUT_DATA_SRC |PERF_OUTPUT_WEIGHT |PERF_OUTPUT_PHYS_ADDR | - PERF_OUTPUT_DATA_PAGE_SIZE | PERF_OUTPUT_CODE_PAGE_SIZE, +PERF_OUTPUT_DATA_PAGE_SIZE |PERF_OUTPUT_CODE_PAGE_SIZE | + PERF_OUTPUT_INS_LAT, .invalid_fields = PERF_OUTPUT_TRACE | PERF_OUTPUT_BPF_OUTPUT, },
@@ -522,6 +525,10 @@ static int evsel__check_attr(struct evsel *evsel, struct perf_session *session) evsel__check_stype(evsel, PERF_SAMPLE_CODE_PAGE_SIZE, "CODE_PAGE_SIZE", PERF_OUTPUT_CODE_PAGE_SIZE)) return -EINVAL; +if (PRINT_FIELD (INS_LAT ) && +evsel__check_stype (evsel,PERF_SAMPLE_WEIGHT_STRUCT ,"WEIGHT_STRUCT" ,PERF_OUTPUT_INS_LAT )) +return -EINVAL ; +return 0 ; }
@@ -2039,6 +2046,9 @@ static void process_event(struct perf_script *script,if (PRINT_FIELD (WEIGHT ))fprintf (fp,"%16" PRIu64, sample->weight); +if (PRINT_FIELD (INS_LAT )) +fprintf (fp,"%16" PRIu16, sample->ins_lat); +if (PRINT_FIELD (IP )) {struct callchain_cursor *cursor =NULL ;
@@ -3715,7 +3725,7 @@ int cmd_script(int argc, const char **argv) "addr,symoff,srcline,period,iregs,uregs,brstack," "brstacksym,flags,bpf-output,brstackinsn,brstackoff," "callindent,insn,insnlen,synth,phys_addr,metric,misc,ipc,tod," - "data_page_size,code_page_size", + "data_page_size,code_page_size,ins_lat", parse_output_fields),OPT_BOOLEAN ('a' ,"all-cpus" , &system_wide, "system-wide collection from all CPUs"),
Signature · 1 line
2.7.4
Arnaldo Carvalho de Melo
maintainerEm Wed, Sep 29, 2021 at 08:38:13AM -0700, [email protected] escreveu:
Quoted 22 lines
From: Kan Liang <[email protected]>
-F weight in perf script is broken.
# ./perf mem record # ./perf script -F weight Samples for 'dummy:HG' event do not have WEIGHT attribute set. Cannot print 'weight' field.The sample type,
PERF_SAMPLE_WEIGHT_STRUCT, is an alternative of thePERF_SAMPLE_WEIGHTsample type. They share the same space, weight. The lower 32 bits are exactly the same for both sample type. The higher 32 bits may be different for different architecture. For a new kernel on x86, thePERF_SAMPLE_WEIGHT_STRUCTis used. For an old kernel or other ARCHs, thePERF_SAMPLE_WEIGHTis used.With -F weight, current perf script will only check the input string "weight" with the
PERF_SAMPLE_WEIGHTsample type. Because the commitea8d0ed6eae3("perf tools: SupportPERF_SAMPLE_WEIGHT_STRUCT") didn't update thePERF_SAMPLE_WEIGHT_STRUCTsample type for perf script. For a new kernel on x86, the check fails.
Quoted 5 lines
Use
PERF_SAMPLE_WEIGHT_TYPE, which supports both sample types, to replacePERF_SAMPLE_WEIGHT.Reported-by Joe Mario <[email protected]>Fixes ea8d0ed6eae3 ("perf tools: Support PERF_SAMPLE_WEIGHT_STRUCT")
Hey Joe, Jiri,
Can I have your Tested-by?
Thanks,
- Arnaldo
Quoted 20 lines
Signed-off-by Kan Liang <[email protected]>--- tools/perf/builtin-script.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/perf/builtin-script.c +1
-1@@ -459,7 +459,7 @@ static int evsel__check_attr(struct evsel *evsel, struct perf_session *session)return -EINVAL ;if (PRINT_FIELD (WEIGHT ) && -evsel__check_stype (evsel,PERF_SAMPLE_WEIGHT ,"WEIGHT" ,PERF_OUTPUT_WEIGHT )) +evsel__check_stype (evsel,PERF_SAMPLE_WEIGHT_TYPE ,"WEIGHT" ,PERF_OUTPUT_WEIGHT ))return -EINVAL ; if (PRINT_FIELD(SYM) &&Signature · 1 line
2.7.4
Signature · 1 line
- Arnaldo
Quoted 26 lines · Arnaldo Carvalho de Melo
Em Wed, Sep 29, 2021 at 08:38:13AM -0700, [email protected] escreveu:
Quoted 25 lines
From: Kan Liang <[email protected]>
-F weight in perf script is broken.
# ./perf mem record # ./perf script -F weight Samples for 'dummy:HG' event do not have WEIGHT attribute set. Cannot print 'weight' field.The sample type,
PERF_SAMPLE_WEIGHT_STRUCT, is an alternative of thePERF_SAMPLE_WEIGHTsample type. They share the same space, weight. The lower 32 bits are exactly the same for both sample type. The higher 32 bits may be different for different architecture. For a new kernel on x86, thePERF_SAMPLE_WEIGHT_STRUCTis used. For an old kernel or other ARCHs, thePERF_SAMPLE_WEIGHTis used.With -F weight, current perf script will only check the input string "weight" with the
PERF_SAMPLE_WEIGHTsample type. Because the commitea8d0ed6eae3("perf tools: SupportPERF_SAMPLE_WEIGHT_STRUCT") didn't update thePERF_SAMPLE_WEIGHT_STRUCTsample type for perf script. For a new kernel on x86, the check fails.Use
PERF_SAMPLE_WEIGHT_TYPE, which supports both sample types, to replacePERF_SAMPLE_WEIGHT.
Quoted 6 lines
Quoted 2 lines
Reported-by Joe Mario <[email protected]>Fixes ea8d0ed6eae3 ("perf tools: Support PERF_SAMPLE_WEIGHT_STRUCT")Hey Joe, Jiri,
Can I have your Tested-by?
Acked/Tested-by: Jiri Olsa <[email protected]>
thanks,
jirka
Quoted 30 lines
Thanks,
- Arnaldo
Quoted 20 lines
Signed-off-by Kan Liang <[email protected]>--- tools/perf/builtin-script.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/perf/builtin-script.c +1
-1@@ -459,7 +459,7 @@ static int evsel__check_attr(struct evsel *evsel, struct perf_session *session)return -EINVAL ;if (PRINT_FIELD (WEIGHT ) && -evsel__check_stype (evsel,PERF_SAMPLE_WEIGHT ,"WEIGHT" ,PERF_OUTPUT_WEIGHT )) +evsel__check_stype (evsel,PERF_SAMPLE_WEIGHT_TYPE ,"WEIGHT" ,PERF_OUTPUT_WEIGHT ))return -EINVAL ; if (PRINT_FIELD(SYM) &&Signature · 1 line
2.7.4Signature · 1 line
- Arnaldo
Quoted 30 lines · Jiri Olsa
Quoted 29 lines · Arnaldo Carvalho de Melo
Em Wed, Sep 29, 2021 at 08:38:13AM -0700, [email protected] escreveu:
Quoted 27 lines
From: Kan Liang <[email protected]>
-F weight in perf script is broken.
# ./perf mem record # ./perf script -F weight Samples for 'dummy:HG' event do not have WEIGHT attribute set. Cannot print 'weight' field.The sample type,
PERF_SAMPLE_WEIGHT_STRUCT, is an alternative of thePERF_SAMPLE_WEIGHTsample type. They share the same space, weight. The lower 32 bits are exactly the same for both sample type. The higher 32 bits may be different for different architecture. For a new kernel on x86, thePERF_SAMPLE_WEIGHT_STRUCTis used. For an old kernel or other ARCHs, thePERF_SAMPLE_WEIGHTis used.With -F weight, current perf script will only check the input string "weight" with the
PERF_SAMPLE_WEIGHTsample type. Because the commitea8d0ed6eae3("perf tools: SupportPERF_SAMPLE_WEIGHT_STRUCT") didn't update thePERF_SAMPLE_WEIGHT_STRUCTsample type for perf script. For a new kernel on x86, the check fails.Use
PERF_SAMPLE_WEIGHT_TYPE, which supports both sample types, to replacePERF_SAMPLE_WEIGHT.Reported-by Joe Mario <[email protected]>Fixes ea8d0ed6eae3 ("perf tools: Support PERF_SAMPLE_WEIGHT_STRUCT")
Quoted 8 lines
Quoted 3 lines
Hey Joe, Jiri,
Can I have your Tested-by?
Acked/Tested-by: Jiri Olsa <[email protected]>
thanks,
jirka
Acked/Tested-by: Joe Mario <[email protected]>
The "perf script -F weight" command works correctly.
And I also verified that when just issuing "perf script", that the weight (cycle latency) column that was missing with this bug, is now fixed and working properly.
Thanks,
Joe
Quoted 32 lines
Quoted 31 lines
Thanks,
- Arnaldo
Quoted 20 lines
Signed-off-by Kan Liang <[email protected]>--- tools/perf/builtin-script.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/perf/builtin-script.c +1
-1@@ -459,7 +459,7 @@ static int evsel__check_attr(struct evsel *evsel, struct perf_session *session)return -EINVAL ;if (PRINT_FIELD (WEIGHT ) && -evsel__check_stype (evsel,PERF_SAMPLE_WEIGHT ,"WEIGHT" ,PERF_OUTPUT_WEIGHT )) +evsel__check_stype (evsel,PERF_SAMPLE_WEIGHT_TYPE ,"WEIGHT" ,PERF_OUTPUT_WEIGHT ))return -EINVAL ; if (PRINT_FIELD(SYM) &&Signature · 1 line
2.7.4Signature · 1 line
- Arnaldo
Em Wed, Sep 29, 2021 at 04:22:19PM -0400, Joe Mario escreveu:
Quoted 42 lines · Jiri Olsa
Quoted 30 lines · Arnaldo Carvalho de Melo
Quoted 29 lines
Em Wed, Sep 29, 2021 at 08:38:13AM -0700, [email protected] escreveu:
Quoted 27 lines
From: Kan Liang <[email protected]>
-F weight in perf script is broken.
# ./perf mem record # ./perf script -F weight Samples for 'dummy:HG' event do not have WEIGHT attribute set. Cannot print 'weight' field.The sample type,
PERF_SAMPLE_WEIGHT_STRUCT, is an alternative of thePERF_SAMPLE_WEIGHTsample type. They share the same space, weight. The lower 32 bits are exactly the same for both sample type. The higher 32 bits may be different for different architecture. For a new kernel on x86, thePERF_SAMPLE_WEIGHT_STRUCTis used. For an old kernel or other ARCHs, thePERF_SAMPLE_WEIGHTis used.With -F weight, current perf script will only check the input string "weight" with the
PERF_SAMPLE_WEIGHTsample type. Because the commitea8d0ed6eae3("perf tools: SupportPERF_SAMPLE_WEIGHT_STRUCT") didn't update thePERF_SAMPLE_WEIGHT_STRUCTsample type for perf script. For a new kernel on x86, the check fails.Use
PERF_SAMPLE_WEIGHT_TYPE, which supports both sample types, to replacePERF_SAMPLE_WEIGHT.Reported-by Joe Mario <[email protected]>Fixes ea8d0ed6eae3 ("perf tools: Support PERF_SAMPLE_WEIGHT_STRUCT")Quoted 8 lines
Quoted 3 lines
Hey Joe, Jiri,
Can I have your Tested-by?
Acked/Tested-by: Jiri Olsa <[email protected]>
thanks,
jirka
Quoted 6 lines
Acked/Tested-by: Joe Mario <[email protected]>
The "perf script -F weight" command works correctly.
And I also verified that when just issuing "perf script", that the weight (cycle latency) column that was missing with this bug, is now fixed and working properly.
Thanks, applied.
- Arnaldo
Quoted 34 lines
Thanks,
JoeQuoted 32 lines
Quoted 31 lines
Thanks,
- Arnaldo
Quoted 20 lines
Signed-off-by Kan Liang <[email protected]>--- tools/perf/builtin-script.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/perf/builtin-script.c +1
-1@@ -459,7 +459,7 @@ static int evsel__check_attr(struct evsel *evsel, struct perf_session *session)return -EINVAL ;if (PRINT_FIELD (WEIGHT ) && -evsel__check_stype (evsel,PERF_SAMPLE_WEIGHT ,"WEIGHT" ,PERF_OUTPUT_WEIGHT )) +evsel__check_stype (evsel,PERF_SAMPLE_WEIGHT_TYPE ,"WEIGHT" ,PERF_OUTPUT_WEIGHT ))return -EINVAL ; if (PRINT_FIELD(SYM) &&Signature · 1 line
2.7.4Signature · 1 line
- Arnaldo
Signature · 1 line
- Arnaldo
Quoted 8 lines · On 9/29/21 9:08 PM, [email protected] wrote:
From: Kan Liang <[email protected]>
-F weight in perf script is broken.
# ./perf mem record # ./perf script -F weight Samples for 'dummy:HG' event do not have WEIGHT attribute set. Cannot print 'weight' field.
Hi Kan,
This issue can also be reproduce in powerpc box.
Given patch fix the issue.
Thanks,
Kajol Jain
Quoted 38 lines
The sample type,
PERF_SAMPLE_WEIGHT_STRUCT, is an alternative of thePERF_SAMPLE_WEIGHTsample type. They share the same space, weight. The lower 32 bits are exactly the same for both sample type. The higher 32 bits may be different for different architecture. For a new kernel on x86, thePERF_SAMPLE_WEIGHT_STRUCTis used. For an old kernel or other ARCHs, thePERF_SAMPLE_WEIGHTis used.With -F weight, current perf script will only check the input string "weight" with the
PERF_SAMPLE_WEIGHTsample type. Because the commitea8d0ed6eae3("perf tools: SupportPERF_SAMPLE_WEIGHT_STRUCT") didn't update thePERF_SAMPLE_WEIGHT_STRUCTsample type for perf script. For a new kernel on x86, the check fails.Use
PERF_SAMPLE_WEIGHT_TYPE, which supports both sample types, to replacePERF_SAMPLE_WEIGHT.Reported-by Joe Mario <[email protected]>Fixes ea8d0ed6eae3 ("perf tools: Support PERF_SAMPLE_WEIGHT_STRUCT")Signed-off-by Kan Liang <[email protected]>--- tools/perf/builtin-script.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/perf/builtin-script.c +1
-1@@ -459,7 +459,7 @@ static int evsel__check_attr(struct evsel *evsel, struct perf_session *session)return -EINVAL ;if (PRINT_FIELD (WEIGHT ) && -evsel__check_stype (evsel,PERF_SAMPLE_WEIGHT ,"WEIGHT" ,PERF_OUTPUT_WEIGHT )) +evsel__check_stype (evsel,PERF_SAMPLE_WEIGHT_TYPE ,"WEIGHT" ,PERF_OUTPUT_WEIGHT ))return -EINVAL ; if (PRINT_FIELD(SYM) &&