From patchwork Tue Mar 5 14:39:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 10839553 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4C1651390 for ; Tue, 5 Mar 2019 14:39:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 38EA22C0BD for ; Tue, 5 Mar 2019 14:39:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2D77F2C0BF; Tue, 5 Mar 2019 14:39:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CE86D2C0BE for ; Tue, 5 Mar 2019 14:39:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727424AbfCEOjy (ORCPT ); Tue, 5 Mar 2019 09:39:54 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:41929 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727839AbfCEOjy (ORCPT ); Tue, 5 Mar 2019 09:39:54 -0500 Received: by mail-wr1-f67.google.com with SMTP id n2so9727730wrw.8 for ; Tue, 05 Mar 2019 06:39:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0rVlCilypZXtg7OYqP+ypxxyEEBDfl2mZysOVwhRsAE=; b=nlBRYEJGe0TWRr4GDYU8JE+B2vhBA/z0JRkmoBJGACMNGinfaD9qCgmyDjHo5lMSfA dEeRhAt51MDJlDfjZa5TEafFyFsGjGf/qbwekoeCDzGF6bIrGpvcylPOb+wIBN2UUknL qSOT2rgovzcCf8X9y9EEFcN6iyvrXCOLJGCvtnXp4zxn0sGaZltUZPU5gQ8zAnBsX2wt xBXdAmdau0ABX+l4PWR6O/YhTKQ8zVvOnkhNDtYLaAZJDKk1GC+++jwC9rezwREPgaOZ HlYt7gCnKHKfID/PMhdmvWFwTo6tq/1UHCgiBo0K69ziv1Ve86MFMtYMIvHrvirLmmdh H7LQ== X-Gm-Message-State: APjAAAXJwlqDrmlwWFSsa36Q3RKFq1H0C2iQORLQG06JsYEZQv+1v4Ay 1EC93mrt9bf0QKvWcIs9dX5zBgR7 X-Google-Smtp-Source: APXvYqxi2eBUEiYGgT67UCpbx3UayGBXz82mDPn94kft+Le8ZiK27DEtV4AwwcMJRN/cJ4MCKWWUgA== X-Received: by 2002:a5d:6785:: with SMTP id v5mr17914891wru.59.1551796792654; Tue, 05 Mar 2019 06:39:52 -0800 (PST) Received: from mamba.eng.vmware.com ([146.247.46.5]) by smtp.gmail.com with ESMTPSA id o12sm31908915wre.0.2019.03.05.06.39.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Mar 2019 06:39:52 -0800 (PST) From: Yordan Karadzhov To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org, Yordan Karadzhov Subject: [PATCH 1/3] kernel-shark: Define free_contex function for the sched_events plugin Date: Tue, 5 Mar 2019 16:39:22 +0200 Message-Id: <20190305143924.11056-2-ykaradzhov@vmware.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190305143924.11056-1-ykaradzhov@vmware.com> References: <20190305143924.11056-1-ykaradzhov@vmware.com> MIME-Version: 1.0 Sender: linux-trace-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This static helper function makes the code of the plugin cleaner and easier to read. Signed-off-by: Yordan Karadzhov Reviewed-by: Slavomir Kaslev --- 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; From patchwork Tue Mar 5 14:39:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 10839555 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E8930139A for ; Tue, 5 Mar 2019 14:39:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D66042C0BD for ; Tue, 5 Mar 2019 14:39:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CAAA62C0BF; Tue, 5 Mar 2019 14:39:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7BFB62C0BD for ; Tue, 5 Mar 2019 14:39:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727839AbfCEOj4 (ORCPT ); Tue, 5 Mar 2019 09:39:56 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:37613 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727836AbfCEOj4 (ORCPT ); Tue, 5 Mar 2019 09:39:56 -0500 Received: by mail-wm1-f66.google.com with SMTP id x10so2773900wmg.2 for ; Tue, 05 Mar 2019 06:39:54 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YeygMsLlMv7wb5bZFSJgMjSgjhS/8Ws01Ad0MJgBvQI=; b=Ye/8bZyflydEHNG/CLFITpI01Bo0qCkUH2mikpMONfjvejnnb33cHvuK2cuzlJf86z Gpfq1EUlNe0HFzEM8rZG3+0pGdbCE0IHbBUktCEgAt6LM80qZAtNanjG1h0i9GkVz5wX Ps26Nb0fHEC1nIjRbNeQEIpG5EbIJGBAPudWMH3RwbjPSZGtS15Ykka4R4/bhkMBYzeS fEbjRccLIxiI6thEPl3P3KO0P5L4BVT20ItFJJGJ49nhWKU6JUZVLww387lmXBWvwj+6 O8DxMvsWPgv90cVEXVlAAQ4pVkYfrmPLrxRvZJitLxLaxtTT/hEcLKOODPu6LlfObGzp 6AHQ== X-Gm-Message-State: APjAAAVS0G0O4p22fP8IA3jUjUOxiBJq0i020qBRMgDXvFICJ6kYaaRB ImVmpE+okWRrgR6/JoINUp0= X-Google-Smtp-Source: APXvYqwsCIAsqDoUB5asZPtkACWAcR4gvB4X56F6JbcBHvnU2NdqAQ6LVVOP5nJujuYT6CINXjmUTA== X-Received: by 2002:a1c:a688:: with SMTP id p130mr3156798wme.53.1551796794182; Tue, 05 Mar 2019 06:39:54 -0800 (PST) Received: from mamba.eng.vmware.com ([146.247.46.5]) by smtp.gmail.com with ESMTPSA id o12sm31908915wre.0.2019.03.05.06.39.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Mar 2019 06:39:53 -0800 (PST) From: Yordan Karadzhov To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org, Yordan Karadzhov Subject: [PATCH 2/3] kernel-shark: Fix a memory leak in the sched_events plugin Date: Tue, 5 Mar 2019 16:39:23 +0200 Message-Id: <20190305143924.11056-3-ykaradzhov@vmware.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190305143924.11056-1-ykaradzhov@vmware.com> References: <20190305143924.11056-1-ykaradzhov@vmware.com> MIME-Version: 1.0 Sender: linux-trace-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When 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. Fixes: 4f392730e ("kernel-shark-qt: Make Sched event plugin use ...") Signed-off-by: Yordan Karadzhov Reviewed-by: Slavomir Kaslev --- kernel-shark/src/plugins/sched_events.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/kernel-shark/src/plugins/sched_events.c b/kernel-shark/src/plugins/sched_events.c index 0d6de2d..fe13e6a 100644 --- a/kernel-shark/src/plugins/sched_events.c +++ b/kernel-shark/src/plugins/sched_events.c @@ -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; From patchwork Tue Mar 5 14:39:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 10839557 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C2EA9139A for ; Tue, 5 Mar 2019 14:39:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B09022C0BD for ; Tue, 5 Mar 2019 14:39:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A49142C0BF; Tue, 5 Mar 2019 14:39:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5DCEC2C0BD for ; Tue, 5 Mar 2019 14:39:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727498AbfCEOj5 (ORCPT ); Tue, 5 Mar 2019 09:39:57 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:38552 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727837AbfCEOj5 (ORCPT ); Tue, 5 Mar 2019 09:39:57 -0500 Received: by mail-wm1-f67.google.com with SMTP id a188so2768003wmf.3 for ; Tue, 05 Mar 2019 06:39:56 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=M9JnMyn5P3axmb34AJFL3gpoI921pB4YzqxxZYAOFcU=; b=E/wV5wJup9I2jh6tiPBAR1E51pc4JqyxTmSeORJ86bE9EpScCDV8rzVsoQ+onfPaeU MYtvDTB8Z6m/Q7UUTdZRhGGxmVRRdLrFCz8soVibNnL+zMBo0DtfblXR296HuwHB5hdJ EEOYjJ1DU6WjPepn0XK7rcu5+kVICKlN3MR07rrHHCvBp7MGm8502/y3EXTBriTWYftp DvlyKFQNyYKppq2nIuW+ABpwBhS+LKLuLkgfkbpGKhqECJfJZgBpGdfGge6Y4ogDnwsv t7PWKr+fyQ4wShOPt+H7tJOs5pSB3e/hjSz/hvLiowDJKcYfdgXFcCNVQlUDVgD/RcII 1YKQ== X-Gm-Message-State: APjAAAVA0KzenMn4LMEzQ4FMjPVjxJVtVbFGVaiglgHY+VStOtv3LLxs T0zc0xV9tr4Sr78GVAibdn/pXpaO X-Google-Smtp-Source: APXvYqwnqIDotaWADcBUViyncAoSLZQoxmCSmzXeIUGwkdUZZXPXuhbiUHlDonKT0OOuFD6AL2El5w== X-Received: by 2002:a1c:cc0c:: with SMTP id h12mr3230587wmb.140.1551796795542; Tue, 05 Mar 2019 06:39:55 -0800 (PST) Received: from mamba.eng.vmware.com ([146.247.46.5]) by smtp.gmail.com with ESMTPSA id o12sm31908915wre.0.2019.03.05.06.39.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Mar 2019 06:39:55 -0800 (PST) From: Yordan Karadzhov To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org, Yordan Karadzhov Subject: [PATCH 3/3] kernel-shark: sched_events plugin init with sched_switch events only Date: Tue, 5 Mar 2019 16:39:24 +0200 Message-Id: <20190305143924.11056-4-ykaradzhov@vmware.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190305143924.11056-1-ykaradzhov@vmware.com> References: <20190305143924.11056-1-ykaradzhov@vmware.com> MIME-Version: 1.0 Sender: linux-trace-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The 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. Signed-off-by: Yordan Karadzhov Reviewed-by: Slavomir Kaslev Reported-by: Phil Auld --- kernel-shark/src/plugins/sched_events.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/kernel-shark/src/plugins/sched_events.c b/kernel-shark/src/plugins/sched_events.c index fe13e6a..c52fb29 100644 --- a/kernel-shark/src/plugins/sched_events.c +++ b/kernel-shark/src/plugins/sched_events.c @@ -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;