Skip to content

Commit

Permalink
util: add --debug-cycle to help debug print
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jensen-yan committed Jan 6, 2025
1 parent 0ded7a0 commit a536721
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
2 changes: 2 additions & 0 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]
Expand Down
7 changes: 7 additions & 0 deletions src/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 18 additions & 6 deletions src/base/trace.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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))) { \
Expand Down

0 comments on commit a536721

Please sign in to comment.