From 5685b285f305813346a2e43a840cdd5c1ee48302 Mon Sep 17 00:00:00 2001 From: Mateusz Hoppe Date: Tue, 10 Dec 2019 16:26:35 +0100 Subject: [PATCH] Extract logging logic from DebugSettingsManager Change-Id: I0ccc68216c1c3bb23d0389bec17124e09e4f98e1 Signed-off-by: Mateusz Hoppe --- core/helpers/aligned_memory.h | 2 +- core/memory_manager/graphics_allocation.cpp | 4 +- offline_compiler/offline_compiler_helper.cpp | 9 - runtime/api/api.cpp | 323 +++--- runtime/command_queue/command_queue.cpp | 2 +- runtime/command_queue/enqueue_common.h | 4 +- runtime/kernel/kernel.h | 4 +- runtime/memory_manager/memory_manager.cpp | 2 +- .../os_interface/debug_settings_manager.cpp | 295 +----- runtime/os_interface/debug_settings_manager.h | 177 ---- runtime/os_interface/windows/api_win.cpp | 32 +- .../windows/wddm_memory_manager.cpp | 2 +- runtime/program/build.cpp | 2 +- runtime/sharings/gl/cl_gl_api.cpp | 16 +- runtime/sharings/va/cl_va_api.cpp | 12 +- runtime/utilities/CMakeLists.txt | 2 + runtime/utilities/api_intercept.h | 4 +- runtime/utilities/logger.cpp | 331 ++++++ runtime/utilities/logger.h | 205 ++++ .../debug_settings_manager_fixture.h | 65 -- .../debug_settings_manager_tests.cpp | 829 --------------- unit_tests/os_interface/linux/CMakeLists.txt | 2 +- ..._tests.cpp => file_logger_linux_tests.cpp} | 56 +- .../os_interface/windows/CMakeLists.txt | 2 +- ...in_tests.cpp => file_logger_win_tests.cpp} | 38 +- unit_tests/utilities/CMakeLists.txt | 2 + .../utilities/debug_settings_reader_tests.cpp | 23 + unit_tests/utilities/file_logger_tests.cpp | 984 ++++++++++++++++++ unit_tests/utilities/file_logger_tests.h | 71 ++ 29 files changed, 1875 insertions(+), 1625 deletions(-) create mode 100644 runtime/utilities/logger.cpp create mode 100644 runtime/utilities/logger.h rename unit_tests/os_interface/linux/{debug_settings_manager_linux_tests.cpp => file_logger_linux_tests.cpp} (61%) rename unit_tests/os_interface/windows/{debug_settings_manager_win_tests.cpp => file_logger_win_tests.cpp} (68%) create mode 100644 unit_tests/utilities/file_logger_tests.cpp create mode 100644 unit_tests/utilities/file_logger_tests.h diff --git a/core/helpers/aligned_memory.h b/core/helpers/aligned_memory.h index bb6bcbbbfd..864fde855a 100644 --- a/core/helpers/aligned_memory.h +++ b/core/helpers/aligned_memory.h @@ -8,7 +8,7 @@ #pragma once #include "core/helpers/debug_helpers.h" #include "core/memory_manager/memory_constants.h" -#include "runtime/os_interface/debug_settings_manager.h" +#include "runtime/utilities/logger.h" #include #include diff --git a/core/memory_manager/graphics_allocation.cpp b/core/memory_manager/graphics_allocation.cpp index 740f3455c6..f944aae518 100644 --- a/core/memory_manager/graphics_allocation.cpp +++ b/core/memory_manager/graphics_allocation.cpp @@ -8,13 +8,13 @@ #include "graphics_allocation.h" #include "core/helpers/aligned_memory.h" -#include "runtime/os_interface/debug_settings_manager.h" +#include "runtime/utilities/logger.h" namespace NEO { void GraphicsAllocation::setAllocationType(AllocationType allocationType) { this->allocationType = allocationType; - DebugManager.logAllocation(this); + FileLoggerInstance().logAllocation(this); } GraphicsAllocation::GraphicsAllocation(uint32_t rootDeviceIndex, AllocationType allocationType, void *cpuPtrIn, uint64_t gpuAddress, uint64_t baseAddress, diff --git a/offline_compiler/offline_compiler_helper.cpp b/offline_compiler/offline_compiler_helper.cpp index 56d60b125f..76e9e9ac08 100644 --- a/offline_compiler/offline_compiler_helper.cpp +++ b/offline_compiler/offline_compiler_helper.cpp @@ -18,15 +18,6 @@ DebugSettingsManager::DebugSettingsManager() { template DebugSettingsManager::~DebugSettingsManager() = default; -template -void DebugSettingsManager::writeToFile(std::string filename, const char *str, size_t length, std::ios_base::openmode mode) { - std::ofstream outFile(filename, mode); - if (outFile.is_open()) { - outFile.write(str, length); - outFile.close(); - } -} - // Global Debug Settings Manager DebugSettingsManager DebugManager; } // namespace NEO diff --git a/runtime/api/api.cpp b/runtime/api/api.cpp index 50d2c055be..55b488a256 100644 --- a/runtime/api/api.cpp +++ b/runtime/api/api.cpp @@ -124,7 +124,7 @@ cl_int CL_API_CALL clGetPlatformInfo(cl_platform_id platform, DBG_LOG_INPUTS("platform", platform, "paramName", paramName, "paramValueSize", paramValueSize, - "paramValue", DebugManager.infoPointerToString(paramValue, paramValueSize), + "paramValue", NEO::FileLoggerInstance().infoPointerToString(paramValue, paramValueSize), "paramValueSizeRet", paramValueSizeRet); auto pPlatform = castToObject(platform); if (pPlatform) { @@ -240,7 +240,7 @@ cl_int CL_API_CALL clGetDeviceInfo(cl_device_id device, TRACING_ENTER(clGetDeviceInfo, &device, ¶mName, ¶mValueSize, ¶mValue, ¶mValueSizeRet); cl_int retVal = CL_INVALID_DEVICE; API_ENTER(&retVal); - DBG_LOG_INPUTS("clDevice", device, "paramName", paramName, "paramValueSize", paramValueSize, "paramValue", DebugManager.infoPointerToString(paramValue, paramValueSize), "paramValueSizeRet", paramValueSizeRet); + DBG_LOG_INPUTS("clDevice", device, "paramName", paramName, "paramValueSize", paramValueSize, "paramValue", NEO::FileLoggerInstance().infoPointerToString(paramValue, paramValueSize), "paramValueSizeRet", paramValueSizeRet); Device *pDevice = castToObject(device); if (pDevice != nullptr) { @@ -453,7 +453,7 @@ cl_int CL_API_CALL clGetContextInfo(cl_context context, DBG_LOG_INPUTS("context", context, "paramName", paramName, "paramValueSize", paramValueSize, - "paramValue", DebugManager.infoPointerToString(paramValue, paramValueSize), + "paramValue", NEO::FileLoggerInstance().infoPointerToString(paramValue, paramValueSize), "paramValueSizeRet", paramValueSizeRet); auto pContext = castToObject(context); @@ -569,7 +569,7 @@ cl_int CL_API_CALL clGetCommandQueueInfo(cl_command_queue commandQueue, DBG_LOG_INPUTS("commandQueue", commandQueue, "paramName", paramName, "paramValueSize", paramValueSize, - "paramValue", DebugManager.infoPointerToString(paramValue, paramValueSize), + "paramValue", NEO::FileLoggerInstance().infoPointerToString(paramValue, paramValueSize), "paramValueSizeRet", paramValueSizeRet); getQueueInfo(commandQueue, paramName, paramValueSize, paramValue, paramValueSizeRet, retVal); @@ -609,7 +609,7 @@ cl_mem CL_API_CALL clCreateBuffer(cl_context context, DBG_LOG_INPUTS("cl_context", context, "cl_mem_flags", flags, "size", size, - "hostPtr", DebugManager.infoPointerToString(hostPtr, size)); + "hostPtr", NEO::FileLoggerInstance().infoPointerToString(hostPtr, size)); cl_int retVal = CL_SUCCESS; API_ENTER(&retVal); @@ -638,7 +638,7 @@ cl_mem CL_API_CALL clCreateBufferWithPropertiesINTEL(cl_context context, DBG_LOG_INPUTS("cl_context", context, "cl_mem_properties_intel", properties, "size", size, - "hostPtr", DebugManager.infoPointerToString(hostPtr, size)); + "hostPtr", NEO::FileLoggerInstance().infoPointerToString(hostPtr, size)); cl_int retVal = CL_SUCCESS; API_ENTER(&retVal); @@ -1022,7 +1022,7 @@ cl_int CL_API_CALL clGetMemObjectInfo(cl_mem memobj, DBG_LOG_INPUTS("memobj", memobj, "paramName", paramName, "paramValueSize", paramValueSize, - "paramValue", DebugManager.infoPointerToString(paramValue, paramValueSize), + "paramValue", NEO::FileLoggerInstance().infoPointerToString(paramValue, paramValueSize), "paramValueSizeRet", paramValueSizeRet); MemObj *pMemObj = nullptr; retVal = validateObjects(WithCastToInternal(memobj, &pMemObj)); @@ -1048,7 +1048,7 @@ cl_int CL_API_CALL clGetImageInfo(cl_mem image, DBG_LOG_INPUTS("image", image, "paramName", paramName, "paramValueSize", paramValueSize, - "paramValue", DebugManager.infoPointerToString(paramValue, paramValueSize), + "paramValue", NEO::FileLoggerInstance().infoPointerToString(paramValue, paramValueSize), "paramValueSizeRet", paramValueSizeRet); retVal = validateObjects(image); if (CL_SUCCESS != retVal) { @@ -1202,7 +1202,7 @@ cl_int CL_API_CALL clGetSamplerInfo(cl_sampler sampler, DBG_LOG_INPUTS("sampler", sampler, "paramName", paramName, "paramValueSize", paramValueSize, - "paramValue", DebugManager.infoPointerToString(paramValue, paramValueSize), + "paramValue", NEO::FileLoggerInstance().infoPointerToString(paramValue, paramValueSize), "paramValueSizeRet", paramValueSizeRet); auto pSampler = castToObject(sampler); @@ -1267,7 +1267,7 @@ cl_program CL_API_CALL clCreateProgramWithBinary(cl_context context, retVal = validateObjects(context, deviceList, *deviceList, binaries, *binaries, lengths, *lengths); cl_program program = nullptr; - DebugManager.dumpBinaryProgram(numDevices, lengths, binaries); + NEO::FileLoggerInstance().dumpBinaryProgram(numDevices, lengths, binaries); if (CL_SUCCESS == retVal) { program = Program::create( @@ -1496,7 +1496,7 @@ cl_int CL_API_CALL clGetProgramInfo(cl_program program, API_ENTER(&retVal); DBG_LOG_INPUTS("clProgram", program, "paramName", paramName, "paramValueSize", paramValueSize, - "paramValue", DebugManager.infoPointerToString(paramValue, paramValueSize), + "paramValue", NEO::FileLoggerInstance().infoPointerToString(paramValue, paramValueSize), "paramValueSizeRet", paramValueSizeRet); retVal = validateObjects(program); @@ -1523,7 +1523,7 @@ cl_int CL_API_CALL clGetProgramBuildInfo(cl_program program, cl_int retVal = CL_SUCCESS; API_ENTER(&retVal); DBG_LOG_INPUTS("clProgram", program, "cl_device_id", device, - "paramName", DebugManager.infoPointerToString(paramValue, paramValueSize), + "paramName", NEO::FileLoggerInstance().infoPointerToString(paramValue, paramValueSize), "paramValueSize", paramValueSize, "paramValue", paramValue, "paramValueSizeRet", paramValueSizeRet); retVal = validateObjects(program); @@ -1687,7 +1687,7 @@ cl_int CL_API_CALL clSetKernelArg(cl_kernel kernel, auto pKernel = castToObject(kernel); DBG_LOG_INPUTS("kernel", kernel, "argIndex", argIndex, - "argSize", argSize, "argValue", DebugManager.infoPointerToString(argValue, argSize)); + "argSize", argSize, "argValue", NEO::FileLoggerInstance().infoPointerToString(argValue, argSize)); do { if (!pKernel) { retVal = CL_INVALID_KERNEL; @@ -1723,7 +1723,7 @@ cl_int CL_API_CALL clGetKernelInfo(cl_kernel kernel, API_ENTER(&retVal); DBG_LOG_INPUTS("kernel", kernel, "paramName", paramName, "paramValueSize", paramValueSize, - "paramValue", DebugManager.infoPointerToString(paramValue, paramValueSize), + "paramValue", NEO::FileLoggerInstance().infoPointerToString(paramValue, paramValueSize), "paramValueSizeRet", paramValueSizeRet); auto pKernel = castToObject(kernel); retVal = pKernel @@ -1751,7 +1751,7 @@ cl_int CL_API_CALL clGetKernelArgInfo(cl_kernel kernel, "argIndx", argIndx, "paramName", paramName, "paramValueSize", paramValueSize, - "paramValue", DebugManager.infoPointerToString(paramValue, paramValueSize), + "paramValue", NEO::FileLoggerInstance().infoPointerToString(paramValue, paramValueSize), "paramValueSizeRet", paramValueSizeRet); auto pKernel = castToObject(kernel); @@ -1781,7 +1781,7 @@ cl_int CL_API_CALL clGetKernelWorkGroupInfo(cl_kernel kernel, "device", device, "paramName", paramName, "paramValueSize", paramValueSize, - "paramValue", DebugManager.infoPointerToString(paramValue, paramValueSize), + "paramValue", NEO::FileLoggerInstance().infoPointerToString(paramValue, paramValueSize), "paramValueSizeRet", paramValueSizeRet); auto pKernel = castToObject(kernel); @@ -1803,7 +1803,7 @@ cl_int CL_API_CALL clWaitForEvents(cl_uint numEvents, auto retVal = CL_SUCCESS; API_ENTER(&retVal); - DBG_LOG_INPUTS("eventList", DebugManager.getEvents(reinterpret_cast(eventList), numEvents)); + DBG_LOG_INPUTS("eventList", NEO::FileLoggerInstance().getEvents(reinterpret_cast(eventList), numEvents)); for (unsigned int i = 0; i < numEvents && retVal == CL_SUCCESS; i++) retVal = validateObjects(eventList[i]); @@ -1830,7 +1830,7 @@ cl_int CL_API_CALL clGetEventInfo(cl_event event, DBG_LOG_INPUTS("event", event, "paramName", paramName, "paramValueSize", paramValueSize, - "paramValue", DebugManager.infoPointerToString(paramValue, paramValueSize), + "paramValue", NEO::FileLoggerInstance().infoPointerToString(paramValue, paramValueSize), "paramValueSizeRet", paramValueSizeRet); Event *neoEvent = castToObject(event); @@ -1914,7 +1914,7 @@ cl_event CL_API_CALL clCreateUserEvent(cl_context context, Event *userEvent = new UserEvent(ctx); cl_event userClEvent = userEvent; - DebugManager.logInputs("cl_event", userClEvent, "UserEvent", userEvent); + DBG_LOG_INPUTS("cl_event", userClEvent, "UserEvent", userEvent); TRACING_EXIT(clCreateUserEvent, &userClEvent); return userClEvent; @@ -1925,10 +1925,8 @@ cl_int CL_API_CALL clRetainEvent(cl_event event) { auto retVal = CL_SUCCESS; API_ENTER(&retVal); - DBG_LOG_INPUTS("event", event); - auto pEvent = castToObject(event); - DebugManager.logInputs("cl_event", event, "Event", pEvent); + DBG_LOG_INPUTS("cl_event", event, "Event", pEvent); if (pEvent) { pEvent->retain(); @@ -1944,9 +1942,8 @@ cl_int CL_API_CALL clReleaseEvent(cl_event event) { TRACING_ENTER(clReleaseEvent, &event); auto retVal = CL_SUCCESS; API_ENTER(&retVal); - DBG_LOG_INPUTS("cl_event", event); auto pEvent = castToObject(event); - DebugManager.logInputs("cl_event", event, "Event", pEvent); + DBG_LOG_INPUTS("cl_event", event, "Event", pEvent); if (pEvent) { pEvent->release(); @@ -2038,7 +2035,7 @@ cl_int CL_API_CALL clGetEventProfilingInfo(cl_event event, DBG_LOG_INPUTS("event", event, "paramName", paramName, "paramValueSize", paramValueSize, - "paramValue", DebugManager.infoPointerToString(paramValue, paramValueSize), + "paramValue", NEO::FileLoggerInstance().infoPointerToString(paramValue, paramValueSize), "paramValueSizeRet", paramValueSizeRet); auto eventObject = castToObject(event); @@ -2107,8 +2104,8 @@ cl_int CL_API_CALL clEnqueueReadBuffer(cl_command_queue commandQueue, DBG_LOG_INPUTS("commandQueue", commandQueue, "buffer", buffer, "blockingRead", blockingRead, "offset", offset, "cb", cb, "ptr", ptr, "numEventsInWaitList", numEventsInWaitList, - "eventWaitList", DebugManager.getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), - "event", DebugManager.getEvents(reinterpret_cast(event), 1)); + "eventWaitList", NEO::FileLoggerInstance().getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), + "event", NEO::FileLoggerInstance().getEvents(reinterpret_cast(event), 1)); if (CL_SUCCESS == retVal) { @@ -2130,7 +2127,7 @@ cl_int CL_API_CALL clEnqueueReadBuffer(cl_command_queue commandQueue, event); } - DBG_LOG_INPUTS("event", DebugManager.getEvents(reinterpret_cast(event), 1u)); + DBG_LOG_INPUTS("event", NEO::FileLoggerInstance().getEvents(reinterpret_cast(event), 1u)); TRACING_EXIT(clEnqueueReadBuffer, &retVal); return retVal; } @@ -2155,23 +2152,23 @@ cl_int CL_API_CALL clEnqueueReadBufferRect(cl_command_queue commandQueue, DBG_LOG_INPUTS("commandQueue", commandQueue, "buffer", buffer, "blockingRead", blockingRead, - "bufferOrigin[0]", DebugManager.getInput(bufferOrigin, 0), - "bufferOrigin[1]", DebugManager.getInput(bufferOrigin, 1), - "bufferOrigin[2]", DebugManager.getInput(bufferOrigin, 2), - "hostOrigin[0]", DebugManager.getInput(hostOrigin, 0), - "hostOrigin[1]", DebugManager.getInput(hostOrigin, 1), - "hostOrigin[2]", DebugManager.getInput(hostOrigin, 2), - "region[0]", DebugManager.getInput(region, 0), - "region[1]", DebugManager.getInput(region, 1), - "region[2]", DebugManager.getInput(region, 2), + "bufferOrigin[0]", NEO::FileLoggerInstance().getInput(bufferOrigin, 0), + "bufferOrigin[1]", NEO::FileLoggerInstance().getInput(bufferOrigin, 1), + "bufferOrigin[2]", NEO::FileLoggerInstance().getInput(bufferOrigin, 2), + "hostOrigin[0]", NEO::FileLoggerInstance().getInput(hostOrigin, 0), + "hostOrigin[1]", NEO::FileLoggerInstance().getInput(hostOrigin, 1), + "hostOrigin[2]", NEO::FileLoggerInstance().getInput(hostOrigin, 2), + "region[0]", NEO::FileLoggerInstance().getInput(region, 0), + "region[1]", NEO::FileLoggerInstance().getInput(region, 1), + "region[2]", NEO::FileLoggerInstance().getInput(region, 2), "bufferRowPitch", bufferRowPitch, "bufferSlicePitch", bufferSlicePitch, "hostRowPitch", hostRowPitch, "hostSlicePitch", hostSlicePitch, "ptr", ptr, "numEventsInWaitList", numEventsInWaitList, - "eventWaitList", DebugManager.getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), - "event", DebugManager.getEvents(reinterpret_cast(event), 1)); + "eventWaitList", NEO::FileLoggerInstance().getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), + "event", NEO::FileLoggerInstance().getEvents(reinterpret_cast(event), 1)); CommandQueue *pCommandQueue = nullptr; Buffer *pBuffer = nullptr; @@ -2237,8 +2234,8 @@ cl_int CL_API_CALL clEnqueueWriteBuffer(cl_command_queue commandQueue, DBG_LOG_INPUTS("commandQueue", commandQueue, "buffer", buffer, "blockingWrite", blockingWrite, "offset", offset, "cb", cb, "ptr", ptr, "numEventsInWaitList", numEventsInWaitList, - "eventWaitList", DebugManager.getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), - "event", DebugManager.getEvents(reinterpret_cast(event), 1)); + "eventWaitList", NEO::FileLoggerInstance().getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), + "event", NEO::FileLoggerInstance().getEvents(reinterpret_cast(event), 1)); CommandQueue *pCommandQueue = nullptr; Buffer *pBuffer = nullptr; @@ -2268,7 +2265,7 @@ cl_int CL_API_CALL clEnqueueWriteBuffer(cl_command_queue commandQueue, event); } - DBG_LOG_INPUTS("event", DebugManager.getEvents(reinterpret_cast(event), 1u)); + DBG_LOG_INPUTS("event", NEO::FileLoggerInstance().getEvents(reinterpret_cast(event), 1u)); TRACING_EXIT(clEnqueueWriteBuffer, &retVal); return retVal; } @@ -2292,14 +2289,14 @@ cl_int CL_API_CALL clEnqueueWriteBufferRect(cl_command_queue commandQueue, API_ENTER(&retVal); DBG_LOG_INPUTS("commandQueue", commandQueue, "buffer", buffer, "blockingWrite", blockingWrite, - "bufferOrigin[0]", DebugManager.getInput(bufferOrigin, 0), "bufferOrigin[1]", DebugManager.getInput(bufferOrigin, 1), "bufferOrigin[2]", DebugManager.getInput(bufferOrigin, 2), - "hostOrigin[0]", DebugManager.getInput(hostOrigin, 0), "hostOrigin[1]", DebugManager.getInput(hostOrigin, 1), "hostOrigin[2]", DebugManager.getInput(hostOrigin, 2), - "region[0]", DebugManager.getInput(region, 0), "region[1]", DebugManager.getInput(region, 1), "region[2]", DebugManager.getInput(region, 2), + "bufferOrigin[0]", NEO::FileLoggerInstance().getInput(bufferOrigin, 0), "bufferOrigin[1]", NEO::FileLoggerInstance().getInput(bufferOrigin, 1), "bufferOrigin[2]", NEO::FileLoggerInstance().getInput(bufferOrigin, 2), + "hostOrigin[0]", NEO::FileLoggerInstance().getInput(hostOrigin, 0), "hostOrigin[1]", NEO::FileLoggerInstance().getInput(hostOrigin, 1), "hostOrigin[2]", NEO::FileLoggerInstance().getInput(hostOrigin, 2), + "region[0]", NEO::FileLoggerInstance().getInput(region, 0), "region[1]", NEO::FileLoggerInstance().getInput(region, 1), "region[2]", NEO::FileLoggerInstance().getInput(region, 2), "bufferRowPitch", bufferRowPitch, "bufferSlicePitch", bufferSlicePitch, "hostRowPitch", hostRowPitch, "hostSlicePitch", hostSlicePitch, "ptr", ptr, "numEventsInWaitList", numEventsInWaitList, - "eventWaitList", DebugManager.getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), - "event", DebugManager.getEvents(reinterpret_cast(event), 1)); + "eventWaitList", NEO::FileLoggerInstance().getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), + "event", NEO::FileLoggerInstance().getEvents(reinterpret_cast(event), 1)); CommandQueue *pCommandQueue = nullptr; Buffer *pBuffer = nullptr; @@ -2364,11 +2361,11 @@ cl_int CL_API_CALL clEnqueueFillBuffer(cl_command_queue commandQueue, API_ENTER(&retVal); DBG_LOG_INPUTS("commandQueue", commandQueue, "buffer", buffer, - "pattern", DebugManager.infoPointerToString(pattern, patternSize), "patternSize", patternSize, + "pattern", NEO::FileLoggerInstance().infoPointerToString(pattern, patternSize), "patternSize", patternSize, "offset", offset, "size", size, "numEventsInWaitList", numEventsInWaitList, - "eventWaitList", DebugManager.getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), - "event", DebugManager.getEvents(reinterpret_cast(event), 1)); + "eventWaitList", NEO::FileLoggerInstance().getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), + "event", NEO::FileLoggerInstance().getEvents(reinterpret_cast(event), 1)); CommandQueue *pCommandQueue = nullptr; Buffer *pBuffer = nullptr; @@ -2411,8 +2408,8 @@ cl_int CL_API_CALL clEnqueueCopyBuffer(cl_command_queue commandQueue, DBG_LOG_INPUTS("commandQueue", commandQueue, "srcBuffer", srcBuffer, "dstBuffer", dstBuffer, "srcOffset", srcOffset, "dstOffset", dstOffset, "cb", cb, "numEventsInWaitList", numEventsInWaitList, - "eventWaitList", DebugManager.getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), - "event", DebugManager.getEvents(reinterpret_cast(event), 1)); + "eventWaitList", NEO::FileLoggerInstance().getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), + "event", NEO::FileLoggerInstance().getEvents(reinterpret_cast(event), 1)); CommandQueue *pCommandQueue = nullptr; Buffer *pSrcBuffer = nullptr; @@ -2442,7 +2439,7 @@ cl_int CL_API_CALL clEnqueueCopyBuffer(cl_command_queue commandQueue, eventWaitList, event); } - DBG_LOG_INPUTS("event", DebugManager.getEvents(reinterpret_cast(event), 1u)); + DBG_LOG_INPUTS("event", NEO::FileLoggerInstance().getEvents(reinterpret_cast(event), 1u)); TRACING_EXIT(clEnqueueCopyBuffer, &retVal); return retVal; } @@ -2465,14 +2462,14 @@ cl_int CL_API_CALL clEnqueueCopyBufferRect(cl_command_queue commandQueue, API_ENTER(&retVal); DBG_LOG_INPUTS("commandQueue", commandQueue, "srcBuffer", srcBuffer, "dstBuffer", dstBuffer, - "srcOrigin[0]", DebugManager.getInput(srcOrigin, 0), "srcOrigin[1]", DebugManager.getInput(srcOrigin, 1), "srcOrigin[2]", DebugManager.getInput(srcOrigin, 2), - "dstOrigin[0]", DebugManager.getInput(dstOrigin, 0), "dstOrigin[1]", DebugManager.getInput(dstOrigin, 1), "dstOrigin[2]", DebugManager.getInput(dstOrigin, 2), - "region[0]", DebugManager.getInput(region, 0), "region[1]", DebugManager.getInput(region, 1), "region[2]", DebugManager.getInput(region, 2), + "srcOrigin[0]", NEO::FileLoggerInstance().getInput(srcOrigin, 0), "srcOrigin[1]", NEO::FileLoggerInstance().getInput(srcOrigin, 1), "srcOrigin[2]", NEO::FileLoggerInstance().getInput(srcOrigin, 2), + "dstOrigin[0]", NEO::FileLoggerInstance().getInput(dstOrigin, 0), "dstOrigin[1]", NEO::FileLoggerInstance().getInput(dstOrigin, 1), "dstOrigin[2]", NEO::FileLoggerInstance().getInput(dstOrigin, 2), + "region[0]", NEO::FileLoggerInstance().getInput(region, 0), "region[1]", NEO::FileLoggerInstance().getInput(region, 1), "region[2]", NEO::FileLoggerInstance().getInput(region, 2), "srcRowPitch", srcRowPitch, "srcSlicePitch", srcSlicePitch, "dstRowPitch", dstRowPitch, "dstSlicePitch", dstSlicePitch, "numEventsInWaitList", numEventsInWaitList, - "eventWaitList", DebugManager.getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), - "event", DebugManager.getEvents(reinterpret_cast(event), 1)); + "eventWaitList", NEO::FileLoggerInstance().getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), + "event", NEO::FileLoggerInstance().getEvents(reinterpret_cast(event), 1)); CommandQueue *pCommandQueue = nullptr; Buffer *pSrcBuffer = nullptr; @@ -2498,7 +2495,7 @@ cl_int CL_API_CALL clEnqueueCopyBufferRect(cl_command_queue commandQueue, eventWaitList, event); } - DBG_LOG_INPUTS("event", DebugManager.getEvents(reinterpret_cast(event), 1u)); + DBG_LOG_INPUTS("event", NEO::FileLoggerInstance().getEvents(reinterpret_cast(event), 1u)); TRACING_EXIT(clEnqueueCopyBufferRect, &retVal); return retVal; } @@ -2526,12 +2523,12 @@ cl_int CL_API_CALL clEnqueueReadImage(cl_command_queue commandQueue, API_ENTER(&retVal); DBG_LOG_INPUTS("commandQueue", commandQueue, "image", image, "blockingRead", blockingRead, - "origin[0]", DebugManager.getInput(origin, 0), "origin[1]", DebugManager.getInput(origin, 1), "origin[2]", DebugManager.getInput(origin, 2), - "region[0]", DebugManager.getInput(region, 0), "region[1]", DebugManager.getInput(region, 1), "region[2]", DebugManager.getInput(region, 2), + "origin[0]", NEO::FileLoggerInstance().getInput(origin, 0), "origin[1]", NEO::FileLoggerInstance().getInput(origin, 1), "origin[2]", NEO::FileLoggerInstance().getInput(origin, 2), + "region[0]", NEO::FileLoggerInstance().getInput(region, 0), "region[1]", NEO::FileLoggerInstance().getInput(region, 1), "region[2]", NEO::FileLoggerInstance().getInput(region, 2), "rowPitch", rowPitch, "slicePitch", slicePitch, "ptr", ptr, "numEventsInWaitList", numEventsInWaitList, - "eventWaitList", DebugManager.getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), - "event", DebugManager.getEvents(reinterpret_cast(event), 1)); + "eventWaitList", NEO::FileLoggerInstance().getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), + "event", NEO::FileLoggerInstance().getEvents(reinterpret_cast(event), 1)); if (CL_SUCCESS == retVal) { @@ -2566,7 +2563,7 @@ cl_int CL_API_CALL clEnqueueReadImage(cl_command_queue commandQueue, eventWaitList, event); } - DBG_LOG_INPUTS("event", DebugManager.getEvents(reinterpret_cast(event), 1u)); + DBG_LOG_INPUTS("event", NEO::FileLoggerInstance().getEvents(reinterpret_cast(event), 1u)); TRACING_EXIT(clEnqueueReadImage, &retVal); return retVal; } @@ -2594,12 +2591,12 @@ cl_int CL_API_CALL clEnqueueWriteImage(cl_command_queue commandQueue, API_ENTER(&retVal); DBG_LOG_INPUTS("commandQueue", commandQueue, "image", image, "blockingWrite", blockingWrite, - "origin[0]", DebugManager.getInput(origin, 0), "origin[1]", DebugManager.getInput(origin, 1), "origin[2]", DebugManager.getInput(origin, 2), - "region[0]", DebugManager.getInput(region, 0), "region[1]", DebugManager.getInput(region, 1), "region[2]", DebugManager.getInput(region, 2), + "origin[0]", NEO::FileLoggerInstance().getInput(origin, 0), "origin[1]", NEO::FileLoggerInstance().getInput(origin, 1), "origin[2]", NEO::FileLoggerInstance().getInput(origin, 2), + "region[0]", NEO::FileLoggerInstance().getInput(region, 0), "region[1]", NEO::FileLoggerInstance().getInput(region, 1), "region[2]", NEO::FileLoggerInstance().getInput(region, 2), "inputRowPitch", inputRowPitch, "inputSlicePitch", inputSlicePitch, "ptr", ptr, "numEventsInWaitList", numEventsInWaitList, - "eventWaitList", DebugManager.getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), - "event", DebugManager.getEvents(reinterpret_cast(event), 1)); + "eventWaitList", NEO::FileLoggerInstance().getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), + "event", NEO::FileLoggerInstance().getEvents(reinterpret_cast(event), 1)); if (CL_SUCCESS == retVal) { if (pImage->writeMemObjFlagsInvalid()) { @@ -2633,7 +2630,7 @@ cl_int CL_API_CALL clEnqueueWriteImage(cl_command_queue commandQueue, eventWaitList, event); } - DBG_LOG_INPUTS("event", DebugManager.getEvents(reinterpret_cast(event), 1u)); + DBG_LOG_INPUTS("event", NEO::FileLoggerInstance().getEvents(reinterpret_cast(event), 1u)); TRACING_EXIT(clEnqueueWriteImage, &retVal); return retVal; } @@ -2660,11 +2657,11 @@ cl_int CL_API_CALL clEnqueueFillImage(cl_command_queue commandQueue, API_ENTER(&retVal); DBG_LOG_INPUTS("commandQueue", commandQueue, "image", image, "fillColor", fillColor, - "origin[0]", DebugManager.getInput(origin, 0), "origin[1]", DebugManager.getInput(origin, 1), "origin[2]", DebugManager.getInput(origin, 2), - "region[0]", DebugManager.getInput(region, 0), "region[1]", DebugManager.getInput(region, 1), "region[2]", DebugManager.getInput(region, 2), + "origin[0]", NEO::FileLoggerInstance().getInput(origin, 0), "origin[1]", NEO::FileLoggerInstance().getInput(origin, 1), "origin[2]", NEO::FileLoggerInstance().getInput(origin, 2), + "region[0]", NEO::FileLoggerInstance().getInput(region, 0), "region[1]", NEO::FileLoggerInstance().getInput(region, 1), "region[2]", NEO::FileLoggerInstance().getInput(region, 2), "numEventsInWaitList", numEventsInWaitList, - "eventWaitList", DebugManager.getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), - "event", DebugManager.getEvents(reinterpret_cast(event), 1)); + "eventWaitList", NEO::FileLoggerInstance().getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), + "event", NEO::FileLoggerInstance().getEvents(reinterpret_cast(event), 1)); if (CL_SUCCESS == retVal) { retVal = Image::validateRegionAndOrigin(origin, region, dstImage->getImageDesc()); @@ -2682,7 +2679,7 @@ cl_int CL_API_CALL clEnqueueFillImage(cl_command_queue commandQueue, eventWaitList, event); } - DBG_LOG_INPUTS("event", DebugManager.getEvents(reinterpret_cast(event), 1u)); + DBG_LOG_INPUTS("event", NEO::FileLoggerInstance().getEvents(reinterpret_cast(event), 1u)); TRACING_EXIT(clEnqueueFillImage, &retVal); return retVal; } @@ -2709,12 +2706,12 @@ cl_int CL_API_CALL clEnqueueCopyImage(cl_command_queue commandQueue, API_ENTER(&retVal); DBG_LOG_INPUTS("commandQueue", commandQueue, "srcImage", srcImage, "dstImage", dstImage, - "srcOrigin[0]", DebugManager.getInput(srcOrigin, 0), "srcOrigin[1]", DebugManager.getInput(srcOrigin, 1), "srcOrigin[2]", DebugManager.getInput(srcOrigin, 2), - "dstOrigin[0]", DebugManager.getInput(dstOrigin, 0), "dstOrigin[1]", DebugManager.getInput(dstOrigin, 1), "dstOrigin[2]", DebugManager.getInput(dstOrigin, 2), + "srcOrigin[0]", NEO::FileLoggerInstance().getInput(srcOrigin, 0), "srcOrigin[1]", NEO::FileLoggerInstance().getInput(srcOrigin, 1), "srcOrigin[2]", NEO::FileLoggerInstance().getInput(srcOrigin, 2), + "dstOrigin[0]", NEO::FileLoggerInstance().getInput(dstOrigin, 0), "dstOrigin[1]", NEO::FileLoggerInstance().getInput(dstOrigin, 1), "dstOrigin[2]", NEO::FileLoggerInstance().getInput(dstOrigin, 2), "region[0]", region ? region[0] : 0, "region[1]", region ? region[1] : 0, "region[2]", region ? region[2] : 0, "numEventsInWaitList", numEventsInWaitList, - "eventWaitList", DebugManager.getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), - "event", DebugManager.getEvents(reinterpret_cast(event), 1)); + "eventWaitList", NEO::FileLoggerInstance().getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), + "event", NEO::FileLoggerInstance().getEvents(reinterpret_cast(event), 1)); if (CL_SUCCESS == retVal) { if (memcmp(&pSrcImage->getImageFormat(), &pDstImage->getImageFormat(), sizeof(cl_image_format))) { @@ -2763,7 +2760,7 @@ cl_int CL_API_CALL clEnqueueCopyImage(cl_command_queue commandQueue, eventWaitList, event); } - DBG_LOG_INPUTS("event", DebugManager.getEvents(reinterpret_cast(event), 1u)); + DBG_LOG_INPUTS("event", NEO::FileLoggerInstance().getEvents(reinterpret_cast(event), 1u)); TRACING_EXIT(clEnqueueCopyImage, &retVal); return retVal; } @@ -2782,12 +2779,12 @@ cl_int CL_API_CALL clEnqueueCopyImageToBuffer(cl_command_queue commandQueue, API_ENTER(&retVal); DBG_LOG_INPUTS("commandQueue", commandQueue, "srcImage", srcImage, "dstBuffer", dstBuffer, - "srcOrigin[0]", DebugManager.getInput(srcOrigin, 0), "srcOrigin[1]", DebugManager.getInput(srcOrigin, 1), "srcOrigin[2]", DebugManager.getInput(srcOrigin, 2), - "region[0]", DebugManager.getInput(region, 0), "region[1]", DebugManager.getInput(region, 1), "region[2]", DebugManager.getInput(region, 2), + "srcOrigin[0]", NEO::FileLoggerInstance().getInput(srcOrigin, 0), "srcOrigin[1]", NEO::FileLoggerInstance().getInput(srcOrigin, 1), "srcOrigin[2]", NEO::FileLoggerInstance().getInput(srcOrigin, 2), + "region[0]", NEO::FileLoggerInstance().getInput(region, 0), "region[1]", NEO::FileLoggerInstance().getInput(region, 1), "region[2]", NEO::FileLoggerInstance().getInput(region, 2), "dstOffset", dstOffset, "numEventsInWaitList", numEventsInWaitList, - "eventWaitList", DebugManager.getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), - "event", DebugManager.getEvents(reinterpret_cast(event), 1)); + "eventWaitList", NEO::FileLoggerInstance().getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), + "event", NEO::FileLoggerInstance().getEvents(reinterpret_cast(event), 1)); CommandQueue *pCommandQueue = nullptr; Image *pSrcImage = nullptr; @@ -2823,7 +2820,7 @@ cl_int CL_API_CALL clEnqueueCopyImageToBuffer(cl_command_queue commandQueue, event); } - DBG_LOG_INPUTS("event", DebugManager.getEvents(reinterpret_cast(event), 1u)); + DBG_LOG_INPUTS("event", NEO::FileLoggerInstance().getEvents(reinterpret_cast(event), 1u)); TRACING_EXIT(clEnqueueCopyImageToBuffer, &retVal); return retVal; } @@ -2842,11 +2839,11 @@ cl_int CL_API_CALL clEnqueueCopyBufferToImage(cl_command_queue commandQueue, API_ENTER(&retVal); DBG_LOG_INPUTS("commandQueue", commandQueue, "srcBuffer", srcBuffer, "dstImage", dstImage, "srcOffset", srcOffset, - "dstOrigin[0]", DebugManager.getInput(dstOrigin, 0), "dstOrigin[1]", DebugManager.getInput(dstOrigin, 1), "dstOrigin[2]", DebugManager.getInput(dstOrigin, 2), - "region[0]", DebugManager.getInput(region, 0), "region[1]", DebugManager.getInput(region, 1), "region[2]", DebugManager.getInput(region, 2), + "dstOrigin[0]", NEO::FileLoggerInstance().getInput(dstOrigin, 0), "dstOrigin[1]", NEO::FileLoggerInstance().getInput(dstOrigin, 1), "dstOrigin[2]", NEO::FileLoggerInstance().getInput(dstOrigin, 2), + "region[0]", NEO::FileLoggerInstance().getInput(region, 0), "region[1]", NEO::FileLoggerInstance().getInput(region, 1), "region[2]", NEO::FileLoggerInstance().getInput(region, 2), "numEventsInWaitList", numEventsInWaitList, - "eventWaitList", DebugManager.getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), - "event", DebugManager.getEvents(reinterpret_cast(event), 1)); + "eventWaitList", NEO::FileLoggerInstance().getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), + "event", NEO::FileLoggerInstance().getEvents(reinterpret_cast(event), 1)); CommandQueue *pCommandQueue = nullptr; Buffer *pSrcBuffer = nullptr; @@ -2882,7 +2879,7 @@ cl_int CL_API_CALL clEnqueueCopyBufferToImage(cl_command_queue commandQueue, event); } - DBG_LOG_INPUTS("event", DebugManager.getEvents(reinterpret_cast(event), 1u)); + DBG_LOG_INPUTS("event", NEO::FileLoggerInstance().getEvents(reinterpret_cast(event), 1u)); TRACING_EXIT(clEnqueueCopyBufferToImage, &retVal); return retVal; } @@ -2905,8 +2902,8 @@ void *CL_API_CALL clEnqueueMapBuffer(cl_command_queue commandQueue, DBG_LOG_INPUTS("commandQueue", commandQueue, "buffer", buffer, "blockingMap", blockingMap, "mapFlags", mapFlags, "offset", offset, "cb", cb, "numEventsInWaitList", numEventsInWaitList, - "eventWaitList", DebugManager.getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), - "event", DebugManager.getEvents(reinterpret_cast(event), 1)); + "eventWaitList", NEO::FileLoggerInstance().getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), + "event", NEO::FileLoggerInstance().getEvents(reinterpret_cast(event), 1)); do { auto pCommandQueue = castToObject(commandQueue); @@ -2940,7 +2937,7 @@ void *CL_API_CALL clEnqueueMapBuffer(cl_command_queue commandQueue, } while (false); err.set(retVal); - DBG_LOG_INPUTS("retPtr", retPtr, "event", DebugManager.getEvents(reinterpret_cast(event), 1u)); + DBG_LOG_INPUTS("retPtr", retPtr, "event", NEO::FileLoggerInstance().getEvents(reinterpret_cast(event), 1u)); TRACING_EXIT(clEnqueueMapBuffer, &retPtr); return retPtr; @@ -2968,14 +2965,14 @@ void *CL_API_CALL clEnqueueMapImage(cl_command_queue commandQueue, DBG_LOG_INPUTS("commandQueue", commandQueue, "image", image, "blockingMap", blockingMap, "mapFlags", mapFlags, - "origin[0]", DebugManager.getInput(origin, 0), "origin[1]", DebugManager.getInput(origin, 1), - "origin[2]", DebugManager.getInput(origin, 2), "region[0]", DebugManager.getInput(region, 0), - "region[1]", DebugManager.getInput(region, 1), "region[2]", DebugManager.getInput(region, 2), - "imageRowPitch", DebugManager.getInput(imageRowPitch, 0), - "imageSlicePitch", DebugManager.getInput(imageSlicePitch, 0), + "origin[0]", NEO::FileLoggerInstance().getInput(origin, 0), "origin[1]", NEO::FileLoggerInstance().getInput(origin, 1), + "origin[2]", NEO::FileLoggerInstance().getInput(origin, 2), "region[0]", NEO::FileLoggerInstance().getInput(region, 0), + "region[1]", NEO::FileLoggerInstance().getInput(region, 1), "region[2]", NEO::FileLoggerInstance().getInput(region, 2), + "imageRowPitch", NEO::FileLoggerInstance().getInput(imageRowPitch, 0), + "imageSlicePitch", NEO::FileLoggerInstance().getInput(imageSlicePitch, 0), "numEventsInWaitList", numEventsInWaitList, - "eventWaitList", DebugManager.getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), - "event", DebugManager.getEvents(reinterpret_cast(event), 1)); + "eventWaitList", NEO::FileLoggerInstance().getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), + "event", NEO::FileLoggerInstance().getEvents(reinterpret_cast(event), 1)); do { Image *pImage = nullptr; @@ -3020,7 +3017,7 @@ void *CL_API_CALL clEnqueueMapImage(cl_command_queue commandQueue, } while (false); err.set(retVal); - DBG_LOG_INPUTS("retPtr", retPtr, "event", DebugManager.getEvents(reinterpret_cast(event), 1u)); + DBG_LOG_INPUTS("retPtr", retPtr, "event", NEO::FileLoggerInstance().getEvents(reinterpret_cast(event), 1u)); TRACING_EXIT(clEnqueueMapImage, &retPtr); return retPtr; @@ -3047,8 +3044,8 @@ cl_int CL_API_CALL clEnqueueUnmapMemObject(cl_command_queue commandQueue, "memObj", memObj, "mappedPtr", mappedPtr, "numEventsInWaitList", numEventsInWaitList, - "eventWaitList", DebugManager.getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), - "event", DebugManager.getEvents(reinterpret_cast(event), 1)); + "eventWaitList", NEO::FileLoggerInstance().getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), + "event", NEO::FileLoggerInstance().getEvents(reinterpret_cast(event), 1)); if (retVal == CL_SUCCESS) { if (pMemObj->peekClMemObjType() == CL_MEM_OBJECT_PIPE) { @@ -3060,7 +3057,7 @@ cl_int CL_API_CALL clEnqueueUnmapMemObject(cl_command_queue commandQueue, retVal = pCommandQueue->enqueueUnmapMemObject(pMemObj, mappedPtr, numEventsInWaitList, eventWaitList, event); } - DBG_LOG_INPUTS("event", DebugManager.getEvents(reinterpret_cast(event), 1u)); + DBG_LOG_INPUTS("event", NEO::FileLoggerInstance().getEvents(reinterpret_cast(event), 1u)); TRACING_EXIT(clEnqueueUnmapMemObject, &retVal); return retVal; } @@ -3081,8 +3078,8 @@ cl_int CL_API_CALL clEnqueueMigrateMemObjects(cl_command_queue commandQueue, "memObjects", memObjects, "flags", flags, "numEventsInWaitList", numEventsInWaitList, - "eventWaitList", DebugManager.getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), - "event", DebugManager.getEvents(reinterpret_cast(event), 1)); + "eventWaitList", NEO::FileLoggerInstance().getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), + "event", NEO::FileLoggerInstance().getEvents(reinterpret_cast(event), 1)); CommandQueue *pCommandQueue = nullptr; retVal = validateObjects( @@ -3114,7 +3111,7 @@ cl_int CL_API_CALL clEnqueueMigrateMemObjects(cl_command_queue commandQueue, numEventsInWaitList, eventWaitList, event); - DBG_LOG_INPUTS("event", DebugManager.getEvents(reinterpret_cast(event), 1u)); + DBG_LOG_INPUTS("event", NEO::FileLoggerInstance().getEvents(reinterpret_cast(event), 1u)); TRACING_EXIT(clEnqueueMigrateMemObjects, &retVal); return retVal; } @@ -3132,14 +3129,14 @@ cl_int CL_API_CALL clEnqueueNDRangeKernel(cl_command_queue commandQueue, cl_int retVal = CL_SUCCESS; API_ENTER(&retVal); DBG_LOG_INPUTS("commandQueue", commandQueue, "cl_kernel", kernel, - "globalWorkOffset[0]", DebugManager.getInput(globalWorkOffset, 0), - "globalWorkOffset[1]", DebugManager.getInput(globalWorkOffset, 1), - "globalWorkOffset[2]", DebugManager.getInput(globalWorkOffset, 2), - "globalWorkSize", DebugManager.getSizes(globalWorkSize, workDim, false), - "localWorkSize", DebugManager.getSizes(localWorkSize, workDim, true), + "globalWorkOffset[0]", NEO::FileLoggerInstance().getInput(globalWorkOffset, 0), + "globalWorkOffset[1]", NEO::FileLoggerInstance().getInput(globalWorkOffset, 1), + "globalWorkOffset[2]", NEO::FileLoggerInstance().getInput(globalWorkOffset, 2), + "globalWorkSize", NEO::FileLoggerInstance().getSizes(globalWorkSize, workDim, false), + "localWorkSize", NEO::FileLoggerInstance().getSizes(localWorkSize, workDim, true), "numEventsInWaitList", numEventsInWaitList, - "eventWaitList", DebugManager.getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), - "event", DebugManager.getEvents(reinterpret_cast(event), 1)); + "eventWaitList", NEO::FileLoggerInstance().getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), + "event", NEO::FileLoggerInstance().getEvents(reinterpret_cast(event), 1)); CommandQueue *pCommandQueue = nullptr; Kernel *pKernel = nullptr; @@ -3175,7 +3172,7 @@ cl_int CL_API_CALL clEnqueueNDRangeKernel(cl_command_queue commandQueue, eventWaitList, event); - DBG_LOG_INPUTS("event", DebugManager.getEvents(reinterpret_cast(event), 1u)); + DBG_LOG_INPUTS("event", NEO::FileLoggerInstance().getEvents(reinterpret_cast(event), 1u)); TRACING_EXIT(clEnqueueNDRangeKernel, &retVal); return retVal; } @@ -3190,8 +3187,8 @@ cl_int CL_API_CALL clEnqueueTask(cl_command_queue commandQueue, API_ENTER(&retVal); DBG_LOG_INPUTS("commandQueue", commandQueue, "kernel", kernel, "numEventsInWaitList", numEventsInWaitList, - "eventWaitList", DebugManager.getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), - "event", DebugManager.getEvents(reinterpret_cast(event), 1)); + "eventWaitList", NEO::FileLoggerInstance().getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), + "event", NEO::FileLoggerInstance().getEvents(reinterpret_cast(event), 1)); cl_uint workDim = 3; size_t *globalWorkOffset = nullptr; size_t globalWorkSize[3] = {1, 1, 1}; @@ -3226,8 +3223,8 @@ cl_int CL_API_CALL clEnqueueNativeKernel(cl_command_queue commandQueue, DBG_LOG_INPUTS("commandQueue", commandQueue, "userFunc", userFunc, "args", args, "cbArgs", cbArgs, "numMemObjects", numMemObjects, "memList", memList, "argsMemLoc", argsMemLoc, "numEventsInWaitList", numEventsInWaitList, - "eventWaitList", DebugManager.getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), - "event", DebugManager.getEvents(reinterpret_cast(event), 1)); + "eventWaitList", NEO::FileLoggerInstance().getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), + "event", NEO::FileLoggerInstance().getEvents(reinterpret_cast(event), 1)); TRACING_EXIT(clEnqueueNativeKernel, &retVal); return retVal; @@ -3262,7 +3259,7 @@ cl_int CL_API_CALL clEnqueueWaitForEvents(cl_command_queue commandQueue, TRACING_ENTER(clEnqueueWaitForEvents, &commandQueue, &numEvents, &eventList); cl_int retVal = CL_SUCCESS; API_ENTER(&retVal); - DBG_LOG_INPUTS("commandQueue", commandQueue, "eventList", DebugManager.getEvents(reinterpret_cast(eventList), numEvents)); + DBG_LOG_INPUTS("commandQueue", commandQueue, "eventList", NEO::FileLoggerInstance().getEvents(reinterpret_cast(eventList), numEvents)); auto pCommandQueue = castToObject(commandQueue); if (!pCommandQueue) { @@ -3312,10 +3309,10 @@ cl_int CL_API_CALL clEnqueueMarkerWithWaitList(cl_command_queue commandQueue, TRACING_ENTER(clEnqueueMarkerWithWaitList, &commandQueue, &numEventsInWaitList, &eventWaitList, &event); cl_int retVal = CL_SUCCESS; API_ENTER(&retVal); - DebugManager.logInputs("cl_command_queue", commandQueue, - "numEventsInWaitList", numEventsInWaitList, - "eventWaitList", DebugManager.getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), - "event", DebugManager.getEvents(reinterpret_cast(event), 1)); + DBG_LOG_INPUTS("cl_command_queue", commandQueue, + "numEventsInWaitList", numEventsInWaitList, + "eventWaitList", NEO::FileLoggerInstance().getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), + "event", NEO::FileLoggerInstance().getEvents(reinterpret_cast(event), 1)); CommandQueue *pCommandQueue = nullptr; retVal = validateObjects( @@ -3344,8 +3341,8 @@ cl_int CL_API_CALL clEnqueueBarrierWithWaitList(cl_command_queue commandQueue, API_ENTER(&retVal); DBG_LOG_INPUTS("cl_command_queue", commandQueue, "numEventsInWaitList", numEventsInWaitList, - "eventWaitList", DebugManager.getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), - "event", DebugManager.getEvents(reinterpret_cast(event), 1)); + "eventWaitList", NEO::FileLoggerInstance().getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), + "event", NEO::FileLoggerInstance().getEvents(reinterpret_cast(event), 1)); CommandQueue *pCommandQueue = nullptr; @@ -3782,7 +3779,7 @@ cl_accelerator_intel CL_API_CALL clCreateAcceleratorINTEL( DBG_LOG_INPUTS("context", context, "acceleratorType", acceleratorType, "descriptorSize", descriptorSize, - "descriptor", DebugManager.infoPointerToString(descriptor, descriptorSize)); + "descriptor", NEO::FileLoggerInstance().infoPointerToString(descriptor, descriptorSize)); cl_accelerator_intel accelerator = nullptr; do { @@ -3852,7 +3849,7 @@ cl_int CL_API_CALL clGetAcceleratorInfoINTEL( DBG_LOG_INPUTS("accelerator", accelerator, "paramName", paramName, "paramValueSize", paramValueSize, - "paramValue", DebugManager.infoPointerToString(paramValue, paramValueSize), + "paramValue", NEO::FileLoggerInstance().infoPointerToString(paramValue, paramValueSize), "paramValueSizeRet", paramValueSizeRet); IntelAccelerator *pAccelerator = nullptr; @@ -3901,7 +3898,7 @@ cl_program CL_API_CALL clCreateProgramWithILKHR(cl_context context, cl_int retVal = CL_SUCCESS; API_ENTER(&retVal); DBG_LOG_INPUTS("context", context, - "il", DebugManager.infoPointerToString(il, length), + "il", NEO::FileLoggerInstance().infoPointerToString(il, length), "length", length); cl_program program = nullptr; @@ -4110,8 +4107,8 @@ cl_int CL_API_CALL clEnqueueSVMFree(cl_command_queue commandQueue, "pfnFreeFunc", pfnFreeFunc, "userData", userData, "numEventsInWaitList", numEventsInWaitList, - "eventWaitList", DebugManager.getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), - "event", DebugManager.getEvents(reinterpret_cast(event), 1)); + "eventWaitList", NEO::FileLoggerInstance().getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), + "event", NEO::FileLoggerInstance().getEvents(reinterpret_cast(event), 1)); if (retVal != CL_SUCCESS) { TRACING_EXIT(clEnqueueSVMFree, &retVal); @@ -4162,8 +4159,8 @@ cl_int CL_API_CALL clEnqueueSVMMemcpy(cl_command_queue commandQueue, "srcPtr", srcPtr, "size", size, "numEventsInWaitList", numEventsInWaitList, - "eventWaitList", DebugManager.getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), - "event", DebugManager.getEvents(reinterpret_cast(event), 1)); + "eventWaitList", NEO::FileLoggerInstance().getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), + "event", NEO::FileLoggerInstance().getEvents(reinterpret_cast(event), 1)); if (retVal != CL_SUCCESS) { TRACING_EXIT(clEnqueueSVMMemcpy, &retVal); @@ -4208,13 +4205,13 @@ cl_int CL_API_CALL clEnqueueSVMMemFill(cl_command_queue commandQueue, API_ENTER(&retVal); DBG_LOG_INPUTS("commandQueue", commandQueue, - "svmPtr", DebugManager.infoPointerToString(svmPtr, size), - "pattern", DebugManager.infoPointerToString(pattern, patternSize), + "svmPtr", NEO::FileLoggerInstance().infoPointerToString(svmPtr, size), + "pattern", NEO::FileLoggerInstance().infoPointerToString(pattern, patternSize), "patternSize", patternSize, "size", size, "numEventsInWaitList", numEventsInWaitList, - "eventWaitList", DebugManager.getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), - "event", DebugManager.getEvents(reinterpret_cast(event), 1)); + "eventWaitList", NEO::FileLoggerInstance().getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), + "event", NEO::FileLoggerInstance().getEvents(reinterpret_cast(event), 1)); if (retVal != CL_SUCCESS) { TRACING_EXIT(clEnqueueSVMMemFill, &retVal); @@ -4259,11 +4256,11 @@ cl_int CL_API_CALL clEnqueueSVMMap(cl_command_queue commandQueue, DBG_LOG_INPUTS("commandQueue", commandQueue, "blockingMap", blockingMap, "mapFlags", mapFlags, - "svmPtr", DebugManager.infoPointerToString(svmPtr, size), + "svmPtr", NEO::FileLoggerInstance().infoPointerToString(svmPtr, size), "size", size, "numEventsInWaitList", numEventsInWaitList, - "eventWaitList", DebugManager.getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), - "event", DebugManager.getEvents(reinterpret_cast(event), 1)); + "eventWaitList", NEO::FileLoggerInstance().getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), + "event", NEO::FileLoggerInstance().getEvents(reinterpret_cast(event), 1)); if (CL_SUCCESS != retVal) { TRACING_EXIT(clEnqueueSVMMap, &retVal); @@ -4309,8 +4306,8 @@ cl_int CL_API_CALL clEnqueueSVMUnmap(cl_command_queue commandQueue, DBG_LOG_INPUTS("commandQueue", commandQueue, "svmPtr", svmPtr, "numEventsInWaitList", numEventsInWaitList, - "eventWaitList", DebugManager.getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), - "event", DebugManager.getEvents(reinterpret_cast(event), 1)); + "eventWaitList", NEO::FileLoggerInstance().getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), + "event", NEO::FileLoggerInstance().getEvents(reinterpret_cast(event), 1)); if (retVal != CL_SUCCESS) { TRACING_EXIT(clEnqueueSVMUnmap, &retVal); @@ -4395,7 +4392,7 @@ cl_int CL_API_CALL clSetKernelExecInfo(cl_kernel kernel, API_ENTER(&retVal); DBG_LOG_INPUTS("kernel", kernel, "paramName", paramName, - "paramValueSize", paramValueSize, "paramValue", DebugManager.infoPointerToString(paramValue, paramValueSize)); + "paramValueSize", paramValueSize, "paramValue", NEO::FileLoggerInstance().infoPointerToString(paramValue, paramValueSize)); if (CL_SUCCESS != retVal) { TRACING_EXIT(clSetKernelExecInfo, &retVal); @@ -4547,7 +4544,7 @@ cl_int CL_API_CALL clGetPipeInfo(cl_mem pipe, DBG_LOG_INPUTS("cl_mem", pipe, "cl_pipe_info", paramName, "size_t", paramValueSize, - "void *", DebugManager.infoPointerToString(paramValue, paramValueSize), + "void *", NEO::FileLoggerInstance().infoPointerToString(paramValue, paramValueSize), "size_t*", paramValueSizeRet); retVal = validateObjects(pipe); @@ -4767,9 +4764,9 @@ cl_int CL_API_CALL clGetKernelSubGroupInfoKHR(cl_kernel kernel, "device", device, "paramName", paramName, "inputValueSize", inputValueSize, - "inputValue", DebugManager.infoPointerToString(inputValue, inputValueSize), + "inputValue", NEO::FileLoggerInstance().infoPointerToString(inputValue, inputValueSize), "paramValueSize", paramValueSize, - "paramValue", DebugManager.infoPointerToString(paramValue, paramValueSize), + "paramValue", NEO::FileLoggerInstance().infoPointerToString(paramValue, paramValueSize), "paramValueSizeRet", paramValueSizeRet); Kernel *pKernel = nullptr; @@ -4867,9 +4864,9 @@ cl_int CL_API_CALL clGetKernelSubGroupInfo(cl_kernel kernel, "device", device, "paramName", paramName, "inputValueSize", inputValueSize, - "inputValue", DebugManager.infoPointerToString(inputValue, inputValueSize), + "inputValue", NEO::FileLoggerInstance().infoPointerToString(inputValue, inputValueSize), "paramValueSize", paramValueSize, - "paramValue", DebugManager.infoPointerToString(paramValue, paramValueSize), + "paramValue", NEO::FileLoggerInstance().infoPointerToString(paramValue, paramValueSize), "paramValueSizeRet", paramValueSizeRet); Kernel *pKernel = nullptr; @@ -4943,12 +4940,12 @@ cl_int CL_API_CALL clEnqueueSVMMigrateMem(cl_command_queue commandQueue, API_ENTER(&retVal); DBG_LOG_INPUTS("commandQueue", commandQueue, "numSvmPointers", numSvmPointers, - "svmPointers", DebugManager.infoPointerToString(svmPointers ? svmPointers[0] : 0, DebugManager.getInput(sizes, 0)), - "sizes", DebugManager.getInput(sizes, 0), + "svmPointers", NEO::FileLoggerInstance().infoPointerToString(svmPointers ? svmPointers[0] : 0, NEO::FileLoggerInstance().getInput(sizes, 0)), + "sizes", NEO::FileLoggerInstance().getInput(sizes, 0), "flags", flags, "numEventsInWaitList", numEventsInWaitList, - "eventWaitList", DebugManager.getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), - "event", DebugManager.getEvents(reinterpret_cast(event), 1)); + "eventWaitList", NEO::FileLoggerInstance().getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), + "event", NEO::FileLoggerInstance().getEvents(reinterpret_cast(event), 1)); CommandQueue *pCommandQueue = nullptr; retVal = validateObjects( @@ -5192,10 +5189,10 @@ cl_int CL_API_CALL clGetExecutionInfoINTEL(cl_command_queue commandQueue, cl_int retVal = CL_SUCCESS; API_ENTER(&retVal); DBG_LOG_INPUTS("commandQueue", commandQueue, "cl_kernel", kernel, - "globalWorkOffset[0]", DebugManager.getInput(globalWorkOffset, 0), - "globalWorkOffset[1]", DebugManager.getInput(globalWorkOffset, 1), - "globalWorkOffset[2]", DebugManager.getInput(globalWorkOffset, 2), - "localWorkSize", DebugManager.getSizes(localWorkSize, workDim, true), + "globalWorkOffset[0]", NEO::FileLoggerInstance().getInput(globalWorkOffset, 0), + "globalWorkOffset[1]", NEO::FileLoggerInstance().getInput(globalWorkOffset, 1), + "globalWorkOffset[2]", NEO::FileLoggerInstance().getInput(globalWorkOffset, 2), + "localWorkSize", NEO::FileLoggerInstance().getSizes(localWorkSize, workDim, true), "paramName", paramName, "paramValueSize", paramValueSize, "paramValue", paramValue, "paramValueSizeRet", paramValueSizeRet); @@ -5242,14 +5239,14 @@ cl_int CL_API_CALL clEnqueueNDRangeKernelINTEL(cl_command_queue commandQueue, cl_int retVal = CL_SUCCESS; API_ENTER(&retVal); DBG_LOG_INPUTS("commandQueue", commandQueue, "cl_kernel", kernel, - "globalWorkOffset[0]", DebugManager.getInput(globalWorkOffset, 0), - "globalWorkOffset[1]", DebugManager.getInput(globalWorkOffset, 1), - "globalWorkOffset[2]", DebugManager.getInput(globalWorkOffset, 2), - "workgroupCount", DebugManager.getSizes(workgroupCount, workDim, false), - "localWorkSize", DebugManager.getSizes(localWorkSize, workDim, true), + "globalWorkOffset[0]", NEO::FileLoggerInstance().getInput(globalWorkOffset, 0), + "globalWorkOffset[1]", NEO::FileLoggerInstance().getInput(globalWorkOffset, 1), + "globalWorkOffset[2]", NEO::FileLoggerInstance().getInput(globalWorkOffset, 2), + "workgroupCount", NEO::FileLoggerInstance().getSizes(workgroupCount, workDim, false), + "localWorkSize", NEO::FileLoggerInstance().getSizes(localWorkSize, workDim, true), "numEventsInWaitList", numEventsInWaitList, - "eventWaitList", DebugManager.getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), - "event", DebugManager.getEvents(reinterpret_cast(event), 1)); + "eventWaitList", NEO::FileLoggerInstance().getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), + "event", NEO::FileLoggerInstance().getEvents(reinterpret_cast(event), 1)); CommandQueue *pCommandQueue = nullptr; Kernel *pKernel = nullptr; @@ -5293,6 +5290,6 @@ cl_int CL_API_CALL clEnqueueNDRangeKernelINTEL(cl_command_queue commandQueue, eventWaitList, event); - DBG_LOG_INPUTS("event", DebugManager.getEvents(reinterpret_cast(event), 1u)); + DBG_LOG_INPUTS("event", NEO::FileLoggerInstance().getEvents(reinterpret_cast(event), 1u)); return retVal; } diff --git a/runtime/command_queue/command_queue.cpp b/runtime/command_queue/command_queue.cpp index 381e5bdd24..cd382bace4 100644 --- a/runtime/command_queue/command_queue.cpp +++ b/runtime/command_queue/command_queue.cpp @@ -179,7 +179,7 @@ bool CommandQueue::isQueueBlocked() { taskLevel = getGpgpuCommandStreamReceiver().peekTaskLevel(); } - DebugManager.log(DebugManager.flags.EventsDebugEnable.get(), "isQueueBlocked taskLevel change from", taskLevel, "to new from virtualEvent", this->virtualEvent, "new tasklevel", this->virtualEvent->taskLevel.load()); + FileLoggerInstance().log(DebugManager.flags.EventsDebugEnable.get(), "isQueueBlocked taskLevel change from", taskLevel, "to new from virtualEvent", this->virtualEvent, "new tasklevel", this->virtualEvent->taskLevel.load()); //close the access to virtual event, driver added only 1 ref count. this->virtualEvent->decRefInternal(); diff --git a/runtime/command_queue/enqueue_common.h b/runtime/command_queue/enqueue_common.h index ceeb623781..a7a0ceda15 100644 --- a/runtime/command_queue/enqueue_common.h +++ b/runtime/command_queue/enqueue_common.h @@ -341,7 +341,7 @@ void CommandQueueHw::enqueueHandler(Surface **surfacesForResidency, if (eventBuilder.getEvent()) { eventBuilder.getEvent()->updateCompletionStamp(completionStamp.taskCount, completionStamp.taskLevel, completionStamp.flushStamp); - DebugManager.log(DebugManager.flags.EventsDebugEnable.get(), "updateCompletionStamp Event", eventBuilder.getEvent(), "taskLevel", eventBuilder.getEvent()->taskLevel.load()); + FileLoggerInstance().log(DebugManager.flags.EventsDebugEnable.get(), "updateCompletionStamp Event", eventBuilder.getEvent(), "taskLevel", eventBuilder.getEvent()->taskLevel.load()); } if (blockQueue) { @@ -391,7 +391,7 @@ void CommandQueueHw::processDispatchForKernels(const MultiDispatchInf KernelOperation *blockedCommandsData, TimestampPacketDependencies ×tampPacketDependencies) { TagNode *hwPerfCounter = nullptr; - DebugManager.dumpKernelArgs(&multiDispatchInfo); + FileLoggerInstance().dumpKernelArgs(&multiDispatchInfo); printfHandler.reset(PrintfHandler::create(multiDispatchInfo, *device)); if (printfHandler) { diff --git a/runtime/kernel/kernel.h b/runtime/kernel/kernel.h index a34d6f4815..de70fec19d 100644 --- a/runtime/kernel/kernel.h +++ b/runtime/kernel/kernel.h @@ -90,10 +90,10 @@ class Kernel : public BaseObject<_cl_kernel> { *errcodeRet = retVal; } - if (DebugManager.debugKernelDumpingAvailable()) { + if (FileLoggerInstance().enabled()) { std::string source; program->getSource(source); - DebugManager.dumpKernel(kernelInfo.name, source); + FileLoggerInstance().dumpKernel(kernelInfo.name, source); } return pKernel; diff --git a/runtime/memory_manager/memory_manager.cpp b/runtime/memory_manager/memory_manager.cpp index 974f694897..0a2bb0e15f 100644 --- a/runtime/memory_manager/memory_manager.cpp +++ b/runtime/memory_manager/memory_manager.cpp @@ -323,7 +323,7 @@ GraphicsAllocation *MemoryManager::allocateGraphicsMemoryInPreferredPool(const A if (!allocation && status == AllocationStatus::RetryInNonDevicePool) { allocation = allocateGraphicsMemory(allocationData); } - DebugManager.logAllocation(allocation); + FileLoggerInstance().logAllocation(allocation); return allocation; } diff --git a/runtime/os_interface/debug_settings_manager.cpp b/runtime/os_interface/debug_settings_manager.cpp index 1f5755026a..c73089a8fc 100644 --- a/runtime/os_interface/debug_settings_manager.cpp +++ b/runtime/os_interface/debug_settings_manager.cpp @@ -7,14 +7,10 @@ #include "debug_settings_manager.h" +#include "core/helpers/debug_helpers.h" #include "core/helpers/ptr_math.h" #include "core/helpers/string.h" #include "core/utilities/debug_settings_reader_creator.h" -#include "runtime/event/event.h" -#include "runtime/helpers/dispatch_info.h" -#include "runtime/helpers/timestamp_packet.h" -#include "runtime/kernel/kernel.h" -#include "runtime/mem_obj/mem_obj.h" #include "runtime/os_interface/definitions/translate_debug_settings.h" #include "runtime/os_interface/ocl_reg_path.h" @@ -35,24 +31,12 @@ DebugSettingsManager DebugManager; template DebugSettingsManager::DebugSettingsManager() { - - logFileName = "igdrcl.log"; if (registryReadAvailable()) { readerImpl = SettingsReaderCreator::create(oclRegPath); injectSettingsFromReader(); dumpFlags(); } translateDebugSettings(flags); - std::remove(logFileName.c_str()); -} - -template -void DebugSettingsManager::writeToFile(std::string filename, const char *str, size_t length, std::ios_base::openmode mode) { - std::ofstream outFile(filename, mode); - if (outFile.is_open()) { - outFile.write(str, length); - outFile.close(); - } } template @@ -69,103 +53,6 @@ void DebugSettingsManager::getHardwareInfoOverride(std::string &hwIn } } -template -void DebugSettingsManager::dumpKernel(const std::string &name, const std::string &src) { - if (false == debugKernelDumpingAvailable()) { - return; - } - - if (flags.DumpKernels.get()) { - DBG_LOG(LogApiCalls, "Kernel size", src.size(), src.c_str()); - writeToFile(name + ".txt", src.c_str(), src.size(), std::ios::trunc); - } -} - -template -void DebugSettingsManager::logApiCall(const char *function, bool enter, int32_t errorCode) { - if (false == debugLoggingAvailable()) { - return; - } - - if (flags.LogApiCalls.get()) { - std::unique_lock theLock(mtx); - std::thread::id thisThread = std::this_thread::get_id(); - - std::stringstream ss; - ss << "ThreadID: " << thisThread << " "; - if (enter) - ss << "Function Enter: "; - else - ss << "Function Leave (" << errorCode << "): "; - ss << function << std::endl; - - auto str = ss.str(); - writeToFile(logFileName, str.c_str(), str.size(), std::ios::app); - } -} - -template -void DebugSettingsManager::logAllocation(GraphicsAllocation const *graphicsAllocation) { - if (false == debugLoggingAvailable()) { - return; - } - - if (flags.LogAllocationMemoryPool.get()) { - std::thread::id thisThread = std::this_thread::get_id(); - - std::stringstream ss; - ss << " ThreadID: " << thisThread; - ss << " AllocationType: " << getAllocationTypeString(graphicsAllocation); - ss << " MemoryPool: " << graphicsAllocation->getMemoryPool(); - ss << graphicsAllocation->getAllocationInfoString(); - ss << std::endl; - - auto str = ss.str(); - - std::unique_lock theLock(mtx); - writeToFile(logFileName, str.c_str(), str.size(), std::ios::app); - } -} - -template -size_t DebugSettingsManager::getInput(const size_t *input, int32_t index) { - if (debugLoggingAvailable() == false) - return 0; - return input != nullptr ? input[index] : 0; -} - -template -const std::string DebugSettingsManager::getEvents(const uintptr_t *input, uint32_t numOfEvents) { - if (false == debugLoggingAvailable()) { - return ""; - } - - std::stringstream os; - for (uint32_t i = 0; i < numOfEvents; i++) { - if (input != nullptr) { - cl_event event = ((cl_event *)input)[i]; - os << "cl_event " << event << ", Event " << (Event *)event << ", "; - } - } - return os.str(); -} - -template -const std::string DebugSettingsManager::getMemObjects(const uintptr_t *input, uint32_t numOfObjects) { - if (false == debugLoggingAvailable()) { - return ""; - } - - std::stringstream os; - for (uint32_t i = 0; i < numOfObjects; i++) { - if (input != nullptr) { - cl_mem mem = const_cast(reinterpret_cast(input)[i]); - os << "cl_mem " << mem << ", MemObj " << static_cast(mem) << ", "; - } - } - return os.str(); -} - template template void DebugSettingsManager::dumpNonDefaultFlag(const char *variableName, const DataType &variableValue, const DataType &defaultValue) { @@ -191,102 +78,6 @@ void DebugSettingsManager::dumpFlags() const { #undef DECLARE_DEBUG_VARIABLE } -template -void DebugSettingsManager::dumpBinaryProgram(int32_t numDevices, const size_t *lengths, const unsigned char **binaries) { - if (false == debugKernelDumpingAvailable()) { - return; - } - - if (flags.DumpKernels.get()) { - if (lengths != nullptr && binaries != nullptr && - lengths[0] != 0 && binaries[0] != nullptr) { - std::unique_lock theLock(mtx); - writeToFile("programBinary.bin", reinterpret_cast(binaries[0]), lengths[0], std::ios::trunc | std::ios::binary); - } - } -} - -template -void DebugSettingsManager::dumpKernelArgs(const Kernel *kernel) { - if (false == kernelArgDumpingAvailable()) { - return; - } - if (flags.DumpKernelArgs.get() && kernel != nullptr) { - std::unique_lock theLock(mtx); - std::ofstream outFile; - - for (unsigned int i = 0; i < kernel->getKernelInfo().kernelArgInfo.size(); i++) { - std::string type; - std::string fileName; - const char *ptr = nullptr; - size_t size = 0; - uint64_t flags = 0; - std::unique_ptr argVal = nullptr; - - auto &argInfo = kernel->getKernelInfo().kernelArgInfo[i]; - - if (argInfo.addressQualifier == CL_KERNEL_ARG_ADDRESS_LOCAL) { - type = "local"; - } else if (argInfo.typeStr.find("image") != std::string::npos) { - type = "image"; - auto clMem = (const cl_mem)kernel->getKernelArg(i); - auto memObj = castToObject(clMem); - if (memObj != nullptr) { - ptr = static_cast(memObj->getCpuAddress()); - size = memObj->getSize(); - flags = memObj->getMemoryPropertiesFlags(); - } - } else if (argInfo.typeStr.find("sampler") != std::string::npos) { - type = "sampler"; - } else if (argInfo.typeStr.find("*") != std::string::npos) { - type = "buffer"; - auto clMem = (const cl_mem)kernel->getKernelArg(i); - auto memObj = castToObject(clMem); - if (memObj != nullptr) { - ptr = static_cast(memObj->getCpuAddress()); - size = memObj->getSize(); - flags = memObj->getMemoryPropertiesFlags(); - } - } else { - type = "immediate"; - auto crossThreadData = kernel->getCrossThreadData(); - auto crossThreadDataSize = kernel->getCrossThreadDataSize(); - argVal = std::unique_ptr(new char[crossThreadDataSize]); - - size_t totalArgSize = 0; - for (const auto &kernelArgPatchInfo : argInfo.kernelArgPatchInfoVector) { - auto pSource = ptrOffset(crossThreadData, kernelArgPatchInfo.crossthreadOffset); - auto pDestination = ptrOffset(argVal.get(), kernelArgPatchInfo.sourceOffset); - memcpy_s(pDestination, kernelArgPatchInfo.size, pSource, kernelArgPatchInfo.size); - totalArgSize += kernelArgPatchInfo.size; - } - size = totalArgSize; - ptr = argVal.get(); - } - - if (ptr && size) { - fileName = kernel->getKernelInfo().name + "_arg_" + std::to_string(i) + "_" + type + "_size_" + std::to_string(size) + "_flags_" + std::to_string(flags) + ".bin"; - writeToFile(fileName, ptr, size, std::ios::trunc | std::ios::binary); - } - } - } -} - -template -void DebugSettingsManager::dumpKernelArgs(const MultiDispatchInfo *multiDispatchInfo) { - if (kernelArgDumpingAvailable() == false) { - return; - } - - if (flags.DumpKernelArgs.get() == false || multiDispatchInfo == nullptr) { - return; - } - - for (auto &dispatchInfo : *multiDispatchInfo) { - dumpKernelArgs(dispatchInfo.getKernel()); - } -} - template void DebugSettingsManager::injectSettingsFromReader() { #undef DECLARE_DEBUG_VARIABLE @@ -299,90 +90,6 @@ void DebugSettingsManager::injectSettingsFromReader() { #undef DECLARE_DEBUG_VARIABLE } -template -const char *DebugSettingsManager::getAllocationTypeString(GraphicsAllocation const *graphicsAllocation) { - if (false == debugLoggingAvailable()) { - return nullptr; - } - - auto type = graphicsAllocation->getAllocationType(); - - switch (type) { - case GraphicsAllocation::AllocationType::BUFFER: - return "BUFFER"; - case GraphicsAllocation::AllocationType::BUFFER_COMPRESSED: - return "BUFFER_COMPRESSED"; - case GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY: - return "BUFFER_HOST_MEMORY"; - case GraphicsAllocation::AllocationType::COMMAND_BUFFER: - return "COMMAND_BUFFER"; - case GraphicsAllocation::AllocationType::CONSTANT_SURFACE: - return "CONSTANT_SURFACE"; - case GraphicsAllocation::AllocationType::DEVICE_QUEUE_BUFFER: - return "DEVICE_QUEUE_BUFFER"; - case GraphicsAllocation::AllocationType::EXTERNAL_HOST_PTR: - return "EXTERNAL_HOST_PTR"; - case GraphicsAllocation::AllocationType::FILL_PATTERN: - return "FILL_PATTERN"; - case GraphicsAllocation::AllocationType::GLOBAL_SURFACE: - return "GLOBAL_SURFACE"; - case GraphicsAllocation::AllocationType::IMAGE: - return "IMAGE"; - case GraphicsAllocation::AllocationType::INDIRECT_OBJECT_HEAP: - return "INDIRECT_OBJECT_HEAP"; - case GraphicsAllocation::AllocationType::INSTRUCTION_HEAP: - return "INSTRUCTION_HEAP"; - case GraphicsAllocation::AllocationType::INTERNAL_HEAP: - return "INTERNAL_HEAP"; - case GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY: - return "INTERNAL_HOST_MEMORY"; - case GraphicsAllocation::AllocationType::KERNEL_ISA: - return "KERNEL_ISA"; - case GraphicsAllocation::AllocationType::LINEAR_STREAM: - return "LINEAR_STREAM"; - case GraphicsAllocation::AllocationType::MCS: - return "MCS"; - case GraphicsAllocation::AllocationType::PIPE: - return "PIPE"; - case GraphicsAllocation::AllocationType::PREEMPTION: - return "PREEMPTION"; - case GraphicsAllocation::AllocationType::PRINTF_SURFACE: - return "PRINTF_SURFACE"; - case GraphicsAllocation::AllocationType::PRIVATE_SURFACE: - return "PRIVATE_SURFACE"; - case GraphicsAllocation::AllocationType::PROFILING_TAG_BUFFER: - return "PROFILING_TAG_BUFFER"; - case GraphicsAllocation::AllocationType::SCRATCH_SURFACE: - return "SCRATCH_SURFACE"; - case GraphicsAllocation::AllocationType::SHARED_BUFFER: - return "SHARED_BUFFER"; - case GraphicsAllocation::AllocationType::SHARED_CONTEXT_IMAGE: - return "SHARED_CONTEXT_IMAGE"; - case GraphicsAllocation::AllocationType::SHARED_IMAGE: - return "SHARED_IMAGE"; - case GraphicsAllocation::AllocationType::SHARED_RESOURCE_COPY: - return "SHARED_RESOURCE_COPY"; - case GraphicsAllocation::AllocationType::SURFACE_STATE_HEAP: - return "SURFACE_STATE_HEAP"; - case GraphicsAllocation::AllocationType::SVM_CPU: - return "SVM_CPU"; - case GraphicsAllocation::AllocationType::SVM_GPU: - return "SVM_GPU"; - case GraphicsAllocation::AllocationType::SVM_ZERO_COPY: - return "SVM_ZERO_COPY"; - case GraphicsAllocation::AllocationType::TAG_BUFFER: - return "TAG_BUFFER"; - case GraphicsAllocation::AllocationType::TIMESTAMP_PACKET_TAG_BUFFER: - return "TIMESTAMP_PACKET_TAG_BUFFER"; - case GraphicsAllocation::AllocationType::UNKNOWN: - return "UNKNOWN"; - case GraphicsAllocation::AllocationType::WRITE_COMBINED: - return "WRITE_COMBINED"; - default: - return "ILLEGAL_VALUE"; - } -} - template class DebugSettingsManager; template class DebugSettingsManager; template class DebugSettingsManager; diff --git a/runtime/os_interface/debug_settings_manager.h b/runtime/os_interface/debug_settings_manager.h index 9c80aa3133..9d885fa8ca 100644 --- a/runtime/os_interface/debug_settings_manager.h +++ b/runtime/os_interface/debug_settings_manager.h @@ -79,18 +79,6 @@ class DebugSettingsManager { DebugSettingsManager(const DebugSettingsManager &) = delete; DebugSettingsManager &operator=(const DebugSettingsManager &) = delete; - static constexpr bool debugLoggingAvailable() { - return DebugLevel == DebugFunctionalityLevel::Full; - } - - static constexpr bool debugKernelDumpingAvailable() { - return DebugLevel == DebugFunctionalityLevel::Full; - } - - static constexpr bool kernelArgDumpingAvailable() { - return DebugLevel == DebugFunctionalityLevel::Full; - } - static constexpr bool registryReadAvailable() { return (DebugLevel == DebugFunctionalityLevel::Full) || (DebugLevel == DebugFunctionalityLevel::RegKeys); } @@ -100,113 +88,12 @@ class DebugSettingsManager { } void getHardwareInfoOverride(std::string &hwInfoConfig); - void dumpKernel(const std::string &name, const std::string &src); - void logApiCall(const char *function, bool enter, int32_t errorCode); - void logAllocation(GraphicsAllocation const *graphicsAllocation); - size_t getInput(const size_t *input, int32_t index); - const std::string getEvents(const uintptr_t *input, uint32_t numOfEvents); - const std::string getMemObjects(const uintptr_t *input, uint32_t numOfObjects); - MOCKABLE_VIRTUAL void writeToFile(std::string filename, const char *str, size_t length, std::ios_base::openmode mode); - - void dumpBinaryProgram(int32_t numDevices, const size_t *lengths, const unsigned char **binaries); - void dumpKernelArgs(const Kernel *kernel); - void dumpKernelArgs(const MultiDispatchInfo *multiDispatchInfo); void injectSettingsFromReader(); - const std::string getSizes(const uintptr_t *input, uint32_t workDim, bool local) { - if (false == debugLoggingAvailable()) { - return ""; - } - - std::stringstream os; - std::string workSize; - if (local) { - workSize = "localWorkSize"; - } else { - workSize = "globalWorkSize"; - } - - for (uint32_t i = 0; i < workDim; i++) { - if (input != nullptr) { - os << workSize << "[" << i << "]: \t" << input[i] << "\n"; - } - } - return os.str(); - } - - const std::string infoPointerToString(const void *paramValue, size_t paramSize) { - if (false == debugLoggingAvailable()) { - return ""; - } - - std::stringstream os; - if (paramValue) { - switch (paramSize) { - case sizeof(uint32_t): - os << *(uint32_t *)paramValue; - break; - case sizeof(uint64_t): - os << *(uint64_t *)paramValue; - break; - case sizeof(uint8_t): - os << (uint32_t)(*(uint8_t *)paramValue); - break; - default: - break; - } - } - return os.str(); - } - - // Expects pairs of args (even number of args) - template - void logInputs(Types &&... params) { - if (debugLoggingAvailable()) { - if (this->flags.LogApiCalls.get()) { - std::unique_lock theLock(mtx); - std::thread::id thisThread = std::this_thread::get_id(); - std::stringstream ss; - ss << "------------------------------\n"; - printInputs(ss, "ThreadID", thisThread, params...); - ss << "------------------------------" << std::endl; - writeToFile(logFileName, ss.str().c_str(), ss.str().length(), std::ios::app); - } - } - } - - template - void logLazyEvaluateArgs(bool predicate, FT &&callable) { - if (debugLoggingAvailable()) { - if (predicate) { - callable(); - } - } - } - - template - void log(bool enableLog, Types... params) { - if (debugLoggingAvailable()) { - if (enableLog) { - std::unique_lock theLock(mtx); - std::thread::id thisThread = std::this_thread::get_id(); - std::stringstream ss; - print(ss, "ThreadID", thisThread, params...); - writeToFile(logFileName, ss.str().c_str(), ss.str().length(), std::ios::app); - } - } - } - DebugVariables flags; void *injectFcn = nullptr; - const char *getLogFileName() { - return logFileName.c_str(); - } - - void setLogFileName(std::string filename) { - logFileName = filename; - } void setReaderImpl(SettingsReader *newReaderImpl) { readerImpl.reset(newReaderImpl); } @@ -214,48 +101,11 @@ class DebugSettingsManager { return readerImpl.get(); } - const char *getAllocationTypeString(GraphicsAllocation const *graphicsAllocation); - protected: std::unique_ptr readerImpl; std::mutex mtx; std::string logFileName; - // Required for variadic template with 0 args passed - void printInputs(std::stringstream &ss) {} - - // Prints inputs in format: InputName: InputValue \newline - template - void printInputs(std::stringstream &ss, T1 first, Types... params) { - if (debugLoggingAvailable()) { - const size_t argsLeft = sizeof...(params); - - ss << "\t" << first; - if (argsLeft % 2) { - ss << ": "; - } else { - ss << std::endl; - } - printInputs(ss, params...); - } - } - - // Required for variadic template with 0 args passed - void print(std::stringstream &ss) {} - - template - void print(std::stringstream &ss, T1 first, Types... params) { - if (debugLoggingAvailable()) { - const size_t argsLeft = sizeof...(params); - - ss << first << " "; - if (argsLeft == 0) { - ss << std::endl; - } - print(ss, params...); - } - } - template static void dumpNonDefaultFlag(const char *variableName, const DataType &variableValue, const DataType &defaultValue); void dumpFlags() const; @@ -266,31 +116,4 @@ extern DebugSettingsManager DebugManager; template const char *DebugSettingsManager::settingsDumpFileName = "igdrcl_dumped.config"; - -template -class DebugSettingsApiEnterWrapper { - public: - DebugSettingsApiEnterWrapper(const char *funcName, const int *errorCode) - : funcName(funcName), errorCode(errorCode) { - if (Enabled) { - DebugManager.logApiCall(funcName, true, 0); - } - } - ~DebugSettingsApiEnterWrapper() { - if (Enabled) { - DebugManager.logApiCall(funcName, false, (errorCode != nullptr) ? *errorCode : 0); - } - } - const char *funcName; - const int *errorCode; -}; }; // namespace NEO - -#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__); }) - -#define DBG_LOG(PREDICATE, ...) \ - DBG_LOG_LAZY_EVALUATE_ARGS(NEO::DebugManager, PREDICATE, log, NEO::DebugManager.flags.PREDICATE.get(), __VA_ARGS__) - -#define DBG_LOG_INPUTS(...) \ - DBG_LOG_LAZY_EVALUATE_ARGS(NEO::DebugManager, LogApiCalls, logInputs, __VA_ARGS__) diff --git a/runtime/os_interface/windows/api_win.cpp b/runtime/os_interface/windows/api_win.cpp index eee6d485e3..4757d8ec17 100644 --- a/runtime/os_interface/windows/api_win.cpp +++ b/runtime/os_interface/windows/api_win.cpp @@ -142,8 +142,8 @@ cl_int CL_API_CALL clEnqueueAcquireDX9ObjectsINTEL(cl_command_queue commandQueue "numObjects", numObjects, "memObjects", memObjects, "numEventsInWaitList", numEventsInWaitList, - "eventWaitList", DebugManager.getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), - "event", DebugManager.getEvents(reinterpret_cast(event), 1)); + "eventWaitList", FileLoggerInstance().getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), + "event", FileLoggerInstance().getEvents(reinterpret_cast(event), 1)); if (retVal != CL_SUCCESS) { return retVal; } @@ -161,8 +161,8 @@ cl_int CL_API_CALL clEnqueueReleaseDX9ObjectsINTEL(cl_command_queue commandQueue "numObjects", numObjects, "memObjects", memObjects, "numEventsInWaitList", numEventsInWaitList, - "eventWaitList", DebugManager.getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), - "event", DebugManager.getEvents(reinterpret_cast(event), 1)); + "eventWaitList", FileLoggerInstance().getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), + "event", FileLoggerInstance().getEvents(reinterpret_cast(event), 1)); if (retVal != CL_SUCCESS) { return retVal; } @@ -234,8 +234,8 @@ cl_int CL_API_CALL clEnqueueAcquireDX9MediaSurfacesKHR(cl_command_queue commandQ "numObjects", numObjects, "memObjects", memObjects, "numEventsInWaitList", numEventsInWaitList, - "eventWaitList", DebugManager.getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), - "event", DebugManager.getEvents(reinterpret_cast(event), 1)); + "eventWaitList", FileLoggerInstance().getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), + "event", FileLoggerInstance().getEvents(reinterpret_cast(event), 1)); if (retVal != CL_SUCCESS) { return retVal; } @@ -254,8 +254,8 @@ cl_int CL_API_CALL clEnqueueReleaseDX9MediaSurfacesKHR(cl_command_queue commandQ "numObjects", numObjects, "memObjects", memObjects, "numEventsInWaitList", numEventsInWaitList, - "eventWaitList", DebugManager.getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), - "event", DebugManager.getEvents(reinterpret_cast(event), 1)); + "eventWaitList", FileLoggerInstance().getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), + "event", FileLoggerInstance().getEvents(reinterpret_cast(event), 1)); if (retVal != CL_SUCCESS) { return retVal; } @@ -426,8 +426,8 @@ cl_int CL_API_CALL clEnqueueAcquireD3D10ObjectsKHR(cl_command_queue commandQueue "numObjects", numObjects, "memObjects", memObjects, "numEventsInWaitList", numEventsInWaitList, - "eventWaitList", DebugManager.getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), - "event", DebugManager.getEvents(reinterpret_cast(event), 1)); + "eventWaitList", FileLoggerInstance().getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), + "event", FileLoggerInstance().getEvents(reinterpret_cast(event), 1)); if (retVal != CL_SUCCESS) { return retVal; } @@ -459,8 +459,8 @@ cl_int CL_API_CALL clEnqueueReleaseD3D10ObjectsKHR(cl_command_queue commandQueue "numObjects", numObjects, "memObjects", memObjects, "numEventsInWaitList", numEventsInWaitList, - "eventWaitList", DebugManager.getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), - "event", DebugManager.getEvents(reinterpret_cast(event), 1)); + "eventWaitList", FileLoggerInstance().getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), + "event", FileLoggerInstance().getEvents(reinterpret_cast(event), 1)); if (retVal != CL_SUCCESS) { return retVal; } @@ -631,8 +631,8 @@ cl_int CL_API_CALL clEnqueueAcquireD3D11ObjectsKHR(cl_command_queue commandQueue "numObjects", numObjects, "memObjects", memObjects, "numEventsInWaitList", numEventsInWaitList, - "eventWaitList", DebugManager.getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), - "event", DebugManager.getEvents(reinterpret_cast(event), 1)); + "eventWaitList", FileLoggerInstance().getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), + "event", FileLoggerInstance().getEvents(reinterpret_cast(event), 1)); if (retVal != CL_SUCCESS) { return retVal; } @@ -664,8 +664,8 @@ cl_int CL_API_CALL clEnqueueReleaseD3D11ObjectsKHR(cl_command_queue commandQueue "numObjects", numObjects, "memObjects", memObjects, "numEventsInWaitList", numEventsInWaitList, - "eventWaitList", DebugManager.getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), - "event", DebugManager.getEvents(reinterpret_cast(event), 1)); + "eventWaitList", FileLoggerInstance().getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), + "event", FileLoggerInstance().getEvents(reinterpret_cast(event), 1)); if (retVal != CL_SUCCESS) { return retVal; } diff --git a/runtime/os_interface/windows/wddm_memory_manager.cpp b/runtime/os_interface/windows/wddm_memory_manager.cpp index b494da3820..d74cfc3b24 100644 --- a/runtime/os_interface/windows/wddm_memory_manager.cpp +++ b/runtime/os_interface/windows/wddm_memory_manager.cpp @@ -247,7 +247,7 @@ GraphicsAllocation *WddmMemoryManager::createAllocationFromHandle(osHandle handl return nullptr; } - DebugManager.logAllocation(allocation.get()); + FileLoggerInstance().logAllocation(allocation.get()); return allocation.release(); } diff --git a/runtime/program/build.cpp b/runtime/program/build.cpp index f0fb817d08..7b6c64e91a 100644 --- a/runtime/program/build.cpp +++ b/runtime/program/build.cpp @@ -10,11 +10,11 @@ #include "runtime/device/device.h" #include "runtime/gtpin/gtpin_notify.h" #include "runtime/helpers/validators.h" -#include "runtime/os_interface/debug_settings_manager.h" #include "runtime/platform/platform.h" #include "runtime/program/kernel_info.h" #include "runtime/program/program.h" #include "runtime/source_level_debugger/source_level_debugger.h" +#include "runtime/utilities/logger.h" #include "compiler_options.h" diff --git a/runtime/sharings/gl/cl_gl_api.cpp b/runtime/sharings/gl/cl_gl_api.cpp index 9a9cf010ab..5b2540dc56 100644 --- a/runtime/sharings/gl/cl_gl_api.cpp +++ b/runtime/sharings/gl/cl_gl_api.cpp @@ -204,8 +204,8 @@ cl_int CL_API_CALL clGetGLTextureInfo(cl_mem memobj, cl_gl_texture_info paramNam cl_int retValue = CL_SUCCESS; API_ENTER(&retValue); DBG_LOG_INPUTS("memobj", memobj, "paramName", paramName, "paramValueSize", paramValueSize, "paramValueSize", - DebugManager.infoPointerToString(paramValue, paramValueSize), "paramValueSizeRet", - DebugManager.getInput(paramValueSizeRet, 0)); + FileLoggerInstance().infoPointerToString(paramValue, paramValueSize), "paramValueSizeRet", + FileLoggerInstance().getInput(paramValueSizeRet, 0)); retValue = validateObjects(memobj); if (retValue == CL_SUCCESS) { auto pMemObj = castToObject(memobj); @@ -224,8 +224,8 @@ cl_int CL_API_CALL clEnqueueAcquireGLObjects(cl_command_queue commandQueue, cl_u API_ENTER(&retVal); DBG_LOG_INPUTS("commandQueue", commandQueue, "numObjects", numObjects, "memObjects", memObjects, "numEventsInWaitList", numEventsInWaitList, "eventWaitList", - DebugManager.getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), "event", - DebugManager.getEvents(reinterpret_cast(event), 1)); + FileLoggerInstance().getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), "event", + FileLoggerInstance().getEvents(reinterpret_cast(event), 1)); CommandQueue *pCommandQueue = nullptr; retVal = validateObjects(WithCastToInternal(commandQueue, &pCommandQueue), EventWaitList(numEventsInWaitList, eventWaitList)); @@ -261,8 +261,8 @@ cl_int CL_API_CALL clEnqueueReleaseGLObjects(cl_command_queue commandQueue, cl_u API_ENTER(&retVal); DBG_LOG_INPUTS("commandQueue", commandQueue, "numObjects", numObjects, "memObjects", memObjects, "numEventsInWaitList", numEventsInWaitList, "eventWaitList", - DebugManager.getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), "event", - DebugManager.getEvents(reinterpret_cast(event), 1)); + FileLoggerInstance().getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), "event", + FileLoggerInstance().getEvents(reinterpret_cast(event), 1)); CommandQueue *pCommandQueue = nullptr; retVal = validateObjects(WithCastToInternal(commandQueue, &pCommandQueue), EventWaitList(numEventsInWaitList, eventWaitList)); @@ -307,8 +307,8 @@ cl_int CL_API_CALL clGetGLContextInfoKHR(const cl_context_properties *properties cl_int retVal = CL_SUCCESS; API_ENTER(&retVal); DBG_LOG_INPUTS("properties", properties, "paramName", paramName, "paramValueSize", paramValueSize, "paramValue", - DebugManager.infoPointerToString(paramValue, paramValueSize), "paramValueSizeRet", - DebugManager.getInput(paramValueSizeRet, 0)); + FileLoggerInstance().infoPointerToString(paramValue, paramValueSize), "paramValueSizeRet", + FileLoggerInstance().getInput(paramValueSizeRet, 0)); GetInfoHelper info(paramValue, paramValueSize, paramValueSizeRet); uint32_t GLHGLRCHandle = 0; diff --git a/runtime/sharings/va/cl_va_api.cpp b/runtime/sharings/va/cl_va_api.cpp index 03ff30e755..e5ce7391b0 100644 --- a/runtime/sharings/va/cl_va_api.cpp +++ b/runtime/sharings/va/cl_va_api.cpp @@ -88,10 +88,10 @@ clEnqueueAcquireVA_APIMediaSurfacesINTEL(cl_command_queue commandQueue, API_ENTER(&status); DBG_LOG_INPUTS("commandQueue", commandQueue, "numObjects", numObjects, - "memObjects", DebugManager.getMemObjects(reinterpret_cast(memObjects), numObjects), + "memObjects", FileLoggerInstance().getMemObjects(reinterpret_cast(memObjects), numObjects), "numEventsInWaitList", numEventsInWaitList, - "eventWaitList", DebugManager.getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), - "event", DebugManager.getEvents(reinterpret_cast(event), 1)); + "eventWaitList", FileLoggerInstance().getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), + "event", FileLoggerInstance().getEvents(reinterpret_cast(event), 1)); CommandQueue *pCommandQueue = nullptr; @@ -115,10 +115,10 @@ clEnqueueReleaseVA_APIMediaSurfacesINTEL(cl_command_queue commandQueue, API_ENTER(&status); DBG_LOG_INPUTS("commandQueue", commandQueue, "numObjects", numObjects, - "memObjects", DebugManager.getMemObjects(reinterpret_cast(memObjects), numObjects), + "memObjects", FileLoggerInstance().getMemObjects(reinterpret_cast(memObjects), numObjects), "numEventsInWaitList", numEventsInWaitList, - "eventWaitList", DebugManager.getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), - "event", DebugManager.getEvents(reinterpret_cast(event), 1)); + "eventWaitList", FileLoggerInstance().getEvents(reinterpret_cast(eventWaitList), numEventsInWaitList), + "event", FileLoggerInstance().getEvents(reinterpret_cast(event), 1)); CommandQueue *pCommandQueue = nullptr; diff --git a/runtime/utilities/CMakeLists.txt b/runtime/utilities/CMakeLists.txt index c050a68483..a10de85fe8 100644 --- a/runtime/utilities/CMakeLists.txt +++ b/runtime/utilities/CMakeLists.txt @@ -7,6 +7,8 @@ set(RUNTIME_SRCS_UTILITIES_BASE ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt ${CMAKE_CURRENT_SOURCE_DIR}/api_intercept.h + ${CMAKE_CURRENT_SOURCE_DIR}/logger.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/logger.h ${CMAKE_CURRENT_SOURCE_DIR}/perf_profiler.cpp ${CMAKE_CURRENT_SOURCE_DIR}/perf_profiler.h ${CMAKE_CURRENT_SOURCE_DIR}/tag_allocator.h diff --git a/runtime/utilities/api_intercept.h b/runtime/utilities/api_intercept.h index 64816834e5..f5b5a3d26e 100644 --- a/runtime/utilities/api_intercept.h +++ b/runtime/utilities/api_intercept.h @@ -6,11 +6,11 @@ */ #pragma once -#include "runtime/os_interface/debug_settings_manager.h" +#include "runtime/utilities/logger.h" #include "runtime/utilities/perf_profiler.h" #define API_ENTER(retValPointer) \ - DebugSettingsApiEnterWrapper ApiWrapperForSingleCall(__FUNCTION__, retValPointer) + LoggerApiEnterWrapper::enabled()> ApiWrapperForSingleCall(__FUNCTION__, retValPointer) #define SYSTEM_ENTER() #define SYSTEM_LEAVE(id) #define WAIT_ENTER() diff --git a/runtime/utilities/logger.cpp b/runtime/utilities/logger.cpp new file mode 100644 index 0000000000..230bd652f8 --- /dev/null +++ b/runtime/utilities/logger.cpp @@ -0,0 +1,331 @@ +/* + * Copyright (C) 2019 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "runtime/utilities/logger.h" + +#include "runtime/event/event.h" +#include "runtime/helpers/dispatch_info.h" +#include "runtime/helpers/timestamp_packet.h" +#include "runtime/kernel/kernel.h" +#include "runtime/mem_obj/mem_obj.h" +#include "runtime/os_interface/debug_settings_manager.h" + +#include +#include + +namespace NEO { + +FileLogger &FileLoggerInstance() { + static FileLogger fileLoggerInstance(std::string("igdrcl.log"), DebugManager.flags); + return fileLoggerInstance; +} + +template +FileLogger::FileLogger(std::string filename, const DebugVariables &flags) { + logFileName = filename; + std::remove(logFileName.c_str()); + + dumpKernels = flags.DumpKernels.get(); + dumpKernelArgsEnabled = flags.DumpKernelArgs.get(); + logApiCalls = flags.LogApiCalls.get(); + logAllocationMemoryPool = flags.LogAllocationMemoryPool.get(); +} + +template +FileLogger::~FileLogger() = default; + +template +void FileLogger::writeToFile(std::string filename, const char *str, size_t length, std::ios_base::openmode mode) { + std::ofstream outFile(filename, mode); + if (outFile.is_open()) { + outFile.write(str, length); + outFile.close(); + } +} + +template +void FileLogger::dumpKernel(const std::string &name, const std::string &src) { + if (false == enabled()) { + return; + } + + if (dumpKernels) { + DBG_LOG(LogApiCalls, "Kernel size", src.size(), src.c_str()); + writeToFile(name + ".txt", src.c_str(), src.size(), std::ios::trunc); + } +} + +template +void FileLogger::logApiCall(const char *function, bool enter, int32_t errorCode) { + if (false == enabled()) { + return; + } + + if (logApiCalls) { + std::unique_lock theLock(mtx); + std::thread::id thisThread = std::this_thread::get_id(); + + std::stringstream ss; + ss << "ThreadID: " << thisThread << " "; + if (enter) + ss << "Function Enter: "; + else + ss << "Function Leave (" << errorCode << "): "; + ss << function << std::endl; + + auto str = ss.str(); + writeToFile(logFileName, str.c_str(), str.size(), std::ios::app); + } +} + +template +void FileLogger::logAllocation(GraphicsAllocation const *graphicsAllocation) { + if (false == enabled()) { + return; + } + + if (logAllocationMemoryPool) { + std::thread::id thisThread = std::this_thread::get_id(); + + std::stringstream ss; + ss << " ThreadID: " << thisThread; + ss << " AllocationType: " << getAllocationTypeString(graphicsAllocation); + ss << " MemoryPool: " << graphicsAllocation->getMemoryPool(); + ss << graphicsAllocation->getAllocationInfoString(); + ss << std::endl; + + auto str = ss.str(); + + std::unique_lock theLock(mtx); + writeToFile(logFileName, str.c_str(), str.size(), std::ios::app); + } +} + +template +size_t FileLogger::getInput(const size_t *input, int32_t index) { + if (enabled() == false) + return 0; + return input != nullptr ? input[index] : 0; +} + +template +const std::string FileLogger::getEvents(const uintptr_t *input, uint32_t numOfEvents) { + if (false == enabled()) { + return ""; + } + + std::stringstream os; + for (uint32_t i = 0; i < numOfEvents; i++) { + if (input != nullptr) { + cl_event event = ((cl_event *)input)[i]; + os << "cl_event " << event << ", Event " << (Event *)event << ", "; + } + } + return os.str(); +} + +template +const std::string FileLogger::getMemObjects(const uintptr_t *input, uint32_t numOfObjects) { + if (false == enabled()) { + return ""; + } + + std::stringstream os; + for (uint32_t i = 0; i < numOfObjects; i++) { + if (input != nullptr) { + cl_mem mem = const_cast(reinterpret_cast(input)[i]); + os << "cl_mem " << mem << ", MemObj " << static_cast(mem) << ", "; + } + } + return os.str(); +} + +template +void FileLogger::dumpBinaryProgram(int32_t numDevices, const size_t *lengths, const unsigned char **binaries) { + if (false == enabled()) { + return; + } + + if (dumpKernels) { + if (lengths != nullptr && binaries != nullptr && + lengths[0] != 0 && binaries[0] != nullptr) { + std::unique_lock theLock(mtx); + writeToFile("programBinary.bin", reinterpret_cast(binaries[0]), lengths[0], std::ios::trunc | std::ios::binary); + } + } +} + +template +void FileLogger::dumpKernelArgs(const Kernel *kernel) { + if (false == enabled()) { + return; + } + if (dumpKernelArgsEnabled && kernel != nullptr) { + std::unique_lock theLock(mtx); + std::ofstream outFile; + + for (unsigned int i = 0; i < kernel->getKernelInfo().kernelArgInfo.size(); i++) { + std::string type; + std::string fileName; + const char *ptr = nullptr; + size_t size = 0; + uint64_t flags = 0; + std::unique_ptr argVal = nullptr; + + auto &argInfo = kernel->getKernelInfo().kernelArgInfo[i]; + + if (argInfo.addressQualifier == CL_KERNEL_ARG_ADDRESS_LOCAL) { + type = "local"; + } else if (argInfo.typeStr.find("image") != std::string::npos) { + type = "image"; + auto clMem = (const cl_mem)kernel->getKernelArg(i); + auto memObj = castToObject(clMem); + if (memObj != nullptr) { + ptr = static_cast(memObj->getCpuAddress()); + size = memObj->getSize(); + flags = memObj->getMemoryPropertiesFlags(); + } + } else if (argInfo.typeStr.find("sampler") != std::string::npos) { + type = "sampler"; + } else if (argInfo.typeStr.find("*") != std::string::npos) { + type = "buffer"; + auto clMem = (const cl_mem)kernel->getKernelArg(i); + auto memObj = castToObject(clMem); + if (memObj != nullptr) { + ptr = static_cast(memObj->getCpuAddress()); + size = memObj->getSize(); + flags = memObj->getMemoryPropertiesFlags(); + } + } else { + type = "immediate"; + auto crossThreadData = kernel->getCrossThreadData(); + auto crossThreadDataSize = kernel->getCrossThreadDataSize(); + argVal = std::unique_ptr(new char[crossThreadDataSize]); + + size_t totalArgSize = 0; + for (const auto &kernelArgPatchInfo : argInfo.kernelArgPatchInfoVector) { + auto pSource = ptrOffset(crossThreadData, kernelArgPatchInfo.crossthreadOffset); + auto pDestination = ptrOffset(argVal.get(), kernelArgPatchInfo.sourceOffset); + memcpy_s(pDestination, kernelArgPatchInfo.size, pSource, kernelArgPatchInfo.size); + totalArgSize += kernelArgPatchInfo.size; + } + size = totalArgSize; + ptr = argVal.get(); + } + + if (ptr && size) { + fileName = kernel->getKernelInfo().name + "_arg_" + std::to_string(i) + "_" + type + "_size_" + std::to_string(size) + "_flags_" + std::to_string(flags) + ".bin"; + writeToFile(fileName, ptr, size, std::ios::trunc | std::ios::binary); + } + } + } +} + +template +void FileLogger::dumpKernelArgs(const MultiDispatchInfo *multiDispatchInfo) { + if (enabled() == false) { + return; + } + + if (dumpKernelArgsEnabled == false || multiDispatchInfo == nullptr) { + return; + } + + for (auto &dispatchInfo : *multiDispatchInfo) { + dumpKernelArgs(dispatchInfo.getKernel()); + } +} + +template +const char *FileLogger::getAllocationTypeString(GraphicsAllocation const *graphicsAllocation) { + if (false == enabled()) { + return nullptr; + } + + auto type = graphicsAllocation->getAllocationType(); + + switch (type) { + case GraphicsAllocation::AllocationType::BUFFER: + return "BUFFER"; + case GraphicsAllocation::AllocationType::BUFFER_COMPRESSED: + return "BUFFER_COMPRESSED"; + case GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY: + return "BUFFER_HOST_MEMORY"; + case GraphicsAllocation::AllocationType::COMMAND_BUFFER: + return "COMMAND_BUFFER"; + case GraphicsAllocation::AllocationType::CONSTANT_SURFACE: + return "CONSTANT_SURFACE"; + case GraphicsAllocation::AllocationType::DEVICE_QUEUE_BUFFER: + return "DEVICE_QUEUE_BUFFER"; + case GraphicsAllocation::AllocationType::EXTERNAL_HOST_PTR: + return "EXTERNAL_HOST_PTR"; + case GraphicsAllocation::AllocationType::FILL_PATTERN: + return "FILL_PATTERN"; + case GraphicsAllocation::AllocationType::GLOBAL_SURFACE: + return "GLOBAL_SURFACE"; + case GraphicsAllocation::AllocationType::IMAGE: + return "IMAGE"; + case GraphicsAllocation::AllocationType::INDIRECT_OBJECT_HEAP: + return "INDIRECT_OBJECT_HEAP"; + case GraphicsAllocation::AllocationType::INSTRUCTION_HEAP: + return "INSTRUCTION_HEAP"; + case GraphicsAllocation::AllocationType::INTERNAL_HEAP: + return "INTERNAL_HEAP"; + case GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY: + return "INTERNAL_HOST_MEMORY"; + case GraphicsAllocation::AllocationType::KERNEL_ISA: + return "KERNEL_ISA"; + case GraphicsAllocation::AllocationType::LINEAR_STREAM: + return "LINEAR_STREAM"; + case GraphicsAllocation::AllocationType::MCS: + return "MCS"; + case GraphicsAllocation::AllocationType::PIPE: + return "PIPE"; + case GraphicsAllocation::AllocationType::PREEMPTION: + return "PREEMPTION"; + case GraphicsAllocation::AllocationType::PRINTF_SURFACE: + return "PRINTF_SURFACE"; + case GraphicsAllocation::AllocationType::PRIVATE_SURFACE: + return "PRIVATE_SURFACE"; + case GraphicsAllocation::AllocationType::PROFILING_TAG_BUFFER: + return "PROFILING_TAG_BUFFER"; + case GraphicsAllocation::AllocationType::SCRATCH_SURFACE: + return "SCRATCH_SURFACE"; + case GraphicsAllocation::AllocationType::SHARED_BUFFER: + return "SHARED_BUFFER"; + case GraphicsAllocation::AllocationType::SHARED_CONTEXT_IMAGE: + return "SHARED_CONTEXT_IMAGE"; + case GraphicsAllocation::AllocationType::SHARED_IMAGE: + return "SHARED_IMAGE"; + case GraphicsAllocation::AllocationType::SHARED_RESOURCE_COPY: + return "SHARED_RESOURCE_COPY"; + case GraphicsAllocation::AllocationType::SURFACE_STATE_HEAP: + return "SURFACE_STATE_HEAP"; + case GraphicsAllocation::AllocationType::SVM_CPU: + return "SVM_CPU"; + case GraphicsAllocation::AllocationType::SVM_GPU: + return "SVM_GPU"; + case GraphicsAllocation::AllocationType::SVM_ZERO_COPY: + return "SVM_ZERO_COPY"; + case GraphicsAllocation::AllocationType::TAG_BUFFER: + return "TAG_BUFFER"; + case GraphicsAllocation::AllocationType::TIMESTAMP_PACKET_TAG_BUFFER: + return "TIMESTAMP_PACKET_TAG_BUFFER"; + case GraphicsAllocation::AllocationType::UNKNOWN: + return "UNKNOWN"; + case GraphicsAllocation::AllocationType::WRITE_COMBINED: + return "WRITE_COMBINED"; + default: + return "ILLEGAL_VALUE"; + } +} + +template class FileLogger; +template class FileLogger; +template class FileLogger; + +} // namespace NEO diff --git a/runtime/utilities/logger.h b/runtime/utilities/logger.h new file mode 100644 index 0000000000..ca2ede8acf --- /dev/null +++ b/runtime/utilities/logger.h @@ -0,0 +1,205 @@ +/* + * Copyright (C) 2019 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once +#include "runtime/os_interface/debug_settings_manager.h" + +namespace NEO { +template +class FileLogger { + public: + FileLogger(std::string filename, const DebugVariables &flags); + ~FileLogger(); + + FileLogger(const FileLogger &) = delete; + FileLogger &operator=(const FileLogger &) = delete; + + static constexpr bool enabled() { + return DebugLevel == DebugFunctionalityLevel::Full; + } + + void dumpKernel(const std::string &name, const std::string &src); + void logApiCall(const char *function, bool enter, int32_t errorCode); + void logAllocation(GraphicsAllocation const *graphicsAllocation); + size_t getInput(const size_t *input, int32_t index); + const std::string getEvents(const uintptr_t *input, uint32_t numOfEvents); + const std::string getMemObjects(const uintptr_t *input, uint32_t numOfObjects); + + MOCKABLE_VIRTUAL void writeToFile(std::string filename, const char *str, size_t length, std::ios_base::openmode mode); + + void dumpBinaryProgram(int32_t numDevices, const size_t *lengths, const unsigned char **binaries); + void dumpKernelArgs(const Kernel *kernel); + void dumpKernelArgs(const MultiDispatchInfo *multiDispatchInfo); + + const std::string getSizes(const uintptr_t *input, uint32_t workDim, bool local) { + if (false == enabled()) { + return ""; + } + + std::stringstream os; + std::string workSize; + if (local) { + workSize = "localWorkSize"; + } else { + workSize = "globalWorkSize"; + } + + for (uint32_t i = 0; i < workDim; i++) { + if (input != nullptr) { + os << workSize << "[" << i << "]: \t" << input[i] << "\n"; + } + } + return os.str(); + } + + const std::string infoPointerToString(const void *paramValue, size_t paramSize) { + if (false == enabled()) { + return ""; + } + + std::stringstream os; + if (paramValue) { + switch (paramSize) { + case sizeof(uint32_t): + os << *(uint32_t *)paramValue; + break; + case sizeof(uint64_t): + os << *(uint64_t *)paramValue; + break; + case sizeof(uint8_t): + os << (uint32_t)(*(uint8_t *)paramValue); + break; + default: + break; + } + } + return os.str(); + } + + // Expects pairs of args (even number of args) + template + void logInputs(Types &&... params) { + if (enabled()) { + if (logApiCalls) { + std::unique_lock theLock(mtx); + std::thread::id thisThread = std::this_thread::get_id(); + std::stringstream ss; + ss << "------------------------------\n"; + printInputs(ss, "ThreadID", thisThread, params...); + ss << "------------------------------" << std::endl; + writeToFile(logFileName, ss.str().c_str(), ss.str().length(), std::ios::app); + } + } + } + + template + void logLazyEvaluateArgs(bool predicate, FT &&callable) { + if (enabled()) { + if (predicate) { + callable(); + } + } + } + + template + void log(bool enableLog, Types... params) { + if (enabled()) { + if (enableLog) { + std::unique_lock theLock(mtx); + std::thread::id thisThread = std::this_thread::get_id(); + std::stringstream ss; + print(ss, "ThreadID", thisThread, params...); + writeToFile(logFileName, ss.str().c_str(), ss.str().length(), std::ios::app); + } + } + } + + const char *getLogFileName() { + return logFileName.c_str(); + } + + void setLogFileName(std::string filename) { + logFileName = filename; + } + + const char *getAllocationTypeString(GraphicsAllocation const *graphicsAllocation); + bool peekLogApiCalls() { return logApiCalls; } + + protected: + std::mutex mtx; + std::string logFileName; + bool dumpKernels = false; + bool dumpKernelArgsEnabled = false; + bool logApiCalls = false; + bool logAllocationMemoryPool = false; + + // Required for variadic template with 0 args passed + void printInputs(std::stringstream &ss) {} + + // Prints inputs in format: InputName: InputValue \newline + template + void printInputs(std::stringstream &ss, T1 first, Types... params) { + if (enabled()) { + const size_t argsLeft = sizeof...(params); + + ss << "\t" << first; + if (argsLeft % 2) { + ss << ": "; + } else { + ss << std::endl; + } + printInputs(ss, params...); + } + } + + // Required for variadic template with 0 args passed + void print(std::stringstream &ss) {} + + template + void print(std::stringstream &ss, T1 first, Types... params) { + if (enabled()) { + const size_t argsLeft = sizeof...(params); + + ss << first << " "; + if (argsLeft == 0) { + ss << std::endl; + } + print(ss, params...); + } + } +}; + +extern FileLogger &FileLoggerInstance(); + +template +class LoggerApiEnterWrapper { + public: + LoggerApiEnterWrapper(const char *funcName, const int *errorCode) + : funcName(funcName), errorCode(errorCode) { + if (Enabled) { + FileLoggerInstance().logApiCall(funcName, true, 0); + } + } + ~LoggerApiEnterWrapper() { + if (Enabled) { + FileLoggerInstance().logApiCall(funcName, false, (errorCode != nullptr) ? *errorCode : 0); + } + } + const char *funcName; + const int *errorCode; +}; + +}; // namespace NEO + +#define DBG_LOG_LAZY_EVALUATE_ARGS(LOGGER, PREDICATE, LOG_FUNCTION, ...) \ + LOGGER.logLazyEvaluateArgs(PREDICATE, [&] { LOGGER.LOG_FUNCTION(__VA_ARGS__); }) + +#define DBG_LOG(PREDICATE, ...) \ + DBG_LOG_LAZY_EVALUATE_ARGS(NEO::FileLoggerInstance(), NEO::DebugManager.flags.PREDICATE.get(), log, NEO::DebugManager.flags.PREDICATE.get(), __VA_ARGS__) + +#define DBG_LOG_INPUTS(...) \ + DBG_LOG_LAZY_EVALUATE_ARGS(NEO::FileLoggerInstance(), NEO::FileLoggerInstance().peekLogApiCalls(), logInputs, __VA_ARGS__) diff --git a/unit_tests/os_interface/debug_settings_manager_fixture.h b/unit_tests/os_interface/debug_settings_manager_fixture.h index 8c832acca4..dd169e2411 100644 --- a/unit_tests/os_interface/debug_settings_manager_fixture.h +++ b/unit_tests/os_interface/debug_settings_manager_fixture.h @@ -19,25 +19,6 @@ using namespace std; #undef DECLARE_DEBUG_VARIABLE -class SettingsFileCreator { - public: - SettingsFileCreator(string &content) { - bool settingsFileExists = fileExists(fileName); - if (settingsFileExists) { - remove(fileName.c_str()); - } - - writeDataToFile(fileName.c_str(), content.c_str(), content.size()); - }; - - ~SettingsFileCreator() { - remove(fileName.c_str()); - }; - - private: - string fileName = "igdrcl.config"; -}; - class TestDebugFlagsChecker { public: static bool isEqual(int32_t returnedValue, bool defaultValue) { @@ -63,55 +44,9 @@ class TestDebugSettingsManager : public DebugSettingsManager { using DebugSettingsManager::dumpFlags; using DebugSettingsManager::settingsDumpFileName; - ~TestDebugSettingsManager() { - remove(DebugSettingsManager::logFileName.c_str()); - } SettingsReader *getSettingsReader() { return DebugSettingsManager::readerImpl.get(); } - - void useRealFiles(bool value) { - mockFileSystem = !value; - } - - void writeToFile(std::string filename, - const char *str, - size_t length, - std::ios_base::openmode mode) override { - - savedFiles[filename] << std::string(str, str + length); - if (mockFileSystem == false) { - DebugSettingsManager::writeToFile(filename, str, length, mode); - } - }; - - int32_t createdFilesCount() { - return static_cast(savedFiles.size()); - } - - bool wasFileCreated(std::string filename) { - return savedFiles.find(filename) != savedFiles.end(); - } - - std::string getFileString(std::string filename) { - return savedFiles[filename].str(); - } - - protected: - bool mockFileSystem = true; - std::map savedFiles; -}; - -template -class TestDebugSettingsApiEnterWrapper : public DebugSettingsApiEnterWrapper { - public: - TestDebugSettingsApiEnterWrapper(const char *functionName, int *errCode) : DebugSettingsApiEnterWrapper(functionName, errCode), loggedEnter(false) { - if (DebugFunctionality) { - loggedEnter = true; - } - } - - bool loggedEnter; }; using FullyEnabledTestDebugManager = TestDebugSettingsManager; diff --git a/unit_tests/os_interface/debug_settings_manager_tests.cpp b/unit_tests/os_interface/debug_settings_manager_tests.cpp index 96e902308e..e6135ba23a 100644 --- a/unit_tests/os_interface/debug_settings_manager_tests.cpp +++ b/unit_tests/os_interface/debug_settings_manager_tests.cpp @@ -37,574 +37,7 @@ TEST(DebugSettingsManager, WithDebugFunctionalityHasSettingsReader) { EXPECT_NE(nullptr, debugManager.getSettingsReader()); } -TEST(DebugSettingsManager, WithDebugFunctionalityCreatesAndDumpsToLogFile) { - string settings = "LogApiCalls = 1"; - SettingsFileCreator settingsFile(settings); - - FullyEnabledTestDebugManager debugManager; - if (debugManager.registryReadAvailable()) { - debugManager.setReaderImpl(SettingsReader::create(oclRegPath)); - debugManager.injectSettingsFromReader(); - } - debugManager.logApiCall("searchString", true, 0); - debugManager.logApiCall("searchString2", false, 0); - debugManager.logInputs("searchString3", "any"); - debugManager.logInputs("searchString3", "any", "and more"); - debugManager.log(false, "searchString4"); - - // Log file not created - EXPECT_TRUE(debugManager.wasFileCreated(debugManager.getLogFileName())); - - if (debugManager.wasFileCreated(debugManager.getLogFileName())) { - auto str = debugManager.getFileString(debugManager.getLogFileName()); - EXPECT_TRUE(str.find("searchString") != std::string::npos); - EXPECT_TRUE(str.find("searchString2") != std::string::npos); - EXPECT_TRUE(str.find("searchString3") != std::string::npos); - EXPECT_FALSE(str.find("searchString4") != std::string::npos); - } - - debugManager.log(true, "searchString4"); - - if (debugManager.wasFileCreated(debugManager.getLogFileName())) { - auto str = debugManager.getFileString(debugManager.getLogFileName()); - EXPECT_TRUE(str.find("searchString4") != std::string::npos); - } -} - -TEST(DebugSettingsManager, WithoutDebugFunctionalityDoesNotCreateLogFile) { - string settings = "LogApiCalls = 1"; - SettingsFileCreator settingsFile(settings); - - FullyDisabledTestDebugManager debugManager; - - debugManager.setLogFileName(" "); - // Log file not created - bool logFileCreated = fileExists(debugManager.getLogFileName()); - EXPECT_FALSE(logFileCreated); - - debugManager.logApiCall("searchString", true, 0); - debugManager.logApiCall("searchString2", false, 0); - debugManager.logInputs("searchString3", "any"); - debugManager.logInputs("searchString3", "any", "and more"); - debugManager.log(false, "searchString4"); - - EXPECT_FALSE(debugManager.wasFileCreated(debugManager.getLogFileName())); -} - -TEST(DebugSettingsManager, WithIncorrectFilenameFileNotCreated) { - FullyEnabledTestDebugManager debugManager; - debugManager.useRealFiles(true); - debugManager.writeToFile("", "", 0, std::ios_base::in | std::ios_base::out); -} - -TEST(DebugSettingsManager, WithCorrectFilenameFileCreated) { - std::string testFile = "testfile"; - - FullyEnabledTestDebugManager debugManager; - debugManager.useRealFiles(true); - debugManager.writeToFile(testFile, "test", 4, std::fstream::out); - - EXPECT_TRUE(fileExists(testFile)); - if (fileExists(testFile)) { - std::remove(testFile.c_str()); - } -} - -TEST(DebugSettingsManager, CreatingNewInstanceRemovesOldFile) { - FullyEnabledTestDebugManager debugManager; - debugManager.useRealFiles(true); - debugManager.writeToFile(debugManager.getLogFileName(), "test", 4, std::fstream::out); - - EXPECT_TRUE(fileExists(debugManager.getLogFileName())); - FullyEnabledTestDebugManager debugManager2; - EXPECT_FALSE(fileExists(debugManager.getLogFileName())); -} - -TEST(DebugSettingsManager, WithDebugFunctionalityDoesNotDumpApiCallLogWhenFlagIsFalseButDumpsCustomLogs) { - FullyEnabledTestDebugManager debugManager; - - // Log file not created - bool logFileCreated = fileExists(debugManager.getLogFileName()); - EXPECT_FALSE(logFileCreated); - - debugManager.flags.LogApiCalls.set(false); - - debugManager.logApiCall("searchString", true, 0); - debugManager.logApiCall("searchString2", false, 0); - debugManager.logInputs("searchString3", "any"); - debugManager.logInputs("searchString3", "any", "and more"); - debugManager.log(false, "searchString4"); - - if (debugManager.wasFileCreated(debugManager.getLogFileName())) { - auto str = debugManager.getFileString(debugManager.getLogFileName()); - EXPECT_FALSE(str.find("searchString") != std::string::npos); - EXPECT_FALSE(str.find("searchString2") != std::string::npos); - EXPECT_FALSE(str.find("searchString3") != std::string::npos); - EXPECT_FALSE(str.find("searchString4") != std::string::npos); - } - - // Log still works - debugManager.log(true, "searchString4"); - - if (debugManager.wasFileCreated(debugManager.getLogFileName())) { - auto str = debugManager.getFileString(debugManager.getLogFileName()); - EXPECT_TRUE(str.find("searchString4") != std::string::npos); - } -} - -TEST(DebugSettingsManager, WithDebugFunctionalityGetInputReturnsCorectValue) { - FullyEnabledTestDebugManager debugManager; - // getInput returns 0 - size_t input = 5; - size_t output = debugManager.getInput(&input, 0); - EXPECT_EQ(input, output); -} - -TEST(DebugSettingsManager, WithDebugFunctionalityGetInputNegative) { - FullyEnabledTestDebugManager debugManager; - // getInput returns 0 - size_t output = debugManager.getInput(nullptr, 2); - EXPECT_EQ(0u, output); -} - -TEST(DebugSettingsManager, WithDebugFunctionalityGetSizesReturnsCorectString) { - FullyEnabledTestDebugManager debugManager; - debugManager.flags.LogApiCalls.set(true); - // getSizes returns string - uintptr_t input[3] = {1, 2, 3}; - string lwsSizes = debugManager.getSizes(input, 3, true); - string gwsSizes = debugManager.getSizes(input, 3, false); - string lwsExpected = "localWorkSize[0]: \t1\nlocalWorkSize[1]: \t2\nlocalWorkSize[2]: \t3\n"; - string gwsExpected = "globalWorkSize[0]: \t1\nglobalWorkSize[1]: \t2\nglobalWorkSize[2]: \t3\n"; - EXPECT_EQ(lwsExpected, lwsSizes); - EXPECT_EQ(gwsExpected, gwsSizes); -} - -TEST(DebugSettingsManager, WithDebugFunctionalityGetSizesNegative) { - FullyEnabledTestDebugManager debugManager; - debugManager.flags.LogApiCalls.set(true); - // getSizes returns string - string lwsSizes = debugManager.getSizes(nullptr, 3, true); - string gwsSizes = debugManager.getSizes(nullptr, 3, false); - - EXPECT_EQ(0u, lwsSizes.size()); - EXPECT_EQ(0u, gwsSizes.size()); -} - -TEST(DebugSettingsManager, WithoutDebugFunctionalityGetSizesDoesNotReturnString) { - FullyDisabledTestDebugManager debugManager; - debugManager.flags.LogApiCalls.set(true); - uintptr_t input[3] = {1, 2, 3}; - string lwsSizes = debugManager.getSizes(input, 3, true); - string gwsSizes = debugManager.getSizes(input, 3, false); - EXPECT_EQ(0u, lwsSizes.size()); - EXPECT_EQ(0u, gwsSizes.size()); -} - -TEST(DebugSettingsManager, WithDebugFunctionalityGetEventsReturnsCorectString) { - FullyEnabledTestDebugManager debugManager; - debugManager.flags.LogApiCalls.set(true); - // getEvents returns string - uintptr_t event = 8; - uintptr_t *input[3] = {&event, &event, &event}; - string eventsString = debugManager.getEvents((uintptr_t *)input, 2); - EXPECT_NE(0u, eventsString.size()); -} - -TEST(DebugSettingsManager, WithDebugFunctionalityGetEventsNegative) { - FullyEnabledTestDebugManager debugManager; - // getEvents returns 0 sized string - string event = debugManager.getEvents(nullptr, 2); - EXPECT_EQ(0u, event.size()); -} - -TEST(DebugSettingsManager, GivenDebugManagerWithDebugFunctionalityWhenGetMemObjectsIsCalledThenCorrectStringIsReturned) { - FullyEnabledTestDebugManager debugManager; - debugManager.flags.LogApiCalls.set(true); - MockBuffer buffer; - MemObj *memoryObject = &buffer; - cl_mem clMem = memoryObject; - cl_mem clMemObjects[] = {clMem, clMem}; - cl_uint numObjects = 2; - - string memObjectString = debugManager.getMemObjects(reinterpret_cast(clMemObjects), numObjects); - EXPECT_NE(0u, memObjectString.size()); - stringstream output; - output << "cl_mem " << clMem << ", MemObj " << memoryObject; - EXPECT_THAT(memObjectString, ::testing::HasSubstr(output.str())); -} - -TEST(DebugSettingsManager, GivenDebugManagerWithDebugFunctionalityWhenGetMemObjectsIsCalledWithNullptrThenStringIsEmpty) { - FullyEnabledTestDebugManager debugManager; - string memObjectString = debugManager.getMemObjects(nullptr, 2); - EXPECT_EQ(0u, memObjectString.size()); -} - -TEST(DebugSettingsManager, GivenDebugManagerWithoutDebugFunctionalityWhenGetMemObjectsIsCalledThenCallReturnsImmediately) { - FullyDisabledTestDebugManager debugManager; - string memObjectString = debugManager.getMemObjects(nullptr, 2); - EXPECT_EQ(0u, memObjectString.size()); -} - -TEST(DebugSettingsManager, WithDebugFunctionalityDumpKernel) { - FullyEnabledTestDebugManager debugManager; - string kernelDumpFile = "testDumpKernel"; - - // test kernel dumping - debugManager.flags.DumpKernels.set(true); - debugManager.dumpKernel(kernelDumpFile, "kernel source here"); - debugManager.flags.DumpKernels.set(false); - EXPECT_TRUE(debugManager.wasFileCreated(kernelDumpFile.append(".txt"))); -} - -TEST(DebugSettingsManager, WithoutDebugFunctionalityDumpKernel) { - FullyEnabledTestDebugManager debugManager; - string kernelDumpFile = "testDumpKernel"; - - // test kernel dumping - debugManager.flags.DumpKernels.set(false); - debugManager.dumpKernel(kernelDumpFile, "kernel source here"); - debugManager.flags.DumpKernels.set(false); - EXPECT_FALSE(debugManager.wasFileCreated(kernelDumpFile.append(".txt"))); -} - -TEST(DebugSettingsManager, WithDebugFunctionalityDumpBinary) { - FullyEnabledTestDebugManager debugManager; - debugManager.flags.DumpKernels.set(true); - string programDumpFile = "programBinary.bin"; - size_t length = 4; - unsigned char binary[4]; - const unsigned char *ptrBinary = binary; - debugManager.dumpBinaryProgram(1, &length, &ptrBinary); - debugManager.flags.DumpKernels.set(false); - - EXPECT_TRUE(debugManager.wasFileCreated(programDumpFile)); -} - -TEST(DebugSettingsManager, WithDebugFunctionalityDumpNullBinary) { - FullyEnabledTestDebugManager debugManager; - debugManager.flags.DumpKernels.set(true); - - string programDumpFile = "programBinary.bin"; - size_t length = 4; - debugManager.dumpBinaryProgram(1, &length, nullptr); - debugManager.flags.DumpKernels.set(false); - - EXPECT_FALSE(debugManager.wasFileCreated(programDumpFile)); -} - -TEST(DebugSettingsManager, WithDebugFunctionalityDontDumpKernelsForNullMdi) { - FullyEnabledTestDebugManager debugManager; - debugManager.flags.DumpKernels.set(true); - debugManager.dumpKernelArgs((const MultiDispatchInfo *)nullptr); - debugManager.flags.DumpKernels.set(false); - - EXPECT_EQ(debugManager.createdFilesCount(), 0); -} - -TEST(DebugSettingsManager, WithDebugFunctionalityDontDumpKernelArgsForNullMdi) { - FullyEnabledTestDebugManager debugManager; - debugManager.flags.DumpKernelArgs.set(true); - debugManager.dumpKernelArgs((const MultiDispatchInfo *)nullptr); - debugManager.flags.DumpKernelArgs.set(false); - - EXPECT_EQ(debugManager.createdFilesCount(), 0); -} - -TEST(DebugSettingsManager, WithDebugFunctionalityDumpKernelArgsForMdi) { - - auto kernelInfo = std::make_unique(); - auto device = unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); - MockProgram program(*device->getExecutionEnvironment()); - auto kernel = unique_ptr(new MockKernel(&program, *kernelInfo, *device)); - auto multiDispatchInfo = unique_ptr(new MockMultiDispatchInfo(kernel.get())); - - KernelArgPatchInfo kernelArgPatchInfo; - - kernelArgPatchInfo.size = 32; - kernelArgPatchInfo.sourceOffset = 0; - kernelArgPatchInfo.crossthreadOffset = 32; - - kernelInfo->kernelArgInfo.resize(1); - kernelInfo->kernelArgInfo[0].kernelArgPatchInfoVector.push_back(kernelArgPatchInfo); - - size_t crossThreadDataSize = 64; - auto crossThreadData = unique_ptr(new uint8_t[crossThreadDataSize]); - kernel->setCrossThreadData(crossThreadData.get(), static_cast(crossThreadDataSize)); - - FullyEnabledTestDebugManager debugManager; - debugManager.flags.DumpKernelArgs.set(true); - debugManager.dumpKernelArgs(multiDispatchInfo.get()); - debugManager.flags.DumpKernelArgs.set(false); - - // check if file was created - std::string expectedFile = "_arg_0_immediate_size_32_flags_0.bin"; - EXPECT_TRUE(debugManager.wasFileCreated(expectedFile)); - - // no files should be created for local buffer - EXPECT_EQ(debugManager.createdFilesCount(), 1); -} - -TEST(DebugSettingsManager, WithDebugFunctionalityDumpKernelNullKernel) { - FullyEnabledTestDebugManager debugManager; - debugManager.flags.DumpKernels.set(true); - debugManager.dumpKernelArgs((const Kernel *)nullptr); - debugManager.flags.DumpKernels.set(false); - - EXPECT_EQ(debugManager.createdFilesCount(), 0); -} - -TEST(DebugSettingsManager, WithDebugFunctionalityAndEmptyKernelDontDumpKernelArgs) { - - auto kernelInfo = std::make_unique(); - auto device = unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); - MockProgram program(*device->getExecutionEnvironment()); - auto kernel = unique_ptr(new MockKernel(&program, *kernelInfo, *device)); - - FullyEnabledTestDebugManager debugManager; - debugManager.flags.DumpKernelArgs.set(true); - debugManager.dumpKernelArgs(kernel.get()); - debugManager.flags.DumpKernelArgs.set(false); - - EXPECT_EQ(debugManager.createdFilesCount(), 0); -} - -TEST(DebugSettingsManager, WithDebugFunctionalityDumpKernelArgsImmediate) { - - auto kernelInfo = std::make_unique(); - auto device = unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); - MockProgram program(*device->getExecutionEnvironment()); - auto kernel = unique_ptr(new MockKernel(&program, *kernelInfo, *device)); - - KernelArgPatchInfo kernelArgPatchInfo; - - kernelArgPatchInfo.size = 32; - kernelArgPatchInfo.sourceOffset = 0; - kernelArgPatchInfo.crossthreadOffset = 32; - - kernelInfo->kernelArgInfo.resize(1); - kernelInfo->kernelArgInfo[0].kernelArgPatchInfoVector.push_back(kernelArgPatchInfo); - - size_t crossThreadDataSize = 64; - auto crossThreadData = unique_ptr(new uint8_t[crossThreadDataSize]); - kernel->setCrossThreadData(crossThreadData.get(), static_cast(crossThreadDataSize)); - - FullyEnabledTestDebugManager debugManager; - debugManager.flags.DumpKernelArgs.set(true); - debugManager.dumpKernelArgs(kernel.get()); - debugManager.flags.DumpKernelArgs.set(false); - - // check if file was created - EXPECT_TRUE(debugManager.wasFileCreated("_arg_0_immediate_size_32_flags_0.bin")); - - // no files should be created for local buffer - EXPECT_EQ(debugManager.createdFilesCount(), 1); -} - -TEST(DebugSettingsManager, WithDebugFunctionalityDumpKernelArgsImmediateZeroSize) { - - auto kernelInfo = std::make_unique(); - auto device = unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); - MockProgram program(*device->getExecutionEnvironment()); - auto kernel = unique_ptr(new MockKernel(&program, *kernelInfo, *device)); - - KernelArgPatchInfo kernelArgPatchInfo; - - kernelArgPatchInfo.size = 0; - kernelArgPatchInfo.sourceOffset = 0; - kernelArgPatchInfo.crossthreadOffset = 32; - - kernelInfo->kernelArgInfo.resize(1); - kernelInfo->kernelArgInfo[0].kernelArgPatchInfoVector.push_back(kernelArgPatchInfo); - - size_t crossThreadDataSize = sizeof(64); - auto crossThreadData = unique_ptr(new uint8_t[crossThreadDataSize]); - kernel->setCrossThreadData(crossThreadData.get(), static_cast(crossThreadDataSize)); - - FullyEnabledTestDebugManager debugManager; - debugManager.flags.DumpKernelArgs.set(true); - debugManager.dumpKernelArgs(kernel.get()); - debugManager.flags.DumpKernelArgs.set(false); - - // no files should be created for zero size - EXPECT_EQ(debugManager.createdFilesCount(), 0); -} - -TEST(DebugSettingsManager, WithDebugFunctionalityDumpKernelArgsLocalBuffer) { - - auto kernelInfo = std::make_unique(); - auto device = unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); - MockProgram program(*device->getExecutionEnvironment()); - auto kernel = unique_ptr(new MockKernel(&program, *kernelInfo, *device)); - - KernelArgPatchInfo kernelArgPatchInfo; - - kernelInfo->kernelArgInfo.resize(1); - kernelInfo->kernelArgInfo[0].kernelArgPatchInfoVector.push_back(kernelArgPatchInfo); - kernelInfo->kernelArgInfo[0].addressQualifier = static_cast(CL_KERNEL_ARG_ADDRESS_LOCAL); - - FullyEnabledTestDebugManager debugManager; - debugManager.flags.DumpKernelArgs.set(true); - debugManager.dumpKernelArgs(kernel.get()); - debugManager.flags.DumpKernelArgs.set(false); - - // no files should be created for local buffer - EXPECT_EQ(debugManager.createdFilesCount(), 0); -} - -TEST(DebugSettingsManager, WithDebugFunctionalityDumpKernelArgsBufferNotSet) { - auto kernelInfo = std::make_unique(); - unique_ptr device(MockDevice::createWithNewExecutionEnvironment(nullptr)); - auto context = clUniquePtr(new MockContext(device.get())); - auto program = clUniquePtr(new MockProgram(*device->getExecutionEnvironment(), context.get(), false)); - auto kernel = clUniquePtr(new MockKernel(program.get(), *kernelInfo, *device)); - - KernelArgPatchInfo kernelArgPatchInfo; - - kernelInfo->kernelArgInfo.resize(1); - kernelInfo->kernelArgInfo[0].kernelArgPatchInfoVector.push_back(kernelArgPatchInfo); - kernelInfo->kernelArgInfo[0].typeStr = "uint8 *buffer"; - - kernel->initialize(); - - size_t crossThreadDataSize = sizeof(void *); - auto crossThreadData = unique_ptr(new uint8_t[crossThreadDataSize]); - kernel->setCrossThreadData(crossThreadData.get(), static_cast(crossThreadDataSize)); - - FullyEnabledTestDebugManager debugManager; - debugManager.flags.DumpKernelArgs.set(true); - debugManager.dumpKernelArgs(kernel.get()); - debugManager.flags.DumpKernelArgs.set(false); - - // no files should be created for local buffer - EXPECT_EQ(debugManager.createdFilesCount(), 0); -} - -TEST(DebugSettingsManager, WithDebugFunctionalityDumpKernelArgsBuffer) { - unique_ptr device(MockDevice::createWithNewExecutionEnvironment(nullptr)); - auto context = clUniquePtr(new MockContext(device.get())); - auto buffer = BufferHelper<>::create(context.get()); - cl_mem clObj = buffer; - - auto kernelInfo = std::make_unique(); - auto program = clUniquePtr(new MockProgram(*device->getExecutionEnvironment(), context.get(), false)); - auto kernel = clUniquePtr(new MockKernel(program.get(), *kernelInfo, *device)); - - KernelArgPatchInfo kernelArgPatchInfo; - - kernelInfo->kernelArgInfo.resize(1); - kernelInfo->kernelArgInfo[0].kernelArgPatchInfoVector.push_back(kernelArgPatchInfo); - kernelInfo->kernelArgInfo[0].typeStr = "uint8 *buffer"; - kernelInfo->kernelArgInfo.at(0).isBuffer = true; - - kernel->initialize(); - - size_t crossThreadDataSize = sizeof(void *); - auto crossThreadData = unique_ptr(new uint8_t[crossThreadDataSize]); - kernel->setCrossThreadData(crossThreadData.get(), static_cast(crossThreadDataSize)); - - kernel->setArg(0, clObj); - - FullyEnabledTestDebugManager debugManager; - debugManager.flags.DumpKernelArgs.set(true); - debugManager.dumpKernelArgs(kernel.get()); - debugManager.flags.DumpKernelArgs.set(false); - - buffer->release(); - - // check if file was created - EXPECT_TRUE(debugManager.wasFileCreated("_arg_0_buffer_size_16_flags_1.bin")); - - // no files should be created for local buffer - EXPECT_EQ(debugManager.createdFilesCount(), 1); -} - -TEST(DebugSettingsManager, WithDebugFunctionalityDumpKernelArgsSampler) { - auto kernelInfo = std::make_unique(); - unique_ptr device(MockDevice::createWithNewExecutionEnvironment(nullptr)); - auto context = clUniquePtr(new MockContext(device.get())); - auto program = clUniquePtr(new MockProgram(*device->getExecutionEnvironment(), context.get(), false)); - auto kernel = clUniquePtr(new MockKernel(program.get(), *kernelInfo, *device)); - - KernelArgPatchInfo kernelArgPatchInfo; - - kernelInfo->kernelArgInfo.resize(1); - kernelInfo->kernelArgInfo[0].kernelArgPatchInfoVector.push_back(kernelArgPatchInfo); - kernelInfo->kernelArgInfo[0].typeStr = "sampler test"; - - kernel->initialize(); - - FullyEnabledTestDebugManager debugManager; - debugManager.flags.DumpKernelArgs.set(true); - debugManager.dumpKernelArgs(kernel.get()); - debugManager.flags.DumpKernelArgs.set(false); - - // no files should be created for sampler arg - EXPECT_EQ(debugManager.createdFilesCount(), 0); -} - -TEST(DebugSettingsManager, WithDebugFunctionalityDumpKernelArgsImageNotSet) { - - auto kernelInfo = std::make_unique(); - unique_ptr device(MockDevice::createWithNewExecutionEnvironment(nullptr)); - auto context = clUniquePtr(new MockContext(device.get())); - auto program = clUniquePtr(new MockProgram(*device->getExecutionEnvironment(), context.get(), false)); - auto kernel = clUniquePtr(new MockKernel(program.get(), *kernelInfo, *device)); - - SKernelBinaryHeaderCommon kernelHeader; - char surfaceStateHeap[0x80]; - - kernelHeader.SurfaceStateHeapSize = sizeof(surfaceStateHeap); - kernelInfo->heapInfo.pSsh = surfaceStateHeap; - kernelInfo->heapInfo.pKernelHeader = &kernelHeader; - kernelInfo->usesSsh = true; - - KernelArgPatchInfo kernelArgPatchInfo; - - kernelInfo->kernelArgInfo.resize(1); - kernelInfo->kernelArgInfo[0].kernelArgPatchInfoVector.push_back(kernelArgPatchInfo); - kernelInfo->kernelArgInfo[0].typeStr = "image2d buffer"; - kernelInfo->kernelArgInfo[0].isImage = true; - kernelInfo->kernelArgInfo[0].offsetImgWidth = 0x4; - - kernel->initialize(); - - size_t crossThreadDataSize = sizeof(void *); - auto crossThreadData = unique_ptr(new uint8_t[crossThreadDataSize]); - kernel->setCrossThreadData(crossThreadData.get(), static_cast(crossThreadDataSize)); - - FullyEnabledTestDebugManager debugManager; - debugManager.flags.DumpKernelArgs.set(true); - debugManager.dumpKernelArgs(kernel.get()); - debugManager.flags.DumpKernelArgs.set(false); - - // no files should be created for local buffer - EXPECT_EQ(debugManager.createdFilesCount(), 0); -} - -TEST(DebugSettingsManager, WithDebugFunctionalityDumpBinaryNegativeCases) { - FullyEnabledTestDebugManager debugManager; - debugManager.flags.DumpKernels.set(true); - size_t length = 1; - unsigned char binary[4]; - const unsigned char *ptrBinary = binary; - debugManager.dumpBinaryProgram(1, nullptr, nullptr); - debugManager.dumpBinaryProgram(1, nullptr, &ptrBinary); - debugManager.dumpBinaryProgram(1, &length, nullptr); - length = 0; - debugManager.dumpBinaryProgram(1, &length, &ptrBinary); - debugManager.dumpBinaryProgram(1, &length, nullptr); - - debugManager.flags.DumpKernels.set(false); - - EXPECT_EQ(debugManager.createdFilesCount(), 0); -} - TEST(DebugSettingsManager, WithoutDebugFunctionality) { - string path = "."; - vector files = Directory::getFiles(path); - size_t initialNumberOfFiles = files.size(); - FullyDisabledTestDebugManager debugManager; // Should not be enabled without debug functionality @@ -612,10 +45,6 @@ TEST(DebugSettingsManager, WithoutDebugFunctionality) { // SettingsReader not created EXPECT_EQ(nullptr, debugManager.getSettingsReader()); - // Log file not created - bool logFileCreated = fileExists(debugManager.getLogFileName()); - EXPECT_FALSE(logFileCreated); - // debug variables / flags set to default #define DECLARE_DEBUG_VARIABLE(dataType, variableName, defaultValue, description) \ { \ @@ -624,185 +53,12 @@ TEST(DebugSettingsManager, WithoutDebugFunctionality) { } #include "debug_variables.inl" #undef DECLARE_DEBUG_VARIABLE - - // test kernel dumping - bool kernelDumpCreated = false; - string kernelDumpFile = "testDumpKernel"; - debugManager.flags.DumpKernels.set(true); - debugManager.dumpKernel(kernelDumpFile, "kernel source here"); - debugManager.flags.DumpKernels.set(false); - kernelDumpCreated = fileExists(kernelDumpFile.append(".txt")); - EXPECT_FALSE(kernelDumpCreated); - - // test api logging - debugManager.flags.LogApiCalls.set(true); - debugManager.logApiCall(__FUNCTION__, true, 0); - debugManager.flags.LogApiCalls.set(false); - logFileCreated = fileExists(debugManager.getLogFileName()); - EXPECT_FALSE(logFileCreated); - - // getInput returns 0 - size_t input = 5; - size_t output = debugManager.getInput(&input, 0); - EXPECT_EQ(0u, output); - - // getEvents returns 0-size string - string event = debugManager.getEvents(&input, 0); - EXPECT_EQ(0u, event.size()); - - // getSizes returns 0-size string - string lwsSizes = debugManager.getSizes(&input, 0, true); - string gwsSizes = debugManager.getSizes(&input, 0, false); - EXPECT_EQ(0u, lwsSizes.size()); - EXPECT_EQ(0u, gwsSizes.size()); - - // no programDump file - debugManager.flags.DumpKernels.set(true); - string programDumpFile = "programBinary.bin"; - size_t length = 4; - unsigned char binary[4]; - const unsigned char *ptrBinary = binary; - debugManager.dumpBinaryProgram(1, &length, &ptrBinary); - debugManager.flags.DumpKernels.set(false); - EXPECT_FALSE(debugManager.wasFileCreated(programDumpFile)); - - debugManager.flags.DumpKernelArgs.set(true); - debugManager.dumpKernelArgs((const Kernel *)nullptr); - debugManager.flags.DumpKernelArgs.set(false); - - // test api input logging - debugManager.flags.LogApiCalls.set(true); - debugManager.logInputs("Arg name", "value"); - debugManager.logInputs("int", 5); - debugManager.flags.LogApiCalls.set(false); - logFileCreated = fileExists(debugManager.getLogFileName()); - EXPECT_FALSE(logFileCreated); - - // check Log - debugManager.flags.LogApiCalls.set(true); - debugManager.log(true, "string to be logged"); - debugManager.flags.LogApiCalls.set(false); - logFileCreated = fileExists(debugManager.getLogFileName()); - EXPECT_FALSE(logFileCreated); - - files = Directory::getFiles(path); - size_t finalNumberOfFiles = files.size(); - - EXPECT_EQ(initialNumberOfFiles, finalNumberOfFiles); -} - -TEST(DebugSettingsApiEnterWrapper, WithDebugFunctionality) { - - const char *name = "function"; - int error = 0; - TestDebugSettingsApiEnterWrapper *debugApiWrapper = new TestDebugSettingsApiEnterWrapper(name, nullptr); - - EXPECT_TRUE(debugApiWrapper->loggedEnter); - - delete debugApiWrapper; - - TestDebugSettingsApiEnterWrapper *debugApiWrapper2 = new TestDebugSettingsApiEnterWrapper(name, &error); - - EXPECT_TRUE(debugApiWrapper2->loggedEnter); - - delete debugApiWrapper2; -} - -TEST(DebugSettingsApiEnterWrapper, WithoutDebugFunctionality) { - - const char *name = "function"; - int error = 0; - TestDebugSettingsApiEnterWrapper *debugApiWrapper = new TestDebugSettingsApiEnterWrapper(name, nullptr); - - EXPECT_FALSE(debugApiWrapper->loggedEnter); - - delete debugApiWrapper; - - TestDebugSettingsApiEnterWrapper *debugApiWrapper2 = new TestDebugSettingsApiEnterWrapper(name, &error); - - EXPECT_FALSE(debugApiWrapper2->loggedEnter); - - delete debugApiWrapper2; -} - -TEST(DebugSettingsManager, infoPointerToStringReturnsCorrectString) { - FullyEnabledTestDebugManager debugManager; - - uint64_t value64bit = 64; - string string64bit = debugManager.infoPointerToString(&value64bit, sizeof(uint64_t)); - uint32_t value32bit = 32; - string string32bit = debugManager.infoPointerToString(&value32bit, sizeof(uint32_t)); - uint8_t value8bit = 0; - string string8bit = debugManager.infoPointerToString(&value8bit, sizeof(uint8_t)); - - EXPECT_STREQ("64", string64bit.c_str()); - EXPECT_STREQ("32", string32bit.c_str()); - EXPECT_STREQ("0", string8bit.c_str()); - - string stringNonValue = debugManager.infoPointerToString(nullptr, 56); - EXPECT_STREQ("", stringNonValue.c_str()); - - char valueChar = 0; - stringNonValue = debugManager.infoPointerToString(&valueChar, 56); - EXPECT_STREQ("", stringNonValue.c_str()); -} - -TEST(DebugSettingsManager, givenDisabledDebugFunctionalityWhenLogLazyEvaluateArgsIsCalledThenCallToLambdaIsDropped) { - FullyDisabledTestDebugManager debugManager; - bool wasCalled = false; - debugManager.logLazyEvaluateArgs(true, [&] { wasCalled = true; }); - EXPECT_FALSE(wasCalled); -} - -TEST(DebugSettingsManager, givenDisabledPredicateWhenLogLazyEvaluateArgsIsCalledThenCallToLambdaIsDropped) { - FullyEnabledTestDebugManager debugManager; - bool wasCalled = false; - debugManager.logLazyEvaluateArgs(false, [&] { wasCalled = true; }); - EXPECT_FALSE(wasCalled); -} - -TEST(DebugSettingsManager, givenEnabledPredicateWhenLogLazyEvaluateArgsIsCalledThenCallToLambdaIsExecuted) { - FullyEnabledTestDebugManager debugManager; - bool wasCalled = false; - debugManager.logLazyEvaluateArgs(true, [&] { wasCalled = true; }); - EXPECT_TRUE(wasCalled); -} - -struct DummyEvaluator { - DummyEvaluator(bool &wasCalled) { - wasCalled = true; - } - - operator const char *() { - return ""; - } -}; - -TEST(DebugSettingsManager, givenDisabledPredicateWhenDbgLogLazyEvaluateArgsIsCalledThenInputParametersAreNotEvaluated) { - FullyEnabledTestDebugManager debugManager; - debugManager.flags.LogApiCalls.set(false); - - bool wasCalled = false; - DBG_LOG_LAZY_EVALUATE_ARGS(debugManager, LogApiCalls, log, true, DummyEvaluator(wasCalled)); - EXPECT_FALSE(wasCalled); -} - -TEST(DebugSettingsManager, givenEnabledPredicateWhenDbgLogLazyEvaluateArgsIsCalledThenInputParametersAreEvaluated) { - FullyEnabledTestDebugManager debugManager; - debugManager.flags.LogApiCalls.set(true); - - bool wasCalled = false; - DBG_LOG_LAZY_EVALUATE_ARGS(debugManager, LogApiCalls, log, true, DummyEvaluator(wasCalled)); - EXPECT_TRUE(wasCalled); } TEST(DebugSettingsManager, whenDebugManagerIsDisabledThenDebugFunctionalityIsNotAvailableAtCompileTime) { TestDebugSettingsManager debugManager; static_assert(debugManager.disabled(), ""); - static_assert(false == debugManager.debugLoggingAvailable(), ""); - static_assert(false == debugManager.debugKernelDumpingAvailable(), ""); - static_assert(false == debugManager.kernelArgDumpingAvailable(), ""); static_assert(false == debugManager.registryReadAvailable(), ""); } @@ -810,9 +66,6 @@ TEST(DebugSettingsManager, whenDebugManagerIsFullyEnabledThenAllDebugFunctionali TestDebugSettingsManager debugManager; static_assert(false == debugManager.disabled(), ""); - static_assert(debugManager.debugLoggingAvailable(), ""); - static_assert(debugManager.debugKernelDumpingAvailable(), ""); - static_assert(debugManager.kernelArgDumpingAvailable(), ""); static_assert(debugManager.registryReadAvailable(), ""); } @@ -820,9 +73,6 @@ TEST(DebugSettingsManager, whenOnlyRegKeysAreEnabledThenAllOtherDebugFunctionali TestDebugSettingsManager debugManager; static_assert(false == debugManager.disabled(), ""); - static_assert(false == debugManager.debugLoggingAvailable(), ""); - static_assert(false == debugManager.debugKernelDumpingAvailable(), ""); - static_assert(false == debugManager.kernelArgDumpingAvailable(), ""); static_assert(debugManager.registryReadAvailable(), ""); } @@ -895,85 +145,6 @@ TEST(DebugSettingsManager, givenPrintDebugSettingsEnabledWhenCallingDumpFlagsThe EXPECT_NE(std::string::npos, output.find("Non-default value of debug variable: Enable64kbpages = 1")); } -struct AllocationTypeTestCase { - GraphicsAllocation::AllocationType type; - const char *str; -}; - -AllocationTypeTestCase allocationTypeValues[] = { - {GraphicsAllocation::AllocationType::BUFFER, "BUFFER"}, - {GraphicsAllocation::AllocationType::BUFFER_COMPRESSED, "BUFFER_COMPRESSED"}, - {GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, "BUFFER_HOST_MEMORY"}, - {GraphicsAllocation::AllocationType::COMMAND_BUFFER, "COMMAND_BUFFER"}, - {GraphicsAllocation::AllocationType::CONSTANT_SURFACE, "CONSTANT_SURFACE"}, - {GraphicsAllocation::AllocationType::DEVICE_QUEUE_BUFFER, "DEVICE_QUEUE_BUFFER"}, - {GraphicsAllocation::AllocationType::EXTERNAL_HOST_PTR, "EXTERNAL_HOST_PTR"}, - {GraphicsAllocation::AllocationType::FILL_PATTERN, "FILL_PATTERN"}, - {GraphicsAllocation::AllocationType::GLOBAL_SURFACE, "GLOBAL_SURFACE"}, - {GraphicsAllocation::AllocationType::IMAGE, "IMAGE"}, - {GraphicsAllocation::AllocationType::INDIRECT_OBJECT_HEAP, "INDIRECT_OBJECT_HEAP"}, - {GraphicsAllocation::AllocationType::INSTRUCTION_HEAP, "INSTRUCTION_HEAP"}, - {GraphicsAllocation::AllocationType::INTERNAL_HEAP, "INTERNAL_HEAP"}, - {GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY, "INTERNAL_HOST_MEMORY"}, - {GraphicsAllocation::AllocationType::KERNEL_ISA, "KERNEL_ISA"}, - {GraphicsAllocation::AllocationType::LINEAR_STREAM, "LINEAR_STREAM"}, - {GraphicsAllocation::AllocationType::MCS, "MCS"}, - {GraphicsAllocation::AllocationType::PIPE, "PIPE"}, - {GraphicsAllocation::AllocationType::PREEMPTION, "PREEMPTION"}, - {GraphicsAllocation::AllocationType::PRINTF_SURFACE, "PRINTF_SURFACE"}, - {GraphicsAllocation::AllocationType::PRIVATE_SURFACE, "PRIVATE_SURFACE"}, - {GraphicsAllocation::AllocationType::PROFILING_TAG_BUFFER, "PROFILING_TAG_BUFFER"}, - {GraphicsAllocation::AllocationType::SCRATCH_SURFACE, "SCRATCH_SURFACE"}, - {GraphicsAllocation::AllocationType::SHARED_BUFFER, "SHARED_BUFFER"}, - {GraphicsAllocation::AllocationType::SHARED_CONTEXT_IMAGE, "SHARED_CONTEXT_IMAGE"}, - {GraphicsAllocation::AllocationType::SHARED_IMAGE, "SHARED_IMAGE"}, - {GraphicsAllocation::AllocationType::SHARED_RESOURCE_COPY, "SHARED_RESOURCE_COPY"}, - {GraphicsAllocation::AllocationType::SURFACE_STATE_HEAP, "SURFACE_STATE_HEAP"}, - {GraphicsAllocation::AllocationType::SVM_CPU, "SVM_CPU"}, - {GraphicsAllocation::AllocationType::SVM_GPU, "SVM_GPU"}, - {GraphicsAllocation::AllocationType::SVM_ZERO_COPY, "SVM_ZERO_COPY"}, - {GraphicsAllocation::AllocationType::TAG_BUFFER, "TAG_BUFFER"}, - {GraphicsAllocation::AllocationType::TIMESTAMP_PACKET_TAG_BUFFER, "TIMESTAMP_PACKET_TAG_BUFFER"}, - {GraphicsAllocation::AllocationType::UNKNOWN, "UNKNOWN"}, - {GraphicsAllocation::AllocationType::WRITE_COMBINED, "WRITE_COMBINED"}}; - -class AllocationTypeLogging : public ::testing::TestWithParam {}; - -TEST_P(AllocationTypeLogging, givenGraphicsAllocationTypeWhenConvertingToStringThenCorrectStringIsReturned) { - FullyEnabledTestDebugManager debugManager; - auto input = GetParam(); - - GraphicsAllocation graphicsAllocation(0, input.type, nullptr, 0ull, 0ull, 0, MemoryPool::MemoryNull); - - auto result = debugManager.getAllocationTypeString(&graphicsAllocation); - - EXPECT_STREQ(result, input.str); -} - -INSTANTIATE_TEST_CASE_P(AllAllocationTypes, - AllocationTypeLogging, - ::testing::ValuesIn(allocationTypeValues)); - -TEST(AllocationTypeLoggingSingle, givenGraphicsAllocationTypeWhenConvertingToStringIllegalValueThenILLEGAL_VALUEIsReturned) { - FullyEnabledTestDebugManager debugManager; - - GraphicsAllocation graphicsAllocation(0, static_cast(999), nullptr, 0ull, 0ull, 0, MemoryPool::MemoryNull); - - auto result = debugManager.getAllocationTypeString(&graphicsAllocation); - - EXPECT_STREQ(result, "ILLEGAL_VALUE"); -} - -TEST(AllocationTypeLoggingSingle, givenGraphicsAllocationTypeWhenDebugManagerDisabledThennullptrReturned) { - FullyDisabledTestDebugManager debugManager; - - GraphicsAllocation graphicsAllocation(0, GraphicsAllocation::AllocationType::BUFFER, nullptr, 0ull, 0ull, 0, MemoryPool::MemoryNull); - - auto result = debugManager.getAllocationTypeString(&graphicsAllocation); - - EXPECT_STREQ(result, nullptr); -} - TEST(AllocationInfoLogging, givenBaseGraphicsAllocationWhenGettingImplementationSpecificAllocationInfoThenReturnEmptyInfoString) { GraphicsAllocation graphicsAllocation(0, GraphicsAllocation::AllocationType::UNKNOWN, nullptr, 0ull, 0ull, 0, MemoryPool::MemoryNull); EXPECT_STREQ(graphicsAllocation.getAllocationInfoString().c_str(), ""); diff --git a/unit_tests/os_interface/linux/CMakeLists.txt b/unit_tests/os_interface/linux/CMakeLists.txt index ccc59dbaac..19362041b6 100644 --- a/unit_tests/os_interface/linux/CMakeLists.txt +++ b/unit_tests/os_interface/linux/CMakeLists.txt @@ -8,7 +8,6 @@ set(IGDRCL_SRCS_tests_os_interface_linux ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt ${CMAKE_CURRENT_SOURCE_DIR}/allocator_helper_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/debug_env_reader.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/debug_settings_manager_linux_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/device_command_stream_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/device_factory_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/device_factory_tests.h @@ -30,6 +29,7 @@ set(IGDRCL_SRCS_tests_os_interface_linux ${CMAKE_CURRENT_SOURCE_DIR}/drm_os_memory_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drm_residency_handler_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drm_tests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/file_logger_linux_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/hw_info_config_linux_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/hw_info_config_linux_tests.h ${CMAKE_CURRENT_SOURCE_DIR}/linux_create_command_queue_with_properties_tests.cpp diff --git a/unit_tests/os_interface/linux/debug_settings_manager_linux_tests.cpp b/unit_tests/os_interface/linux/file_logger_linux_tests.cpp similarity index 61% rename from unit_tests/os_interface/linux/debug_settings_manager_linux_tests.cpp rename to unit_tests/os_interface/linux/file_logger_linux_tests.cpp index ae822ecdd5..46a8f7bf76 100644 --- a/unit_tests/os_interface/linux/debug_settings_manager_linux_tests.cpp +++ b/unit_tests/os_interface/linux/file_logger_linux_tests.cpp @@ -8,17 +8,20 @@ #include "runtime/os_interface/debug_settings_manager.h" #include "test.h" #include "unit_tests/mocks/linux/mock_drm_allocation.h" -#include "unit_tests/os_interface/debug_settings_manager_fixture.h" +#include "unit_tests/utilities/file_logger_tests.h" -TEST(DebugSettingsManager, GivenDebugSettingsManagerWithLogAllocationsThenLogsCorrectInfo) { - FullyEnabledTestDebugManager debugManager; +using namespace NEO; + +TEST(FileLogger, GivenLogAllocationMemoryPoolFlagThenLogsCorrectInfo) { + std::string testFile = "testfile"; + DebugVariables flags; + flags.LogAllocationMemoryPool.set(true); + FullyEnabledFileLogger fileLogger(testFile, flags); // Log file not created - bool logFileCreated = fileExists(debugManager.getLogFileName()); + bool logFileCreated = fileExists(fileLogger.getLogFileName()); EXPECT_FALSE(logFileCreated); - debugManager.flags.LogAllocationMemoryPool.set(true); - MockDrmAllocation allocation(GraphicsAllocation::AllocationType::BUFFER, MemoryPool::System64KBPages); MockBufferObject bo; @@ -26,7 +29,7 @@ TEST(DebugSettingsManager, GivenDebugSettingsManagerWithLogAllocationsThenLogsCo allocation.bufferObjects[0] = &bo; - debugManager.logAllocation(&allocation); + fileLogger.logAllocation(&allocation); std::thread::id thisThread = std::this_thread::get_id(); @@ -36,8 +39,8 @@ TEST(DebugSettingsManager, GivenDebugSettingsManagerWithLogAllocationsThenLogsCo std::stringstream memoryPoolCheck; memoryPoolCheck << " MemoryPool: " << allocation.getMemoryPool(); - if (debugManager.wasFileCreated(debugManager.getLogFileName())) { - auto str = debugManager.getFileString(debugManager.getLogFileName()); + if (fileLogger.wasFileCreated(fileLogger.getLogFileName())) { + auto str = fileLogger.getFileString(fileLogger.getLogFileName()); EXPECT_TRUE(str.find(threadIDCheck.str()) != std::string::npos); EXPECT_TRUE(str.find(memoryPoolCheck.str()) != std::string::npos); EXPECT_TRUE(str.find("AllocationType: BUFFER") != std::string::npos); @@ -45,18 +48,18 @@ TEST(DebugSettingsManager, GivenDebugSettingsManagerWithLogAllocationsThenLogsCo } } -TEST(DebugSettingsManager, GivenDebugSettingsManagerWithDrmAllocationWithoutBOThenNoHandleLogged) { - FullyEnabledTestDebugManager debugManager; +TEST(FileLogger, GivenDrmAllocationWithoutBOThenNoHandleLogged) { + std::string testFile = "testfile"; + DebugVariables flags; + flags.LogAllocationMemoryPool.set(true); + FullyEnabledFileLogger fileLogger(testFile, flags); // Log file not created - bool logFileCreated = fileExists(debugManager.getLogFileName()); + bool logFileCreated = fileExists(fileLogger.getLogFileName()); EXPECT_FALSE(logFileCreated); - - debugManager.flags.LogAllocationMemoryPool.set(true); - MockDrmAllocation allocation(GraphicsAllocation::AllocationType::BUFFER, MemoryPool::System64KBPages); - debugManager.logAllocation(&allocation); + fileLogger.logAllocation(&allocation); std::thread::id thisThread = std::this_thread::get_id(); @@ -66,8 +69,8 @@ TEST(DebugSettingsManager, GivenDebugSettingsManagerWithDrmAllocationWithoutBOTh std::stringstream memoryPoolCheck; memoryPoolCheck << " MemoryPool: " << allocation.getMemoryPool(); - if (debugManager.wasFileCreated(debugManager.getLogFileName())) { - auto str = debugManager.getFileString(debugManager.getLogFileName()); + if (fileLogger.wasFileCreated(fileLogger.getLogFileName())) { + auto str = fileLogger.getFileString(fileLogger.getLogFileName()); EXPECT_TRUE(str.find(threadIDCheck.str()) != std::string::npos); EXPECT_TRUE(str.find(memoryPoolCheck.str()) != std::string::npos); EXPECT_TRUE(str.find("AllocationType: BUFFER") != std::string::npos); @@ -75,18 +78,19 @@ TEST(DebugSettingsManager, GivenDebugSettingsManagerWithDrmAllocationWithoutBOTh } } -TEST(DebugSettingsManager, GivenDebugSettingsManagerWithoutLogAllocationsThenAllocationIsNotLogged) { - FullyEnabledTestDebugManager debugManager; +TEST(FileLogger, GivenLogAllocationMemoryPoolFlagSetFalseThenAllocationIsNotLogged) { + std::string testFile = "testfile"; + DebugVariables flags; + flags.LogAllocationMemoryPool.set(false); + FullyEnabledFileLogger fileLogger(testFile, flags); // Log file not created - bool logFileCreated = fileExists(debugManager.getLogFileName()); + bool logFileCreated = fileExists(fileLogger.getLogFileName()); EXPECT_FALSE(logFileCreated); - debugManager.flags.LogAllocationMemoryPool.set(false); - MockDrmAllocation allocation(GraphicsAllocation::AllocationType::BUFFER, MemoryPool::System64KBPages); - debugManager.logAllocation(&allocation); + fileLogger.logAllocation(&allocation); std::thread::id thisThread = std::this_thread::get_id(); @@ -96,8 +100,8 @@ TEST(DebugSettingsManager, GivenDebugSettingsManagerWithoutLogAllocationsThenAll std::stringstream memoryPoolCheck; memoryPoolCheck << " MemoryPool: " << allocation.getMemoryPool(); - if (debugManager.wasFileCreated(debugManager.getLogFileName())) { - auto str = debugManager.getFileString(debugManager.getLogFileName()); + if (fileLogger.wasFileCreated(fileLogger.getLogFileName())) { + auto str = fileLogger.getFileString(fileLogger.getLogFileName()); EXPECT_FALSE(str.find(threadIDCheck.str()) != std::string::npos); EXPECT_FALSE(str.find(memoryPoolCheck.str()) != std::string::npos); EXPECT_FALSE(str.find("AllocationType: BUFFER") != std::string::npos); diff --git a/unit_tests/os_interface/windows/CMakeLists.txt b/unit_tests/os_interface/windows/CMakeLists.txt index 5f3f0409b5..afd9edf86f 100644 --- a/unit_tests/os_interface/windows/CMakeLists.txt +++ b/unit_tests/os_interface/windows/CMakeLists.txt @@ -6,11 +6,11 @@ set(IGDRCL_SRCS_tests_os_interface_windows ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt - ${CMAKE_CURRENT_SOURCE_DIR}/debug_settings_manager_win_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/deferrable_deletion_win_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/device_command_stream_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/device_os_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/driver_info_tests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/file_logger_win_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gdi_dll_fixture.h ${CMAKE_CURRENT_SOURCE_DIR}/gdi_interface_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gmm_memory_tests.cpp diff --git a/unit_tests/os_interface/windows/debug_settings_manager_win_tests.cpp b/unit_tests/os_interface/windows/file_logger_win_tests.cpp similarity index 68% rename from unit_tests/os_interface/windows/debug_settings_manager_win_tests.cpp rename to unit_tests/os_interface/windows/file_logger_win_tests.cpp index fcc68ffedd..30767837f3 100644 --- a/unit_tests/os_interface/windows/debug_settings_manager_win_tests.cpp +++ b/unit_tests/os_interface/windows/file_logger_win_tests.cpp @@ -8,18 +8,21 @@ #include "runtime/gmm_helper/gmm.h" #include "runtime/os_interface/debug_settings_manager.h" #include "test.h" -#include "unit_tests/os_interface/debug_settings_manager_fixture.h" #include "unit_tests/os_interface/windows/mock_wddm_allocation.h" +#include "unit_tests/utilities/file_logger_tests.h" -TEST(DebugSettingsManager, GivenDebugSettingsManagerWithLogAllocationsThenLogsCorrectInfo) { - FullyEnabledTestDebugManager debugManager; +using namespace NEO; + +TEST(FileLogger, GivenLogAllocationMemoryPoolFlagThenLogsCorrectInfo) { + std::string testFile = "testfile"; + DebugVariables flags; + flags.LogAllocationMemoryPool.set(true); + FullyEnabledFileLogger fileLogger(testFile, flags); // Log file not created - bool logFileCreated = fileExists(debugManager.getLogFileName()); + bool logFileCreated = fileExists(fileLogger.getLogFileName()); EXPECT_FALSE(logFileCreated); - debugManager.flags.LogAllocationMemoryPool.set(true); - MockWddmAllocation allocation; allocation.handle = 4; allocation.setAllocationType(GraphicsAllocation::AllocationType::BUFFER); @@ -28,7 +31,7 @@ TEST(DebugSettingsManager, GivenDebugSettingsManagerWithLogAllocationsThenLogsCo allocation.setDefaultGmm(gmm.get()); allocation.getDefaultGmm()->resourceParams.Flags.Info.NonLocalOnly = 0; - debugManager.logAllocation(&allocation); + fileLogger.logAllocation(&allocation); std::thread::id thisThread = std::this_thread::get_id(); @@ -38,8 +41,8 @@ TEST(DebugSettingsManager, GivenDebugSettingsManagerWithLogAllocationsThenLogsCo std::stringstream memoryPoolCheck; memoryPoolCheck << " MemoryPool: " << allocation.getMemoryPool(); - if (debugManager.wasFileCreated(debugManager.getLogFileName())) { - auto str = debugManager.getFileString(debugManager.getLogFileName()); + if (fileLogger.wasFileCreated(fileLogger.getLogFileName())) { + auto str = fileLogger.getFileString(fileLogger.getLogFileName()); EXPECT_TRUE(str.find(threadIDCheck.str()) != std::string::npos); EXPECT_TRUE(str.find("Handle: 4") != std::string::npos); EXPECT_TRUE(str.find(memoryPoolCheck.str()) != std::string::npos); @@ -47,15 +50,16 @@ TEST(DebugSettingsManager, GivenDebugSettingsManagerWithLogAllocationsThenLogsCo } } -TEST(DebugSettingsManager, GivenDebugSettingsManagerWithoutLogAllocationsThenAllocationIsNotLogged) { - FullyEnabledTestDebugManager debugManager; +TEST(FileLogger, GivenLogAllocationMemoryPoolFlagSetFalseThenAllocationIsNotLogged) { + std::string testFile = "testfile"; + DebugVariables flags; + flags.LogAllocationMemoryPool.set(false); + FullyEnabledFileLogger fileLogger(testFile, flags); // Log file not created - bool logFileCreated = fileExists(debugManager.getLogFileName()); + bool logFileCreated = fileExists(fileLogger.getLogFileName()); EXPECT_FALSE(logFileCreated); - debugManager.flags.LogAllocationMemoryPool.set(false); - MockWddmAllocation allocation; allocation.handle = 4; allocation.setAllocationType(GraphicsAllocation::AllocationType::BUFFER); @@ -64,7 +68,7 @@ TEST(DebugSettingsManager, GivenDebugSettingsManagerWithoutLogAllocationsThenAll allocation.setDefaultGmm(gmm.get()); allocation.getDefaultGmm()->resourceParams.Flags.Info.NonLocalOnly = 0; - debugManager.logAllocation(&allocation); + fileLogger.logAllocation(&allocation); std::thread::id thisThread = std::this_thread::get_id(); @@ -74,8 +78,8 @@ TEST(DebugSettingsManager, GivenDebugSettingsManagerWithoutLogAllocationsThenAll std::stringstream memoryPoolCheck; memoryPoolCheck << " MemoryPool: " << allocation.getMemoryPool(); - if (debugManager.wasFileCreated(debugManager.getLogFileName())) { - auto str = debugManager.getFileString(debugManager.getLogFileName()); + if (fileLogger.wasFileCreated(fileLogger.getLogFileName())) { + auto str = fileLogger.getFileString(fileLogger.getLogFileName()); EXPECT_FALSE(str.find(threadIDCheck.str()) != std::string::npos); EXPECT_FALSE(str.find("Handle: 4") != std::string::npos); EXPECT_FALSE(str.find(memoryPoolCheck.str()) != std::string::npos); diff --git a/unit_tests/utilities/CMakeLists.txt b/unit_tests/utilities/CMakeLists.txt index 65b00c9049..bee8fbe5bf 100644 --- a/unit_tests/utilities/CMakeLists.txt +++ b/unit_tests/utilities/CMakeLists.txt @@ -9,6 +9,8 @@ set(IGDRCL_SRCS_tests_utilities ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/debug_file_reader_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/debug_file_reader_tests.inl ${CMAKE_CURRENT_SOURCE_DIR}/debug_settings_reader_tests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/file_logger_tests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/file_logger_tests.h ${CMAKE_CURRENT_SOURCE_DIR}/perf_profiler.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tag_allocator_tests.cpp ) diff --git a/unit_tests/utilities/debug_settings_reader_tests.cpp b/unit_tests/utilities/debug_settings_reader_tests.cpp index 115b9bc7ab..c5512382e1 100644 --- a/unit_tests/utilities/debug_settings_reader_tests.cpp +++ b/unit_tests/utilities/debug_settings_reader_tests.cpp @@ -25,6 +25,29 @@ TEST(SettingsReader, Create) { delete reader; } +TEST(SettingsReader, GivenNoSettingsFileWhenCreatingSettingsReaderThenOsReaderIsCreated) { + remove(SettingsReader::settingsFileName); + auto fileReader = std::unique_ptr(SettingsReader::createFileReader()); + EXPECT_EQ(nullptr, fileReader.get()); + + auto osReader = std::unique_ptr(SettingsReader::create(oclRegPath)); + EXPECT_NE(nullptr, osReader.get()); +} + +TEST(SettingsReader, GivenSettingsFileExistsWhenCreatingSettingsReaderThenFileReaderIsCreated) { + bool settingsFileExists = fileExists(SettingsReader::settingsFileName); + if (!settingsFileExists) { + const char data[] = "ProductFamilyOverride = test"; + writeDataToFile(SettingsReader::settingsFileName, &data, sizeof(data)); + } + auto reader = std::unique_ptr(SettingsReader::create(oclRegPath)); + EXPECT_NE(nullptr, reader.get()); + string defaultValue("unk"); + EXPECT_STREQ("test", reader->getSetting("ProductFamilyOverride", defaultValue).c_str()); + + remove(SettingsReader::settingsFileName); +} + TEST(SettingsReader, CreateFileReader) { bool settingsFileExists = fileExists(SettingsReader::settingsFileName); if (!settingsFileExists) { diff --git a/unit_tests/utilities/file_logger_tests.cpp b/unit_tests/utilities/file_logger_tests.cpp new file mode 100644 index 0000000000..7a0d8af47c --- /dev/null +++ b/unit_tests/utilities/file_logger_tests.cpp @@ -0,0 +1,984 @@ +/* + * Copyright (C) 2019 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "unit_tests/utilities/file_logger_tests.h" + +#include "core/unit_tests/helpers/debug_manager_state_restore.h" +#include "core/unit_tests/utilities/base_object_utils.h" +#include "runtime/utilities/logger.h" +#include "unit_tests/fixtures/buffer_fixture.h" +#include "unit_tests/fixtures/image_fixture.h" +#include "unit_tests/mocks/mock_buffer.h" +#include "unit_tests/mocks/mock_context.h" +#include "unit_tests/mocks/mock_kernel.h" +#include "unit_tests/mocks/mock_mdi.h" +#include "unit_tests/mocks/mock_program.h" + +#include +#include +#include +#include + +using namespace std; +using namespace NEO; + +TEST(FileLogger, WithDebugFunctionality) { + DebugVariables flags; + FullyEnabledFileLogger fileLogger(std::string(""), flags); + + EXPECT_TRUE(fileLogger.enabled()); +} + +TEST(FileLogger, GivenFileLoggerWhenSettingFileNameThenCorrectFilenameIsSet) { + DebugVariables flags; + FullyEnabledFileLogger fileLogger(std::string(""), flags); + fileLogger.setLogFileName("new_filename"); + EXPECT_STREQ("new_filename", fileLogger.getLogFileName()); +} + +TEST(FileLogger, WithDebugFunctionalityCreatesAndDumpsToLogFile) { + DebugVariables flags; + flags.LogApiCalls.set(true); + FullyEnabledFileLogger fileLogger(std::string("test.log"), flags); + + fileLogger.logApiCall("searchString", true, 0); + fileLogger.logApiCall("searchString2", false, 0); + fileLogger.logInputs("searchString3", "any"); + fileLogger.logInputs("searchString3", "any", "and more"); + fileLogger.log(false, "searchString4"); + + // Log file not created + EXPECT_TRUE(fileLogger.wasFileCreated(fileLogger.getLogFileName())); + + if (fileLogger.wasFileCreated(fileLogger.getLogFileName())) { + auto str = fileLogger.getFileString(fileLogger.getLogFileName()); + EXPECT_TRUE(str.find("searchString") != std::string::npos); + EXPECT_TRUE(str.find("searchString2") != std::string::npos); + EXPECT_TRUE(str.find("searchString3") != std::string::npos); + EXPECT_FALSE(str.find("searchString4") != std::string::npos); + } + + fileLogger.log(true, "searchString4"); + + if (fileLogger.wasFileCreated(fileLogger.getLogFileName())) { + auto str = fileLogger.getFileString(fileLogger.getLogFileName()); + EXPECT_TRUE(str.find("searchString4") != std::string::npos); + } +} + +TEST(FileLogger, WithoutDebugFunctionalityDoesNotCreateLogFile) { + DebugVariables flags; + flags.LogApiCalls.set(true); + + FullyDisabledFileLogger fileLogger(std::string(" "), flags); + + // Log file not created + bool logFileCreated = fileExists(fileLogger.getLogFileName()); + EXPECT_FALSE(logFileCreated); + + fileLogger.logApiCall("searchString", true, 0); + fileLogger.logApiCall("searchString2", false, 0); + fileLogger.logInputs("searchString3", "any"); + fileLogger.logInputs("searchString3", "any", "and more"); + fileLogger.log(false, "searchString4"); + + EXPECT_FALSE(fileLogger.wasFileCreated(fileLogger.getLogFileName())); +} + +TEST(FileLogger, WithIncorrectFilenameFileNotCreated) { + DebugVariables flags; + flags.LogApiCalls.set(true); + FullyEnabledFileLogger fileLogger(std::string("test.log"), flags); + fileLogger.useRealFiles(true); + fileLogger.writeToFile("", "", 0, std::ios_base::in | std::ios_base::out); + + EXPECT_FALSE(fileLogger.wasFileCreated(fileLogger.getLogFileName())); +} + +TEST(FileLogger, WithCorrectFilenameFileCreated) { + std::string testFile = "testfile"; + DebugVariables flags; + FullyEnabledFileLogger fileLogger(testFile, flags); + fileLogger.useRealFiles(true); + fileLogger.writeToFile(testFile, "test", 4, std::fstream::out); + + EXPECT_TRUE(fileExists(testFile)); + if (fileExists(testFile)) { + std::remove(testFile.c_str()); + } +} + +TEST(FileLogger, CreatingNewInstanceRemovesOldFile) { + std::string testFile = "testfile"; + DebugVariables flags; + flags.LogApiCalls.set(true); + FullyEnabledFileLogger fileLogger(testFile, flags); + fileLogger.useRealFiles(true); + fileLogger.writeToFile(fileLogger.getLogFileName(), "test", 4, std::fstream::out); + + EXPECT_TRUE(fileExists(fileLogger.getLogFileName())); + FullyEnabledFileLogger fileLogger2(testFile, flags); + EXPECT_FALSE(fileExists(fileLogger.getLogFileName())); +} + +TEST(FileLogger, WithDebugFunctionalityDoesNotDumpApiCallLogWhenFlagIsFalseButDumpsCustomLogs) { + std::string testFile = "testfile"; + DebugVariables flags; + flags.LogApiCalls.set(false); + + FullyEnabledFileLogger fileLogger(testFile, flags); + + // Log file not created + bool logFileCreated = fileExists(fileLogger.getLogFileName()); + EXPECT_FALSE(logFileCreated); + + fileLogger.logApiCall("searchString", true, 0); + fileLogger.logApiCall("searchString2", false, 0); + fileLogger.logInputs("searchString3", "any"); + fileLogger.logInputs("searchString3", "any", "and more"); + fileLogger.log(false, "searchString4"); + + if (fileLogger.wasFileCreated(fileLogger.getLogFileName())) { + auto str = fileLogger.getFileString(fileLogger.getLogFileName()); + EXPECT_FALSE(str.find("searchString\n") != std::string::npos); + EXPECT_FALSE(str.find("searchString2\n") != std::string::npos); + EXPECT_FALSE(str.find("searchString3") != std::string::npos); + EXPECT_FALSE(str.find("searchString4") != std::string::npos); + } + + // Log still works + fileLogger.log(true, "searchString4"); + + if (fileLogger.wasFileCreated(fileLogger.getLogFileName())) { + auto str = fileLogger.getFileString(fileLogger.getLogFileName()); + EXPECT_TRUE(str.find("searchString4") != std::string::npos); + } +} + +TEST(FileLogger, WithDebugFunctionalityGetInputReturnsCorectValue) { + std::string testFile = "testfile"; + DebugVariables flags; + + FullyEnabledFileLogger fileLogger(testFile, flags); + + // getInput returns 0 + size_t input = 5; + size_t output = fileLogger.getInput(&input, 0); + EXPECT_EQ(input, output); +} + +TEST(FileLogger, WithDebugFunctionalityGetInputNegative) { + std::string testFile = "testfile"; + DebugVariables flags; + + FullyEnabledFileLogger fileLogger(testFile, flags); + // getInput returns 0 + size_t output = fileLogger.getInput(nullptr, 2); + EXPECT_EQ(0u, output); +} + +TEST(FileLogger, WithDebugFunctionalityGetSizesReturnsCorectString) { + std::string testFile = "testfile"; + DebugVariables flags; + flags.LogApiCalls.set(true); + + FullyEnabledFileLogger fileLogger(testFile, flags); + // getSizes returns string + uintptr_t input[3] = {1, 2, 3}; + string lwsSizes = fileLogger.getSizes(input, 3, true); + string gwsSizes = fileLogger.getSizes(input, 3, false); + string lwsExpected = "localWorkSize[0]: \t1\nlocalWorkSize[1]: \t2\nlocalWorkSize[2]: \t3\n"; + string gwsExpected = "globalWorkSize[0]: \t1\nglobalWorkSize[1]: \t2\nglobalWorkSize[2]: \t3\n"; + EXPECT_EQ(lwsExpected, lwsSizes); + EXPECT_EQ(gwsExpected, gwsSizes); +} + +TEST(FileLogger, WithDebugFunctionalityGetSizesNegative) { + std::string testFile = "testfile"; + DebugVariables flags; + flags.LogApiCalls.set(true); + + FullyEnabledFileLogger fileLogger(testFile, flags); + // getSizes returns string + string lwsSizes = fileLogger.getSizes(nullptr, 3, true); + string gwsSizes = fileLogger.getSizes(nullptr, 3, false); + + EXPECT_EQ(0u, lwsSizes.size()); + EXPECT_EQ(0u, gwsSizes.size()); +} + +TEST(FileLogger, WithoutDebugFunctionalityGetSizesDoesNotReturnString) { + std::string testFile = "testfile"; + DebugVariables flags; + flags.LogApiCalls.set(true); + + FullyDisabledFileLogger fileLogger(testFile, flags); + uintptr_t input[3] = {1, 2, 3}; + string lwsSizes = fileLogger.getSizes(input, 3, true); + string gwsSizes = fileLogger.getSizes(input, 3, false); + EXPECT_EQ(0u, lwsSizes.size()); + EXPECT_EQ(0u, gwsSizes.size()); +} + +TEST(FileLogger, WithDebugFunctionalityGetEventsReturnsCorectString) { + std::string testFile = "testfile"; + DebugVariables flags; + flags.LogApiCalls.set(true); + + FullyEnabledFileLogger fileLogger(testFile, flags); + // getEvents returns string + uintptr_t event = 8; + uintptr_t *input[3] = {&event, &event, &event}; + string eventsString = fileLogger.getEvents((uintptr_t *)input, 2); + EXPECT_NE(0u, eventsString.size()); +} + +TEST(FileLogger, WithDebugFunctionalityGetEventsNegative) { + std::string testFile = "testfile"; + DebugVariables flags; + + FullyEnabledFileLogger fileLogger(testFile, flags); + // getEvents returns 0 sized string + string event = fileLogger.getEvents(nullptr, 2); + EXPECT_EQ(0u, event.size()); +} + +TEST(FileLogger, GivenLoggerWithDebugFunctionalityWhenGetMemObjectsIsCalledThenCorrectStringIsReturned) { + std::string testFile = "testfile"; + DebugVariables flags; + flags.LogApiCalls.set(true); + + FullyEnabledFileLogger fileLogger(testFile, flags); + MockBuffer buffer; + MemObj *memoryObject = &buffer; + cl_mem clMem = memoryObject; + cl_mem clMemObjects[] = {clMem, clMem}; + cl_uint numObjects = 2; + + string memObjectString = fileLogger.getMemObjects(reinterpret_cast(clMemObjects), numObjects); + EXPECT_NE(0u, memObjectString.size()); + stringstream output; + output << "cl_mem " << clMem << ", MemObj " << memoryObject; + EXPECT_THAT(memObjectString, ::testing::HasSubstr(output.str())); +} + +TEST(FileLogger, GivenDebugFunctionalityWhenGetMemObjectsIsCalledWithNullptrThenStringIsEmpty) { + std::string testFile = "testfile"; + DebugVariables flags; + FullyEnabledFileLogger fileLogger(testFile, flags); + string memObjectString = fileLogger.getMemObjects(nullptr, 2); + EXPECT_EQ(0u, memObjectString.size()); +} + +TEST(FileLogger, GiveDisabledDebugFunctionalityWhenGetMemObjectsIsCalledThenCallReturnsImmediately) { + std::string testFile = "testfile"; + DebugVariables flags; + FullyDisabledFileLogger fileLogger(testFile, flags); + string memObjectString = fileLogger.getMemObjects(nullptr, 2); + EXPECT_EQ(0u, memObjectString.size()); +} + +TEST(FileLogger, WithDebugFunctionalityDumpKernel) { + std::string testFile = "testfile"; + DebugVariables flags; + flags.DumpKernels.set(true); + FullyEnabledFileLogger fileLogger(testFile, flags); + string kernelDumpFile = "testDumpKernel"; + + // test kernel dumping + fileLogger.dumpKernel(kernelDumpFile, "kernel source here"); + EXPECT_TRUE(fileLogger.wasFileCreated(kernelDumpFile.append(".txt"))); +} + +TEST(FileLogger, WithoutDebugFunctionalityDumpKernel) { + std::string testFile = "testfile"; + DebugVariables flags; + flags.DumpKernels.set(false); + string kernelDumpFile = "testDumpKernel"; + FullyEnabledFileLogger fileLogger(testFile, flags); + + // test kernel dumping + fileLogger.dumpKernel(kernelDumpFile, "kernel source here"); + EXPECT_FALSE(fileLogger.wasFileCreated(kernelDumpFile.append(".txt"))); +} + +TEST(FileLogger, WithDebugFunctionalityDumpBinary) { + std::string testFile = "testfile"; + DebugVariables flags; + flags.DumpKernels.set(true); + FullyEnabledFileLogger fileLogger(testFile, flags); + string programDumpFile = "programBinary.bin"; + size_t length = 4; + unsigned char binary[4]; + const unsigned char *ptrBinary = binary; + fileLogger.dumpBinaryProgram(1, &length, &ptrBinary); + + EXPECT_TRUE(fileLogger.wasFileCreated(programDumpFile)); +} + +TEST(FileLogger, WithDebugFunctionalityDumpNullBinary) { + std::string testFile = "testfile"; + DebugVariables flags; + flags.DumpKernels.set(true); + FullyEnabledFileLogger fileLogger(testFile, flags); + + string programDumpFile = "programBinary.bin"; + size_t length = 4; + fileLogger.dumpBinaryProgram(1, &length, nullptr); + + EXPECT_FALSE(fileLogger.wasFileCreated(programDumpFile)); +} + +TEST(FileLogger, WithDebugFunctionalityDontDumpKernelsForNullMdi) { + std::string testFile = "testfile"; + DebugVariables flags; + flags.DumpKernelArgs.set(true); + FullyEnabledFileLogger fileLogger(testFile, flags); + + fileLogger.dumpKernelArgs((const MultiDispatchInfo *)nullptr); + + EXPECT_EQ(fileLogger.createdFilesCount(), 0); +} + +TEST(FileLogger, WithDebugFunctionalityDontDumpKernelArgsForNullMdi) { + std::string testFile = "testfile"; + DebugVariables flags; + flags.DumpKernelArgs.set(true); + FullyEnabledFileLogger fileLogger(testFile, flags); + + fileLogger.dumpKernelArgs((const MultiDispatchInfo *)nullptr); + + EXPECT_EQ(fileLogger.createdFilesCount(), 0); +} + +TEST(FileLogger, GivenDebugFunctionalityWhenDebugFlagIsDisabledThenDoNotDumpKernelArgsForMdi) { + auto kernelInfo = std::make_unique(); + auto device = unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); + MockProgram program(*device->getExecutionEnvironment()); + auto kernel = unique_ptr(new MockKernel(&program, *kernelInfo, *device)); + auto multiDispatchInfo = unique_ptr(new MockMultiDispatchInfo(kernel.get())); + + KernelArgPatchInfo kernelArgPatchInfo; + + kernelArgPatchInfo.size = 32; + kernelArgPatchInfo.sourceOffset = 0; + kernelArgPatchInfo.crossthreadOffset = 32; + + kernelInfo->kernelArgInfo.resize(1); + kernelInfo->kernelArgInfo[0].kernelArgPatchInfoVector.push_back(kernelArgPatchInfo); + + size_t crossThreadDataSize = 64; + auto crossThreadData = unique_ptr(new uint8_t[crossThreadDataSize]); + kernel->setCrossThreadData(crossThreadData.get(), static_cast(crossThreadDataSize)); + + std::string testFile = "testfile"; + DebugVariables flags; + flags.DumpKernelArgs.set(false); + FullyEnabledFileLogger fileLogger(testFile, flags); + + fileLogger.dumpKernelArgs(multiDispatchInfo.get()); + + // check if file was created + std::string expectedFile = "_arg_0_immediate_size_32_flags_0.bin"; + EXPECT_FALSE(fileLogger.wasFileCreated(expectedFile)); + + // no files should be created + EXPECT_EQ(fileLogger.createdFilesCount(), 0); +} + +TEST(FileLogger, WithDebugFunctionalityDumpKernelArgsForMdi) { + auto kernelInfo = std::make_unique(); + auto device = unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); + MockProgram program(*device->getExecutionEnvironment()); + auto kernel = unique_ptr(new MockKernel(&program, *kernelInfo, *device)); + auto multiDispatchInfo = unique_ptr(new MockMultiDispatchInfo(kernel.get())); + + KernelArgPatchInfo kernelArgPatchInfo; + + kernelArgPatchInfo.size = 32; + kernelArgPatchInfo.sourceOffset = 0; + kernelArgPatchInfo.crossthreadOffset = 32; + + kernelInfo->kernelArgInfo.resize(1); + kernelInfo->kernelArgInfo[0].kernelArgPatchInfoVector.push_back(kernelArgPatchInfo); + + size_t crossThreadDataSize = 64; + auto crossThreadData = unique_ptr(new uint8_t[crossThreadDataSize]); + kernel->setCrossThreadData(crossThreadData.get(), static_cast(crossThreadDataSize)); + + std::string testFile = "testfile"; + DebugVariables flags; + flags.DumpKernelArgs.set(true); + FullyEnabledFileLogger fileLogger(testFile, flags); + + fileLogger.dumpKernelArgs(multiDispatchInfo.get()); + + // check if file was created + std::string expectedFile = "_arg_0_immediate_size_32_flags_0.bin"; + EXPECT_TRUE(fileLogger.wasFileCreated(expectedFile)); + + // file should be created + EXPECT_EQ(fileLogger.createdFilesCount(), 1); +} + +TEST(FileLogger, WithDebugFunctionalityDumpKernelNullKernel) { + std::string testFile = "testfile"; + DebugVariables flags; + flags.DumpKernelArgs.set(true); + FullyEnabledFileLogger fileLogger(testFile, flags); + fileLogger.dumpKernelArgs((const Kernel *)nullptr); + + EXPECT_EQ(fileLogger.createdFilesCount(), 0); +} + +TEST(FileLogger, WithDebugFunctionalityAndEmptyKernelDontDumpKernelArgs) { + auto kernelInfo = std::make_unique(); + auto device = unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); + MockProgram program(*device->getExecutionEnvironment()); + auto kernel = unique_ptr(new MockKernel(&program, *kernelInfo, *device)); + + std::string testFile = "testfile"; + DebugVariables flags; + flags.DumpKernelArgs.set(true); + FullyEnabledFileLogger fileLogger(testFile, flags); + + fileLogger.dumpKernelArgs(kernel.get()); + + EXPECT_EQ(fileLogger.createdFilesCount(), 0); +} + +TEST(FileLogger, WithDebugFunctionalityDumpKernelArgsImmediate) { + auto kernelInfo = std::make_unique(); + auto device = unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); + MockProgram program(*device->getExecutionEnvironment()); + auto kernel = unique_ptr(new MockKernel(&program, *kernelInfo, *device)); + + KernelArgPatchInfo kernelArgPatchInfo; + + kernelArgPatchInfo.size = 32; + kernelArgPatchInfo.sourceOffset = 0; + kernelArgPatchInfo.crossthreadOffset = 32; + + kernelInfo->kernelArgInfo.resize(1); + kernelInfo->kernelArgInfo[0].kernelArgPatchInfoVector.push_back(kernelArgPatchInfo); + + size_t crossThreadDataSize = 64; + auto crossThreadData = unique_ptr(new uint8_t[crossThreadDataSize]); + kernel->setCrossThreadData(crossThreadData.get(), static_cast(crossThreadDataSize)); + + std::string testFile = "testfile"; + DebugVariables flags; + flags.DumpKernelArgs.set(true); + FullyEnabledFileLogger fileLogger(testFile, flags); + + fileLogger.dumpKernelArgs(kernel.get()); + + // check if file was created + EXPECT_TRUE(fileLogger.wasFileCreated("_arg_0_immediate_size_32_flags_0.bin")); + + // no files should be created for local buffer + EXPECT_EQ(fileLogger.createdFilesCount(), 1); +} + +TEST(FileLogger, WithDebugFunctionalityDumpKernelArgsImmediateZeroSize) { + + auto kernelInfo = std::make_unique(); + auto device = unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); + MockProgram program(*device->getExecutionEnvironment()); + auto kernel = unique_ptr(new MockKernel(&program, *kernelInfo, *device)); + + KernelArgPatchInfo kernelArgPatchInfo; + + kernelArgPatchInfo.size = 0; + kernelArgPatchInfo.sourceOffset = 0; + kernelArgPatchInfo.crossthreadOffset = 32; + + kernelInfo->kernelArgInfo.resize(1); + kernelInfo->kernelArgInfo[0].kernelArgPatchInfoVector.push_back(kernelArgPatchInfo); + + size_t crossThreadDataSize = sizeof(64); + auto crossThreadData = unique_ptr(new uint8_t[crossThreadDataSize]); + kernel->setCrossThreadData(crossThreadData.get(), static_cast(crossThreadDataSize)); + + std::string testFile = "testfile"; + DebugVariables flags; + flags.DumpKernelArgs.set(true); + FullyEnabledFileLogger fileLogger(testFile, flags); + fileLogger.dumpKernelArgs(kernel.get()); + + // no files should be created for zero size + EXPECT_EQ(fileLogger.createdFilesCount(), 0); +} + +TEST(FileLogger, WithDebugFunctionalityDumpKernelArgsLocalBuffer) { + + auto kernelInfo = std::make_unique(); + auto device = unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); + MockProgram program(*device->getExecutionEnvironment()); + auto kernel = unique_ptr(new MockKernel(&program, *kernelInfo, *device)); + + KernelArgPatchInfo kernelArgPatchInfo; + + kernelInfo->kernelArgInfo.resize(1); + kernelInfo->kernelArgInfo[0].kernelArgPatchInfoVector.push_back(kernelArgPatchInfo); + kernelInfo->kernelArgInfo[0].addressQualifier = static_cast(CL_KERNEL_ARG_ADDRESS_LOCAL); + + std::string testFile = "testfile"; + DebugVariables flags; + flags.DumpKernelArgs.set(true); + FullyEnabledFileLogger fileLogger(testFile, flags); + fileLogger.dumpKernelArgs(kernel.get()); + + // no files should be created for local buffer + EXPECT_EQ(fileLogger.createdFilesCount(), 0); +} + +TEST(FileLogger, WithDebugFunctionalityDumpKernelArgsBufferNotSet) { + auto kernelInfo = std::make_unique(); + unique_ptr device(MockDevice::createWithNewExecutionEnvironment(nullptr)); + auto context = clUniquePtr(new MockContext(device.get())); + auto program = clUniquePtr(new MockProgram(*device->getExecutionEnvironment(), context.get(), false)); + auto kernel = clUniquePtr(new MockKernel(program.get(), *kernelInfo, *device)); + + KernelArgPatchInfo kernelArgPatchInfo; + + kernelInfo->kernelArgInfo.resize(1); + kernelInfo->kernelArgInfo[0].kernelArgPatchInfoVector.push_back(kernelArgPatchInfo); + kernelInfo->kernelArgInfo[0].typeStr = "uint8 *buffer"; + + kernel->initialize(); + + size_t crossThreadDataSize = sizeof(void *); + auto crossThreadData = unique_ptr(new uint8_t[crossThreadDataSize]); + kernel->setCrossThreadData(crossThreadData.get(), static_cast(crossThreadDataSize)); + + std::string testFile = "testfile"; + DebugVariables flags; + flags.DumpKernelArgs.set(true); + FullyEnabledFileLogger fileLogger(testFile, flags); + + fileLogger.dumpKernelArgs(kernel.get()); + + // no files should be created for local buffer + EXPECT_EQ(fileLogger.createdFilesCount(), 0); +} + +TEST(FileLogger, WithDebugFunctionalityDumpKernelArgsBuffer) { + unique_ptr device(MockDevice::createWithNewExecutionEnvironment(nullptr)); + auto context = clUniquePtr(new MockContext(device.get())); + auto buffer = BufferHelper<>::create(context.get()); + cl_mem clObj = buffer; + + auto kernelInfo = std::make_unique(); + auto program = clUniquePtr(new MockProgram(*device->getExecutionEnvironment(), context.get(), false)); + auto kernel = clUniquePtr(new MockKernel(program.get(), *kernelInfo, *device)); + + KernelArgPatchInfo kernelArgPatchInfo; + + kernelInfo->kernelArgInfo.resize(1); + kernelInfo->kernelArgInfo[0].kernelArgPatchInfoVector.push_back(kernelArgPatchInfo); + kernelInfo->kernelArgInfo[0].typeStr = "uint8 *buffer"; + kernelInfo->kernelArgInfo.at(0).isBuffer = true; + + kernel->initialize(); + + size_t crossThreadDataSize = sizeof(void *); + auto crossThreadData = unique_ptr(new uint8_t[crossThreadDataSize]); + kernel->setCrossThreadData(crossThreadData.get(), static_cast(crossThreadDataSize)); + + kernel->setArg(0, clObj); + + std::string testFile = "testfile"; + DebugVariables flags; + flags.DumpKernelArgs.set(true); + FullyEnabledFileLogger fileLogger(testFile, flags); + + fileLogger.dumpKernelArgs(kernel.get()); + + buffer->release(); + + // check if file was created + EXPECT_TRUE(fileLogger.wasFileCreated("_arg_0_buffer_size_16_flags_1.bin")); + + // no files should be created for local buffer + EXPECT_EQ(fileLogger.createdFilesCount(), 1); +} + +TEST(FileLogger, WithDebugFunctionalityDumpKernelArgsSampler) { + auto kernelInfo = std::make_unique(); + unique_ptr device(MockDevice::createWithNewExecutionEnvironment(nullptr)); + auto context = clUniquePtr(new MockContext(device.get())); + auto program = clUniquePtr(new MockProgram(*device->getExecutionEnvironment(), context.get(), false)); + auto kernel = clUniquePtr(new MockKernel(program.get(), *kernelInfo, *device)); + + KernelArgPatchInfo kernelArgPatchInfo; + + kernelInfo->kernelArgInfo.resize(1); + kernelInfo->kernelArgInfo[0].kernelArgPatchInfoVector.push_back(kernelArgPatchInfo); + kernelInfo->kernelArgInfo[0].typeStr = "sampler test"; + + kernel->initialize(); + + std::string testFile = "testfile"; + DebugVariables flags; + flags.DumpKernelArgs.set(true); + FullyEnabledFileLogger fileLogger(testFile, flags); + + fileLogger.dumpKernelArgs(kernel.get()); + + // no files should be created for sampler arg + EXPECT_EQ(fileLogger.createdFilesCount(), 0); +} + +TEST(FileLogger, WithDebugFunctionalityDumpKernelArgsImageNotSet) { + + auto kernelInfo = std::make_unique(); + unique_ptr device(MockDevice::createWithNewExecutionEnvironment(nullptr)); + auto context = clUniquePtr(new MockContext(device.get())); + auto program = clUniquePtr(new MockProgram(*device->getExecutionEnvironment(), context.get(), false)); + auto kernel = clUniquePtr(new MockKernel(program.get(), *kernelInfo, *device)); + + SKernelBinaryHeaderCommon kernelHeader; + char surfaceStateHeap[0x80]; + + kernelHeader.SurfaceStateHeapSize = sizeof(surfaceStateHeap); + kernelInfo->heapInfo.pSsh = surfaceStateHeap; + kernelInfo->heapInfo.pKernelHeader = &kernelHeader; + kernelInfo->usesSsh = true; + + KernelArgPatchInfo kernelArgPatchInfo; + + kernelInfo->kernelArgInfo.resize(1); + kernelInfo->kernelArgInfo[0].kernelArgPatchInfoVector.push_back(kernelArgPatchInfo); + kernelInfo->kernelArgInfo[0].typeStr = "image2d buffer"; + kernelInfo->kernelArgInfo[0].isImage = true; + kernelInfo->kernelArgInfo[0].offsetImgWidth = 0x4; + + kernel->initialize(); + + size_t crossThreadDataSize = sizeof(void *); + auto crossThreadData = unique_ptr(new uint8_t[crossThreadDataSize]); + kernel->setCrossThreadData(crossThreadData.get(), static_cast(crossThreadDataSize)); + + std::string testFile = "testfile"; + DebugVariables flags; + flags.DumpKernelArgs.set(true); + FullyEnabledFileLogger fileLogger(testFile, flags); + + fileLogger.dumpKernelArgs(kernel.get()); + + // no files should be created for local buffer + EXPECT_EQ(fileLogger.createdFilesCount(), 0); +} + +TEST(FileLogger, WithDebugFunctionalityDumpBinaryNegativeCases) { + std::string testFile = "testfile"; + DebugVariables flags; + flags.DumpKernels.set(true); + FullyEnabledFileLogger fileLogger(testFile, flags); + size_t length = 1; + unsigned char binary[4]; + const unsigned char *ptrBinary = binary; + fileLogger.dumpBinaryProgram(1, nullptr, nullptr); + fileLogger.dumpBinaryProgram(1, nullptr, &ptrBinary); + fileLogger.dumpBinaryProgram(1, &length, nullptr); + length = 0; + fileLogger.dumpBinaryProgram(1, &length, &ptrBinary); + fileLogger.dumpBinaryProgram(1, &length, nullptr); + + EXPECT_EQ(fileLogger.createdFilesCount(), 0); +} + +TEST(FileLogger, WithoutDebugFunctionality) { + string path = "."; + vector files = Directory::getFiles(path); + size_t initialNumberOfFiles = files.size(); + + std::string testFile = "testfile"; + DebugVariables flags; + flags.DumpKernels.set(true); + flags.LogApiCalls.set(true); + flags.DumpKernelArgs.set(true); + FullyDisabledFileLogger fileLogger(testFile, flags); + + // Should not be enabled without debug functionality + EXPECT_FALSE(fileLogger.enabled()); + + // Log file not created + bool logFileCreated = fileExists(fileLogger.getLogFileName()); + EXPECT_FALSE(logFileCreated); + + // test kernel dumping + bool kernelDumpCreated = false; + string kernelDumpFile = "testDumpKernel"; + fileLogger.dumpKernel(kernelDumpFile, "kernel source here"); + + kernelDumpCreated = fileExists(kernelDumpFile.append(".txt")); + EXPECT_FALSE(kernelDumpCreated); + + // test api logging + fileLogger.logApiCall(__FUNCTION__, true, 0); + logFileCreated = fileExists(fileLogger.getLogFileName()); + EXPECT_FALSE(logFileCreated); + + // getInput returns 0 + size_t input = 5; + size_t output = fileLogger.getInput(&input, 0); + EXPECT_EQ(0u, output); + + // getEvents returns 0-size string + string event = fileLogger.getEvents(&input, 0); + EXPECT_EQ(0u, event.size()); + + // getSizes returns 0-size string + string lwsSizes = fileLogger.getSizes(&input, 0, true); + string gwsSizes = fileLogger.getSizes(&input, 0, false); + EXPECT_EQ(0u, lwsSizes.size()); + EXPECT_EQ(0u, gwsSizes.size()); + + // no programDump file + string programDumpFile = "programBinary.bin"; + size_t length = 4; + unsigned char binary[4]; + const unsigned char *ptrBinary = binary; + fileLogger.dumpBinaryProgram(1, &length, &ptrBinary); + EXPECT_FALSE(fileLogger.wasFileCreated(programDumpFile)); + + fileLogger.dumpKernelArgs((const Kernel *)nullptr); + + // test api input logging + fileLogger.logInputs("Arg name", "value"); + fileLogger.logInputs("int", 5); + logFileCreated = fileExists(fileLogger.getLogFileName()); + EXPECT_FALSE(logFileCreated); + + // check Log + fileLogger.log(true, "string to be logged"); + logFileCreated = fileExists(fileLogger.getLogFileName()); + EXPECT_FALSE(logFileCreated); + + files = Directory::getFiles(path); + size_t finalNumberOfFiles = files.size(); + + EXPECT_EQ(initialNumberOfFiles, finalNumberOfFiles); +} + +TEST(LoggerApiEnterWrapper, WithDebugFunctionality) { + + const char *name = "function"; + int error = 0; + { + auto debugApiWrapper = std::make_unique>(name, nullptr); + EXPECT_TRUE(debugApiWrapper->loggedEnter); + } + + { + auto debugApiWrapper2 = std::make_unique>(name, &error); + EXPECT_TRUE(debugApiWrapper2->loggedEnter); + } +} + +TEST(LoggerApiEnterWrapper, WithoutDebugFunctionality) { + + const char *name = "function"; + int error = 0; + { + auto debugApiWrapper = std::make_unique>(name, nullptr); + EXPECT_FALSE(debugApiWrapper->loggedEnter); + } + + { + auto debugApiWrapper2 = std::make_unique>(name, &error); + EXPECT_FALSE(debugApiWrapper2->loggedEnter); + } +} + +TEST(FileLogger, infoPointerToStringReturnsCorrectString) { + std::string testFile = "testfile"; + DebugVariables flags; + FullyEnabledFileLogger fileLogger(testFile, flags); + + uint64_t value64bit = 64; + string string64bit = fileLogger.infoPointerToString(&value64bit, sizeof(uint64_t)); + uint32_t value32bit = 32; + string string32bit = fileLogger.infoPointerToString(&value32bit, sizeof(uint32_t)); + uint8_t value8bit = 0; + string string8bit = fileLogger.infoPointerToString(&value8bit, sizeof(uint8_t)); + + EXPECT_STREQ("64", string64bit.c_str()); + EXPECT_STREQ("32", string32bit.c_str()); + EXPECT_STREQ("0", string8bit.c_str()); + + string stringNonValue = fileLogger.infoPointerToString(nullptr, 56); + EXPECT_STREQ("", stringNonValue.c_str()); + + char valueChar = 0; + stringNonValue = fileLogger.infoPointerToString(&valueChar, 56); + EXPECT_STREQ("", stringNonValue.c_str()); +} + +TEST(FileLogger, givenDisabledDebugFunctionalityWhenLogLazyEvaluateArgsIsCalledThenCallToLambdaIsDropped) { + std::string testFile = "testfile"; + DebugVariables flags; + FullyDisabledFileLogger fileLogger(testFile, flags); + + bool wasCalled = false; + fileLogger.logLazyEvaluateArgs(true, [&] { wasCalled = true; }); + EXPECT_FALSE(wasCalled); +} + +TEST(FileLogger, givenDisabledPredicateWhenLogLazyEvaluateArgsIsCalledThenCallToLambdaIsDropped) { + std::string testFile = "testfile"; + DebugVariables flags; + FullyEnabledFileLogger fileLogger(testFile, flags); + + bool wasCalled = false; + fileLogger.logLazyEvaluateArgs(false, [&] { wasCalled = true; }); + EXPECT_FALSE(wasCalled); +} + +TEST(FileLogger, givenEnabledPredicateWhenLogLazyEvaluateArgsIsCalledThenCallToLambdaIsExecuted) { + std::string testFile = "testfile"; + DebugVariables flags; + FullyEnabledFileLogger fileLogger(testFile, flags); + bool wasCalled = false; + fileLogger.logLazyEvaluateArgs(true, [&] { wasCalled = true; }); + EXPECT_TRUE(wasCalled); +} + +struct DummyEvaluator { + DummyEvaluator(bool &wasCalled) { + wasCalled = true; + } + + operator const char *() { + return ""; + } +}; + +TEST(FileLogger, givenDisabledPredicateWhenDbgLogLazyEvaluateArgsIsCalledThenInputParametersAreNotEvaluated) { + std::string testFile = "testfile"; + DebugVariables flags; + flags.LogApiCalls.set(false); + FullyEnabledFileLogger fileLogger(testFile, flags); + + bool wasCalled = false; + DBG_LOG_LAZY_EVALUATE_ARGS(fileLogger, false, log, true, DummyEvaluator(wasCalled)); + EXPECT_FALSE(wasCalled); +} + +TEST(FileLogger, givenEnabledPredicateWhenDbgLogLazyEvaluateArgsIsCalledThenInputParametersAreEvaluated) { + std::string testFile = "testfile"; + DebugVariables flags; + flags.LogApiCalls.set(true); + FullyEnabledFileLogger fileLogger(testFile, flags); + + bool wasCalled = false; + DBG_LOG_LAZY_EVALUATE_ARGS(fileLogger, true, log, true, DummyEvaluator(wasCalled)); + EXPECT_TRUE(wasCalled); +} + +TEST(FileLogger, whenDisabledThenDebugFunctionalityIsNotAvailableAtCompileTime) { + std::string testFile = "testfile"; + DebugVariables flags; + FileLogger fileLogger(testFile, flags); + + static_assert(false == fileLogger.enabled(), ""); +} + +TEST(FileLogger, whenFullyEnabledThenAllDebugFunctionalityIsAvailableAtCompileTime) { + std::string testFile = "testfile"; + DebugVariables flags; + FileLogger fileLogger(testFile, flags); + + static_assert(true == fileLogger.enabled(), ""); +} + +struct AllocationTypeTestCase { + GraphicsAllocation::AllocationType type; + const char *str; +}; + +AllocationTypeTestCase allocationTypeValues[] = { + {GraphicsAllocation::AllocationType::BUFFER, "BUFFER"}, + {GraphicsAllocation::AllocationType::BUFFER_COMPRESSED, "BUFFER_COMPRESSED"}, + {GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, "BUFFER_HOST_MEMORY"}, + {GraphicsAllocation::AllocationType::COMMAND_BUFFER, "COMMAND_BUFFER"}, + {GraphicsAllocation::AllocationType::CONSTANT_SURFACE, "CONSTANT_SURFACE"}, + {GraphicsAllocation::AllocationType::DEVICE_QUEUE_BUFFER, "DEVICE_QUEUE_BUFFER"}, + {GraphicsAllocation::AllocationType::EXTERNAL_HOST_PTR, "EXTERNAL_HOST_PTR"}, + {GraphicsAllocation::AllocationType::FILL_PATTERN, "FILL_PATTERN"}, + {GraphicsAllocation::AllocationType::GLOBAL_SURFACE, "GLOBAL_SURFACE"}, + {GraphicsAllocation::AllocationType::IMAGE, "IMAGE"}, + {GraphicsAllocation::AllocationType::INDIRECT_OBJECT_HEAP, "INDIRECT_OBJECT_HEAP"}, + {GraphicsAllocation::AllocationType::INSTRUCTION_HEAP, "INSTRUCTION_HEAP"}, + {GraphicsAllocation::AllocationType::INTERNAL_HEAP, "INTERNAL_HEAP"}, + {GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY, "INTERNAL_HOST_MEMORY"}, + {GraphicsAllocation::AllocationType::KERNEL_ISA, "KERNEL_ISA"}, + {GraphicsAllocation::AllocationType::LINEAR_STREAM, "LINEAR_STREAM"}, + {GraphicsAllocation::AllocationType::MCS, "MCS"}, + {GraphicsAllocation::AllocationType::PIPE, "PIPE"}, + {GraphicsAllocation::AllocationType::PREEMPTION, "PREEMPTION"}, + {GraphicsAllocation::AllocationType::PRINTF_SURFACE, "PRINTF_SURFACE"}, + {GraphicsAllocation::AllocationType::PRIVATE_SURFACE, "PRIVATE_SURFACE"}, + {GraphicsAllocation::AllocationType::PROFILING_TAG_BUFFER, "PROFILING_TAG_BUFFER"}, + {GraphicsAllocation::AllocationType::SCRATCH_SURFACE, "SCRATCH_SURFACE"}, + {GraphicsAllocation::AllocationType::SHARED_BUFFER, "SHARED_BUFFER"}, + {GraphicsAllocation::AllocationType::SHARED_CONTEXT_IMAGE, "SHARED_CONTEXT_IMAGE"}, + {GraphicsAllocation::AllocationType::SHARED_IMAGE, "SHARED_IMAGE"}, + {GraphicsAllocation::AllocationType::SHARED_RESOURCE_COPY, "SHARED_RESOURCE_COPY"}, + {GraphicsAllocation::AllocationType::SURFACE_STATE_HEAP, "SURFACE_STATE_HEAP"}, + {GraphicsAllocation::AllocationType::SVM_CPU, "SVM_CPU"}, + {GraphicsAllocation::AllocationType::SVM_GPU, "SVM_GPU"}, + {GraphicsAllocation::AllocationType::SVM_ZERO_COPY, "SVM_ZERO_COPY"}, + {GraphicsAllocation::AllocationType::TAG_BUFFER, "TAG_BUFFER"}, + {GraphicsAllocation::AllocationType::TIMESTAMP_PACKET_TAG_BUFFER, "TIMESTAMP_PACKET_TAG_BUFFER"}, + {GraphicsAllocation::AllocationType::UNKNOWN, "UNKNOWN"}, + {GraphicsAllocation::AllocationType::WRITE_COMBINED, "WRITE_COMBINED"}}; + +class AllocationTypeLogging : public ::testing::TestWithParam {}; + +TEST_P(AllocationTypeLogging, givenGraphicsAllocationTypeWhenConvertingToStringThenCorrectStringIsReturned) { + std::string testFile = "testfile"; + DebugVariables flags; + FullyEnabledFileLogger fileLogger(testFile, flags); + auto input = GetParam(); + + GraphicsAllocation graphicsAllocation(0, input.type, nullptr, 0ull, 0ull, 0, MemoryPool::MemoryNull); + + auto result = fileLogger.getAllocationTypeString(&graphicsAllocation); + + EXPECT_STREQ(result, input.str); +} + +INSTANTIATE_TEST_CASE_P(AllAllocationTypes, + AllocationTypeLogging, + ::testing::ValuesIn(allocationTypeValues)); + +TEST(AllocationTypeLoggingSingle, givenGraphicsAllocationTypeWhenConvertingToStringIllegalValueThenILLEGAL_VALUEIsReturned) { + std::string testFile = "testfile"; + DebugVariables flags; + FullyEnabledFileLogger fileLogger(testFile, flags); + + GraphicsAllocation graphicsAllocation(0, static_cast(999), nullptr, 0ull, 0ull, 0, MemoryPool::MemoryNull); + + auto result = fileLogger.getAllocationTypeString(&graphicsAllocation); + + EXPECT_STREQ(result, "ILLEGAL_VALUE"); +} + +TEST(AllocationTypeLoggingSingle, givenDisabledDebugFunctionalityWhenGettingGraphicsAllocationTypeThenNullptrReturned) { + std::string testFile = "testfile"; + DebugVariables flags; + FullyDisabledFileLogger fileLogger(testFile, flags); + + GraphicsAllocation graphicsAllocation(0, GraphicsAllocation::AllocationType::BUFFER, nullptr, 0ull, 0ull, 0, MemoryPool::MemoryNull); + + auto result = fileLogger.getAllocationTypeString(&graphicsAllocation); + + EXPECT_STREQ(result, nullptr); +} diff --git a/unit_tests/utilities/file_logger_tests.h b/unit_tests/utilities/file_logger_tests.h new file mode 100644 index 0000000000..5a3d24bf84 --- /dev/null +++ b/unit_tests/utilities/file_logger_tests.h @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2019 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once + +#include "core/helpers/file_io.h" +#include "core/utilities/directory.h" +#include "runtime/helpers/string_helpers.h" +#include "runtime/utilities/logger.h" + +#include + +template +class TestFileLogger : public NEO::FileLogger { + public: + using NEO::FileLogger::FileLogger; + + ~TestFileLogger() { + std::remove(NEO::FileLogger::logFileName.c_str()); + } + + void useRealFiles(bool value) { + mockFileSystem = !value; + } + + void writeToFile(std::string filename, + const char *str, + size_t length, + std::ios_base::openmode mode) override { + + savedFiles[filename] << std::string(str, str + length); + if (mockFileSystem == false) { + NEO::FileLogger::writeToFile(filename, str, length, mode); + } + }; + + int32_t createdFilesCount() { + return static_cast(savedFiles.size()); + } + + bool wasFileCreated(std::string filename) { + return savedFiles.find(filename) != savedFiles.end(); + } + + std::string getFileString(std::string filename) { + return savedFiles[filename].str(); + } + + protected: + bool mockFileSystem = true; + std::map savedFiles; +}; + +using FullyEnabledFileLogger = TestFileLogger; +using FullyDisabledFileLogger = TestFileLogger; + +template +class TestLoggerApiEnterWrapper : public NEO::LoggerApiEnterWrapper { + public: + TestLoggerApiEnterWrapper(const char *functionName, int *errCode) : NEO::LoggerApiEnterWrapper(functionName, errCode), loggedEnter(false) { + if (DebugFunctionality) { + loggedEnter = true; + } + } + + bool loggedEnter; +};