From a536721aa9c5001b0b252bb097c1c84bc0071934 Mon Sep 17 00:00:00 2001 From: Yan Yue <1131531947@qq.com> Date: Sat, 4 Jan 2025 18:46:30 +0800 Subject: [PATCH] util: add --debug-cycle to help debug print it will enable print cycle in DPRINTF, print tick is difficult to debug, print cycle helps, DPRINTF print like: 31635: system.cpu.branchPred: [c: 95] DecoupledBPUWithFTB::tick() c: 95 means cycle, 95 = 31635 / 333, 333 is ticks for 1 cycle in 3GHz, use cpu->clockPeriod() is greater, but not all class have cpu member. Change-Id: I0ff1f3e3290842e6ba110393705c003616103924 --- SConstruct | 2 ++ src/SConscript | 7 +++++++ src/base/trace.hh | 24 ++++++++++++++++++------ 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/SConstruct b/SConstruct index 32284fccae..f3beb1e555 100755 --- a/SConstruct +++ b/SConstruct @@ -149,6 +149,8 @@ AddOption('--pgo-prof', action='store_true', help='Enable pgo profiling generation') AddOption('--pgo-use', action='store', default=None, help='Use pgo profiling results') +AddOption('--debug-cycle', action='store_true', + help='Enable print cycle in DPRINTF') # Inject the built_tools directory into the python path. sys.path[1:1] = [ Dir('#build_tools').abspath ] diff --git a/src/SConscript b/src/SConscript index 77c004239c..01bd5c8f78 100644 --- a/src/SConscript +++ b/src/SConscript @@ -665,6 +665,13 @@ envs['debug'].Append(CPPDEFINES=['DEBUG', 'TRACING_ON=1']) envs['opt'].Append(CCFLAGS=['-g'], CPPDEFINES=['TRACING_ON=1']) envs['fast'].Append(CPPDEFINES=['NDEBUG', 'TRACING_ON=0']) +if GetOption('debug_cycle'): + for target in ['debug', 'opt', 'fast']: + envs[target].Append(CPPDEFINES=['DEBUG_SHOW_CYCLES=1']) +else: + for target in ['debug', 'opt', 'fast']: + envs[target].Append(CPPDEFINES=['DEBUG_SHOW_CYCLES=0']) + # For Link Time Optimization, the optimisation flags used to compile # individual files are decoupled from those used at link time # (i.e. you can compile with -O3 and perform LTO with -O0), so we need diff --git a/src/base/trace.hh b/src/base/trace.hh index 18d4d7b6d7..8bb388d2ff 100644 --- a/src/base/trace.hh +++ b/src/base/trace.hh @@ -183,12 +183,24 @@ struct StringWrap ::gem5::curTick(), name(), data, count, #x); \ } while (0) -#define DPRINTF(x, ...) do { \ - if (GEM5_UNLIKELY(TRACING_ON && (::gem5::debug::x))) { \ - ::gem5::Trace::getDebugLogger()->dprintf_flag( \ - ::gem5::curTick(), name(), #x, __VA_ARGS__); \ - } \ -} while (0) +#if DEBUG_SHOW_CYCLES + #define DPRINTF(x, ...) do { \ + if (GEM5_UNLIKELY(TRACING_ON && (::gem5::debug::x))) { \ + ::gem5::Trace::getDebugLogger()->dprintf_flag( \ + ::gem5::curTick(), name(), #x, \ + "[c: %llu] %s", \ + ::gem5::curTick()/333, \ + ::gem5::csprintf(__VA_ARGS__).c_str()); \ + } /* todo: remove 333, use cpu->clockPeriod() */ \ + } while (0) +#else + #define DPRINTF(x, ...) do { \ + if (GEM5_UNLIKELY(TRACING_ON && (::gem5::debug::x))) { \ + ::gem5::Trace::getDebugLogger()->dprintf_flag( \ + ::gem5::curTick(), name(), #x, __VA_ARGS__); \ + } \ + } while (0) +#endif #define DPRINTFS(x, s, ...) do { \ if (GEM5_UNLIKELY(TRACING_ON && (::gem5::debug::x))) { \