From patchwork Thu Feb 13 22:51:05 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: 183444 Delivered-To: patch@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp1085179ile; Thu, 13 Feb 2020 15:01:09 -0800 (PST) X-Google-Smtp-Source: APXvYqwiEykZ3b+55nwdaLD7ahSUsktKP4KcE7sTmGErEQZylShjunz10yhsF7xNhjQB6+G603wk X-Received: by 2002:a1c:7215:: with SMTP id n21mr374981wmc.154.1581634869530; Thu, 13 Feb 2020 15:01:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581634869; cv=none; d=google.com; s=arc-20160816; b=F66IYgfzEvb1u2lvBTKIigz8+2+0okldQ/b7+TzDOEjqcr7HnOM78YXvqmWj23v0QH SHnWa9S9Ad4sI/9lfy2x0o7Ocb/9kqLcfJrxSJQ5lWUcMbJ3ZahtCCzf3KqtPMOKbSiQ Wm7srIjc5cixrBpanOpK45JgZMAR5CmV0BycN21XdPLEj2J3M/qQDUcdmKXtuojBdQaF +7X2VeRM0+/N/6WTiUqqExU2KL2SyK5dDAzeGUSaGf7xn/ChwFy7feJT8aRl3ARiRSWs cQtvTH3/c+uX3rfzd83k1V/lmeE9THjMXdHDAE3jBPCcHtGQl+UrTEhRGBS845TpApP6 sBhg== 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=zVLKtA5Wmrt21a2oWSd8x1CUubxahgQrKJmoXoXKY6SUUuUq+6XFdLKKiw5ME1BxXh a8xcXFgAGHnRWkVad/1ksssewEmM+Ce8Fv9P/vUU6Fcju+n7z7bhVGtOwUlsZYwoeQka VEJHDvsjsXbpMAaCYuOZkl2UFHNoJ8Ty2KV27uSvt2wUyh3eSmHzVK2glaAJNBoY9/BI +1nC0bK1BjzKgeTqUtemVuVinZbfxC1jkRlSiQoJqDScFwvTI2UfFuJPVcb/h52Ej9dV iYAfMPHeb1v55IKiCbIlvvAdCwIxO3tvtHH37rVvuPFxq0jDYKhWELUVZQO4QVcXjBu5 Uzbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=HETjkqaC; 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 p16si2932314wmi.43.2020.02.13.15.01.09 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 13 Feb 2020 15:01:09 -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=HETjkqaC; 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]:60562 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2NTo-0002VS-DF for patch@linaro.org; Thu, 13 Feb 2020 18:01:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55333) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2NTV-0002PN-Jg for qemu-devel@nongnu.org; Thu, 13 Feb 2020 18:00:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j2NTU-0002T2-4v for qemu-devel@nongnu.org; Thu, 13 Feb 2020 18:00:49 -0500 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]:56142) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j2NTT-0002Qg-TZ for qemu-devel@nongnu.org; Thu, 13 Feb 2020 18:00:48 -0500 Received: by mail-wm1-x32b.google.com with SMTP id q9so8070047wmj.5 for ; Thu, 13 Feb 2020 15:00:47 -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=HETjkqaCsZnbseyYwDHmOQypUJuhl3zS5WaQLTWTJL5QazZy0NBdJRmUtTpAkewGaK SVUbV9uNQlt8Z+AOsDo/ZJ9DFRASPWFWjILsSZo7u98tWhCLn0yLg0OKUsgP4lriIh+8 Xf1CAwBF9Q4b3X3Vo/C8OIXRoT6Cn1iFi9IO455MxPKYN1sJfD6AuYuZ4W6ipwUqr0y/ 7MhQFyN2B31x/uoRr2MiPaop/7YZ6UzxsR6YoIQNLwH4DjfGc/hGIxUcgjxIvHnLE6LW lXimG0kez3PmHttEOXn4GYM36yigxqoLvOE/0ebbQqGlnOpgod8e7bo8Dh08qObk+jUK hu0A== 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=RaAZDwE/f3HaPANDJlTTUSIxbB8EG2zpPRyFb3CmIutQSAWOm9c042gm2Ktw2yfy8l njg3cjb5FyzA0Zq12W/1wvmS9hvJoZwVuszPsyp+Gi9Ym/9vw3aBu/JsMlya/4+TtNLm qM8wwSGqioZGvO2RbPIRoEIbQ4ek94Sl1DqfmpK5N3Y2otzKX14w7w84EwNqEVPS43mq aCJEFKEOQ1ybNRZY0BGCILI3q7NiNspwPoaGsyLen91H3P5IhBpsbr2jzcKcbuHZBQ8/ 7kME+flc94+w4GjFmDOH/T6ApTX9OixGGsYl4uP89AJImCNr7xjxBUaEZswxPGmTaN6K J9WQ== X-Gm-Message-State: APjAAAXKQwnd/7EuBAcmaPWB6fPaHWW+TRKmwzCa8O7vw8MATo6e5xOB GLiWBjGZ/Fqg9xt0MfS0c8HFfw== X-Received: by 2002:a7b:c3d1:: with SMTP id t17mr337769wmj.27.1581634846542; Thu, 13 Feb 2020 15:00:46 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id a9sm4612064wmm.15.2020.02.13.15.00.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Feb 2020 15:00:45 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id ED62F1FF9F; Thu, 13 Feb 2020 22:51:10 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v2 15/19] tests/plugins: make howvec clean-up after itself. Date: Thu, 13 Feb 2020 22:51:05 +0000 Message-Id: <20200213225109.13120-16-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200213225109.13120-1-alex.bennee@linaro.org> References: <20200213225109.13120-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::32b 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)