Capture TBS at startup instead of an explicit 'tb_stats start' command. Signed-off-by: Vanderson M. do Rosario <vanderson...@gmail.com> Signed-off-by: Alex Bennée <alex.ben...@linaro.org> Signed-off-by: Fei Wu <fei2...@intel.com> --- include/exec/tb-stats-flags.h | 1 + include/qemu/log.h | 1 + stubs/meson.build | 1 + stubs/tb-stats.c | 32 ++++++++++++++++++++++++++++++++ util/log.c | 18 ++++++++++++++++++ 5 files changed, 53 insertions(+) create mode 100644 stubs/tb-stats.c
diff --git a/include/exec/tb-stats-flags.h b/include/exec/tb-stats-flags.h index d8b844be99..936bd35707 100644 --- a/include/exec/tb-stats-flags.h +++ b/include/exec/tb-stats-flags.h @@ -14,6 +14,7 @@ #define TB_NONE_STATS (0) /* no stats */ #define TB_EXEC_STATS (1 << 0) #define TB_JIT_STATS (1 << 1) +#define TB_ALL_STATS (TB_EXEC_STATS | TB_JIT_STATS) /* TBStatistic collection controls */ void enable_collect_tb_stats(void); diff --git a/include/qemu/log.h b/include/qemu/log.h index df59bfabcd..eca10f02a3 100644 --- a/include/qemu/log.h +++ b/include/qemu/log.h @@ -36,6 +36,7 @@ bool qemu_log_separate(void); #define LOG_STRACE (1 << 19) #define LOG_PER_THREAD (1 << 20) #define CPU_LOG_TB_VPU (1 << 21) +#define CPU_LOG_TB_STATS (1 << 22) /* Lock/unlock output. */ diff --git a/stubs/meson.build b/stubs/meson.build index a56645e2f7..e926649d40 100644 --- a/stubs/meson.build +++ b/stubs/meson.build @@ -65,3 +65,4 @@ else endif stub_ss.add(files('semihost-all.c')) stub_ss.add(when: 'CONFIG_VFIO_USER_SERVER', if_false: files('vfio-user-obj.c')) +stub_ss.add(files('tb-stats.c')) diff --git a/stubs/tb-stats.c b/stubs/tb-stats.c new file mode 100644 index 0000000000..38ee12313e --- /dev/null +++ b/stubs/tb-stats.c @@ -0,0 +1,32 @@ +/* + * TB Stats Stubs + * + * Copyright (c) 2019 + * Written by Alex Bennée <alex.ben...@linaro.org> + * + * This code is licensed under the GNU GPL v2, or later. + */ + + +#include "qemu/osdep.h" +#include "exec/tb-stats-flags.h" + +void enable_collect_tb_stats(void) +{ + return; +} + +void disable_collect_tb_stats(void) +{ + return; +} + +bool tb_stats_collection_enabled(void) +{ + return false; +} + +void set_tbstats_flag(uint32_t flag) +{ + return; +} diff --git a/util/log.c b/util/log.c index def88a9402..59c781de36 100644 --- a/util/log.c +++ b/util/log.c @@ -27,6 +27,7 @@ #include "qemu/thread.h" #include "qemu/lockable.h" #include "qemu/rcu.h" +#include "exec/tb-stats-flags.h" #ifdef CONFIG_LINUX #include <sys/syscall.h> #endif @@ -497,6 +498,8 @@ 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" }, { 0, NULL, NULL }, }; @@ -518,6 +521,21 @@ int qemu_str_to_log_mask(const char *str) trace_enable_events((*tmp) + 6); mask |= LOG_TRACE; #endif + } else if (g_str_has_prefix(*tmp, "tb_stats_")) { + char *p = *tmp + 9; + uint32_t flag = TB_NONE_STATS; + if (g_str_has_prefix(p, "all")) { + flag = TB_ALL_STATS; + } else if (g_str_has_prefix(p, "jit")) { + flag = TB_JIT_STATS; + } else if (g_str_has_prefix(p, "exec")) { + flag = TB_EXEC_STATS; + } + if (flag != TB_NONE_STATS) { + mask |= CPU_LOG_TB_STATS; + set_tbstats_flag(flag); + enable_collect_tb_stats(); + } } else { for (item = qemu_log_items; item->mask != 0; item++) { if (g_str_equal(*tmp, item->name)) { -- 2.25.1