diff mbox series

[v5,06/16] perf kvm: Introduce histograms data structures

Message ID 20230315145112.186603-7-leo.yan@linaro.org (mailing list archive)
State New, archived
Headers show
Series perf kvm: Support histograms and TUI mode | expand

Commit Message

Leo Yan March 15, 2023, 2:51 p.m. UTC
This is a preparation to support histograms in perf kvm tool.  As first
step, this patch defines histograms data structures and initialize them.

Signed-off-by: Leo Yan <leo.yan@linaro.org>
Reviewed-by: James Clark <james.clark@arm.com>
---
 tools/perf/builtin-kvm.c   | 18 ++++++++++++++++++
 tools/perf/util/kvm-stat.h |  1 +
 2 files changed, 19 insertions(+)

Comments

Arnaldo Carvalho de Melo March 15, 2023, 7:45 p.m. UTC | #1
Em Wed, Mar 15, 2023 at 10:51:02PM +0800, Leo Yan escreveu:
> This is a preparation to support histograms in perf kvm tool.  As first
> step, this patch defines histograms data structures and initialize them.
> 
> Signed-off-by: Leo Yan <leo.yan@linaro.org>
> Reviewed-by: James Clark <james.clark@arm.com>
> ---
>  tools/perf/builtin-kvm.c   | 18 ++++++++++++++++++
>  tools/perf/util/kvm-stat.h |  1 +
>  2 files changed, 19 insertions(+)
> 
> diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
> index d400434aa137..384992c8a01a 100644
> --- a/tools/perf/builtin-kvm.c
> +++ b/tools/perf/builtin-kvm.c
> @@ -85,6 +85,20 @@ static struct kvm_event_key keys[] = {
>  	{ NULL, NULL }
>  };
>  
> +struct kvm_hists {
> +	struct hists		hists;
> +	struct perf_hpp_list	list;
> +};
> +
> +static struct kvm_hists kvm_hists;
> +
> +static int kvm_hists__init(void)
> +{
> +	__hists__init(&kvm_hists.hists, &kvm_hists.list);
> +	perf_hpp_list__init(&kvm_hists.list);
> +	return 0;
> +}
> +

Had to add:


diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index c4cb34df155fec67..b06c11d306a11cab 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -85,7 +85,6 @@ static struct kvm_event_key keys[] = {
 	DEF_SORT_NAME_KEY(time, mean),
 	{ NULL, NULL }
 };
-#endif // defined(HAVE_KVM_STAT_SUPPORT) && defined(HAVE_LIBTRACEEVENT)
 
 struct kvm_hists {
 	struct hists		hists;
@@ -100,6 +99,7 @@ static int kvm_hists__init(void)
 	perf_hpp_list__init(&kvm_hists.list);
 	return 0;
 }
+#endif // defined(HAVE_KVM_STAT_SUPPORT) && defined(HAVE_LIBTRACEEVENT)
 
 static const char *get_filename_for_perf_kvm(void)
 {

>  static const char *get_filename_for_perf_kvm(void)
>  {
>  	const char *filename;
> @@ -957,6 +971,8 @@ static int kvm_events_live_report(struct perf_kvm_stat *kvm)
>  	set_term_quiet_input(&save);
>  	init_kvm_event_record(kvm);
>  
> +	kvm_hists__init();
> +
>  	signal(SIGINT, sig_handler);
>  	signal(SIGTERM, sig_handler);
>  
> @@ -1152,6 +1168,8 @@ static int kvm_events_report_vcpu(struct perf_kvm_stat *kvm)
>  	init_kvm_event_record(kvm);
>  	setup_pager();
>  
> +	kvm_hists__init();
> +
>  	ret = read_events(kvm);
>  	if (ret)
>  		goto exit;
> diff --git a/tools/perf/util/kvm-stat.h b/tools/perf/util/kvm-stat.h
> index 841b3174c211..e2c17662bac7 100644
> --- a/tools/perf/util/kvm-stat.h
> +++ b/tools/perf/util/kvm-stat.h
> @@ -5,6 +5,7 @@
>  #ifdef HAVE_KVM_STAT_SUPPORT
>  
>  #include "tool.h"
> +#include "sort.h"
>  #include "stat.h"
>  #include "record.h"
>  
> -- 
> 2.34.1
>
Leo Yan March 16, 2023, 3:02 a.m. UTC | #2
Hi Arnaldo,

On Wed, Mar 15, 2023 at 04:45:53PM -0300, Arnaldo Carvalho de Melo wrote:

[...]

> Had to add:
> 
> 
> diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
> index c4cb34df155fec67..b06c11d306a11cab 100644
> --- a/tools/perf/builtin-kvm.c
> +++ b/tools/perf/builtin-kvm.c
> @@ -85,7 +85,6 @@ static struct kvm_event_key keys[] = {
>  	DEF_SORT_NAME_KEY(time, mean),
>  	{ NULL, NULL }
>  };
> -#endif // defined(HAVE_KVM_STAT_SUPPORT) && defined(HAVE_LIBTRACEEVENT)
>  
>  struct kvm_hists {
>  	struct hists		hists;
> @@ -100,6 +99,7 @@ static int kvm_hists__init(void)
>  	perf_hpp_list__init(&kvm_hists.list);
>  	return 0;
>  }
> +#endif // defined(HAVE_KVM_STAT_SUPPORT) && defined(HAVE_LIBTRACEEVENT)

Thanks for fixing up, this is fine for me.

Seems to me it is not a good practice to use macros (and nested macros) to
mute or unmute big chunk code.  I will try to refine the building
builtin-kvm.c and prepare patches based on current code base.

P.s. I saw this series has been picked up into your branch
acme/tmp.perf-tools-next, if you want me to follow up anything, please
let me know.  Thank you!

Leo
diff mbox series

Patch

diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index d400434aa137..384992c8a01a 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -85,6 +85,20 @@  static struct kvm_event_key keys[] = {
 	{ NULL, NULL }
 };
 
+struct kvm_hists {
+	struct hists		hists;
+	struct perf_hpp_list	list;
+};
+
+static struct kvm_hists kvm_hists;
+
+static int kvm_hists__init(void)
+{
+	__hists__init(&kvm_hists.hists, &kvm_hists.list);
+	perf_hpp_list__init(&kvm_hists.list);
+	return 0;
+}
+
 static const char *get_filename_for_perf_kvm(void)
 {
 	const char *filename;
@@ -957,6 +971,8 @@  static int kvm_events_live_report(struct perf_kvm_stat *kvm)
 	set_term_quiet_input(&save);
 	init_kvm_event_record(kvm);
 
+	kvm_hists__init();
+
 	signal(SIGINT, sig_handler);
 	signal(SIGTERM, sig_handler);
 
@@ -1152,6 +1168,8 @@  static int kvm_events_report_vcpu(struct perf_kvm_stat *kvm)
 	init_kvm_event_record(kvm);
 	setup_pager();
 
+	kvm_hists__init();
+
 	ret = read_events(kvm);
 	if (ret)
 		goto exit;
diff --git a/tools/perf/util/kvm-stat.h b/tools/perf/util/kvm-stat.h
index 841b3174c211..e2c17662bac7 100644
--- a/tools/perf/util/kvm-stat.h
+++ b/tools/perf/util/kvm-stat.h
@@ -5,6 +5,7 @@ 
 #ifdef HAVE_KVM_STAT_SUPPORT
 
 #include "tool.h"
+#include "sort.h"
 #include "stat.h"
 #include "record.h"