perf kvm stat: unify print_vcpu_info() for report/live
PATCH 1/1 perf kvm stat: unify print_vcpu_info() for report/live
The print_vcpu_info() function prints title line "Analyze events ..." with a description of the current target. For 'live' option, the output includes "system-wide/specific pids, all vcpus/specific vcpus". Example:
$ sudo perf kvm stat live -p 1 Analyze events for pid(s) 1, all VCPUs: [..]
But for 'report' option the output only contains "all vcpus/specific vcpus":
$ sudo perf kvm stat report -p 1 Analyze events for all VCPUs: [..]
Adding '-a' option for 'stat report' and unifying the print_vcpu_info() function, so it can print complete target info for 'stat report':
$ sudo perf kvm stat report -p 1 Analyze events for pid(s) 1, all VCPUs: [..]
--- tools/perf/builtin-kvm.c | 37 ++++++++++++++++++++++++++----------- tools/perf/util/kvm-stat.h | 1 - 2 files changed, 26 insertions(+), 12 deletions(-)
tools/perf/builtin-kvm.c +26 -11
@@ -543,14 +543,12 @@ static void print_vcpu_info(struct perf_kvm_stat *kvm)pr_info ("Analyze events for " ); -if (kvm->live) { -if (kvm->opts.target.system_wide) -pr_info ("all VMs, " ); -else if (kvm->opts.target.pid) -pr_info ("pid(s) %s, " , kvm->opts.target.pid); -else -pr_info ("dazed and confused on what is monitored, " ); - } +if (kvm->opts.target.system_wide) +pr_info ("all VMs, " ); +else if (kvm->opts.target.pid) +pr_info ("pid(s) %s, " , kvm->opts.target.pid); +else +pr_info ("dazed and confused on what is monitored, " );if (vcpu ==-1 )pr_info ("all VCPUs:\n\n" );
@@ -1088,8 +1086,8 @@ static int read_events(struct perf_kvm_stat *kvm)static int parse_target_str (struct perf_kvm_stat *kvm) { -if (kvm->pid_str) { - kvm->pid_list =intlist__new (kvm->pid_str); +if (kvm->opts.target.pid) { + kvm->pid_list =intlist__new (kvm->opts.target.pid);if (kvm->pid_list ==NULL ) {pr_err ("Error parsing process id string\n" );return -EINVAL ;
@@ -1182,16 +1180,21 @@ kvm_events_record(struct perf_kvm_stat *kvm, int argc, const char **argv)static int kvm_events_report (struct perf_kvm_stat *kvm,int argc,const char **argv) { +char errbuf[BUFSIZ ]; +int err; +const struct option kvm_events_report_options[] = {OPT_STRING (0 ,"event" , &kvm->report_event,"report event" ,"event for reporting: vmexit, " "mmio (x86 only), ioport (x86 only)" ), +OPT_BOOLEAN ('a' ,"all-cpus" , &kvm->opts.target.system_wide, +"system-wide collection from all CPUs" ),OPT_INTEGER (0 ,"vcpu" , &kvm->trace_vcpu,"vcpu id to report" ),OPT_STRING ('k' ,"key" , &kvm->sort_key,"sort-key" ,"key for sorting: sample(sort by samples number)" " time (sort by avg time)" ), -OPT_STRING ('p' ,"pid" , &kvm->pid_str,"pid" , +OPT_STRING ('p' ,"pid" , &kvm->opts.target.pid,"pid" ,"analyze events only for given process id(s)" ),OPT_END () };
@@ -1212,6 +1215,18 @@ kvm_events_report(struct perf_kvm_stat *kvm, int argc, const char **argv) kvm_events_report_options); } +/* +* target related setups +*/ + err =target__validate (&kvm->opts.target); +if (err) { +target__strerror (&kvm->opts.target, err, errbuf,BUFSIZ ); +ui__warning ("%s" , errbuf); + } + +if (target__none (&kvm->opts.target)) + kvm->opts.target.system_wide = true; +return kvm_events_report_vcpu (kvm); }
tools/perf/util/kvm-stat.h +0 -1
@@ -92,7 +92,6 @@ struct perf_kvm_stat {u64 lost_events;u64 duration; -const char *pid_str;struct intlist *pid_list;struct rb_root result;
--
1.7.9.5
Quoted 9 lines · Alexander Yarygin
The
print_vcpu_info()function prints title line "Analyze events ..." with a description of the current target. For 'live' option, the output includes "system-wide/specific pids, all vcpus/specific vcpus". Example:$ sudo perf kvm stat live -p 1 Analyze events for pid(s) 1, all VCPUs: [..]But for 'report' option the output only contains "all vcpus/specific vcpus":
Quoted 8 lines
$ sudo perf kvm stat report -p 1 Analyze events for all VCPUs: [..]Adding '-a' option for 'stat report' and unifying the
print_vcpu_info()function, so it can print complete target info for 'stat report':$ sudo perf kvm stat report -p 1 Analyze events for pid(s) 1, all VCPUs: [..]
I did not follow that commit message at all.
Quoted 26 lines
Cc Arnaldo Carvalho de Melo <[email protected]>Cc Christian Borntraeger <[email protected]>Cc David Ahern <[email protected]>Cc Ingo Molnar <[email protected]>Cc Jiri Olsa <[email protected]>Cc Paul Mackerras <[email protected]>Cc Peter Zijlstra <[email protected]>Signed-off-by Alexander Yarygin <[email protected]>--- tools/perf/builtin-kvm.c | 37 ++++++++++++++++++++++++++----------- tools/perf/util/kvm-stat.h | 1 - 2 files changed, 26 insertions(+), 12 deletions(-)tools/perf/builtin-kvm.c +0
-4@@ -543,14 +543,12 @@ static void print_vcpu_info(struct perf_kvm_stat *kvm)pr_info ("Analyze events for " ); -if (kvm->live) { -if (kvm->opts.target.system_wide) -pr_info ("all VMs, " ); -else if (kvm->opts.target.pid)
tools/perf/builtin-kvm.c static void print_vcpu_info(struct perf_kvm_stat *kvm) · line 551
Quoted 10 lines
tools/perf/builtin-kvm.c +6
-4-pr_info ("pid(s) %s, " , kvm->opts.target.pid); - else - pr_info("dazed and confused on what is monitored, "); - } +if (kvm->opts.target.system_wide) +pr_info ("all VMs, " ); +else if (kvm->opts.target.pid) +pr_info ("pid(s) %s, " , kvm->opts.target.pid); +else +pr_info ("dazed and confused on what is monitored, " );
Ah, you are unifying the output -- same title bar for both live and report.
Quoted 4 lines
tools/perf/builtin-kvm.c +0
-0if (vcpu ==-1 )pr_info ("all VCPUs:\n\n" );
tools/perf/builtin-kvm.c static int read_events(struct perf_kvm_stat *kvm) · line 1093
Quoted 10 lines
tools/perf/builtin-kvm.c +2
-2@@ -1088,8 +1086,8 @@ static int read_events(struct perf_kvm_stat *kvm)static int parse_target_str (struct perf_kvm_stat *kvm) { -if (kvm->pid_str) { - kvm->pid_list =intlist__new (kvm->pid_str); +if (kvm->opts.target.pid) { + kvm->pid_list =intlist__new (kvm->opts.target.pid);if (kvm->pid_list ==NULL ) {pr_err ("Error parsing process id string\n" );return -EINVAL ;
And this is an unrelated change. please make it a separate patch.
David
Quoted 57 lines
tools/perf/builtin-kvm.c +18
-1@@ -1182,16 +1180,21 @@ kvm_events_record(struct perf_kvm_stat *kvm, int argc, const char **argv)static int kvm_events_report (struct perf_kvm_stat *kvm,int argc,const char **argv) { +char errbuf[BUFSIZ ]; +int err; +const struct option kvm_events_report_options[] = {OPT_STRING (0 ,"event" , &kvm->report_event,"report event" ,"event for reporting: vmexit, " "mmio (x86 only), ioport (x86 only)" ), +OPT_BOOLEAN ('a' ,"all-cpus" , &kvm->opts.target.system_wide, +"system-wide collection from all CPUs" ),OPT_INTEGER (0 ,"vcpu" , &kvm->trace_vcpu,"vcpu id to report" ),OPT_STRING ('k' ,"key" , &kvm->sort_key,"sort-key" ,"key for sorting: sample(sort by samples number)" " time (sort by avg time)" ), -OPT_STRING ('p' ,"pid" , &kvm->pid_str,"pid" , +OPT_STRING ('p' ,"pid" , &kvm->opts.target.pid,"pid" ,"analyze events only for given process id(s)" ),OPT_END () };@@ -1212,6 +1215,18 @@ kvm_events_report(struct perf_kvm_stat *kvm, int argc, const char **argv) kvm_events_report_options); } +/* +* target related setups +*/ + err =target__validate (&kvm->opts.target); +if (err) { +target__strerror (&kvm->opts.target, err, errbuf,BUFSIZ ); +ui__warning ("%s" , errbuf); + } + +if (target__none (&kvm->opts.target)) + kvm->opts.target.system_wide = true; +return kvm_events_report_vcpu (kvm); }tools/perf/util/kvm-stat.h +0
-2@@ -92,7 +92,6 @@ struct perf_kvm_stat {u64 lost_events;u64 duration; -const char *pid_str;struct intlist *pid_list;struct rb_root result; --1.7.9.5
Quoted 13 lines · David Ahern
Quoted 12 lines · Alexander Yarygin
The
print_vcpu_info()function prints title line "Analyze events ..." with a description of the current target. For 'live' option, the output includes "system-wide/specific pids, all vcpus/specific vcpus". Example:$ sudo perf kvm stat live -p 1 Analyze events for pid(s) 1, all VCPUs: [..]But for 'report' option the output only contains "all vcpus/specific vcpus":
$ sudo perf kvm stat report -p 1 Analyze events for all VCPUs: [..]
Quoted 8 lines
Quoted 5 lines
Adding '-a' option for 'stat report' and unifying the
print_vcpu_info()function, so it can print complete target info for 'stat report':$ sudo perf kvm stat report -p 1 Analyze events for pid(s) 1, all VCPUs: [..]I did not follow that commit message at all.
I'll rephrase.
Quoted 56 lines
Quoted 26 lines
Cc Arnaldo Carvalho de Melo <[email protected]>Cc Christian Borntraeger <[email protected]>Cc David Ahern <[email protected]>Cc Ingo Molnar <[email protected]>Cc Jiri Olsa <[email protected]>Cc Paul Mackerras <[email protected]>Cc Peter Zijlstra <[email protected]>Signed-off-by Alexander Yarygin <[email protected]>--- tools/perf/builtin-kvm.c | 37 ++++++++++++++++++++++++++----------- tools/perf/util/kvm-stat.h | 1 - 2 files changed, 26 insertions(+), 12 deletions(-)tools/perf/builtin-kvm.c +0
-4@@ -543,14 +543,12 @@ static void print_vcpu_info(struct perf_kvm_stat *kvm)pr_info ("Analyze events for " ); -if (kvm->live) { -if (kvm->opts.target.system_wide) -pr_info ("all VMs, " ); -else if (kvm->opts.target.pid)tools/perf/builtin-kvm.c static void print_vcpu_info(struct perf_kvm_stat *kvm) · line 551
Quoted 10 lines
tools/perf/builtin-kvm.c +6
-4-pr_info ("pid(s) %s, " , kvm->opts.target.pid); - else - pr_info("dazed and confused on what is monitored, "); - } +if (kvm->opts.target.system_wide) +pr_info ("all VMs, " ); +else if (kvm->opts.target.pid) +pr_info ("pid(s) %s, " , kvm->opts.target.pid); +else +pr_info ("dazed and confused on what is monitored, " );Ah, you are unifying the output -- same title bar for both live and report.
Quoted 4 lines
tools/perf/builtin-kvm.c +0
-0if (vcpu ==-1 )pr_info ("all VCPUs:\n\n" );tools/perf/builtin-kvm.c static int read_events(struct perf_kvm_stat *kvm) · line 1093
Quoted 10 lines
tools/perf/builtin-kvm.c +2
-2@@ -1088,8 +1086,8 @@ static int read_events(struct perf_kvm_stat *kvm)static int parse_target_str (struct perf_kvm_stat *kvm) { -if (kvm->pid_str) { - kvm->pid_list =intlist__new (kvm->pid_str); +if (kvm->opts.target.pid) { + kvm->pid_list =intlist__new (kvm->opts.target.pid);if (kvm->pid_list ==NULL ) {pr_err ("Error parsing process id string\n" );return -EINVAL ;And this is an unrelated change. please make it a separate patch.
Quoted 2 lines
David
Why? These are necessary changes for the output unification part:print_vcpu_info() looks for a pid string in kvm->opts.target.pid, but 'report' command keeps it in kvm->pid_str instead. It also wants the kvm->opts.target.system_wide flag, that 'report' doesn't have, so this patch switches from kvm->pid_str to kvm->opts.target.pid, adds the flag and enables it by default.
So, should I resend it with 2 patches?
Quoted 57 lines
Quoted 57 lines
tools/perf/builtin-kvm.c +18
-1@@ -1182,16 +1180,21 @@ kvm_events_record(struct perf_kvm_stat *kvm, int argc, const char **argv)static int kvm_events_report (struct perf_kvm_stat *kvm,int argc,const char **argv) { +char errbuf[BUFSIZ ]; +int err; +const struct option kvm_events_report_options[] = {OPT_STRING (0 ,"event" , &kvm->report_event,"report event" ,"event for reporting: vmexit, " "mmio (x86 only), ioport (x86 only)" ), +OPT_BOOLEAN ('a' ,"all-cpus" , &kvm->opts.target.system_wide, +"system-wide collection from all CPUs" ),OPT_INTEGER (0 ,"vcpu" , &kvm->trace_vcpu,"vcpu id to report" ),OPT_STRING ('k' ,"key" , &kvm->sort_key,"sort-key" ,"key for sorting: sample(sort by samples number)" " time (sort by avg time)" ), -OPT_STRING ('p' ,"pid" , &kvm->pid_str,"pid" , +OPT_STRING ('p' ,"pid" , &kvm->opts.target.pid,"pid" ,"analyze events only for given process id(s)" ),OPT_END () };@@ -1212,6 +1215,18 @@ kvm_events_report(struct perf_kvm_stat *kvm, int argc, const char **argv) kvm_events_report_options); } +/* +* target related setups +*/ + err =target__validate (&kvm->opts.target); +if (err) { +target__strerror (&kvm->opts.target, err, errbuf,BUFSIZ ); +ui__warning ("%s" , errbuf); + } + +if (target__none (&kvm->opts.target)) + kvm->opts.target.system_wide = true; +return kvm_events_report_vcpu (kvm); }tools/perf/util/kvm-stat.h +0
-2@@ -92,7 +92,6 @@ struct perf_kvm_stat {u64 lost_events;u64 duration; -const char *pid_str;struct intlist *pid_list;struct rb_root result; --1.7.9.5
Quoted 1 line · Alexander Yarygin
So, should I resend it with 2 patches?
It would be simpler that way. Change the pid handling first and then the title.
David