[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v1 19/28] tests/plugins: extend the insn plugin to track opcode s
From: |
Alex Bennée |
Subject: |
[PATCH v1 19/28] tests/plugins: extend the insn plugin to track opcode sizes |
Date: |
Tue, 26 Oct 2021 11:22:25 +0100 |
This is mostly a convenience feature for identifying frontends that do
multiple repeat loads so I can test changes to the instruction
tracking interface.
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
tests/plugin/insn.c | 37 +++++++++++++++++++++++++++++++++++--
1 file changed, 35 insertions(+), 2 deletions(-)
diff --git a/tests/plugin/insn.c b/tests/plugin/insn.c
index 0f6a1938c1..d229fdc001 100644
--- a/tests/plugin/insn.c
+++ b/tests/plugin/insn.c
@@ -18,6 +18,8 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_version =
QEMU_PLUGIN_VERSION;
static uint64_t insn_count;
static bool do_inline;
+static bool do_size;
+static GArray *sizes;
static void vcpu_insn_exec_before(unsigned int cpu_index, void *udata)
{
@@ -49,13 +51,35 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct
qemu_plugin_tb *tb)
insn, vcpu_insn_exec_before, QEMU_PLUGIN_CB_NO_REGS,
GUINT_TO_POINTER(vaddr));
}
+
+ if (do_size) {
+ size_t sz = qemu_plugin_insn_size(insn);
+ if (sz > sizes->len) {
+ g_array_set_size(sizes, sz);
+ }
+ unsigned long *cnt = &g_array_index(sizes, unsigned long, sz);
+ (*cnt)++;
+ }
}
}
static void plugin_exit(qemu_plugin_id_t id, void *p)
{
- g_autofree gchar *out = g_strdup_printf("insns: %" PRIu64 "\n",
insn_count);
- qemu_plugin_outs(out);
+ g_autoptr(GString) out = g_string_new(NULL);
+
+ if (do_size) {
+ int i;
+ for (i = 0; i <= sizes->len; i++) {
+ unsigned long *cnt = &g_array_index(sizes, unsigned long, i);
+ if (*cnt) {
+ g_string_append_printf(out,
+ "len %d bytes: %ld insns\n", i, *cnt);
+ }
+ }
+ } else {
+ g_string_append_printf(out, "insns: %" PRIu64 "\n", insn_count);
+ }
+ qemu_plugin_outs(out->str);
}
QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id,
@@ -70,12 +94,21 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t
id,
fprintf(stderr, "boolean argument parsing failed: %s\n", opt);
return -1;
}
+ } else if (g_strcmp0(tokens[0], "sizes") == 0) {
+ if (!qemu_plugin_bool_parse(tokens[0], tokens[1], &do_size)) {
+ fprintf(stderr, "boolean argument parsing failed: %s\n", opt);
+ return -1;
+ }
} else {
fprintf(stderr, "option parsing failed: %s\n", opt);
return -1;
}
}
+ if (do_size) {
+ sizes = g_array_new(true, true, sizeof(unsigned long));
+ }
+
qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans);
qemu_plugin_register_atexit_cb(id, plugin_exit, NULL);
return 0;
--
2.30.2
- [PATCH v1 12/28] ebpf: really include it only in system emulators, (continued)
- [PATCH v1 12/28] ebpf: really include it only in system emulators, Alex Bennée, 2021/10/26
- [PATCH v1 09/28] tests/docker: split PARTIAL into PARTIAL and VIRTUAL images, Alex Bennée, 2021/10/26
- [PATCH v1 25/28] plugins: add helper functions for coverage plugins, Alex Bennée, 2021/10/26
- [PATCH v1 08/28] tests/tcg: Fix some targets default cross compiler path, Alex Bennée, 2021/10/26
- [PATCH v1 17/28] docs/tcg-plugins: add L2 arguments to cache docs, Alex Bennée, 2021/10/26
- [PATCH v1 18/28] chardev: don't exit() straight away on C-a x, Alex Bennée, 2021/10/26
- [PATCH v1 19/28] tests/plugins: extend the insn plugin to track opcode sizes,
Alex Bennée <=
- [PATCH v1 26/28] contrib/plugins: add a drcov plugin, Alex Bennée, 2021/10/26
- [PATCH v1 28/28] gdbstub: Switch to the thread receiving a signal, Alex Bennée, 2021/10/26
- [PATCH v1 15/28] plugins/cache: split command line arguments into name and value, Alex Bennée, 2021/10/26
- [PATCH v1 13/28] plugins/cache: freed heap-allocated mutexes, Alex Bennée, 2021/10/26
- [PATCH v1 23/28] tracing: remove the trace-tcg includes from the build, Alex Bennée, 2021/10/26
- [PATCH v1 24/28] tracing: excise the tcg related from tracetool, Alex Bennée, 2021/10/26