@@ -17,6 +17,7 @@
#include "qemu/log.h"
#include "exec/tb-stats.h"
+#include "exec/tb-stats-dump.h"
#include "tb-context.h"
#include "internal.h"
@@ -29,6 +30,7 @@ enum TBStatsStatus {
static enum TBStatsStatus tcg_collect_tb_stats;
static uint32_t tbstats_flag;
+static int max_dump_tbs;
static GPtrArray *last_search;
@@ -300,6 +302,20 @@ void dump_tblist_info(GString *buf, int total, int sort_by)
}
}
+/*
+ * Dump the final stats
+ */
+void tb_stats_dump(void)
+{
+ if (!tb_stats_collection_enabled()) {
+ return;
+ }
+
+ g_autoptr(GString) buf = g_string_new("");
+ dump_tblist_info(buf, max_dump_tbs, SORT_BY_HOTNESS);
+ qemu_printf("%s", buf->str);
+}
+
void enable_collect_tb_stats(void)
{
tcg_collect_tb_stats = TB_STATS_RUNNING;
@@ -343,3 +359,8 @@ bool tbs_stats_enabled(struct TBStatistics *tbs, uint32_t flag)
return tb_stats_collection_enabled() &&
(tbstats_flag & flag);
}
+
+void set_tbstats_max_tbs(int max)
+{
+ max_dump_tbs = max;
+}
new file mode 100644
@@ -0,0 +1,21 @@
+/*
+ * TB Stats common dump functions across sysemu/linux-user
+ *
+ * Copyright (c) 2019 Linaro
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#ifndef _TB_STATS_DUMP_H_
+#define _TB_STATS_DUMP_H_
+
+/**
+ * tb_stats_dump: dump final tb_stats at end of execution
+ */
+#ifdef CONFIG_TCG
+void tb_stats_dump(void);
+#else
+static inline void tb_stats_dump(void) { /* do nothing */ };
+#endif
+
+#endif /* _TB_STATS_DUMP_H_ */
@@ -24,5 +24,6 @@ bool tb_stats_collection_disabled(void);
uint32_t get_tbstats_flag(void);
void set_tbstats_flag(uint32_t flag);
+void set_tbstats_max_tbs(int max);
#endif
@@ -25,6 +25,7 @@
#ifdef CONFIG_GPROF
#include <sys/gmon.h>
#endif
+#include "exec/tb-stats-dump.h"
#ifdef CONFIG_GCOV
extern void __gcov_dump(void);
@@ -41,4 +42,5 @@ void preexit_cleanup(CPUArchState *env, int code)
gdb_exit(code);
qemu_plugin_user_exit();
perf_exit();
+ tb_stats_dump();
}
@@ -30,6 +30,7 @@
#include "crypto/cipher.h"
#include "crypto/init.h"
#include "exec/cpu-common.h"
+#include "exec/tb-stats-dump.h"
#include "gdbstub/syscalls.h"
#include "hw/boards.h"
#include "migration/misc.h"
@@ -817,6 +818,7 @@ void qemu_cleanup(void)
vm_shutdown();
replay_finish();
+ tb_stats_dump();
job_cancel_sync_all();
bdrv_close_all();
@@ -30,3 +30,7 @@ void set_tbstats_flag(uint32_t flag)
{
return;
}
+
+void set_tbstats_max_tbs(int max) {
+ return;
+}
@@ -498,8 +498,9 @@ const QEMULogItem qemu_log_items[] = {
"open a separate log file per thread; filename must contain '%d'" },
{ CPU_LOG_TB_VPU, "vpu",
"include VPU registers in the 'cpu' logging" },
- { CPU_LOG_TB_STATS, "tb_stats_{all,jit,exec}",
- "enable collection of TBs statistics at startup" },
+ { CPU_LOG_TB_STATS, "tb_stats_{all,jit,exec}[:dump_num_at_exit]",
+ "enable collection of TBs statistics at startup "
+ "and dump at exit until given a limit" },
{ 0, NULL, NULL },
};
@@ -526,16 +527,23 @@ int qemu_str_to_log_mask(const char *str)
uint32_t flag = TB_NONE_STATS;
if (g_str_has_prefix(p, "all")) {
flag = TB_ALL_STATS;
+ p += 3;
} else if (g_str_has_prefix(p, "jit")) {
flag = TB_JIT_STATS;
+ p += 3;
} else if (g_str_has_prefix(p, "exec")) {
flag = TB_EXEC_STATS;
+ p += 4;
}
if (flag != TB_NONE_STATS) {
mask |= CPU_LOG_TB_STATS;
set_tbstats_flag(flag);
enable_collect_tb_stats();
}
+ if (p[0] == ':') {
+ int max_to_dump = atoi(p + 1);
+ set_tbstats_max_tbs(max_to_dump);
+ }
} else {
for (item = qemu_log_items; item->mask != 0; item++) {
if (g_str_equal(*tmp, item->name)) {