*: Add missing includes of tcg/tcg.h
[qemu/ar7.git] / accel / tcg / monitor.c
blobf171bc6f5edc1bd9dd72fba6d6af06f973c27bdf
1 /*
2 * SPDX-License-Identifier: LGPL-2.1-or-later
4 * QEMU TCG monitor
6 * Copyright (c) 2003-2005 Fabrice Bellard
7 */
9 #include "qemu/osdep.h"
10 #include "qemu/accel.h"
11 #include "qapi/error.h"
12 #include "qapi/type-helpers.h"
13 #include "qapi/qapi-commands-machine.h"
14 #include "monitor/monitor.h"
15 #include "sysemu/cpus.h"
16 #include "sysemu/cpu-timers.h"
17 #include "sysemu/tcg.h"
18 #include "tcg/tcg.h"
19 #include "internal.h"
22 static void dump_drift_info(GString *buf)
24 if (!icount_enabled()) {
25 return;
28 g_string_append_printf(buf, "Host - Guest clock %"PRIi64" ms\n",
29 (cpu_get_clock() - icount_get()) / SCALE_MS);
30 if (icount_align_option) {
31 g_string_append_printf(buf, "Max guest delay %"PRIi64" ms\n",
32 -max_delay / SCALE_MS);
33 g_string_append_printf(buf, "Max guest advance %"PRIi64" ms\n",
34 max_advance / SCALE_MS);
35 } else {
36 g_string_append_printf(buf, "Max guest delay NA\n");
37 g_string_append_printf(buf, "Max guest advance NA\n");
41 static void dump_accel_info(GString *buf)
43 AccelState *accel = current_accel();
44 bool one_insn_per_tb = object_property_get_bool(OBJECT(accel),
45 "one-insn-per-tb",
46 &error_fatal);
48 g_string_append_printf(buf, "Accelerator settings:\n");
49 g_string_append_printf(buf, "one-insn-per-tb: %s\n\n",
50 one_insn_per_tb ? "on" : "off");
53 HumanReadableText *qmp_x_query_jit(Error **errp)
55 g_autoptr(GString) buf = g_string_new("");
57 if (!tcg_enabled()) {
58 error_setg(errp, "JIT information is only available with accel=tcg");
59 return NULL;
62 dump_accel_info(buf);
63 dump_exec_info(buf);
64 dump_drift_info(buf);
66 return human_readable_text_from_str(buf);
69 HumanReadableText *qmp_x_query_opcount(Error **errp)
71 g_autoptr(GString) buf = g_string_new("");
73 if (!tcg_enabled()) {
74 error_setg(errp,
75 "Opcode count information is only available with accel=tcg");
76 return NULL;
79 tcg_dump_op_count(buf);
81 return human_readable_text_from_str(buf);
84 #ifdef CONFIG_PROFILER
86 int64_t dev_time;
88 HumanReadableText *qmp_x_query_profile(Error **errp)
90 g_autoptr(GString) buf = g_string_new("");
91 static int64_t last_cpu_exec_time;
92 int64_t cpu_exec_time;
93 int64_t delta;
95 cpu_exec_time = tcg_cpu_exec_time();
96 delta = cpu_exec_time - last_cpu_exec_time;
98 g_string_append_printf(buf, "async time %" PRId64 " (%0.3f)\n",
99 dev_time, dev_time / (double)NANOSECONDS_PER_SECOND);
100 g_string_append_printf(buf, "qemu time %" PRId64 " (%0.3f)\n",
101 delta, delta / (double)NANOSECONDS_PER_SECOND);
102 last_cpu_exec_time = cpu_exec_time;
103 dev_time = 0;
105 return human_readable_text_from_str(buf);
107 #else
108 HumanReadableText *qmp_x_query_profile(Error **errp)
110 error_setg(errp, "Internal profiler not compiled");
111 return NULL;
113 #endif
115 static void hmp_tcg_register(void)
117 monitor_register_hmp_info_hrt("jit", qmp_x_query_jit);
118 monitor_register_hmp_info_hrt("opcount", qmp_x_query_opcount);
121 type_init(hmp_tcg_register);