Skip to content

Commit a111c18

Browse files
refactor: Add timestamp to all debugger log
Signed-off-by: Jitendra Sharma <[email protected]>
1 parent 91f1f58 commit a111c18

File tree

6 files changed

+65
-24
lines changed

6 files changed

+65
-24
lines changed

level_zero/tools/source/debug/debug_session_imp.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,7 @@ bool DebugSessionImp::isAIPequalToThreadStartIP(uint32_t *cr0, uint32_t *dbg0) {
830830
void DebugSessionImp::fillResumeAndStoppedThreadsFromNewlyStopped(std::vector<EuThread::ThreadId> &resumeThreads, std::vector<EuThread::ThreadId> &stoppedThreadsToReport, std::vector<EuThread::ThreadId> &interruptedThreads) {
831831

832832
if (newlyStoppedThreads.empty()) {
833+
PRINT_DEBUGGER_INFO_LOG("%s", "No newly stopped threads found. Returning");
833834
return;
834835
}
835836
const auto regSize = std::max(getRegisterSize(ZET_DEBUG_REGSET_TYPE_CR_INTEL_GPU), 64u);
@@ -1716,14 +1717,14 @@ ze_result_t DebugSessionImp::readFifo(uint64_t vmHandle, std::vector<EuThread::T
17161717
for (uint32_t i = 0; i < readSize; i++) {
17171718
const uint64_t gpuVa = currentFifoOffset + (i * sizeof(SIP::fifo_node));
17181719
PRINT_DEBUGGER_FIFO_LOG("Validate entry at index %u in SW Fifo:: vmHandle: %" SCNx64
1719-
" gpuVa: %" SCNx64
1720-
" valid: %" SCNx8
1721-
" thread_id: %" SCNx8
1722-
" eu_id: %" SCNx8
1723-
" subslice_id: %" SCNx8
1724-
" slice_id: %" SCNx8
1720+
" gpuVa = %" SCNx64
1721+
" valid = %" SCNx8
1722+
" slice = %" SCNx8
1723+
" subslice = %" SCNx8
1724+
" eu = %" SCNx8
1725+
" thread = %" SCNx8
17251726
"\n",
1726-
(i + fifoTailIndex), vmHandle, gpuVa, nodes[i].valid, nodes[i].thread_id, nodes[i].eu_id, nodes[i].subslice_id, nodes[i].slice_id);
1727+
(i + fifoTailIndex), vmHandle, gpuVa, nodes[i].valid, nodes[i].slice_id, nodes[i].subslice_id, nodes[i].eu_id, nodes[i].thread_id);
17271728
retVal = isValidNode(vmHandle, gpuVa, nodes[i]);
17281729
if (retVal != ZE_RESULT_SUCCESS) {
17291730
return retVal;

level_zero/tools/test/unit_tests/sources/debug/eu_thread_tests.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2021-2023 Intel Corporation
2+
* Copyright (C) 2021-2024 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -158,7 +158,10 @@ TEST(EuThread, GivenEnabledErrorLogsWhenThreadStateStoppedAndVerifyingStopWithEv
158158
EXPECT_TRUE(euThread.isRunning());
159159

160160
auto message = ::testing::internal::GetCapturedStderr();
161-
EXPECT_STREQ("\nERROR: Thread: device index = 0 slice = 0 subslice = 0 eu = 0 thread = 0 state STOPPED when thread is running. Switching to RUNNING", message.c_str());
161+
// Trim message and remove timestamp + first space
162+
size_t pos = message.find(']');
163+
message.erase(0, pos + 2);
164+
EXPECT_STREQ("ERROR: Thread: device index = 0 slice = 0 subslice = 0 eu = 0 thread = 0 state STOPPED when thread is running. Switching to RUNNING", message.c_str());
162165
}
163166

164167
TEST(EuThread, GivenThreadStateRunningWhenVerifyingStopWithOddCounterForSecondStopThenTrueIsReturnedAndStateStopped) {
@@ -210,7 +213,10 @@ TEST(EuThread, GivenEnabledErrorLogsWhenThreadStateStoppedAndVerifyingStopWithOd
210213
EXPECT_TRUE(euThread.isStopped());
211214

212215
auto message = ::testing::internal::GetCapturedStderr();
213-
EXPECT_STREQ("\nERROR: Thread: device index = 0 slice = 0 subslice = 0 eu = 0 thread = 0 state out of sync.", message.c_str());
216+
// Trim message and remove timestamp + first space
217+
size_t pos = message.find(']');
218+
message.erase(0, pos + 2);
219+
EXPECT_STREQ("ERROR: Thread: device index = 0 slice = 0 subslice = 0 eu = 0 thread = 0 state out of sync.", message.c_str());
214220
}
215221

216222
TEST(EuThread, GivenEnabledErrorLogsWhenThreadStateRunningAndVerifyingStopWithOddCounterEqualToPreviousThenErrorMessageIsPrinted) {
@@ -230,7 +236,10 @@ TEST(EuThread, GivenEnabledErrorLogsWhenThreadStateRunningAndVerifyingStopWithOd
230236
EXPECT_TRUE(euThread.isStopped());
231237

232238
auto message = ::testing::internal::GetCapturedStderr();
233-
EXPECT_STREQ("\nERROR: Thread: device index = 0 slice = 0 subslice = 0 eu = 0 thread = 0 state RUNNING when thread is stopped. Switching to STOPPED", message.c_str());
239+
// Trim message and remove timestamp + first space
240+
size_t pos = message.find(']');
241+
message.erase(0, pos + 2);
242+
EXPECT_STREQ("ERROR: Thread: device index = 0 slice = 0 subslice = 0 eu = 0 thread = 0 state RUNNING when thread is stopped. Switching to STOPPED", message.c_str());
234243
}
235244

236245
TEST(EuThread, GivenThreadStateStoppedWhenVerifyingStopWithEvenCounterBiggerByMoreThanTwoThenFalseIsReturnedAndStateRunning) {

level_zero/tools/test/unit_tests/sources/debug/linux/prelim/test_debug_api_linux.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,10 @@ TEST_F(DebugApiLinuxTest, GivenDebuggerLogsWhenOpenDebuggerFailsThenCorrectMessa
10031003
EXPECT_EQ(ZE_RESULT_ERROR_UNKNOWN, result);
10041004

10051005
auto errorMessage = ::testing::internal::GetCapturedStderr();
1006-
EXPECT_EQ(std::string("\nERROR: PRELIM_DRM_IOCTL_I915_DEBUGGER_OPEN failed: open.pid: 4660, open.events: 0, retCode: -1, errno: 22\n"), errorMessage);
1006+
// Trim errorMessage and remove timestamp + first space
1007+
size_t pos = errorMessage.find(']');
1008+
errorMessage.erase(0, pos + 2);
1009+
EXPECT_EQ(std::string("ERROR: PRELIM_DRM_IOCTL_I915_DEBUGGER_OPEN failed: open.pid: 4660, open.events: 0, retCode: -1, errno: 22\n"), errorMessage);
10071010
}
10081011

10091012
TEST_F(DebugApiLinuxTest, WhenOpenDebuggerFailsThenCorrectErrorIsReturned) {
@@ -1147,7 +1150,10 @@ TEST_F(DebugApiLinuxTest, GivenPrintDebugMessagesWhenDebugSessionClosesConnectio
11471150
NEO::SysCalls::closeFuncRetVal = 0;
11481151

11491152
auto errorMessage = ::testing::internal::GetCapturedStderr();
1150-
EXPECT_EQ(std::string("\nERROR: Debug connection close() on fd: 10 failed: retCode: -1\n"), errorMessage);
1153+
// Trim errorMessage and remove timestamp + first space
1154+
size_t pos = errorMessage.find(']');
1155+
errorMessage.erase(0, pos + 2);
1156+
EXPECT_EQ(std::string("ERROR: Debug connection close() on fd: 10 failed: retCode: -1\n"), errorMessage);
11511157
}
11521158

11531159
TEST_F(DebugApiLinuxTest, GivenDebugSessionWhenCallingIoctlThenIoctlHandlerIsInvokedWithDebugFd) {
@@ -5076,7 +5082,10 @@ TEST_F(DebugApiLinuxTest, GivenDebuggerLogsAndFailingReadUuidEventIoctlWhenHandl
50765082
EXPECT_EQ(0u, session->getClassHandleToIndex().size());
50775083

50785084
auto errorMessage = ::testing::internal::GetCapturedStderr();
5079-
EXPECT_EQ(std::string("\nERROR: PRELIM_I915_DEBUG_IOCTL_READ_UUID ret = -1 errno = 0\n"), errorMessage);
5085+
// Trim errorMessage and remove timestamp + first space
5086+
size_t pos = errorMessage.find(']');
5087+
errorMessage.erase(0, pos + 2);
5088+
EXPECT_EQ(std::string("ERROR: PRELIM_I915_DEBUG_IOCTL_READ_UUID ret = -1 errno = 0\n"), errorMessage);
50805089
}
50815090

50825091
TEST_F(DebugApiLinuxTest, GivenEventsAvailableWhenReadingEventThenEventsAreReturned) {
@@ -5316,7 +5325,10 @@ TEST_F(DebugApiLinuxTest, GivenDebuggerErrorLogsWhenContextParamWithInvalidConte
53165325
session->clientHandleToConnection[contextParamEvent.client_handle]->contextsCreated.find(77));
53175326

53185327
auto errorMessage = ::testing::internal::GetCapturedStderr();
5319-
EXPECT_EQ(std::string("\nERROR: CONTEXT handle does not exist\n"), errorMessage);
5328+
// Trim errorMessage and remove timestamp + first space
5329+
size_t pos = errorMessage.find(']');
5330+
errorMessage.erase(0, pos + 2);
5331+
EXPECT_EQ(std::string("ERROR: CONTEXT handle does not exist\n"), errorMessage);
53205332
}
53215333

53225334
TEST_F(DebugApiLinuxTest, GivenDebuggerInfoLogsWhenHandlingContextParamEventWithUnknownParamThenInfoIsPrinted) {

shared/source/debug_settings/debug_settings_manager.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
#include "shared/source/utilities/io_functions.h"
1717
#include "shared/source/utilities/logger.h"
1818

19+
#include <chrono>
20+
#include <cinttypes>
1921
#include <fstream>
22+
#include <iomanip>
2023
#include <iostream>
2124
#include <sstream>
2225
#include <type_traits>
@@ -165,10 +168,14 @@ void logDebugString(std::string_view debugString) {
165168
}
166169

167170
std::string DurationLog::getTimeString() {
168-
static const std::chrono::time_point<std::chrono::steady_clock> processStartTime = std::chrono::steady_clock::now();
169-
auto elapsedTime = std::chrono::steady_clock::now().time_since_epoch() - processStartTime.time_since_epoch();
170-
auto elapsedTimeUs = std::chrono::duration_cast<std::chrono::microseconds>(elapsedTime);
171-
return std::to_string(elapsedTimeUs.count());
171+
auto now = std::chrono::steady_clock::now();
172+
auto microseconds = std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch());
173+
auto seconds = microseconds.count() / 1000000;
174+
auto remainingMicroSeconds = microseconds.count() % 1000000;
175+
char buffer[32];
176+
std::snprintf(buffer, sizeof(buffer), "[%5" PRId64 ".%06" PRId64 "]",
177+
static_cast<int64_t>(seconds), static_cast<int64_t>(remainingMicroSeconds));
178+
return std::string(buffer);
172179
}
173180

174181
template class DebugSettingsManager<DebugFunctionalityLevel::none>;

shared/source/debug_settings/debug_settings_manager.h

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,22 +208,34 @@ class DurationLog {
208208

209209
#define PRINT_DEBUGGER_THREAD_LOG(STR, ...) \
210210
if (NEO::debugManager.flags.DebuggerLogBitmask.get() & NEO::DebugVariables::DEBUGGER_LOG_BITMASK::LOG_THREADS) { \
211-
PRINT_DEBUGGER_LOG(stdout, "\nTHREAD INFO: " STR, __VA_ARGS__) \
211+
\
212+
auto time = NEO::DurationLog::getTimeString(); \
213+
time = "\n" + time + " THREAD INFO: " + STR; \
214+
PRINT_DEBUGGER_LOG(stdout, time.c_str(), __VA_ARGS__) \
212215
}
213216

214217
#define PRINT_DEBUGGER_ERROR_LOG(STR, ...) \
215218
if (NEO::debugManager.flags.DebuggerLogBitmask.get() & NEO::DebugVariables::DEBUGGER_LOG_BITMASK::LOG_ERROR) { \
216-
PRINT_DEBUGGER_LOG(stderr, "\nERROR: " STR, __VA_ARGS__) \
219+
\
220+
auto time = NEO::DurationLog::getTimeString(); \
221+
time = "\n" + time + " ERROR: " + STR; \
222+
PRINT_DEBUGGER_LOG(stderr, time.c_str(), __VA_ARGS__) \
217223
}
218224

219225
#define PRINT_DEBUGGER_MEM_ACCESS_LOG(STR, ...) \
220226
if (NEO::debugManager.flags.DebuggerLogBitmask.get() & NEO::DebugVariables::DEBUGGER_LOG_BITMASK::LOG_MEM) { \
221-
PRINT_DEBUGGER_LOG(stdout, "\nINFO: " STR, __VA_ARGS__) \
227+
\
228+
auto time = NEO::DurationLog::getTimeString(); \
229+
time = "\n" + time + " MEM_ACCESS: " + STR; \
230+
PRINT_DEBUGGER_LOG(stdout, time.c_str(), __VA_ARGS__) \
222231
}
223232

224233
#define PRINT_DEBUGGER_FIFO_LOG(STR, ...) \
225234
if (NEO::debugManager.flags.DebuggerLogBitmask.get() & NEO::DebugVariables::DEBUGGER_LOG_BITMASK::LOG_FIFO) { \
226-
PRINT_DEBUGGER_LOG(stdout, "\nFIFO ACCESS: " STR, __VA_ARGS__) \
235+
\
236+
auto time = NEO::DurationLog::getTimeString(); \
237+
time = "\n" + time + " FIFO ACCESS: " + STR; \
238+
PRINT_DEBUGGER_LOG(stdout, time.c_str(), __VA_ARGS__) \
227239
}
228240

229241
template <DebugFunctionalityLevel debugLevel>

shared/test/unit_test/debug_settings/debug_settings_manager_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,6 @@ TEST(DebugLog, WhenLogDebugStringCalledThenNothingIsPrintedToStdout) {
446446
TEST(DurationLogTest, givenDurationGetTimeStringThenTimeStringIsCorrect) {
447447
auto timeString = DurationLog::getTimeString();
448448
for (auto c : timeString) {
449-
EXPECT_TRUE(std::isdigit(c));
449+
EXPECT_TRUE(std::isdigit(c) || c == '[' || c == ']' || c == '.');
450450
}
451451
}

0 commit comments

Comments
 (0)