aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAlex Bennée <alex.bennee@linaro.org>2020-02-25 12:47:06 +0000
committerAlex Bennée <alex.bennee@linaro.org>2020-02-25 20:20:23 +0000
commitec11c4a8ec7e858ec328772910def6e2fca9079a (patch)
treec93d8cc0a5a546e68ab6507f26da93196c3d64f8 /tests
parent25139bf7f87a0d0e758d4198579a227ab551802a (diff)
tests/plugins: make howvec clean-up after itself.
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>
Diffstat (limited to 'tests')
-rw-r--r--tests/plugin/howvec.c26
1 files changed, 17 insertions, 9 deletions
diff --git a/tests/plugin/howvec.c b/tests/plugin/howvec.c
index 4ca555e123..3b9a6939f2 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)