Debug: Add Systrace Markers
Update ScopedPerfEventHelper class to add systrace markers by default.
This change unifies ANGLE EVENT* macro system so that at the base level
in LoggingAnnotator class, systrace markers will be added by default.
Modify the base DebugLogger to use char* by default and move any
conversions to wchar_t to the Windows specializations where wchar is
used. This limits type conversions to only where they're needed.
This change also includes some new TRACE_EVENT() calls in the VK
backend which will result in systrace markers for those calls on the
Android platform.
The new build flag "angle_enable_trace" is added to enable the tracing
calls.
Bug: angleproject:2528
Change-Id: Icefc197d4407e1cd31338710e37865abae6a0b15
Reviewed-on: https://chromium-review.googlesource.com/c/1042785
Commit-Queue: Tobin Ehlis <tobine@google.com>
Commit-Queue: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Yuly Novikov <ynovikov@chromium.org>
diff --git a/BUILD.gn b/BUILD.gn
index f4070ef..b102cc8 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -86,6 +86,10 @@
defines += [ "ANGLE_ENABLE_VULKAN_GPU_TRACE_EVENTS=1" ]
}
}
+
+ if (angle_enable_trace) {
+ defines += [ "ANGLE_ENABLE_DEBUG_TRACE=1" ]
+ }
}
config("extra_warnings") {
diff --git a/gni/angle.gni b/gni/angle.gni
index e771daf..537774b 100644
--- a/gni/angle.gni
+++ b/gni/angle.gni
@@ -71,6 +71,7 @@
declare_args() {
angle_enable_gl_null = angle_enable_gl
angle_enable_hlsl = angle_enable_d3d9 || angle_enable_d3d11
+ angle_enable_trace = false
# Disable the layers in ubsan builds because of really slow builds.
angle_enable_vulkan_validation_layers =
diff --git a/include/platform/Platform.h b/include/platform/Platform.h
index d59fa8f..f2b501c 100644
--- a/include/platform/Platform.h
+++ b/include/platform/Platform.h
@@ -123,7 +123,7 @@
// - name is the name of the event. Also used to match BEGIN/END and
// START/FINISH pairs.
// - id optionally allows events of the same name to be distinguished from
-// each other. For example, to trace the consutruction and destruction of
+// each other. For example, to trace the construction and destruction of
// objects, specify the pointer as the id parameter.
// - timestamp should be a time value returned from monotonicallyIncreasingTime.
// - numArgs specifies the number of elements in argNames, argTypes, and
diff --git a/src/common/debug.cpp b/src/common/debug.cpp
index 29adc48..4ad7960 100644
--- a/src/common/debug.cpp
+++ b/src/common/debug.cpp
@@ -20,8 +20,8 @@
#include <android/log.h>
#endif
-#include "common/angleutils.h"
#include "common/Optional.h"
+#include "common/angleutils.h"
namespace gl
{
@@ -96,10 +96,11 @@
g_debugAnnotator = nullptr;
}
-ScopedPerfEventHelper::ScopedPerfEventHelper(const char *format, ...)
+ScopedPerfEventHelper::ScopedPerfEventHelper(const char *format, ...) : mFunctionName(nullptr)
{
+ bool dbgTrace = DebugAnnotationsActive();
#if !defined(ANGLE_ENABLE_DEBUG_TRACE)
- if (!DebugAnnotationsActive())
+ if (!dbgTrace)
{
return;
}
@@ -110,14 +111,20 @@
std::vector<char> buffer(512);
size_t len = FormatStringIntoVector(format, vararg, buffer);
ANGLE_LOG(EVENT) << std::string(&buffer[0], len);
+ // Pull function name from variable args
+ mFunctionName = va_arg(vararg, const char *);
va_end(vararg);
+ if (dbgTrace)
+ {
+ g_debugAnnotator->beginEvent(mFunctionName, buffer.data());
+ }
}
ScopedPerfEventHelper::~ScopedPerfEventHelper()
{
if (DebugAnnotationsActive())
{
- g_debugAnnotator->endEvent();
+ g_debugAnnotator->endEvent(mFunctionName);
}
}
@@ -154,15 +161,14 @@
if (DebugAnnotationsActive())
{
- std::wstring formattedWideMessage(str.begin(), str.end());
switch (severity)
{
case LOG_EVENT:
- g_debugAnnotator->beginEvent(formattedWideMessage.c_str());
+ // Debugging logging done in ScopedPerfEventHelper
break;
default:
- g_debugAnnotator->setMarker(formattedWideMessage.c_str());
+ g_debugAnnotator->setMarker(message);
break;
}
}
diff --git a/src/common/debug.h b/src/common/debug.h
index e798572..bb3c662 100644
--- a/src/common/debug.h
+++ b/src/common/debug.h
@@ -34,6 +34,9 @@
ANGLE_FORMAT_PRINTF(2, 3)
ScopedPerfEventHelper(const char *format, ...);
~ScopedPerfEventHelper();
+
+ private:
+ const char *mFunctionName;
};
using LogSeverity = int;
@@ -72,16 +75,16 @@
std::ostringstream mStream;
};
-// Wraps the D3D9/D3D11 debug annotation functions.
+// Wraps the API/Platform-specific debug annotation functions.
// Also handles redirecting logging destination.
class DebugAnnotator : angle::NonCopyable
{
public:
DebugAnnotator(){};
virtual ~DebugAnnotator() { };
- virtual void beginEvent(const wchar_t *eventName) = 0;
- virtual void endEvent() = 0;
- virtual void setMarker(const wchar_t *markerName) = 0;
+ virtual void beginEvent(const char *eventName, const char *eventMessage) = 0;
+ virtual void endEvent(const char *eventName) = 0;
+ virtual void setMarker(const char *markerName) = 0;
virtual bool getStatus() = 0;
// Log Message Handler that gets passed every log message,
// when debug annotations are initialized,
diff --git a/src/libANGLE/LoggingAnnotator.cpp b/src/libANGLE/LoggingAnnotator.cpp
index 799399e..cabf9cd 100644
--- a/src/libANGLE/LoggingAnnotator.cpp
+++ b/src/libANGLE/LoggingAnnotator.cpp
@@ -9,6 +9,7 @@
#include "libANGLE/LoggingAnnotator.h"
#include <platform/Platform.h>
+#include "third_party/trace_event/trace_event.h"
namespace angle
{
@@ -18,6 +19,21 @@
return false;
}
+void LoggingAnnotator::beginEvent(const char *eventName, const char *eventMessage)
+{
+ TRACE_EVENT_BEGIN0("gpu.angle", eventName);
+}
+
+void LoggingAnnotator::endEvent(const char *eventName)
+{
+ TRACE_EVENT_END0("gpu.angle", eventName);
+}
+
+void LoggingAnnotator::setMarker(const char *markerName)
+{
+ TRACE_EVENT_INSTANT0("gpu.angle", markerName);
+}
+
void LoggingAnnotator::logMessage(const gl::LogMessage &msg) const
{
auto *plat = ANGLEPlatformCurrent();
diff --git a/src/libANGLE/LoggingAnnotator.h b/src/libANGLE/LoggingAnnotator.h
index 5bec68e..97936f3 100644
--- a/src/libANGLE/LoggingAnnotator.h
+++ b/src/libANGLE/LoggingAnnotator.h
@@ -17,11 +17,11 @@
class LoggingAnnotator : public gl::DebugAnnotator
{
public:
- LoggingAnnotator(){};
+ LoggingAnnotator() {}
~LoggingAnnotator() override{};
- void beginEvent(const wchar_t *eventName) override {}
- void endEvent() override {}
- void setMarker(const wchar_t *markerName) override {}
+ void beginEvent(const char *eventName, const char *eventMessage) override;
+ void endEvent(const char *eventName) override;
+ void setMarker(const char *markerName) override;
bool getStatus() override;
void logMessage(const gl::LogMessage &msg) const override;
};
diff --git a/src/libANGLE/renderer/d3d/d3d11/Context11.cpp b/src/libANGLE/renderer/d3d/d3d11/Context11.cpp
index 3ee92d7..41edebf 100644
--- a/src/libANGLE/renderer/d3d/d3d11/Context11.cpp
+++ b/src/libANGLE/renderer/d3d/d3d11/Context11.cpp
@@ -402,25 +402,24 @@
void Context11::insertEventMarker(GLsizei length, const char *marker)
{
- auto optionalString = angle::WidenString(static_cast<size_t>(length), marker);
- if (optionalString.valid())
- {
- mRenderer->getAnnotator()->setMarker(optionalString.value().data());
- }
+ mRenderer->getAnnotator()->setMarker(marker);
}
void Context11::pushGroupMarker(GLsizei length, const char *marker)
{
- auto optionalString = angle::WidenString(static_cast<size_t>(length), marker);
- if (optionalString.valid())
- {
- mRenderer->getAnnotator()->beginEvent(optionalString.value().data());
- }
+ mRenderer->getAnnotator()->beginEvent(marker, marker);
+ mMarkerStack.push(std::string(marker));
}
void Context11::popGroupMarker()
{
- mRenderer->getAnnotator()->endEvent();
+ const char *marker = nullptr;
+ if (!mMarkerStack.empty())
+ {
+ marker = mMarkerStack.top().c_str();
+ mMarkerStack.pop();
+ mRenderer->getAnnotator()->endEvent(marker);
+ }
}
void Context11::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const char *message)
diff --git a/src/libANGLE/renderer/d3d/d3d11/Context11.h b/src/libANGLE/renderer/d3d/d3d11/Context11.h
index d51da68..e2bde41 100644
--- a/src/libANGLE/renderer/d3d/d3d11/Context11.h
+++ b/src/libANGLE/renderer/d3d/d3d11/Context11.h
@@ -10,8 +10,8 @@
#ifndef LIBANGLE_RENDERER_D3D_D3D11_CONTEXT11_H_
#define LIBANGLE_RENDERER_D3D_D3D11_CONTEXT11_H_
+#include <stack>
#include "libANGLE/renderer/ContextImpl.h"
-
#include "libANGLE/renderer/d3d/ContextD3D.h"
namespace rx
@@ -177,6 +177,7 @@
Renderer11 *mRenderer;
IncompleteTextureSet mIncompleteTextures;
+ std::stack<std::string> mMarkerStack;
};
} // namespace rx
diff --git a/src/libANGLE/renderer/d3d/d3d11/DebugAnnotator11.cpp b/src/libANGLE/renderer/d3d/d3d11/DebugAnnotator11.cpp
index 1e70363..e7e3425 100644
--- a/src/libANGLE/renderer/d3d/d3d11/DebugAnnotator11.cpp
+++ b/src/libANGLE/renderer/d3d/d3d11/DebugAnnotator11.cpp
@@ -35,33 +35,40 @@
}
}
-void DebugAnnotator11::beginEvent(const wchar_t *eventName)
+void DebugAnnotator11::beginEvent(const char *eventName, const char *eventMessage)
{
initializeDevice();
+ angle::LoggingAnnotator::beginEvent(eventName, eventMessage);
if (mUserDefinedAnnotation != nullptr)
{
- mUserDefinedAnnotation->BeginEvent(eventName);
+ std::mbstate_t state = std::mbstate_t();
+ std::mbsrtowcs(mWCharMessage, &eventMessage, kMaxMessageLength, &state);
+ mUserDefinedAnnotation->BeginEvent(mWCharMessage);
}
}
-void DebugAnnotator11::endEvent()
+void DebugAnnotator11::endEvent(const char *eventName)
{
initializeDevice();
+ angle::LoggingAnnotator::endEvent(eventName);
if (mUserDefinedAnnotation != nullptr)
{
mUserDefinedAnnotation->EndEvent();
}
}
-void DebugAnnotator11::setMarker(const wchar_t *markerName)
+void DebugAnnotator11::setMarker(const char *markerName)
{
initializeDevice();
+ angle::LoggingAnnotator::setMarker(markerName);
if (mUserDefinedAnnotation != nullptr)
{
- mUserDefinedAnnotation->SetMarker(markerName);
+ std::mbstate_t state = std::mbstate_t();
+ std::mbsrtowcs(mWCharMessage, &markerName, kMaxMessageLength, &state);
+ mUserDefinedAnnotation->SetMarker(mWCharMessage);
}
}
diff --git a/src/libANGLE/renderer/d3d/d3d11/DebugAnnotator11.h b/src/libANGLE/renderer/d3d/d3d11/DebugAnnotator11.h
index 62662c4..a918984 100644
--- a/src/libANGLE/renderer/d3d/d3d11/DebugAnnotator11.h
+++ b/src/libANGLE/renderer/d3d/d3d11/DebugAnnotator11.h
@@ -19,9 +19,9 @@
public:
DebugAnnotator11();
~DebugAnnotator11() override;
- void beginEvent(const wchar_t *eventName) override;
- void endEvent() override;
- void setMarker(const wchar_t *markerName) override;
+ void beginEvent(const char *eventName, const char *eventMessage) override;
+ void endEvent(const char *eventName) override;
+ void setMarker(const char *markerName) override;
bool getStatus() override;
private:
@@ -30,6 +30,8 @@
bool mInitialized;
HMODULE mD3d11Module;
ID3DUserDefinedAnnotation *mUserDefinedAnnotation;
+ static constexpr size_t kMaxMessageLength = 256;
+ wchar_t mWCharMessage[kMaxMessageLength];
};
}
diff --git a/src/libANGLE/renderer/d3d/d3d9/Context9.cpp b/src/libANGLE/renderer/d3d/d3d9/Context9.cpp
index 0528190..ddf74fc 100644
--- a/src/libANGLE/renderer/d3d/d3d9/Context9.cpp
+++ b/src/libANGLE/renderer/d3d/d3d9/Context9.cpp
@@ -227,25 +227,24 @@
void Context9::insertEventMarker(GLsizei length, const char *marker)
{
- auto optionalString = angle::WidenString(static_cast<size_t>(length), marker);
- if (optionalString.valid())
- {
- mRenderer->getAnnotator()->setMarker(optionalString.value().data());
- }
+ mRenderer->getAnnotator()->setMarker(marker);
}
void Context9::pushGroupMarker(GLsizei length, const char *marker)
{
- auto optionalString = angle::WidenString(static_cast<size_t>(length), marker);
- if (optionalString.valid())
- {
- mRenderer->getAnnotator()->beginEvent(optionalString.value().data());
- }
+ mRenderer->getAnnotator()->beginEvent(marker, marker);
+ mMarkerStack.push(std::string(marker));
}
void Context9::popGroupMarker()
{
- mRenderer->getAnnotator()->endEvent();
+ const char *marker = nullptr;
+ if (!mMarkerStack.empty())
+ {
+ marker = mMarkerStack.top().c_str();
+ mMarkerStack.pop();
+ mRenderer->getAnnotator()->endEvent(marker);
+ }
}
void Context9::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const char *message)
diff --git a/src/libANGLE/renderer/d3d/d3d9/Context9.h b/src/libANGLE/renderer/d3d/d3d9/Context9.h
index ee3855e..f9f1456 100644
--- a/src/libANGLE/renderer/d3d/d3d9/Context9.h
+++ b/src/libANGLE/renderer/d3d/d3d9/Context9.h
@@ -10,6 +10,7 @@
#ifndef LIBANGLE_RENDERER_D3D_D3D9_CONTEXT9_H_
#define LIBANGLE_RENDERER_D3D_D3D9_CONTEXT9_H_
+#include <stack>
#include "libANGLE/renderer/d3d/ContextD3D.h"
namespace rx
@@ -162,6 +163,7 @@
private:
Renderer9 *mRenderer;
IncompleteTextureSet mIncompleteTextures;
+ std::stack<std::string> mMarkerStack;
};
} // namespace rx
diff --git a/src/libANGLE/renderer/d3d/d3d9/DebugAnnotator9.cpp b/src/libANGLE/renderer/d3d/d3d9/DebugAnnotator9.cpp
index 6ec35e1..b699603 100644
--- a/src/libANGLE/renderer/d3d/d3d9/DebugAnnotator9.cpp
+++ b/src/libANGLE/renderer/d3d/d3d9/DebugAnnotator9.cpp
@@ -13,19 +13,26 @@
namespace rx
{
-void DebugAnnotator9::beginEvent(const wchar_t *eventName)
+void DebugAnnotator9::beginEvent(const char *eventName, const char *eventMessage)
{
- D3DPERF_BeginEvent(0, eventName);
+ angle::LoggingAnnotator::beginEvent(eventName, eventMessage);
+ std::mbstate_t state = std::mbstate_t();
+ std::mbsrtowcs(mWCharMessage, &eventMessage, kMaxMessageLength, &state);
+ D3DPERF_BeginEvent(0, mWCharMessage);
}
-void DebugAnnotator9::endEvent()
+void DebugAnnotator9::endEvent(const char *eventName)
{
+ angle::LoggingAnnotator::endEvent(eventName);
D3DPERF_EndEvent();
}
-void DebugAnnotator9::setMarker(const wchar_t *markerName)
+void DebugAnnotator9::setMarker(const char *markerName)
{
- D3DPERF_SetMarker(0, markerName);
+ angle::LoggingAnnotator::setMarker(markerName);
+ std::mbstate_t state = std::mbstate_t();
+ std::mbsrtowcs(mWCharMessage, &markerName, kMaxMessageLength, &state);
+ D3DPERF_SetMarker(0, mWCharMessage);
}
bool DebugAnnotator9::getStatus()
diff --git a/src/libANGLE/renderer/d3d/d3d9/DebugAnnotator9.h b/src/libANGLE/renderer/d3d/d3d9/DebugAnnotator9.h
index b280083..4b6d12f 100644
--- a/src/libANGLE/renderer/d3d/d3d9/DebugAnnotator9.h
+++ b/src/libANGLE/renderer/d3d/d3d9/DebugAnnotator9.h
@@ -18,10 +18,14 @@
{
public:
DebugAnnotator9() {}
- void beginEvent(const wchar_t *eventName) override;
- void endEvent() override;
- void setMarker(const wchar_t *markerName) override;
+ void beginEvent(const char *eventName, const char *eventMessage) override;
+ void endEvent(const char *eventName) override;
+ void setMarker(const char *markerName) override;
bool getStatus() override;
+
+ private:
+ static constexpr size_t kMaxMessageLength = 256;
+ wchar_t mWCharMessage[kMaxMessageLength];
};
}
diff --git a/src/libANGLE/renderer/vulkan/ContextVk.cpp b/src/libANGLE/renderer/vulkan/ContextVk.cpp
index da3496b..c08a251 100644
--- a/src/libANGLE/renderer/vulkan/ContextVk.cpp
+++ b/src/libANGLE/renderer/vulkan/ContextVk.cpp
@@ -32,6 +32,8 @@
#include "libANGLE/renderer/vulkan/TransformFeedbackVk.h"
#include "libANGLE/renderer/vulkan/VertexArrayVk.h"
+#include "third_party/trace_event/trace_event.h"
+
namespace rx
{
@@ -122,6 +124,7 @@
mViewport{},
mScissor{}
{
+ TRACE_EVENT0("gpu.angle", "ContextVk::ContextVk");
memset(&mClearColorValue, 0, sizeof(mClearColorValue));
memset(&mClearDepthStencilValue, 0, sizeof(mClearDepthStencilValue));
@@ -189,6 +192,7 @@
angle::Result ContextVk::initialize()
{
+ TRACE_EVENT0("gpu.angle", "ContextVk::initialize");
// Note that this may reserve more sets than strictly necessary for a particular layout.
ANGLE_TRY(mDynamicDescriptorPools[kUniformsDescriptorSetIndex].init(
this, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, GetUniformBufferDescriptorCount()));
diff --git a/src/libANGLE/renderer/vulkan/RendererVk.cpp b/src/libANGLE/renderer/vulkan/RendererVk.cpp
index 6d85f90..f148613 100644
--- a/src/libANGLE/renderer/vulkan/RendererVk.cpp
+++ b/src/libANGLE/renderer/vulkan/RendererVk.cpp
@@ -1020,6 +1020,7 @@
const VkSubmitInfo &submitInfo,
vk::CommandBuffer &&commandBuffer)
{
+ TRACE_EVENT0("gpu.angle", "RendererVk::submitFrame");
VkFenceCreateInfo fenceInfo = {};
fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
fenceInfo.flags = 0;