From patchwork Wed Feb 26 07:39:25 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: 183906 Delivered-To: patch@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp2796437ile; Tue, 25 Feb 2020 23:51:08 -0800 (PST) X-Google-Smtp-Source: APXvYqwnOEzBUgtlTkK2jDT8jSQqIgaHv0G8e1ZGKfd9Jm5fu/hGbyadqyO9VOa0mm842QVndNmL X-Received: by 2002:a05:620a:13b5:: with SMTP id m21mr3619381qki.469.1582703468170; Tue, 25 Feb 2020 23:51:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582703468; cv=none; d=google.com; s=arc-20160816; b=HMKSdOCDqpXVyySFd1crKjwRiGdZVTDdvICjXmSJC5vNpXzobVgfKyaLhKdtx8N4Xb Bh7DgeI6oCEO5wILCIhaKe0YsIWwIEaNhGIUoJXLeL6u468ES6l/X1NWuz4m0R9k9ix4 VWJkRxoihYBp8sZPrwgl7tcUjIPvS/QzK0XwpirjGDQbeYRVvPwFC+JOup3ywy63o09H J7C21acT8/EdXkevjteMuzGLmnQgrm2/UTUDEM6D0MeD8TfT4S1BDlu8k8Du9utd3IuU K+e4f78nJ4pXEfVijtlObcgnnCwPail1q6lkjOswYcGEDLyXcxbNvjLcCkzguc7BCEGD Mv1g== 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=SKIVM/nv6pvrBs0kbqjR1dcnk9jHgbZ0MPB1gDBk62c=; b=ATRci6/Jusx49uHQJbhuFmkeZLduBkl0cA2jUAyXu493eLiqC2UHcgCF1L2pM1RWll R0vnwTZajdIt1+eBEnCjm+cWMNgJq2ieqeyT7LylLydmEbq+Ni/0uos/5y37xa15gOLb pMAynRZFk/aSroTJk1TQgmjkp8Cdi8/ycZQ3k/as/D7B6rWZUoWilPk2cfTRruLQGIZ7 9fEBvT99efTrFDxR1lFtif07bAZ+QBteKY2ht5wD8iz8HAnWhyg3sQlgRUW4AjF/u4dU c1ZKtO54Cwq2X1mpB3UcKn8pu8b3FQJhviePzeJwvSDCyDz3ys3p+Wy2pO2cHqwDh8sl zcBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=CtWcg8dE; 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 x74si532494qka.199.2020.02.25.23.51.08 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 25 Feb 2020 23:51:08 -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=CtWcg8dE; 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]:39528 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6rTH-0001cE-LU for patch@linaro.org; Wed, 26 Feb 2020 02:51:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50456) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6rO6-0003XY-4F for qemu-devel@nongnu.org; Wed, 26 Feb 2020 02:45:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6rO4-0005dw-AU for qemu-devel@nongnu.org; Wed, 26 Feb 2020 02:45:45 -0500 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]:52413) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j6rO3-0005a1-3N for qemu-devel@nongnu.org; Wed, 26 Feb 2020 02:45:43 -0500 Received: by mail-wm1-x332.google.com with SMTP id p9so1817131wmc.2 for ; Tue, 25 Feb 2020 23:45:43 -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=SKIVM/nv6pvrBs0kbqjR1dcnk9jHgbZ0MPB1gDBk62c=; b=CtWcg8dEkhnd0+Y5sXJjEWQmwy5kebfuQzeFRbn+bEcd8p4TF65H3IOBPij1UOpYms LL7R8RDnMUpym+Zy89ZHo3S/SDD921qeqxhO+7aIOrLs7F09WQbnZx6bedwWvGmKO/UC I67y8CuK0FAFAeCdiJP9OWnQzV8XPK/NlJr2yAaIfxx8cEVoe/FCwAxadz953LKd4aqD bU1nzwR/9ym+am9ptJl1SGcZvjwVTHelos/LoBZBA1BA82WgdEFszbEq0ovw/JWoXcPM kMvR6NfDTHA/y0I2ZscSS8EOdLTv+jHXgIRytf0khKDoFBc/Zop2DzxMBCxNYGjqwVGB GONQ== 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=SKIVM/nv6pvrBs0kbqjR1dcnk9jHgbZ0MPB1gDBk62c=; b=kjfrXMxwlVotB94p2R1LBKovMP1Q7akgsagDDawoE1+dzEjKgdvPnAmhy4cEeTHaJR yhQpOorxidvyoAw6hhWaAcmj1CVrCusrYTAhI922u/1O/gHEJSH0JIwo+d8vwmLmZVrZ 0xKsGWghpDIgJr4xzsCd/0cU8rFbstBdzAeMYNFiGWllK/4WLjFrktO/b81uKooN5wi5 5ujdXWjdMKpBv1Ak6ILFDFVVpXTev1iIQ+1AGzMVQjUMv47nyXtNtwu3A1mjFWpDthwq FGcUVeCSomFYv3Qz97c+0ykBqzAEIJosB1/oBEv7jZ5ci0hESIe0hkviUIPLcUn6FCTx Khkg== X-Gm-Message-State: APjAAAUJc5nYb811WLMckEz1pt+DQLfYAnnyHcCN8LHJ9e1iYSbKKxYp anIfm6l3rLi5eQoaftt7oYrV0g== X-Received: by 2002:a7b:cb97:: with SMTP id m23mr3640772wmi.37.1582703141998; Tue, 25 Feb 2020 23:45:41 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id t131sm1861721wmb.13.2020.02.25.23.45.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 23:45:40 -0800 (PST) Received: from zen.home.arpa (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 920C01FF9F; Wed, 26 Feb 2020 07:39:30 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Subject: [PULL 15/19] tests/plugins: make howvec clean-up after itself. Date: Wed, 26 Feb 2020 07:39:25 +0000 Message-Id: <20200226073929.28237-16-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200226073929.28237-1-alex.bennee@linaro.org> References: <20200226073929.28237-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::332 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: Richard Henderson , =?utf-8?q?Alex_Benn?= =?utf-8?b?w6ll?= , qemu-devel@nongnu.org, Robert Foley 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 Message-Id: <20200225124710.14152-16-alex.bennee@linaro.org> -- 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)