Improvements and fixes for sched_switch plugin
cover Improvements and fixes for sched_switch plugin
Yordan Karadzhov (3):
kernel-shark: Define free_contex function for the sched_events plugin
kernel-shark: Fix a memory leak in the sched_events plugin
kernel-shark: sched_events plugin init with sched_switch events only
kernel-shark/src/plugins/sched_events.c | 30 +++++++++++++++---------- 1 file changed, 18 insertions(+), 12 deletions(-)
Signature · 1 line
2.19.1
PATCH 1/3 kernel-shark: Define free_contex function for the sched_events plugin
This static helper function makes the code of the plugin cleaner and easier to read.
--- kernel-shark/src/plugins/sched_events.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
kernel-shark/src/plugins/sched_events.c +12 -4
@@ -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 ;
Signature · 1 line
2.19.1
Re: [PATCH 1/3] kernel-shark: Define free_contex function for the sched_events plugin
Quoted 32 lines · Yordan Karadzhov
This static helper function makes the code of the plugin cleaner and easier to read.
Signed-off-by Yordan Karadzhov <[email protected]>--- kernel-shark/src/plugins/sched_events.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)kernel-shark/src/plugins/sched_events.c +11
-0@@ -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,
kernel-shark/src/plugins/sched_events.c static int plugin_sched_close(struct kshark_context *kshark_ctx) · line 356
Quoted 10 lines
kernel-shark/src/plugins/sched_events.c +1
-4plugin_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
Quoted 1 line
kernel-shark: Define
free_contexfunction for thesched_eventsplugin
^
:s/free_contex/plugin_free_context/g ?
Other than that it looks good to me.
Cheers,
-- Slavi
Re: [PATCH 1/3] kernel-shark: Define free_contex function for the sched_events plugin
Quoted 5 lines · On Tue, 5 Mar 2019 17:54:26 +0200 Slavomir Kaslev <[email protected]> wrote:
Nit: there's a typo in the commit message
Quoted 1 line
kernel-shark: Define
free_contexfunction for thesched_eventsplugin^:s/free_contex/plugin_free_context/g ?
I caught that too, and fixed it.
Quoted 4 lines
Other than that it looks good to me.
Reviewed-by Slavomir Kaslev <[email protected]>
Thanks Slavomir,
I'll add your review tag.
-- Steve
PATCH 2/3 kernel-shark: Fix a memory leak in the sched_events plugin
In reply to Yordan KaradzhovWhen the sched_events plugin fails to initialize not all the memory allocated for the context of the plugin is freed properly. The problem gets fixed by using the free_context helper function defined in the previous patch.
--- kernel-shark/src/plugins/sched_events.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
kernel-shark/src/plugins/sched_events.c +6 -5
@@ -74,8 +74,12 @@ static bool plugin_sched_init_context(struct kshark_context *kshark_ctx) event =tep_find_event_by_name (plugin_ctx->pevent,"sched" ,"sched_switch" ); -if (!event) +if (!event) { +plugin_free_context (plugin_ctx); + plugin_sched_context_handler =NULL ; +return false; + } plugin_ctx->sched_switch_event = event; plugin_ctx->sched_switch_next_field =
@@ -320,11 +324,8 @@ static int plugin_sched_init(struct kshark_context *kshark_ctx) {struct plugin_sched_context *plugin_ctx; -if (!plugin_sched_init_context (kshark_ctx)) { -free (plugin_sched_context_handler); - plugin_sched_context_handler =NULL ; +if (!plugin_sched_init_context (kshark_ctx))return 0 ; - } plugin_ctx = plugin_sched_context_handler;
Signature · 1 line
2.19.1
Re: [PATCH 2/3] kernel-shark: Fix a memory leak in the sched_events plugin
Quoted 16 lines · Yordan Karadzhov
When the
sched_eventsplugin fails to initialize not all the memory allocated for the context of the plugin is freed properly. The problem gets fixed by using thefree_contexthelper function defined in the previous patch.Fixes 4f392730e ("kernel-shark-qt: Make Sched event plugin use ...")Signed-off-by Yordan Karadzhov <[email protected]>--- kernel-shark/src/plugins/sched_events.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)kernel-shark/src/plugins/sched_events.c +0
-0
kernel-shark/src/plugins/sched_events.c static bool plugin_sched_init_context(struct kshark_context *kshark_ctx) · line 80
Quoted 8 lines
kernel-shark/src/plugins/sched_events.c +4
-1@@ -74,8 +74,12 @@ static bool plugin_sched_init_context(struct kshark_context *kshark_ctx) event =tep_find_event_by_name (plugin_ctx->pevent,"sched" ,"sched_switch" ); -if (!event) +if (!event) { +plugin_free_context (plugin_ctx); + plugin_sched_context_handler =NULL ; +
Nit: drop the above empty line?
Quoted 7 lines
kernel-shark/src/plugins/sched_events.c +1
-0return false; + } plugin_ctx->sched_switch_event = event; plugin_ctx->sched_switch_next_field =@@ -320,11 +324,8 @@ static int plugin_sched_init(struct kshark_context *kshark_ctx) {
kernel-shark/src/plugins/sched_events.c static int plugin_sched_init(struct kshark_context *kshark_ctx) · line 330
Quoted 10 lines
kernel-shark/src/plugins/sched_events.c +1
-4struct plugin_sched_context *plugin_ctx; -if (!plugin_sched_init_context (kshark_ctx)) { -free (plugin_sched_context_handler); - plugin_sched_context_handler =NULL ; +if (!plugin_sched_init_context (kshark_ctx))return 0 ; - } plugin_ctx = plugin_sched_context_handler;
Looks good to me.
-- Slavi
Re: [PATCH 2/3] kernel-shark: Fix a memory leak in the sched_events plugin
Quoted 18 lines · On Tue, 5 Mar 2019 17:56:28 +0200 Slavomir Kaslev <[email protected]> wrote:
Quoted 17 lines · Yordan Karadzhov
When the
sched_eventsplugin fails to initialize not all the memory allocated for the context of the plugin is freed properly. The problem gets fixed by using thefree_contexthelper function defined in the previous patch.Fixes 4f392730e ("kernel-shark-qt: Make Sched event plugin use ...")Signed-off-by Yordan Karadzhov <[email protected]>--- kernel-shark/src/plugins/sched_events.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)kernel-shark/src/plugins/sched_events.c +0
-0@@ -74,8 +74,12 @@ static bool plugin_sched_init_context(struct kshark_context *kshark_ctx)
Quoted 9 lines
kernel-shark/src/plugins/sched_events.c static bool plugin_sched_init_context(struct kshark_context *kshark_ctx) · line 80
Quoted 7 lines
kernel-shark/src/plugins/sched_events.c +4
-1event =tep_find_event_by_name (plugin_ctx->pevent,"sched" ,"sched_switch" ); -if (!event) +if (!event) { +plugin_free_context (plugin_ctx); + plugin_sched_context_handler =NULL ; +Nit: drop the above empty line?
Yeah, it would be better to do that. But for now, I'll take the patch anyway. Perhaps clean it up later.
Quoted 17 lines
Quoted 17 lines
kernel-shark/src/plugins/sched_events.c +2
-4return false; + } plugin_ctx->sched_switch_event = event; plugin_ctx->sched_switch_next_field =@@ -320,11 +324,8 @@ static int plugin_sched_init(struct kshark_context *kshark_ctx) {struct plugin_sched_context *plugin_ctx; -if (!plugin_sched_init_context (kshark_ctx)) { -free (plugin_sched_context_handler); - plugin_sched_context_handler =NULL ; +if (!plugin_sched_init_context (kshark_ctx))return 0 ; - }
Quoted 5 lines
kernel-shark/src/plugins/sched_events.c static int plugin_sched_init(struct kshark_context *kshark_ctx) · line 330
Quoted 1 line
kernel-shark/src/plugins/sched_events.c +0
-0plugin_ctx = plugin_sched_context_handler;Looks good to me.
Reviewed-by Slavomir Kaslev <[email protected]>
Thanks Slavomir!
-- Steve
Re: [PATCH 2/3] kernel-shark: Fix a memory leak in the sched_events plugin
In reply to Yordan KaradzhovQuoted 6 lines · On Tue, 5 Mar 2019 16:39:23 +0200 Yordan Karadzhov <[email protected]>…
When the
sched_eventsplugin fails to initialize not all the memory allocated for the context of the plugin is freed properly. The problem gets fixed by using thefree_contexthelper function defined in the previous patch.Fixes 4f392730e ("kernel-shark-qt: Make Sched event plugin use ...")
I took the patch, but don't truncate the fixes line. It's fine to go over 80 characters:
-- Steve
Quoted 36 lines
Signed-off-by Yordan Karadzhov <[email protected]>--- kernel-shark/src/plugins/sched_events.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)kernel-shark/src/plugins/sched_events.c +6
-5@@ -74,8 +74,12 @@ static bool plugin_sched_init_context(struct kshark_context *kshark_ctx) event =tep_find_event_by_name (plugin_ctx->pevent,"sched" ,"sched_switch" ); -if (!event) +if (!event) { +plugin_free_context (plugin_ctx); + plugin_sched_context_handler =NULL ; +return false; + } plugin_ctx->sched_switch_event = event; plugin_ctx->sched_switch_next_field =@@ -320,11 +324,8 @@ static int plugin_sched_init(struct kshark_context *kshark_ctx) {struct plugin_sched_context *plugin_ctx; -if (!plugin_sched_init_context (kshark_ctx)) { -free (plugin_sched_context_handler); - plugin_sched_context_handler =NULL ; +if (!plugin_sched_init_context (kshark_ctx))return 0 ; - } plugin_ctx = plugin_sched_context_handler;
PATCH 3/3 kernel-shark: sched_events plugin init with sched_switch events only
In reply to Yordan KaradzhovThe sched_events plugin should not be totally disabled when the wakeup events are missing. The initialization of the plugin must fail only if the trace.dat file contains no sched_switch events.
--- kernel-shark/src/plugins/sched_events.c | 3 --- 1 file changed, 3 deletions(-)
kernel-shark/src/plugins/sched_events.c +0 -3
@@ -104,9 +104,6 @@ static bool plugin_sched_init_context(struct kshark_context *kshark_ctx) &plugin_ctx->sched_waking_event, &plugin_ctx->sched_waking_pid_field); -if (!wakeup_found) -return false; - plugin_ctx->second_pass_hash =tracecmd_filter_id_hash_alloc ();return true;
Signature · 1 line
2.19.1
Re: [PATCH 3/3] kernel-shark: sched_events plugin init with sched_switch events only
Quoted 14 lines · Yordan Karadzhov
The
sched_eventsplugin should not be totally disabled when the wakeup events are missing. The initialization of the plugin must fail only if the trace.dat file contains nosched_switchevents.Signed-off-by Yordan Karadzhov <[email protected]>--- kernel-shark/src/plugins/sched_events.c | 3 --- 1 file changed, 3 deletions(-)kernel-shark/src/plugins/sched_events.c +0
-0
kernel-shark/src/plugins/sched_events.c static bool plugin_sched_init_context(struct kshark_context *kshark_ctx) · line 109
Quoted 9 lines
kernel-shark/src/plugins/sched_events.c +0
-3@@ -104,9 +104,6 @@ static bool plugin_sched_init_context(struct kshark_context *kshark_ctx) &plugin_ctx->sched_waking_event, &plugin_ctx->sched_waking_pid_field); -if (!wakeup_found) -return false; - plugin_ctx->second_pass_hash =tracecmd_filter_id_hash_alloc ();return true;
Looks good to me.
Thank you,
-- Slavi
Re: [PATCH 3/3] kernel-shark: sched_events plugin init with sched_switch events only
Quoted 3 lines · On Tue, 5 Mar 2019 17:57:55 +0200 Slavomir Kaslev <[email protected]> wrote:
Looks good to me.
Reviewed-by Slavomir Kaslev <[email protected]>
Thanks Yordan and Slavomir,
I applied the patches.
-- Steve
Re: [PATCH 3/3] kernel-shark: sched_events plugin init with sched_switch events only
In reply to Yordan KaradzhovQuoted 4 lines · On Tue, 5 Mar 2019 16:39:24 +0200 Yordan Karadzhov <[email protected]>…
The
sched_eventsplugin should not be totally disabled when the wakeup events are missing. The initialization of the plugin must fail only if the trace.dat file contains nosched_switchevents.
I added:
-- Steve
Quoted 19 lines
Signed-off-by Yordan Karadzhov <[email protected]>--- kernel-shark/src/plugins/sched_events.c | 3 --- 1 file changed, 3 deletions(-)kernel-shark/src/plugins/sched_events.c +0
-3@@ -104,9 +104,6 @@ static bool plugin_sched_init_context(struct kshark_context *kshark_ctx) &plugin_ctx->sched_waking_event, &plugin_ctx->sched_waking_pid_field); -if (!wakeup_found) -return false; - plugin_ctx->second_pass_hash =tracecmd_filter_id_hash_alloc ();return true;