refactor: add timestamps to xe logs

Signed-off-by: Bartosz Dunajski <bartosz.dunajski@intel.com>
This commit is contained in:
Bartosz Dunajski
2024-10-07 10:46:27 +00:00
committed by Compute-Runtime-Automation
parent a915ef4b7b
commit 9a280892f8
4 changed files with 37 additions and 4 deletions

View File

@@ -152,6 +152,7 @@ set(NEO_CORE_HELPERS
${CMAKE_CURRENT_SOURCE_DIR}/string.h
${CMAKE_CURRENT_SOURCE_DIR}/string_helpers.h
${CMAKE_CURRENT_SOURCE_DIR}/surface_format_info.h
${CMAKE_CURRENT_SOURCE_DIR}/timestamp.h
${CMAKE_CURRENT_SOURCE_DIR}/timestamp_packet.cpp
${CMAKE_CURRENT_SOURCE_DIR}/timestamp_packet.h
${CMAKE_CURRENT_SOURCE_DIR}/timestamp_packet_container.h

View File

@@ -0,0 +1,29 @@
/*
* Copyright (C) 2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include <chrono>
#include <ctime>
#include <iomanip>
#include <sstream>
#include <string>
namespace TimestampHelper {
static inline std::string getTimestamp() {
auto now = std::chrono::system_clock::now();
std::time_t nowTime = std::chrono::system_clock::to_time_t(now);
tm timeInfo = *std::localtime(&nowTime);
std::stringstream ss;
ss << "[" << std::put_time(&timeInfo, "%Y-%m-%d %H:%M:%S") << "] ";
return ss.str();
}
} // namespace TimestampHelper

View File

@@ -7,6 +7,7 @@
#pragma once
#include "shared/source/debug_settings/debug_settings_manager.h"
#include "shared/source/helpers/timestamp.h"
#include "shared/source/os_interface/linux/drm_debug.h"
#include "shared/source/os_interface/linux/engine_info.h"
#include "shared/source/os_interface/linux/ioctl_helper.h"
@@ -225,6 +226,7 @@ class IoctlHelperXe : public IoctlHelper {
template <typename... XeLogArgs>
void IoctlHelperXe::xeLog(XeLogArgs &&...args) const {
PRINT_DEBUG_STRING(debugManager.flags.PrintXeLogs.get(), stderr, TimestampHelper::getTimestamp().c_str());
PRINT_DEBUG_STRING(debugManager.flags.PrintXeLogs.get(), stderr, args...);
}

View File

@@ -1731,10 +1731,11 @@ TEST(IoctlHelperXeTest, whenXeShowBindTableIsCalledThenBindLogsArePrinted) {
debugManager.flags.PrintXeLogs.set(false);
std::string output = testing::internal::GetCapturedStderr();
std::string expectedOutput = R"(show bind: (<index> <handle> <userptr> <addr> <size>)
0 x00000001 x0000000000000002 x0000000000000003 x0000000000000004
)";
EXPECT_STREQ(expectedOutput.c_str(), output.c_str());
std::string expectedOutput1 = "show bind: (<index> <handle> <userptr> <addr> <size>)\n";
std::string expectedOutput2 = "0 x00000001 x0000000000000002 x0000000000000003 x0000000000000004";
EXPECT_NE(std::string::npos, output.find(expectedOutput1));
EXPECT_NE(std::string::npos, output.find(expectedOutput2, expectedOutput1.size()));
}
TEST(IoctlHelperXeTest, whenFillBindInfoForIpcHandleIsCalledThenBindInfoIsCorrect) {