Dump the hottest TBs if -d tb_stats_{all,jit,exec}[:dump_num_at_exit] --- accel/tcg/tb-stats.c | 21 +++++++++++++++++++++ include/exec/tb-stats-dump.h | 21 +++++++++++++++++++++ include/exec/tb-stats-flags.h | 1 + linux-user/exit.c | 2 ++ softmmu/runstate.c | 2 ++ stubs/tb-stats.c | 4 ++++ util/log.c | 12 ++++++++++-- 7 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 include/exec/tb-stats-dump.h
diff --git a/accel/tcg/tb-stats.c b/accel/tcg/tb-stats.c index 53a4f448dc..a5fc3c1c74 100644 --- a/accel/tcg/tb-stats.c +++ b/accel/tcg/tb-stats.c @@ -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; @@ -299,6 +301,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; @@ -342,3 +358,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; +} diff --git a/include/exec/tb-stats-dump.h b/include/exec/tb-stats-dump.h new file mode 100644 index 0000000000..197c6148e9 --- /dev/null +++ b/include/exec/tb-stats-dump.h @@ -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_ */ diff --git a/include/exec/tb-stats-flags.h b/include/exec/tb-stats-flags.h index 936bd35707..52d0429eeb 100644 --- a/include/exec/tb-stats-flags.h +++ b/include/exec/tb-stats-flags.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 diff --git a/linux-user/exit.c b/linux-user/exit.c index 3017d28a3c..4fd23bcf60 100644 --- a/linux-user/exit.c +++ b/linux-user/exit.c @@ -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(); } diff --git a/softmmu/runstate.c b/softmmu/runstate.c index bd50062ed0..156156815b 100644 --- a/softmmu/runstate.c +++ b/softmmu/runstate.c @@ -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" @@ -818,6 +819,7 @@ void qemu_cleanup(void) vm_shutdown(); replay_finish(); + tb_stats_dump(); job_cancel_sync_all(); bdrv_close_all(); diff --git a/stubs/tb-stats.c b/stubs/tb-stats.c index 38ee12313e..78ae1aa217 100644 --- a/stubs/tb-stats.c +++ b/stubs/tb-stats.c @@ -30,3 +30,7 @@ void set_tbstats_flag(uint32_t flag) { return; } + +void set_tbstats_max_tbs(int max) { + return; +} diff --git a/util/log.c b/util/log.c index 419f02c380..ae5398fb69 100644 --- a/util/log.c +++ b/util/log.c @@ -496,8 +496,9 @@ const QEMULogItem qemu_log_items[] = { "log every user-mode syscall, its input, and its result" }, { LOG_PER_THREAD, "tid", "open a separate log file per thread; filename must contain '%d'" }, - { 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 }, }; @@ -524,16 +525,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)) { -- 2.25.1