Commit f47a73af by Antonio Maiorano

Debug: add trace to debug out

If enabled, TRACE macros (in Reactor and Vulkan) will use OutputDebugString on Windows, printf otherwise, to print the trace. On Windows, this allows us to use DbgView to monitor and filter the trace easily, especially useful when running with Chrome, for e.g. Bug: b/146051794 Change-Id: I15a46f5f0e8bc4e9edcacaf63c15dc605323356d Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/39568 Kokoro-Presubmit: kokoro <noreply+kokoro@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Tested-by: 's avatarAntonio Maiorano <amaiorano@google.com>
parent 19e00af6
...@@ -14,15 +14,34 @@ ...@@ -14,15 +14,34 @@
#include "Debug.hpp" #include "Debug.hpp"
#include <stdarg.h> #include <cstdarg>
#include <cstdio>
#include <string> #include <string>
#if defined(_WIN32)
# include <windows.h>
#endif
namespace rr { namespace rr {
void tracev(const char *format, va_list args) void tracev(const char *format, va_list args)
{ {
#ifndef RR_DISABLE_TRACE #ifndef RR_DISABLE_TRACE
if(false) const bool traceToDebugOut = false;
const bool traceToFile = false;
if(traceToDebugOut)
{
char buffer[2048];
vsnprintf(buffer, sizeof(buffer), format, args);
# if defined(_WIN32)
::OutputDebugString(buffer);
# else
printf("%s", buffer);
# endif
}
if(traceToFile)
{ {
FILE *file = fopen(TRACE_OUTPUT_FILE, "a"); FILE *file = fopen(TRACE_OUTPUT_FILE, "a");
......
...@@ -14,8 +14,9 @@ ...@@ -14,8 +14,9 @@
#include "VkDebug.hpp" #include "VkDebug.hpp"
#include <stdarg.h>
#include <atomic> #include <atomic>
#include <cstdarg>
#include <cstdio>
#include <string> #include <string>
#if defined(__unix__) #if defined(__unix__)
...@@ -90,7 +91,21 @@ namespace vk { ...@@ -90,7 +91,21 @@ namespace vk {
void tracev(const char *format, va_list args) void tracev(const char *format, va_list args)
{ {
#ifndef SWIFTSHADER_DISABLE_TRACE #ifndef SWIFTSHADER_DISABLE_TRACE
if(false) const bool traceToDebugOut = false;
const bool traceToFile = false;
if(traceToDebugOut)
{
char buffer[2048];
vsnprintf(buffer, sizeof(buffer), format, args);
# if defined(_WIN32)
::OutputDebugString(buffer);
# else
printf("%s", buffer);
# endif
}
if(traceToFile)
{ {
FILE *file = fopen(TRACE_OUTPUT_FILE, "a"); FILE *file = fopen(TRACE_OUTPUT_FILE, "a");
...@@ -100,7 +115,7 @@ void tracev(const char *format, va_list args) ...@@ -100,7 +115,7 @@ void tracev(const char *format, va_list args)
fclose(file); fclose(file);
} }
} }
#endif #endif // SWIFTSHADER_DISABLE_TRACE
} }
void trace(const char *format, ...) void trace(const char *format, ...)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment