problem with 'perf script -F weight'
hi,
Joe reported broken -F weight in perf script with (on x86):
# ./perf mem record # ./perf script -F weight Samples for 'dummy:HG' event do not have WEIGHT attribute set. Cannot print 'weight' field.
the problem seems to be introduced with the WEIGHT_STRUCT change:
ea8d0ed6eae3 perf tools: Support PERF_SAMPLE_WEIGHT_STRUCT
which enables WEIGHT_STRUCT sample_type on x86 instead of WEIGHT, and leaves 'perf script -F weight' in the dark
I'm not sure what the fix should look like.. should we allow user to use just 'WEIGHT' sample type? or is there a way to get original weight from 'WEIGHT_STRUCT' data, so we could fix just perf script?
FYI when I switch back the WEIGHT_STRUCT to WEIGHT again it seems to work as before.. as expected ;-)
any thoughts? thanks
jirka
---
tools/perf/arch/x86/util/evsel.c +1 -1
@@ -4,5 +4,5 @@void arch_evsel__set_sample_weight (struct evsel *evsel) { -evsel__set_sample_bit (evsel,WEIGHT_STRUCT ); +evsel__set_sample_bit (evsel,WEIGHT ); }
Quoted 10 lines · Jiri Olsa
hi,
Joe reported broken -F weight in perf script with (on x86):# ./perf mem record # ./perf script -F weight Samples for 'dummy:HG' event do not have WEIGHT attribute set. Cannot print 'weight' field.the problem seems to be introduced with the
WEIGHT_STRUCTchange:
ea8d0ed6eae3perf tools: SupportPERF_SAMPLE_WEIGHT_STRUCT
Quoted 6 lines
which enables
WEIGHT_STRUCTsample_typeon x86 instead of WEIGHT, and leaves 'perf script -F weight' in the darkI'm not sure what the fix should look like.. should we allow user to use just 'WEIGHT' sample type? or is there a way to get original weight from '
WEIGHT_STRUCT' data, so we could fix just perf script?
We would need to support both in perf script, to handle both perf.data generated by old and new kernels on both big and little endian
So probably try one first and then the other while parsing
The same is true for all other users, so probably there needs to be a library function for this somewhere.
-Andi
Quoted 11 lines · Jiri Olsa
Joe reported broken -F weight in perf script with (on x86):
# ./perf mem record # ./perf script -F weight Samples for 'dummy:HG' event do not have WEIGHT attribute set. Cannot print 'weight' field.the problem seems to be introduced with the
WEIGHT_STRUCTchange:
ea8d0ed6eae3perf tools: SupportPERF_SAMPLE_WEIGHT_STRUCTwhich enables
WEIGHT_STRUCTsample_typeon x86 instead of WEIGHT, and leaves 'perf script -F weight' in the dark
Right, I missed the support for the perf script. Because the default perf script worked. It didn't ring the bell. :(
Quoted 4 lines
I'm not sure what the fix should look like.. should we allow user to use just 'WEIGHT' sample type? or is there a way to get original weight from '
WEIGHT_STRUCT' data, so we could fix just perf script?
Just fix the perf script is enough.
Could you please try the below patch?
(I probably need to split the patch into two patches, since it fixed two issues, one is this error, the other is to print the instruction latency. Anyway, let's try it first.)
From 99443f49a6236ef6e3bea3930792967a7863f753 Mon Sep 17 00:00:00 2001
From: Kan Liang <[email protected]>
Date: Tue, 28 Sep 2021 13:57:18 -0700
Subject: [PATCH] perf script: Fix PERF_SAMPLE_WEIGHT_STRUCT support
-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 check the input string "weight" with the corresponding sample type. However, the commit ID ea8d0ed6eae3 ("perf tools: Support PERF_SAMPLE_WEIGHT_STRUCT") didn't update the sample type for perf script. The check fails with a new kernel on x86.
Use PERF_SAMPLE_WEIGHT_TYPE, which supports both sample types, to replace PERF_SAMPLE_WEIGHT.
Also, print the instruction latency for PERF_SAMPLE_WEIGHT_STRUCT type.
--- tools/perf/builtin-script.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
tools/perf/builtin-script.c +5 -2
@@ -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) &&
@@ -2036,8 +2036,11 @@ static void process_event(struct perf_script *script,if (PRINT_FIELD (DATA_SRC ))data_src__fprintf (sample->data_src, fp); -if (PRINT_FIELD (WEIGHT )) +if (PRINT_FIELD (WEIGHT )) {fprintf (fp,"%16" PRIu64, sample->weight); +if (attr->sample_type &PERF_SAMPLE_WEIGHT_STRUCT ) +fprintf (fp,",0x%" PRIx16, sample->ins_lat); + }if (PRINT_FIELD (IP )) {struct callchain_cursor *cursor =NULL ;
Signature · 4 lines
2.7.4 Thanks, Kan
Quoted 83 lines · Kan
Quoted 11 lines · Jiri Olsa
Joe reported broken -F weight in perf script with (on x86):
# ./perf mem record # ./perf script -F weight Samples for 'dummy:HG' event do not have WEIGHT attribute set. Cannot print 'weight' field.the problem seems to be introduced with the
WEIGHT_STRUCTchange:
ea8d0ed6eae3perf tools: SupportPERF_SAMPLE_WEIGHT_STRUCTwhich enables
WEIGHT_STRUCTsample_typeon x86 instead of WEIGHT, and leaves 'perf script -F weight' in the darkRight, I missed the support for the perf script. Because the default perf script worked. It didn't ring the bell. :(
Quoted 4 lines
I'm not sure what the fix should look like.. should we allow user to use just 'WEIGHT' sample type? or is there a way to get original weight from '
WEIGHT_STRUCT' data, so we could fix just perf script?Just fix the perf script is enough.
Could you please try the below patch?(I probably need to split the patch into two patches, since it fixed two issues, one is this error, the other is to print the instruction latency. Anyway, let's try it first.)
From
99443f49a6236ef6e3bea3930792967a7863f753Mon Sep 17 00:00:00 2001
From: Kan Liang <[email protected]>
Date: Tue, 28 Sep 2021 13:57:18 -0700
Subject: [PATCH] perf script: FixPERF_SAMPLE_WEIGHT_STRUCTsupport-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 check the input string "weight" with the corresponding sample type. However, the commit ID
ea8d0ed6eae3("perf tools: SupportPERF_SAMPLE_WEIGHT_STRUCT") didn't update the sample type for perf script. The check fails with a new kernel on x86.Use
PERF_SAMPLE_WEIGHT_TYPE, which supports both sample types, to replacePERF_SAMPLE_WEIGHT.Also, print the instruction latency for
PERF_SAMPLE_WEIGHT_STRUCTtype.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 | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)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))tools/perf/builtin-script.c +0
-0return -EINVAL ; if (PRINT_FIELD(SYM) &&
tools/perf/builtin-script.c static void process_event(struct perf_script *script, · line 2042
Quoted 8 lines
tools/perf/builtin-script.c +3
-1@@ -2036,8 +2036,11 @@ static void process_event(struct perf_script *script,if (PRINT_FIELD (DATA_SRC ))data_src__fprintf (sample->data_src, fp); -if (PRINT_FIELD (WEIGHT )) +if (PRINT_FIELD (WEIGHT )) {fprintf (fp,"%16" PRIu64, sample->weight); +if (attr->sample_type &PERF_SAMPLE_WEIGHT_STRUCT ) +fprintf (fp,",0x%" PRIx16, sample->ins_lat);
this will add extra number to weight.. should we add separate column for that -F 'insn-lat' ? users expect just single value for -F weight
thanks,
jirka
Quoted 10 lines
tools/perf/builtin-script.c +1
-0+ }if (PRINT_FIELD (IP )) {struct callchain_cursor *cursor =NULL ;Signature · 4 lines
2.7.4 Thanks, Kan
Quoted 87 lines · Jiri Olsa
Quoted 86 lines · Kan
Quoted 11 lines · Jiri Olsa
Joe reported broken -F weight in perf script with (on x86):
# ./perf mem record # ./perf script -F weight Samples for 'dummy:HG' event do not have WEIGHT attribute set. Cannot print 'weight' field.the problem seems to be introduced with the
WEIGHT_STRUCTchange:
ea8d0ed6eae3perf tools: SupportPERF_SAMPLE_WEIGHT_STRUCTwhich enables
WEIGHT_STRUCTsample_typeon x86 instead of WEIGHT, and leaves 'perf script -F weight' in the darkRight, I missed the support for the perf script. Because the default perf script worked. It didn't ring the bell. :(
Quoted 4 lines
I'm not sure what the fix should look like.. should we allow user to use just 'WEIGHT' sample type? or is there a way to get original weight from '
WEIGHT_STRUCT' data, so we could fix just perf script?Just fix the perf script is enough.
Could you please try the below patch?(I probably need to split the patch into two patches, since it fixed two issues, one is this error, the other is to print the instruction latency. Anyway, let's try it first.)
From
99443f49a6236ef6e3bea3930792967a7863f753Mon Sep 17 00:00:00 2001
From: Kan Liang <[email protected]>
Date: Tue, 28 Sep 2021 13:57:18 -0700
Subject: [PATCH] perf script: FixPERF_SAMPLE_WEIGHT_STRUCTsupport-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 check the input string "weight" with the corresponding sample type. However, the commit ID
ea8d0ed6eae3("perf tools: SupportPERF_SAMPLE_WEIGHT_STRUCT") didn't update the sample type for perf script. The check fails with a new kernel on x86.Use
PERF_SAMPLE_WEIGHT_TYPE, which supports both sample types, to replacePERF_SAMPLE_WEIGHT.Also, print the instruction latency for
PERF_SAMPLE_WEIGHT_STRUCTtype.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 | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)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)&&tools/perf/builtin-script.c +0
-0@@ -2036,8 +2036,11 @@ static void process_event(struct perf_script *script,if (PRINT_FIELD (DATA_SRC ))data_src__fprintf (sample->data_src, fp);
Quoted 9 lines
tools/perf/builtin-script.c static void process_event(struct perf_script *script, · line 2042
Quoted 5 lines
tools/perf/builtin-script.c +3
-1-if (PRINT_FIELD (WEIGHT )) +if (PRINT_FIELD (WEIGHT )) {fprintf (fp,"%16" PRIu64, sample->weight); +if (attr->sample_type &PERF_SAMPLE_WEIGHT_STRUCT ) +fprintf (fp,",0x%" PRIx16, sample->ins_lat);this will add extra number to weight.. should we add separate column for that -F 'insn-lat' ? users expect just single value for -F weight
Sure, I will send out a patch set to LKML for review shortly.
Thanks,
Kan