refactor: Add timestamp to all debugger log

Signed-off-by: Jitendra Sharma <jitendra.sharma@intel.com>
This commit is contained in:
Jitendra Sharma
2024-10-08 14:32:40 +00:00
committed by Compute-Runtime-Automation
parent 91f1f58a47
commit a111c18fb1
6 changed files with 65 additions and 24 deletions

View File

@@ -16,7 +16,10 @@
#include "shared/source/utilities/io_functions.h"
#include "shared/source/utilities/logger.h"
#include <chrono>
#include <cinttypes>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <type_traits>
@@ -165,10 +168,14 @@ void logDebugString(std::string_view debugString) {
}
std::string DurationLog::getTimeString() {
static const std::chrono::time_point<std::chrono::steady_clock> processStartTime = std::chrono::steady_clock::now();
auto elapsedTime = std::chrono::steady_clock::now().time_since_epoch() - processStartTime.time_since_epoch();
auto elapsedTimeUs = std::chrono::duration_cast<std::chrono::microseconds>(elapsedTime);
return std::to_string(elapsedTimeUs.count());
auto now = std::chrono::steady_clock::now();
auto microseconds = std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch());
auto seconds = microseconds.count() / 1000000;
auto remainingMicroSeconds = microseconds.count() % 1000000;
char buffer[32];
std::snprintf(buffer, sizeof(buffer), "[%5" PRId64 ".%06" PRId64 "]",
static_cast<int64_t>(seconds), static_cast<int64_t>(remainingMicroSeconds));
return std::string(buffer);
}
template class DebugSettingsManager<DebugFunctionalityLevel::none>;

View File

@@ -208,22 +208,34 @@ class DurationLog {
#define PRINT_DEBUGGER_THREAD_LOG(STR, ...) \
if (NEO::debugManager.flags.DebuggerLogBitmask.get() & NEO::DebugVariables::DEBUGGER_LOG_BITMASK::LOG_THREADS) { \
PRINT_DEBUGGER_LOG(stdout, "\nTHREAD INFO: " STR, __VA_ARGS__) \
\
auto time = NEO::DurationLog::getTimeString(); \
time = "\n" + time + " THREAD INFO: " + STR; \
PRINT_DEBUGGER_LOG(stdout, time.c_str(), __VA_ARGS__) \
}
#define PRINT_DEBUGGER_ERROR_LOG(STR, ...) \
if (NEO::debugManager.flags.DebuggerLogBitmask.get() & NEO::DebugVariables::DEBUGGER_LOG_BITMASK::LOG_ERROR) { \
PRINT_DEBUGGER_LOG(stderr, "\nERROR: " STR, __VA_ARGS__) \
\
auto time = NEO::DurationLog::getTimeString(); \
time = "\n" + time + " ERROR: " + STR; \
PRINT_DEBUGGER_LOG(stderr, time.c_str(), __VA_ARGS__) \
}
#define PRINT_DEBUGGER_MEM_ACCESS_LOG(STR, ...) \
if (NEO::debugManager.flags.DebuggerLogBitmask.get() & NEO::DebugVariables::DEBUGGER_LOG_BITMASK::LOG_MEM) { \
PRINT_DEBUGGER_LOG(stdout, "\nINFO: " STR, __VA_ARGS__) \
\
auto time = NEO::DurationLog::getTimeString(); \
time = "\n" + time + " MEM_ACCESS: " + STR; \
PRINT_DEBUGGER_LOG(stdout, time.c_str(), __VA_ARGS__) \
}
#define PRINT_DEBUGGER_FIFO_LOG(STR, ...) \
if (NEO::debugManager.flags.DebuggerLogBitmask.get() & NEO::DebugVariables::DEBUGGER_LOG_BITMASK::LOG_FIFO) { \
PRINT_DEBUGGER_LOG(stdout, "\nFIFO ACCESS: " STR, __VA_ARGS__) \
\
auto time = NEO::DurationLog::getTimeString(); \
time = "\n" + time + " FIFO ACCESS: " + STR; \
PRINT_DEBUGGER_LOG(stdout, time.c_str(), __VA_ARGS__) \
}
template <DebugFunctionalityLevel debugLevel>

View File

@@ -446,6 +446,6 @@ TEST(DebugLog, WhenLogDebugStringCalledThenNothingIsPrintedToStdout) {
TEST(DurationLogTest, givenDurationGetTimeStringThenTimeStringIsCorrect) {
auto timeString = DurationLog::getTimeString();
for (auto c : timeString) {
EXPECT_TRUE(std::isdigit(c));
EXPECT_TRUE(std::isdigit(c) || c == '[' || c == ']' || c == '.');
}
}