diff mbox series

[1/3] kernel-shark: Define free_contex function for the sched_events plugin

Message ID 20190305143924.11056-2-ykaradzhov@vmware.com (mailing list archive)
State Accepted
Commit ab266c8253d5737fb292794a9ab235a1de1f722d
Headers show
Series Improvements and fixes for sched_switch plugin | expand

Commit Message

Yordan Karadzhov March 5, 2019, 2:39 p.m. UTC
This static helper function makes the code of the plugin cleaner and
easier to read.

Signed-off-by: Yordan Karadzhov <ykaradzhov@vmware.com>
---
 kernel-shark/src/plugins/sched_events.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

Comments

Slavomir Kaslev March 5, 2019, 3:54 p.m. UTC | #1
On Tue, Mar 05, 2019 at 04:39:22PM +0200, Yordan Karadzhov wrote:
> This static helper function makes the code of the plugin cleaner and
> easier to read.
> 
> Signed-off-by: Yordan Karadzhov <ykaradzhov@vmware.com>
> ---
>  kernel-shark/src/plugins/sched_events.c | 16 ++++++++++++----
>  1 file changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/kernel-shark/src/plugins/sched_events.c b/kernel-shark/src/plugins/sched_events.c
> index 68734d4..0d6de2d 100644
> --- a/kernel-shark/src/plugins/sched_events.c
> +++ b/kernel-shark/src/plugins/sched_events.c
> @@ -39,6 +39,17 @@ static bool define_wakeup_event(struct tep_handle *tep, const char *wakeup_name,
>  	return true;
>  }
>  
> +static void plugin_free_context(struct plugin_sched_context *plugin_ctx)
> +{
> +	if (!plugin_ctx)
> +		return;
> +
> +	tracecmd_filter_id_hash_free(plugin_ctx->second_pass_hash);
> +	kshark_free_collection_list(plugin_ctx->collections);
> +
> +	free(plugin_ctx);
> +}
> +
>  static bool plugin_sched_init_context(struct kshark_context *kshark_ctx)
>  {
>  	struct plugin_sched_context *plugin_ctx;
> @@ -339,10 +350,7 @@ static int plugin_sched_close(struct kshark_context *kshark_ctx)
>  					plugin_sched_action,
>  					plugin_draw);
>  
> -	tracecmd_filter_id_hash_free(plugin_ctx->second_pass_hash);
> -
> -	kshark_free_collection_list(plugin_ctx->collections);
> -	free(plugin_ctx);
> +	plugin_free_context(plugin_ctx);
>  	plugin_sched_context_handler = NULL;
>  
>  	return 1;

Nit: there's a typo in the commit message

>    kernel-shark: Define free_contex function for the sched_events plugin
                                     ^
:s/free_contex/plugin_free_context/g ?

Other than that it looks good to me.

Reviewed-by: Slavomir Kaslev <kaslevs@vmware.com>

Cheers,

-- Slavi
Steven Rostedt March 5, 2019, 5:11 p.m. UTC | #2
On Tue, 5 Mar 2019 17:54:26 +0200
Slavomir Kaslev <kaslevs@vmware.com> wrote:


> Nit: there's a typo in the commit message
> 
> >    kernel-shark: Define free_contex function for the sched_events plugin  
>                                      ^
> :s/free_contex/plugin_free_context/g ?

I caught that too, and fixed it.


> 
> Other than that it looks good to me.
> 
> Reviewed-by: Slavomir Kaslev <kaslevs@vmware.com>

Thanks Slavomir,

I'll add your review tag.

-- Steve
diff mbox series

Patch

diff --git a/kernel-shark/src/plugins/sched_events.c b/kernel-shark/src/plugins/sched_events.c
index 68734d4..0d6de2d 100644
--- a/kernel-shark/src/plugins/sched_events.c
+++ b/kernel-shark/src/plugins/sched_events.c
@@ -39,6 +39,17 @@  static bool define_wakeup_event(struct tep_handle *tep, const char *wakeup_name,
 	return true;
 }
 
+static void plugin_free_context(struct plugin_sched_context *plugin_ctx)
+{
+	if (!plugin_ctx)
+		return;
+
+	tracecmd_filter_id_hash_free(plugin_ctx->second_pass_hash);
+	kshark_free_collection_list(plugin_ctx->collections);
+
+	free(plugin_ctx);
+}
+
 static bool plugin_sched_init_context(struct kshark_context *kshark_ctx)
 {
 	struct plugin_sched_context *plugin_ctx;
@@ -339,10 +350,7 @@  static int plugin_sched_close(struct kshark_context *kshark_ctx)
 					plugin_sched_action,
 					plugin_draw);
 
-	tracecmd_filter_id_hash_free(plugin_ctx->second_pass_hash);
-
-	kshark_free_collection_list(plugin_ctx->collections);
-	free(plugin_ctx);
+	plugin_free_context(plugin_ctx);
 	plugin_sched_context_handler = NULL;
 
 	return 1;