diff --git a/runtime/os_interface/debug_settings_manager.cpp b/runtime/os_interface/debug_settings_manager.cpp index 1252a30874..e11e07a978 100644 --- a/runtime/os_interface/debug_settings_manager.cpp +++ b/runtime/os_interface/debug_settings_manager.cpp @@ -22,6 +22,12 @@ #include #include +namespace std { +static std::string to_string(const std::string &arg) { + return arg; +} +} // namespace std + namespace NEO { DebugSettingsManager DebugManager; @@ -33,6 +39,7 @@ DebugSettingsManager::DebugSettingsManager() { if (registryReadAvailable()) { readerImpl = SettingsReaderCreator::create(); injectSettingsFromReader(); + dumpFlags(); } translateDebugSettings(flags); std::remove(logFileName.c_str()); @@ -158,6 +165,31 @@ const std::string DebugSettingsManager::getMemObjects(const uintptr_ return os.str(); } +template +template +void DebugSettingsManager::dumpNonDefaultFlag(const char *variableName, const DataType &variableValue, const DataType &defaultValue) { + if (variableValue != defaultValue) { + const char *variableStringValue = std::to_string(variableValue).c_str(); + printDebugString(DebugManager.flags.PrintDebugMessages.get(), stdout, "Non-default value of debug variable: %s = %s", variableName, variableStringValue); + } +} + +template +void DebugSettingsManager::dumpFlags() const { + if (flags.PrintDebugSettings.get() == false) { + return; + } + + std::ofstream settingsDumpFile{settingsDumpFileName, std::ios::out}; + DEBUG_BREAK_IF(!settingsDumpFile.good()); + +#define DECLARE_DEBUG_VARIABLE(dataType, variableName, defaultValue, description) \ + settingsDumpFile << #variableName << " = " << flags.variableName.get() << '\n'; \ + dumpNonDefaultFlag(#variableName, flags.variableName.get(), defaultValue); +#include "debug_variables.inl" +#undef DECLARE_DEBUG_VARIABLE +} // namespace NEO + template void DebugSettingsManager::dumpBinaryProgram(int32_t numDevices, const size_t *lengths, const unsigned char **binaries) { if (false == debugKernelDumpingAvailable()) { @@ -253,6 +285,7 @@ void DebugSettingsManager::dumpKernelArgs(const MultiDispatchInfo *m dumpKernelArgs(dispatchInfo.getKernel()); } } + template void DebugSettingsManager::injectSettingsFromReader() { #undef DECLARE_DEBUG_VARIABLE diff --git a/runtime/os_interface/debug_settings_manager.h b/runtime/os_interface/debug_settings_manager.h index 01201f2732..ce6d7c1685 100644 --- a/runtime/os_interface/debug_settings_manager.h +++ b/runtime/os_interface/debug_settings_manager.h @@ -59,7 +59,7 @@ struct DebugVar##variableName void set(dataType data) { \ value = data; \ } \ - dataType& getRef() { \ + dataType &getRef() { \ return value; \ } \ private: \ @@ -262,10 +262,18 @@ class DebugSettingsManager { print(ss, params...); } } + + template + static void dumpNonDefaultFlag(const char *variableName, const DataType &variableValue, const DataType &defaultValue); + void dumpFlags() const; + static const char *settingsDumpFileName; }; extern DebugSettingsManager DebugManager; +template +const char *DebugSettingsManager::settingsDumpFileName = "igdrcl_dumped.config"; + template class DebugSettingsApiEnterWrapper { public: @@ -285,8 +293,6 @@ class DebugSettingsApiEnterWrapper { }; }; // namespace NEO -#define DECLARE_DEBUG_VARIABLE(dataType, variableName, defaultValue, description) - #define DBG_LOG_LAZY_EVALUATE_ARGS(DBG_MANAGER, PREDICATE, LOG_FUNCTION, ...) \ DBG_MANAGER.logLazyEvaluateArgs(DBG_MANAGER.flags.PREDICATE.get(), [&] { DBG_MANAGER.LOG_FUNCTION(__VA_ARGS__); }) diff --git a/runtime/os_interface/debug_variables_base.inl b/runtime/os_interface/debug_variables_base.inl index acfbb8a51a..7ac1a235e7 100644 --- a/runtime/os_interface/debug_variables_base.inl +++ b/runtime/os_interface/debug_variables_base.inl @@ -49,6 +49,7 @@ DECLARE_DEBUG_VARIABLE(bool, RebuildPrecompiledKernels, false, "forces driver to DECLARE_DEBUG_VARIABLE(bool, LoopAtPlatformInitialize, false, "Adds endless loop in platform initalize, useful for debugging.") DECLARE_DEBUG_VARIABLE(bool, DoNotRegisterTrimCallback, false, "When set to true driver is not registering trim callback.") /*LOGGING FLAGS*/ +DECLARE_DEBUG_VARIABLE(bool, PrintDebugSettings, false, "Enables dumping debug variables settings to text file") DECLARE_DEBUG_VARIABLE(bool, PrintDebugMessages, false, "when enabled, some debug messages will be propagated to console") DECLARE_DEBUG_VARIABLE(bool, DumpKernels, false, "Enables dumping kernels' program source code to text files and program from binary to bin file") DECLARE_DEBUG_VARIABLE(bool, DumpKernelArgs, false, "Enables dumping kernels args to binary files") @@ -58,8 +59,8 @@ DECLARE_DEBUG_VARIABLE(bool, LogTaskCounts, false, "Enables logging taskCounts a DECLARE_DEBUG_VARIABLE(bool, LogAlignedAllocations, false, "Logs alignedMalloc and alignedFree allocations") DECLARE_DEBUG_VARIABLE(bool, LogAllocationMemoryPool, false, "Logs memory pool for allocations") DECLARE_DEBUG_VARIABLE(bool, LogMemoryObject, false, "Logs memory object ptrs, sizes and operations") -DECLARE_DEBUG_VARIABLE(bool, ResidencyDebugEnable, 0, "enables debug messages and checks for Residency Model") -DECLARE_DEBUG_VARIABLE(bool, EventsDebugEnable, 0, "enables debug messages for events, virtual events, blocked enqueues, events trees etc.") +DECLARE_DEBUG_VARIABLE(bool, ResidencyDebugEnable, false, "enables debug messages and checks for Residency Model") +DECLARE_DEBUG_VARIABLE(bool, EventsDebugEnable, false, "enables debug messages for events, virtual events, blocked enqueues, events trees etc.") DECLARE_DEBUG_VARIABLE(bool, EventsTrackerEnable, false, "enables event graphs dumping") DECLARE_DEBUG_VARIABLE(bool, PrintEMDebugInformation, false, "prints execution model related debug information") DECLARE_DEBUG_VARIABLE(bool, PrintLWSSizes, false, "prints driver choosen local workgroup sizes") diff --git a/unit_tests/os_interface/debug_settings_manager_fixture.h b/unit_tests/os_interface/debug_settings_manager_fixture.h index 6d97c55a99..3080eddc13 100644 --- a/unit_tests/os_interface/debug_settings_manager_fixture.h +++ b/unit_tests/os_interface/debug_settings_manager_fixture.h @@ -60,6 +60,9 @@ class TestDebugFlagsChecker { template class TestDebugSettingsManager : public DebugSettingsManager { public: + using DebugSettingsManager::dumpFlags; + using DebugSettingsManager::settingsDumpFileName; + ~TestDebugSettingsManager() { remove(DebugSettingsManager::logFileName.c_str()); } diff --git a/unit_tests/os_interface/debug_settings_manager_tests.cpp b/unit_tests/os_interface/debug_settings_manager_tests.cpp index c121144ecf..8cbe515c21 100644 --- a/unit_tests/os_interface/debug_settings_manager_tests.cpp +++ b/unit_tests/os_interface/debug_settings_manager_tests.cpp @@ -5,6 +5,7 @@ * */ +#include "runtime/utilities/debug_file_reader.h" #include "unit_tests/fixtures/buffer_fixture.h" #include "unit_tests/fixtures/image_fixture.h" #include "unit_tests/helpers/debug_manager_state_restore.h" @@ -864,6 +865,27 @@ TEST(DebugSettingsManager, givenReaderImplInDebugManagerWhenSettingDifferentRead EXPECT_EQ(readerImpl2, debugManager.getReaderImpl()); } +TEST(DebugSettingsManager, givenPrintDebugSettingsEnabledWhenCallingDumpFlagsThenFlagsAreWrittenToDumpFile) { + FullyEnabledTestDebugManager debugManager; + debugManager.flags.PrintDebugSettings.set(true); + debugManager.flags.LoopAtPlatformInitialize.set(true); + debugManager.flags.Enable64kbpages.set(1); + debugManager.flags.TbxServer.set("192.168.0.1"); + + // Clear dump files and generate new + std::remove(FullyEnabledTestDebugManager::settingsDumpFileName); + debugManager.dumpFlags(); + + // Validate allSettingsDumpFile + SettingsFileReader allSettingsReader{FullyEnabledTestDebugManager::settingsDumpFileName}; +#define DECLARE_DEBUG_VARIABLE(dataType, varName, defaultValue, description) \ + EXPECT_EQ(debugManager.flags.varName.get(), allSettingsReader.getSetting(#varName, defaultValue)); + +#include "debug_variables.inl" +#undef DECLARE_DEBUG_VARIABLE + std::remove(FullyEnabledTestDebugManager::settingsDumpFileName); +} + struct AllocationTypeTestCase { GraphicsAllocation::AllocationType type; const char *str; diff --git a/unit_tests/test_files/igdrcl.config b/unit_tests/test_files/igdrcl.config index 15151b5bf4..3f8125f7bc 100644 --- a/unit_tests/test_files/igdrcl.config +++ b/unit_tests/test_files/igdrcl.config @@ -4,6 +4,7 @@ EnableNullHardware = 0 DoCpuCopyOnReadBuffer = 0 DoCpuCopyOnWriteBuffer = 0 DisableResourceRecycling = 0 +PrintDebugSettings = 0 PrintDebugMessages = 0 DumpKernels = 0 DumpKernelArgs = 0