]>
Commit | Line | Data |
---|---|---|
671f760b EC |
1 | /* |
2 | * Copyright (C) 2018, Emilio G. Cota <cota@braap.org> | |
3 | * | |
4 | * License: GNU GPL, version 2 or later. | |
5 | * See the COPYING file in the top-level directory. | |
6 | */ | |
7 | #include <inttypes.h> | |
8 | #include <assert.h> | |
9 | #include <stdlib.h> | |
10 | #include <string.h> | |
11 | #include <unistd.h> | |
12 | #include <stdio.h> | |
13 | #include <glib.h> | |
14 | ||
15 | #include <qemu-plugin.h> | |
16 | ||
17 | static uint64_t bb_count; | |
18 | static uint64_t insn_count; | |
19 | static bool do_inline; | |
20 | ||
21 | static void plugin_exit(qemu_plugin_id_t id, void *p) | |
22 | { | |
23 | g_autofree gchar *out; | |
24 | out = g_strdup_printf("bb's: %" PRIu64", insns: %" PRIu64 "\n", | |
25 | bb_count, insn_count); | |
26 | qemu_plugin_outs(out); | |
27 | } | |
28 | ||
29 | static void vcpu_tb_exec(unsigned int cpu_index, void *udata) | |
30 | { | |
31 | unsigned long n_insns = (unsigned long)udata; | |
32 | ||
33 | insn_count += n_insns; | |
34 | bb_count++; | |
35 | } | |
36 | ||
37 | static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) | |
38 | { | |
39 | unsigned long n_insns = qemu_plugin_tb_n_insns(tb); | |
40 | ||
41 | if (do_inline) { | |
42 | qemu_plugin_register_vcpu_tb_exec_inline(tb, QEMU_PLUGIN_INLINE_ADD_U64, | |
43 | &bb_count, 1); | |
44 | qemu_plugin_register_vcpu_tb_exec_inline(tb, QEMU_PLUGIN_INLINE_ADD_U64, | |
45 | &insn_count, n_insns); | |
46 | } else { | |
47 | qemu_plugin_register_vcpu_tb_exec_cb(tb, vcpu_tb_exec, | |
48 | QEMU_PLUGIN_CB_NO_REGS, | |
49 | (void *)n_insns); | |
50 | } | |
51 | } | |
52 | ||
53 | QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, | |
54 | const qemu_info_t *info, | |
55 | int argc, char **argv) | |
56 | { | |
57 | if (argc && strcmp(argv[0], "inline") == 0) { | |
58 | do_inline = true; | |
59 | } | |
60 | ||
61 | qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans); | |
62 | qemu_plugin_register_atexit_cb(id, plugin_exit, NULL); | |
63 | return 0; | |
64 | } |