qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

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>

+17 -9
+17 -9
tests/plugin/howvec.c
··· 163 163 return ea->count > eb->count ? -1 : 1; 164 164 } 165 165 166 + static void free_record(gpointer data) 167 + { 168 + InsnExecCount *rec = (InsnExecCount *) data; 169 + g_free(rec->insn); 170 + g_free(rec); 171 + } 172 + 166 173 static void plugin_exit(qemu_plugin_id_t id, void *p) 167 174 { 168 175 g_autoptr(GString) report = g_string_new("Instruction Classes:\n"); ··· 195 202 196 203 counts = g_hash_table_get_values(insns); 197 204 if (counts && g_list_next(counts)) { 198 - GList *it; 199 - 200 205 g_string_append_printf(report,"Individual Instructions:\n"); 201 - 202 - it = g_list_sort(counts, cmp_exec_count); 206 + counts = g_list_sort(counts, cmp_exec_count); 203 207 204 - for (i = 0; i < limit && it->next; i++, it = it->next) { 205 - InsnExecCount *rec = (InsnExecCount *) it->data; 206 - g_string_append_printf(report, "Instr: %-24s\t(%ld hits)\t(op=%#08x/%s)\n", 208 + for (i = 0; i < limit && g_list_next(counts); 209 + i++, counts = g_list_next(counts)) { 210 + InsnExecCount *rec = (InsnExecCount *) counts->data; 211 + g_string_append_printf(report, 212 + "Instr: %-24s\t(%ld hits)\t(op=%#08x/%s)\n", 207 213 rec->insn, 208 214 rec->count, 209 215 rec->opcode, 210 216 rec->class ? 211 217 rec->class->class : "un-categorised"); 212 218 } 213 - g_list_free(it); 219 + g_list_free(counts); 214 220 } 215 221 222 + g_hash_table_destroy(insns); 223 + 216 224 qemu_plugin_outs(report->str); 217 225 } 218 226 219 227 static void plugin_init(void) 220 228 { 221 - insns = g_hash_table_new(NULL, g_direct_equal); 229 + insns = g_hash_table_new_full(NULL, g_direct_equal, NULL, &free_record); 222 230 } 223 231 224 232 static void vcpu_insn_exec_before(unsigned int cpu_index, void *udata)