summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/angle/src/common/debug.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdparty/angle/src/common/debug.cpp')
-rw-r--r--src/3rdparty/angle/src/common/debug.cpp226
1 files changed, 149 insertions, 77 deletions
diff --git a/src/3rdparty/angle/src/common/debug.cpp b/src/3rdparty/angle/src/common/debug.cpp
index 1fcc062908..b02e80be5f 100644
--- a/src/3rdparty/angle/src/common/debug.cpp
+++ b/src/3rdparty/angle/src/common/debug.cpp
@@ -7,92 +7,61 @@
// debug.cpp: Debugging utilities.
#include "common/debug.h"
-#include "common/platform.h"
-#include "common/angleutils.h"
#include <stdarg.h>
-#include <vector>
-#include <fstream>
+
+#include <array>
#include <cstdio>
+#include <fstream>
+#include <ostream>
+#include <vector>
+
+#include "common/angleutils.h"
+#include "common/Optional.h"
namespace gl
{
namespace
{
-enum DebugTraceOutputType
-{
- DebugTraceOutputTypeNone,
- DebugTraceOutputTypeSetMarker,
- DebugTraceOutputTypeBeginEvent
-};
DebugAnnotator *g_debugAnnotator = nullptr;
-void output(bool traceInDebugOnly, MessageType messageType, DebugTraceOutputType outputType,
- const char *format, va_list vararg)
-{
- if (DebugAnnotationsActive())
- {
- static std::vector<char> buffer(512);
- size_t len = FormatStringIntoVector(format, vararg, buffer);
- std::wstring formattedWideMessage(buffer.begin(), buffer.begin() + len);
-
- ASSERT(g_debugAnnotator != nullptr);
- switch (outputType)
- {
- case DebugTraceOutputTypeNone:
- break;
- case DebugTraceOutputTypeBeginEvent:
- g_debugAnnotator->beginEvent(formattedWideMessage.c_str());
- break;
- case DebugTraceOutputTypeSetMarker:
- g_debugAnnotator->setMarker(formattedWideMessage.c_str());
- break;
- }
- }
+constexpr std::array<const char *, LOG_NUM_SEVERITIES> g_logSeverityNames = {
+ {"EVENT", "WARN", "ERR"}};
- std::string formattedMessage;
- UNUSED_VARIABLE(formattedMessage);
+constexpr const char *LogSeverityName(int severity)
+{
+ return (severity >= 0 && severity < LOG_NUM_SEVERITIES) ? g_logSeverityNames[severity]
+ : "UNKNOWN";
+}
-#if !defined(NDEBUG) && defined(_MSC_VER)
- if (messageType == MESSAGE_ERR)
- {
- if (formattedMessage.empty())
- {
- formattedMessage = FormatString(format, vararg);
- }
- OutputDebugStringA(formattedMessage.c_str());
- }
+bool ShouldCreateLogMessage(LogSeverity severity)
+{
+#if defined(ANGLE_TRACE_ENABLED)
+ return true;
+#elif defined(ANGLE_ENABLE_ASSERTS)
+ return severity == LOG_ERR;
+#else
+ return false;
#endif
+}
-#if defined(ANGLE_ENABLE_DEBUG_TRACE)
-#if defined(NDEBUG)
- if (traceInDebugOnly)
- {
- return;
- }
-#endif // NDEBUG
- if (formattedMessage.empty())
- {
- formattedMessage = FormatString(format, vararg);
- }
-
- static std::ofstream file(TRACE_OUTPUT_FILE, std::ofstream::app);
- if (file)
- {
- file.write(formattedMessage.c_str(), formattedMessage.length());
- file.flush();
- }
+} // namespace
-#if defined(ANGLE_ENABLE_DEBUG_TRACE_TO_DEBUGGER)
- OutputDebugStringA(formattedMessage.c_str());
-#endif // ANGLE_ENABLE_DEBUG_TRACE_TO_DEBUGGER
+namespace priv
+{
-#endif // ANGLE_ENABLE_DEBUG_TRACE
+bool ShouldCreatePlatformLogMessage(LogSeverity severity)
+{
+#if defined(ANGLE_TRACE_ENABLED)
+ return true;
+#else
+ return severity != LOG_EVENT;
+#endif
}
-} // namespace
+} // namespace priv
bool DebugAnnotationsActive()
{
@@ -103,6 +72,11 @@ bool DebugAnnotationsActive()
#endif
}
+bool DebugAnnotationsInitialized()
+{
+ return g_debugAnnotator != nullptr;
+}
+
void InitializeDebugAnnotations(DebugAnnotator *debugAnnotator)
{
UninitializeDebugAnnotations();
@@ -115,25 +89,20 @@ void UninitializeDebugAnnotations()
g_debugAnnotator = nullptr;
}
-void trace(bool traceInDebugOnly, MessageType messageType, const char *format, ...)
-{
- va_list vararg;
- va_start(vararg, format);
- output(traceInDebugOnly, messageType, DebugTraceOutputTypeSetMarker, format, vararg);
- va_end(vararg);
-}
-
-ScopedPerfEventHelper::ScopedPerfEventHelper(const char* format, ...)
+ScopedPerfEventHelper::ScopedPerfEventHelper(const char *format, ...)
{
#if !defined(ANGLE_ENABLE_DEBUG_TRACE)
if (!DebugAnnotationsActive())
{
return;
}
-#endif // !ANGLE_ENABLE_DEBUG_TRACE
+#endif // !ANGLE_ENABLE_DEBUG_TRACE
+
va_list vararg;
va_start(vararg, format);
- output(true, MESSAGE_EVENT, DebugTraceOutputTypeBeginEvent, format, vararg);
+ std::vector<char> buffer(512);
+ size_t len = FormatStringIntoVector(format, vararg, buffer);
+ ANGLE_LOG(EVENT) << std::string(&buffer[0], len);
va_end(vararg);
}
@@ -145,4 +114,107 @@ ScopedPerfEventHelper::~ScopedPerfEventHelper()
}
}
+LogMessage::LogMessage(const char *function, int line, LogSeverity severity)
+ : mFunction(function), mLine(line), mSeverity(severity)
+{
+ // EVENT() does not require additional function(line) info.
+ if (mSeverity != LOG_EVENT)
+ {
+ mStream << mFunction << "(" << mLine << "): ";
+ }
+}
+
+LogMessage::~LogMessage()
+{
+ if (DebugAnnotationsInitialized() && (mSeverity == LOG_ERR || mSeverity == LOG_WARN))
+ {
+ g_debugAnnotator->logMessage(*this);
+ }
+ else
+ {
+ Trace(getSeverity(), getMessage().c_str());
+ }
+}
+
+void Trace(LogSeverity severity, const char *message)
+{
+ if (!ShouldCreateLogMessage(severity))
+ {
+ return;
+ }
+
+ std::string str(message);
+
+ if (DebugAnnotationsActive())
+ {
+ std::wstring formattedWideMessage(str.begin(), str.end());
+
+ switch (severity)
+ {
+ case LOG_EVENT:
+ g_debugAnnotator->beginEvent(formattedWideMessage.c_str());
+ break;
+ default:
+ g_debugAnnotator->setMarker(formattedWideMessage.c_str());
+ break;
+ }
+ }
+
+ if (severity == LOG_ERR)
+ {
+ // Note: we use fprintf because <iostream> includes static initializers.
+ fprintf(stderr, "%s: %s\n", LogSeverityName(severity), str.c_str());
+ }
+
+#if defined(ANGLE_PLATFORM_WINDOWS) && \
+ (defined(ANGLE_ENABLE_DEBUG_TRACE_TO_DEBUGGER) || !defined(NDEBUG))
+#if !defined(ANGLE_ENABLE_DEBUG_TRACE_TO_DEBUGGER)
+ if (severity == LOG_ERR)
+#endif // !defined(ANGLE_ENABLE_DEBUG_TRACE_TO_DEBUGGER)
+ {
+ OutputDebugStringA(str.c_str());
+ }
+#endif
+
+#if defined(ANGLE_ENABLE_DEBUG_TRACE)
+#if defined(NDEBUG)
+ if (severity == LOG_EVENT || severity == LOG_WARN)
+ {
+ return;
+ }
+#endif // defined(NDEBUG)
+ static std::ofstream file(TRACE_OUTPUT_FILE, std::ofstream::app);
+ if (file)
+ {
+ file << LogSeverityName(severity) << ": " << str << std::endl;
+ file.flush();
+ }
+#endif // defined(ANGLE_ENABLE_DEBUG_TRACE)
}
+
+LogSeverity LogMessage::getSeverity() const
+{
+ return mSeverity;
+}
+
+std::string LogMessage::getMessage() const
+{
+ return mStream.str();
+}
+
+#if defined(ANGLE_PLATFORM_WINDOWS)
+std::ostream &operator<<(std::ostream &os, const FmtHR &fmt)
+{
+ os << "HRESULT: ";
+ return FmtHexInt(os, fmt.mHR);
+}
+
+std::ostream &operator<<(std::ostream &os, const FmtErr &fmt)
+{
+ os << "error: ";
+ return FmtHexInt(os, fmt.mErr);
+}
+
+#endif // defined(ANGLE_PLATFORM_WINDOWS)
+
+} // namespace gl