2 * Copyright (C) 2018, Emilio G. Cota <cota@braap.org>
4 * License: GNU GPL, version 2 or later.
5 * See the COPYING file in the top-level directory.
15 #include <qemu-plugin.h>
17 QEMU_PLUGIN_EXPORT
int qemu_plugin_version
= QEMU_PLUGIN_VERSION
;
19 static uint64_t bb_count
;
20 static uint64_t insn_count
;
21 static bool do_inline
;
23 static void plugin_exit(qemu_plugin_id_t id
, void *p
)
25 g_autofree gchar
*out
;
26 out
= g_strdup_printf("bb's: %" PRIu64
", insns: %" PRIu64
"\n",
27 bb_count
, insn_count
);
28 qemu_plugin_outs(out
);
31 static void vcpu_tb_exec(unsigned int cpu_index
, void *udata
)
33 unsigned long n_insns
= (unsigned long)udata
;
35 insn_count
+= n_insns
;
39 static void vcpu_tb_trans(qemu_plugin_id_t id
, struct qemu_plugin_tb
*tb
)
41 unsigned long n_insns
= qemu_plugin_tb_n_insns(tb
);
44 qemu_plugin_register_vcpu_tb_exec_inline(tb
, QEMU_PLUGIN_INLINE_ADD_U64
,
46 qemu_plugin_register_vcpu_tb_exec_inline(tb
, QEMU_PLUGIN_INLINE_ADD_U64
,
47 &insn_count
, n_insns
);
49 qemu_plugin_register_vcpu_tb_exec_cb(tb
, vcpu_tb_exec
,
50 QEMU_PLUGIN_CB_NO_REGS
,
55 QEMU_PLUGIN_EXPORT
int qemu_plugin_install(qemu_plugin_id_t id
,
56 const qemu_info_t
*info
,
57 int argc
, char **argv
)
59 if (argc
&& strcmp(argv
[0], "inline") == 0) {
63 qemu_plugin_register_vcpu_tb_trans_cb(id
, vcpu_tb_trans
);
64 qemu_plugin_register_atexit_cb(id
, plugin_exit
, NULL
);