]>
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 | ||
3fb356cc AB |
17 | QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION; |
18 | ||
671f760b EC |
19 | static uint64_t bb_count; |
20 | static uint64_t insn_count; | |
21 | static bool do_inline; | |
22 | ||
23 | static void plugin_exit(qemu_plugin_id_t id, void *p) | |
24 | { | |
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); | |
29 | } | |
30 | ||
31 | static void vcpu_tb_exec(unsigned int cpu_index, void *udata) | |
32 | { | |
33 | unsigned long n_insns = (unsigned long)udata; | |
34 | ||
35 | insn_count += n_insns; | |
36 | bb_count++; | |
37 | } | |
38 | ||
39 | static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) | |
40 | { | |
41 | unsigned long n_insns = qemu_plugin_tb_n_insns(tb); | |
42 | ||
43 | if (do_inline) { | |
44 | qemu_plugin_register_vcpu_tb_exec_inline(tb, QEMU_PLUGIN_INLINE_ADD_U64, | |
45 | &bb_count, 1); | |
46 | qemu_plugin_register_vcpu_tb_exec_inline(tb, QEMU_PLUGIN_INLINE_ADD_U64, | |
47 | &insn_count, n_insns); | |
48 | } else { | |
49 | qemu_plugin_register_vcpu_tb_exec_cb(tb, vcpu_tb_exec, | |
50 | QEMU_PLUGIN_CB_NO_REGS, | |
51 | (void *)n_insns); | |
52 | } | |
53 | } | |
54 | ||
55 | QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, | |
56 | const qemu_info_t *info, | |
57 | int argc, char **argv) | |
58 | { | |
59 | if (argc && strcmp(argv[0], "inline") == 0) { | |
60 | do_inline = true; | |
61 | } | |
62 | ||
63 | qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans); | |
64 | qemu_plugin_register_atexit_cb(id, plugin_exit, NULL); | |
65 | return 0; | |
66 | } |