From 35795357e9891637e086a8f539e9fd1cd0d4d412 Mon Sep 17 00:00:00 2001 From: Mateusz Hoppe Date: Mon, 15 Nov 2021 11:52:19 +0000 Subject: [PATCH] DebugSession - add printBitmask() Signed-off-by: Mateusz Hoppe --- .../tools/source/debug/debug_session.cpp | 15 ++++++++++ level_zero/tools/source/debug/debug_session.h | 2 ++ .../sources/debug/debug_session_tests.cpp | 30 +++++++++++++++++++ 3 files changed, 47 insertions(+) diff --git a/level_zero/tools/source/debug/debug_session.cpp b/level_zero/tools/source/debug/debug_session.cpp index a34f1a2b4f..a35260a677 100644 --- a/level_zero/tools/source/debug/debug_session.cpp +++ b/level_zero/tools/source/debug/debug_session.cpp @@ -213,4 +213,19 @@ size_t DebugSession::getPerThreadScratchOffset(size_t ptss, EuThread::ThreadId t return threadOffset; } +void DebugSession::printBitmask(uint8_t *bitmask, size_t bitmaskSize) { + if (NEO::DebugManager.flags.DebuggerLogBitmask.get() & NEO::DebugVariables::DEBUGGER_LOG_BITMASK::LOG_INFO) { + + DEBUG_BREAK_IF(bitmaskSize % sizeof(uint64_t) != 0); + + PRINT_DEBUGGER_LOG(stdout, "\nINFO: Bitmask: ", ""); + + for (size_t i = 0; i < bitmaskSize / sizeof(uint64_t); i++) { + uint64_t bitmask64 = 0; + memcpy_s(&bitmask64, sizeof(uint64_t), &bitmask[i * sizeof(uint64_t)], sizeof(uint64_t)); + PRINT_DEBUGGER_LOG(stdout, "\n [%lu] = %#018" PRIx64, static_cast(i), bitmask64); + } + } +} + } // namespace L0 diff --git a/level_zero/tools/source/debug/debug_session.h b/level_zero/tools/source/debug/debug_session.h index 771daf90a6..7a76f8e297 100644 --- a/level_zero/tools/source/debug/debug_session.h +++ b/level_zero/tools/source/debug/debug_session.h @@ -69,6 +69,8 @@ struct DebugSession : _zet_debug_session_handle_t { return threadMatch && euMatch && subsliceMatch && sliceMatch; } + static void printBitmask(uint8_t *bitmask, size_t bitmaskSize); + virtual ze_device_thread_t convertToPhysical(ze_device_thread_t thread, uint32_t &deviceIndex); virtual EuThread::ThreadId convertToThreadId(ze_device_thread_t thread); virtual ze_device_thread_t convertToApi(EuThread::ThreadId threadId); diff --git a/level_zero/tools/test/unit_tests/sources/debug/debug_session_tests.cpp b/level_zero/tools/test/unit_tests/sources/debug/debug_session_tests.cpp index decbaf18b7..5c34862d47 100644 --- a/level_zero/tools/test/unit_tests/sources/debug/debug_session_tests.cpp +++ b/level_zero/tools/test/unit_tests/sources/debug/debug_session_tests.cpp @@ -453,6 +453,36 @@ TEST(DebugSession, givenDifferentThreadsWhenGettingPerThreadScratchOffsetThenCor EXPECT_EQ(2 * ptss + ptss * hwInfo.gtSystemInfo.MaxEuPerSubSlice * numThreadsPerEu, size); } +TEST(DebugSession, GivenLogsEnabledWhenPrintBitmaskCalledThenBitmaskIsPrinted) { + DebugManagerStateRestore restorer; + NEO::DebugManager.flags.DebuggerLogBitmask.set(255); + + ::testing::internal::CaptureStdout(); + + uint64_t bitmask[2] = {0x404080808080, 0x1111ffff1111ffff}; + DebugSession::printBitmask(reinterpret_cast(bitmask), sizeof(bitmask)); + + auto output = ::testing::internal::GetCapturedStdout(); + + EXPECT_THAT(output, testing::HasSubstr(std::string("\nINFO: Bitmask: "))); + EXPECT_THAT(output, testing::HasSubstr(std::string("[0] = 0x0000404080808080"))); + EXPECT_THAT(output, testing::HasSubstr(std::string("[1] = 0x1111ffff1111ffff"))); +} + +TEST(DebugSession, GivenLogsDisabledWhenPrintBitmaskCalledThenBitmaskIsNotPrinted) { + DebugManagerStateRestore restorer; + NEO::DebugManager.flags.DebuggerLogBitmask.set(0); + + ::testing::internal::CaptureStdout(); + + uint64_t bitmask[2] = {0x404080808080, 0x1111ffff1111ffff}; + DebugSession::printBitmask(reinterpret_cast(bitmask), sizeof(bitmask)); + + auto output = ::testing::internal::GetCapturedStdout(); + + EXPECT_EQ(0u, output.size()); +} + using DebugSessionMultiTile = Test; TEST_F(DebugSessionMultiTile, givenApiThreadAndMultipleTilesWhenConvertingToPhysicalThenCorrectValueReturned) {