From patchwork Tue Feb 25 12:47:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 183845 Delivered-To: patch@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp1776204ile; Tue, 25 Feb 2020 05:50:43 -0800 (PST) X-Google-Smtp-Source: APXvYqzCo9ty5FaqKXX9tcFv1A2NwxKYEhhAbjanCmnprZzo+lV06ypgf+FMoheTibo8hkxptNH8 X-Received: by 2002:ac8:42de:: with SMTP id g30mr54384502qtm.195.1582638643017; Tue, 25 Feb 2020 05:50:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582638643; cv=none; d=google.com; s=arc-20160816; b=elc6tyjlQo4+r5uspbOonL+FcqpiNQTiPV8GRnJxPrzcZGloiNWA7qcnGeb/3mTIb9 nU0AQjeWVhM8a5/xKJWttWQwFs85XKE+9gM3tCf3/fXwcqHF1dMUwSazsb9766GgesEq kgq6ihaVsmQ+IPSbFEN0u/cN1oKCcL9K7fM2hAV9VArdqOwtfxXDjXwDFgpI++r6I5xm K/3E43yt/qn1SJNlHNZxhOflt2W7b2nekbW1bASyvMeyijhAcAobiM/JVxq7EZhCSbsk vgMgdAQsCfH5X+zeguAOGWmat7LNVKFlbxcn8w4iWhlfgf3DeEWd8tMYAnEB5aSX7YCF ulig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=py9bcDZz909NEUPFg69hhSHq8thghQZDr3PiUGhEcOg=; b=P4s0aMyBq/bb7ZDpxpx56a5hMCBy06nLUHORpEV1dmPZTSGsCliaQX3yCa2FQ0VWS8 7DZtbp5uoFg0Oiuih0Wb0lNpouR6iVyk041gNO/hRRjQRER0EzSQjns2FQshWrcFtLcz C2PLbTheb9JZc3Boc4jVqRmJFkaVJL58MssZdmL9738KqfKOQ6rSfpZ2xY25sk2h2WOH HlaANBlYW3pVliCrzigJLXGq+yc6/cmnDSfQ0r2jC8OlF279sc/FYe2uT1jtJ8IjDjPy xktVWaA/5j5CViMrsPX2WWPKrcoZV3i4e79H0qtAb2cMP6SF4APGNi/X2NuB8LbCqyNv Fi+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=JhWdVKhB; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id q34si7848401qtb.199.2020.02.25.05.50.42 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 25 Feb 2020 05:50:43 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=JhWdVKhB; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:56662 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6abi-0002fU-Hq for patch@linaro.org; Tue, 25 Feb 2020 08:50:42 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:34147) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6ZkV-0003ms-Dp for qemu-devel@nongnu.org; Tue, 25 Feb 2020 07:55:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6ZkU-00046r-7v for qemu-devel@nongnu.org; Tue, 25 Feb 2020 07:55:43 -0500 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]:33643) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j6ZkU-00044r-0y for qemu-devel@nongnu.org; Tue, 25 Feb 2020 07:55:42 -0500 Received: by mail-wr1-x431.google.com with SMTP id u6so14647548wrt.0 for ; Tue, 25 Feb 2020 04:55:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=py9bcDZz909NEUPFg69hhSHq8thghQZDr3PiUGhEcOg=; b=JhWdVKhBnzZN3VXdrNxeEqtU6f7bJmlP8kAme/ZPKWBW8/pUkbagIf4ZJDn+Vz7T/J mzaU4LKuKHJEx5HWeQs2LF+fF2OeIovwqWS2HZO4gEAxKNlS+6cO/4xlnWr+HM3XAELx kukRsRi2eysjuAl+8C6v/Vl6gk6z/YdXMrZIrysXk4kXZbSWrk5PUmijWlyuhyNrWxb6 E0SeHL7fKs4W+WNUQYuXicKfpCTu3ONGzSJnRCt367YWgQAI7Lutp6WuOFwdjj4NrFPX pON3z8pB/f1JIEIPOea6/Yra/uLxJT6IQGFIjb202zziGcYrM8zlOT44Ncn4MLCOdNOR 4k2A== 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=py9bcDZz909NEUPFg69hhSHq8thghQZDr3PiUGhEcOg=; b=DpleG9G4khcjXl2SyPodx6/PouTQ/G9iuHCscLSuWWrmXs3jdCz+pcVysIuKD+oKFM W52r6YCrqtmPfQfj6y9cxjEbvoyBLdclLTKD4eP52lgz/Vx3z1jv3nnmbFx87oDGxG+Q naKgI/4Ex/RSYPbIBTklxlf6C2t2PfWrzVKLsUbj3edg9SB2uRXF3hjOyBBYwLO83FZG d7CWo4SULol/LrneT9LFxJ6vSUe3v9iNhgkN9VYK6IGrCjeWKTy4Bcg++Iuxyf8jzoBq Y8e6vGKhWD6PzLxxYVsCQLtJYMdZwv/sccC5JyHFROFP/NkeGrzyBNz4UIYDN1Fla7lX U/Vg== X-Gm-Message-State: APjAAAXhAiWB+LCRmjI6h00lTeejthwlCVivxgqonR89+iUxnvwXYv3j dkYzKNw+NTE/oP4JgX/u22c1Ww== X-Received: by 2002:adf:9cca:: with SMTP id h10mr2875933wre.390.1582635340968; Tue, 25 Feb 2020 04:55:40 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id e22sm4118189wme.45.2020.02.25.04.55.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 04:55:37 -0800 (PST) Received: from zen.home.arpa (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 9F8AA1FF9F; Tue, 25 Feb 2020 12:47:11 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v3 15/19] tests/plugins: make howvec clean-up after itself. Date: Tue, 25 Feb 2020 12:47:06 +0000 Message-Id: <20200225124710.14152-16-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200225124710.14152-1-alex.bennee@linaro.org> References: <20200225124710.14152-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::431 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: fam@euphon.net, berrange@redhat.com, robert.foley@linaro.org, pbonzini@redhat.com, stefanb@linux.vnet.ibm.com, =?utf-8?q?Alex_Benn?= =?utf-8?b?w6ll?= , richard.henderson@linaro.org, f4bug@amsat.org, robhenry@microsoft.com, marcandre.lureau@redhat.com, aaron@os.amperecomputing.com, cota@braap.org, stefanha@redhat.com, kuhn.chenqun@huawei.com, peter.puhov@linaro.org, aurelien@aurel32.net Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" TCG plugins are responsible for their own memory usage and although the plugin_exit is tied to the end of execution in this case it is still poor practice. Ensure we delete the hash table and related data when we are done to be a good plugin citizen. Signed-off-by: Alex Bennée Reviewed-by: Robert Foley Reviewed-by: Richard Henderson --- v2 - re-use counts for g_list_sort() as it modifies list - drop it list squash! tests/plugins: make howvec clean-up after itself. --- tests/plugin/howvec.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) -- 2.20.1 diff --git a/tests/plugin/howvec.c b/tests/plugin/howvec.c index 4ca555e1239..3b9a6939f23 100644 --- a/tests/plugin/howvec.c +++ b/tests/plugin/howvec.c @@ -163,6 +163,13 @@ static gint cmp_exec_count(gconstpointer a, gconstpointer b) return ea->count > eb->count ? -1 : 1; } +static void free_record(gpointer data) +{ + InsnExecCount *rec = (InsnExecCount *) data; + g_free(rec->insn); + g_free(rec); +} + static void plugin_exit(qemu_plugin_id_t id, void *p) { g_autoptr(GString) report = g_string_new("Instruction Classes:\n"); @@ -195,30 +202,31 @@ static void plugin_exit(qemu_plugin_id_t id, void *p) counts = g_hash_table_get_values(insns); if (counts && g_list_next(counts)) { - GList *it; - g_string_append_printf(report,"Individual Instructions:\n"); + counts = g_list_sort(counts, cmp_exec_count); - it = g_list_sort(counts, cmp_exec_count); - - for (i = 0; i < limit && it->next; i++, it = it->next) { - InsnExecCount *rec = (InsnExecCount *) it->data; - g_string_append_printf(report, "Instr: %-24s\t(%ld hits)\t(op=%#08x/%s)\n", + for (i = 0; i < limit && g_list_next(counts); + i++, counts = g_list_next(counts)) { + InsnExecCount *rec = (InsnExecCount *) counts->data; + g_string_append_printf(report, + "Instr: %-24s\t(%ld hits)\t(op=%#08x/%s)\n", rec->insn, rec->count, rec->opcode, rec->class ? rec->class->class : "un-categorised"); } - g_list_free(it); + g_list_free(counts); } + g_hash_table_destroy(insns); + qemu_plugin_outs(report->str); } static void plugin_init(void) { - insns = g_hash_table_new(NULL, g_direct_equal); + insns = g_hash_table_new_full(NULL, g_direct_equal, NULL, &free_record); } static void vcpu_insn_exec_before(unsigned int cpu_index, void *udata)