s390x/cpumodel: Fix feature property error API violations
[qemu/ar7.git] / tests / plugin / bb.c
blobf30bea08dccfcd502686d370421545e7d4f37f00
1 /*
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.
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>
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;
36 bb_count++;
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);
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);
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) {
60 do_inline = true;
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;