feature: Add elapsed time to debugger logs

Related-to: NEO-11469

Signed-off-by: Brandon Yates <brandon.yates@intel.com>
This commit is contained in:
Brandon Yates
2024-05-20 17:33:59 +00:00
committed by Compute-Runtime-Automation
parent e5f9761baa
commit cb6e63ed05
4 changed files with 35 additions and 5 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2023 Intel Corporation
* Copyright (C) 2018-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -164,6 +164,13 @@ void logDebugString(std::string_view debugString) {
NEO::fileLoggerInstance().logDebugString(true, 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());
}
template class DebugSettingsManager<DebugFunctionalityLevel::none>;
template class DebugSettingsManager<DebugFunctionalityLevel::full>;
template class DebugSettingsManager<DebugFunctionalityLevel::regKeys>;

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2023 Intel Corporation
* Copyright (C) 2018-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -9,8 +9,11 @@
#include "shared/source/helpers/string.h"
#include "shared/source/utilities/io_functions.h"
#include <chrono>
#include <cstdint>
#include <iostream>
#include <memory>
#include <sstream>
#include <string_view>
enum class DebugFunctionalityLevel {
@@ -172,6 +175,13 @@ class DebugSettingsManager {
extern DebugSettingsManager<globalDebugFunctionalityLevel> debugManager;
class DurationLog {
DurationLog() = delete;
public:
static std::string getTimeString();
};
#define PRINT_DEBUGGER_LOG_TO_FILE(...) \
NEO::debugManager.logLazyEvaluateArgs([&] { \
char temp[4000]; \
@@ -189,7 +199,10 @@ extern DebugSettingsManager<globalDebugFunctionalityLevel> debugManager;
#define PRINT_DEBUGGER_INFO_LOG(STR, ...) \
if (NEO::debugManager.flags.DebuggerLogBitmask.get() & NEO::DebugVariables::DEBUGGER_LOG_BITMASK::LOG_INFO) { \
PRINT_DEBUGGER_LOG(stdout, "\nINFO: " STR, __VA_ARGS__) \
\
auto time = NEO::DurationLog::getTimeString(); \
time = "\n" + time + " INFO: " + STR; \
PRINT_DEBUGGER_LOG(stdout, time.c_str(), __VA_ARGS__) \
}
#define PRINT_DEBUGGER_THREAD_LOG(STR, ...) \

View File

@@ -12,6 +12,7 @@
#include "shared/source/utilities/logger.h"
#include "shared/test/common/debug_settings/debug_settings_manager_fixture.h"
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/helpers/gtest_helpers.h"
#include "shared/test/common/helpers/variable_backup.h"
#include "shared/test/common/mocks/mock_io_functions.h"
#include "shared/test/common/test_macros/test.h"
@@ -20,6 +21,7 @@
#include <cstdio>
#include <fstream>
#include <memory>
#include <regex>
#include <sstream>
#include <string>
@@ -440,3 +442,10 @@ TEST(DebugLog, WhenLogDebugStringCalledThenNothingIsPrintedToStdout) {
auto output = ::testing::internal::GetCapturedStdout();
EXPECT_EQ(0u, output.size());
}
TEST(DurationLogTest, givenDurationGetTimeStringThenTimeStringIsCorrect) {
auto timeString = DurationLog::getTimeString();
for (auto c : timeString) {
EXPECT_TRUE(std::isdigit(c));
}
}