perf kvm: fix sample_type manipulation
Adrian Hunter
reviewerPATCH 1/1 perf kvm: fix sample_type manipulation
Manipulating the sample_type of an evsel requires
the use of:
perf_evsel__set_sample_bit()
and perf_evsel__reset_sample_bit()
Manipulating the sample type of an evlist requires the id position to be recalculated.
--- tools/perf/builtin-kvm.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-)
tools/perf/builtin-kvm.c +11 -9
@@ -1165,16 +1165,16 @@ static int kvm_live_open_events(struct perf_kvm_stat *kvm)struct perf_event_attr *attr = &pos->attr;/* make sure these *are* set */ - attr->sample_type |=PERF_SAMPLE_TID ; - attr->sample_type |=PERF_SAMPLE_TIME ; - attr->sample_type |=PERF_SAMPLE_CPU ; - attr->sample_type |=PERF_SAMPLE_RAW ; +perf_evsel__set_sample_bit (pos,TID ); +perf_evsel__set_sample_bit (pos,TIME ); +perf_evsel__set_sample_bit (pos,CPU ); +perf_evsel__set_sample_bit (pos,RAW );/* make sure these are *not*; want as small a sample as possible */ - attr->sample_type &= ~PERF_SAMPLE_PERIOD ; - attr->sample_type &= ~PERF_SAMPLE_IP ; - attr->sample_type &= ~PERF_SAMPLE_CALLCHAIN ; - attr->sample_type &= ~PERF_SAMPLE_ADDR ; - attr->sample_type &= ~PERF_SAMPLE_READ ; +perf_evsel__reset_sample_bit (pos,PERIOD ); +perf_evsel__reset_sample_bit (pos,IP ); +perf_evsel__reset_sample_bit (pos,CALLCHAIN ); +perf_evsel__reset_sample_bit (pos,ADDR ); +perf_evsel__reset_sample_bit (pos,READ ); attr->mmap =0 ; attr->comm =0 ; attr->task =0 ;
@@ -1188,6 +1188,8 @@ static int kvm_live_open_events(struct perf_kvm_stat *kvm) attr->disabled =1 ; } +perf_evlist__set_id_pos (evlist); + err =perf_evlist__open (evlist);if (err <0 ) {printf ("Couldn't create the events: %s\n" ,strerror (errno));
Signature · 1 line
1.7.11.7
Em Fri, Sep 06, 2013 at 09:48:54AM +0300, Adrian Hunter escreveu:
Quoted 4 lines
Manipulating the
sample_typeof an evsel requires
the use of:
perf_evsel__set_sample_bit()
andperf_evsel__reset_sample_bit()
Fine, but...
Quoted 2 lines
Manipulating the sample type of an evlist requires the id position to be recalculated.
... can't we hide this detail? I.e. we could do it like we do with the alloc_{mmap,poll}() evlist methods in perf_evlist__mmap(), checking if it was already done, etc.
This we reduce the contact surface for tools using evlists and evsels.
I.e., this sequence:
+ perf_evlist__set_id_pos(evlist);
+
err = perf_evlist__open(evlist);
Could remain just:
err = perf_evlist__open(evlist);
I'm auditing the other calls to evlist now, to check if there are other cases.
Thanks for the patch!
- Arnaldo
Quoted 46 lines
Signed-off-by Adrian Hunter <[email protected]>--- tools/perf/builtin-kvm.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-)tools/perf/builtin-kvm.c +11
-9@@ -1165,16 +1165,16 @@ static int kvm_live_open_events(struct perf_kvm_stat *kvm)struct perf_event_attr *attr = &pos->attr;/* make sure these *are* set */ - attr->sample_type |=PERF_SAMPLE_TID ; - attr->sample_type |=PERF_SAMPLE_TIME ; - attr->sample_type |=PERF_SAMPLE_CPU ; - attr->sample_type |=PERF_SAMPLE_RAW ; +perf_evsel__set_sample_bit (pos,TID ); +perf_evsel__set_sample_bit (pos,TIME ); +perf_evsel__set_sample_bit (pos,CPU ); +perf_evsel__set_sample_bit (pos,RAW );/* make sure these are *not*; want as small a sample as possible */ - attr->sample_type &= ~PERF_SAMPLE_PERIOD ; - attr->sample_type &= ~PERF_SAMPLE_IP ; - attr->sample_type &= ~PERF_SAMPLE_CALLCHAIN ; - attr->sample_type &= ~PERF_SAMPLE_ADDR ; - attr->sample_type &= ~PERF_SAMPLE_READ ; +perf_evsel__reset_sample_bit (pos,PERIOD ); +perf_evsel__reset_sample_bit (pos,IP ); +perf_evsel__reset_sample_bit (pos,CALLCHAIN ); +perf_evsel__reset_sample_bit (pos,ADDR ); +perf_evsel__reset_sample_bit (pos,READ ); attr->mmap =0 ; attr->comm =0 ; attr->task =0 ;@@ -1188,6 +1188,8 @@ static int kvm_live_open_events(struct perf_kvm_stat *kvm) attr->disabled =1 ; } +perf_evlist__set_id_pos (evlist); + err =perf_evlist__open (evlist);if (err <0 ) {printf ("Couldn't create the events: %s\n" ,strerror (errno));Signature · 1 line
1.7.11.7
Quoted 7 lines · Arnaldo Carvalho de Melo
Em Fri, Sep 06, 2013 at 09:48:54AM +0300, Adrian Hunter escreveu:
Quoted 4 lines
Manipulating the
sample_typeof an evsel requires
the use of:
perf_evsel__set_sample_bit()
andperf_evsel__reset_sample_bit()Fine, but...
hmmm... this is a relatively new API (7be5ebe8). The kvm-live command and my scheduling daemon pre-date its introduction.
Quoted 3 lines
Quoted 3 lines
Manipulating the sample type of an evlist requires the id position to be recalculated.
And this is hot of the presses ... 75562573.
Quoted 14 lines
... can't we hide this detail? I.e. we could do it like we do with the alloc_{mmap,poll}() evlist methods in
perf_evlist__mmap(), checking if it was already done, etc.This we reduce the contact surface for tools using evlists and evsels.
I.e., this sequence:
tools/perf/builtin-kvm.c +2
-0+perf_evlist__set_id_pos (evlist); + err =perf_evlist__open (evlist);
Quoted 3 lines
Could remain just:
err = perf_evlist__open(evlist);
perf code has been around a while now and I know there are a number of local analysis commands built around it. API changes like this -- required ones at that -- need to be simple and some error checking built in where possible.
... and documentation for the API on what commands should be doing and in what order.
David
Quoted 9 lines · Adrian Hunter
Manipulating the
sample_typeof an evsel requires
the use of:
perf_evsel__set_sample_bit()
andperf_evsel__reset_sample_bit()Manipulating the sample type of an evlist requires the id position to be recalculated.
Signed-off-by Adrian Hunter <[email protected]>
Fixes the regression. Thanks for taking care of it