qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Alex Bennée" <alex.bennee@linaro.org>
To: peter.maydell@linaro.org
Cc: "Richard Henderson" <richard.henderson@linaro.org>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	qemu-devel@nongnu.org, "Robert Foley" <robert.foley@linaro.org>
Subject: [PULL 15/19] tests/plugins: make howvec clean-up after itself.
Date: Wed, 26 Feb 2020 07:39:25 +0000	[thread overview]
Message-ID: <20200226073929.28237-16-alex.bennee@linaro.org> (raw)
In-Reply-To: <20200226073929.28237-1-alex.bennee@linaro.org>

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 <alex.bennee@linaro.org>
Reviewed-by: Robert Foley <robert.foley@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

Message-Id: <20200225124710.14152-16-alex.bennee@linaro.org>

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)
-- 
2.20.1



  parent reply	other threads:[~2020-02-26  7:51 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-26  7:39 [PULL 00/19] testing and plugin updates Alex Bennée
2020-02-26  7:39 ` [PULL 01/19] tests/tcg: include a skip runner for pauth3 with plugins Alex Bennée
2020-02-26  7:39 ` [PULL 02/19] tests/rcutorture: update usage hint Alex Bennée
2020-02-26  7:39 ` [PULL 03/19] tests/rcutorture: better document locking of stats Alex Bennée
2020-02-26  7:39 ` [PULL 04/19] tests/rcutorture: mild documenting refactor of update thread Alex Bennée
2020-02-26  7:39 ` [PULL 05/19] travis.yml: Test the s390-ccw build, too Alex Bennée
2020-02-26  7:39 ` [PULL 06/19] travis.yml: Fix Travis YAML configuration warnings Alex Bennée
2020-02-26  7:39 ` [PULL 07/19] travis.yml: single-thread build-tcg stages Alex Bennée
2020-02-26  7:39 ` [PULL 08/19] tests/iotests: be a little more forgiving on the size test Alex Bennée
2020-02-26  7:39 ` [PULL 09/19] tracing: only allow -trace to override -D if set Alex Bennée
2020-02-26  7:39 ` [PULL 10/19] docs/devel: document query handle lifetimes Alex Bennée
2020-02-26  7:39 ` [PULL 11/19] plugins/core: add missing break in cb_to_tcg_flags Alex Bennée
2020-02-26  7:39 ` [PULL 12/19] tests/plugin: prevent uninitialized warning Alex Bennée
2020-02-26  7:39 ` [PULL 13/19] qemu/bitops.h: Add extract8 and extract16 Alex Bennée
2020-02-26  7:39 ` [PULL 14/19] target/riscv: progressively load the instruction during decode Alex Bennée
2020-02-26  7:39 ` Alex Bennée [this message]
2020-02-26  7:39 ` [PULL 16/19] tests/tcg: give debug builds a little bit longer Alex Bennée
2020-02-26  7:39 ` [PULL 17/19] tcg: save vaddr temp for plugin usage Alex Bennée
2020-02-26  7:39 ` [PULL 18/19] tests/tcg: fix typo in configure.sh test for v8.3 Alex Bennée
2020-02-26  7:39 ` [PULL 19/19] tests/tcg: take into account expected clashes pauth-4 Alex Bennée
2020-02-27 18:15 ` [PULL 00/19] testing and plugin updates Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200226073929.28237-16-alex.bennee@linaro.org \
    --to=alex.bennee@linaro.org \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=robert.foley@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).