Move event tracer back into common.

Requires that we update the TRACE_EVENT macros to accept a platform as
an argument. The refactor isn't complete. In order to finish we'd need
to ensure we have the Display's PlatformMethods available at all sites.

Unblocks adding trace events directly in the perf tests.

Bug: angleproject:1892
Bug: angleproject:3117
Change-Id: Iee0ca086ccfe23acab3fc186fb042f018711a94c
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1664794
Commit-Queue: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org>
diff --git a/src/common/event_tracer.cpp b/src/common/event_tracer.cpp
index 8e810df..95d1977 100644
--- a/src/common/event_tracer.cpp
+++ b/src/common/event_tracer.cpp
@@ -9,9 +9,8 @@
 namespace angle
 {
 
-const unsigned char *GetTraceCategoryEnabledFlag(const char *name)
+const unsigned char *GetTraceCategoryEnabledFlag(PlatformMethods *platform, const char *name)
 {
-    auto *platform = ANGLEPlatformCurrent();
     ASSERT(platform);
 
     const unsigned char *categoryEnabledFlag =
@@ -25,7 +24,8 @@
     return &disabled;
 }
 
-angle::TraceEventHandle AddTraceEvent(char phase,
+angle::TraceEventHandle AddTraceEvent(PlatformMethods *platform,
+                                      char phase,
                                       const unsigned char *categoryGroupEnabled,
                                       const char *name,
                                       unsigned long long id,
@@ -35,7 +35,6 @@
                                       const unsigned long long *argValues,
                                       unsigned char flags)
 {
-    auto *platform = ANGLEPlatformCurrent();
     ASSERT(platform);
 
     double timestamp = platform->monotonicallyIncreasingTime(platform);
diff --git a/src/common/event_tracer.h b/src/common/event_tracer.h
index 0c27552..231ecfd 100644
--- a/src/common/event_tracer.h
+++ b/src/common/event_tracer.h
@@ -10,9 +10,9 @@
 
 namespace angle
 {
-
-const unsigned char *GetTraceCategoryEnabledFlag(const char *name);
-angle::TraceEventHandle AddTraceEvent(char phase,
+const unsigned char *GetTraceCategoryEnabledFlag(PlatformMethods *platform, const char *name);
+angle::TraceEventHandle AddTraceEvent(PlatformMethods *platform,
+                                      char phase,
                                       const unsigned char *categoryGroupEnabled,
                                       const char *name,
                                       unsigned long long id,
diff --git a/src/libANGLE/Display.cpp b/src/libANGLE/Display.cpp
index 9b7df24..f3cbfbe 100644
--- a/src/libANGLE/Display.cpp
+++ b/src/libANGLE/Display.cpp
@@ -37,7 +37,7 @@
 #include "libANGLE/renderer/DeviceImpl.h"
 #include "libANGLE/renderer/DisplayImpl.h"
 #include "libANGLE/renderer/ImageImpl.h"
-#include "third_party/trace_event/trace_event.h"
+#include "libANGLE/trace.h"
 
 #if defined(ANGLE_ENABLE_D3D9) || defined(ANGLE_ENABLE_D3D11)
 #    include "libANGLE/renderer/d3d/DisplayD3D.h"
@@ -531,7 +531,7 @@
     gl::InitializeDebugMutexIfNeeded();
 
     SCOPED_ANGLE_HISTOGRAM_TIMER("GPU.ANGLE.DisplayInitializeMS");
-    TRACE_EVENT0("gpu.angle", "egl::Display::initialize");
+    ANGLE_TRACE_EVENT0("gpu.angle", "egl::Display::initialize");
 
     if (isInitialized())
     {
diff --git a/src/libANGLE/LoggingAnnotator.cpp b/src/libANGLE/LoggingAnnotator.cpp
index 2f11719..b3721ac 100644
--- a/src/libANGLE/LoggingAnnotator.cpp
+++ b/src/libANGLE/LoggingAnnotator.cpp
@@ -8,8 +8,7 @@
 
 #include "libANGLE/LoggingAnnotator.h"
 
-#include <platform/Platform.h>
-#include "third_party/trace_event/trace_event.h"
+#include "libANGLE/trace.h"
 
 namespace angle
 {
@@ -21,17 +20,17 @@
 
 void LoggingAnnotator::beginEvent(const char *eventName, const char *eventMessage)
 {
-    TRACE_EVENT_BEGIN0("gpu.angle", eventName);
+    ANGLE_TRACE_EVENT_BEGIN0("gpu.angle", eventName);
 }
 
 void LoggingAnnotator::endEvent(const char *eventName)
 {
-    TRACE_EVENT_END0("gpu.angle", eventName);
+    ANGLE_TRACE_EVENT_END0("gpu.angle", eventName);
 }
 
 void LoggingAnnotator::setMarker(const char *markerName)
 {
-    TRACE_EVENT_INSTANT0("gpu.angle", markerName);
+    ANGLE_TRACE_EVENT_INSTANT0("gpu.angle", markerName);
 }
 
 void LoggingAnnotator::logMessage(const gl::LogMessage &msg) const
diff --git a/src/libANGLE/Surface.cpp b/src/libANGLE/Surface.cpp
index 2ae3289..b540799 100644
--- a/src/libANGLE/Surface.cpp
+++ b/src/libANGLE/Surface.cpp
@@ -20,7 +20,7 @@
 #include "libANGLE/Thread.h"
 #include "libANGLE/formatutils.h"
 #include "libANGLE/renderer/EGLImplFactory.h"
-#include "third_party/trace_event/trace_event.h"
+#include "libANGLE/trace.h"
 
 namespace egl
 {
@@ -231,7 +231,7 @@
 
 Error Surface::swap(const gl::Context *context)
 {
-    TRACE_EVENT0("gpu.angle", "egl::Surface::swap");
+    ANGLE_TRACE_EVENT0("gpu.angle", "egl::Surface::swap");
 
     ANGLE_TRY(mImplementation->swap(context));
     postSwap();
diff --git a/src/libANGLE/renderer/d3d/HLSLCompiler.cpp b/src/libANGLE/renderer/d3d/HLSLCompiler.cpp
index 31b7fe8..4fb5cd4 100644
--- a/src/libANGLE/renderer/d3d/HLSLCompiler.cpp
+++ b/src/libANGLE/renderer/d3d/HLSLCompiler.cpp
@@ -14,7 +14,7 @@
 #include "libANGLE/features.h"
 #include "libANGLE/histogram_macros.h"
 #include "libANGLE/renderer/d3d/ContextD3D.h"
-#include "third_party/trace_event/trace_event.h"
+#include "libANGLE/trace.h"
 
 namespace
 {
@@ -120,7 +120,7 @@
         return angle::Result::Continue;
     }
 
-    TRACE_EVENT0("gpu.angle", "HLSLCompiler::initialize");
+    ANGLE_TRACE_EVENT0("gpu.angle", "HLSLCompiler::initialize");
 #if !defined(ANGLE_ENABLE_WINDOWS_STORE)
 #    if defined(ANGLE_PRELOADED_D3DCOMPILER_MODULE_NAMES)
     // Find a D3DCompiler module that had already been loaded based on a predefined list of
@@ -239,7 +239,7 @@
         HRESULT result         = S_OK;
 
         {
-            TRACE_EVENT0("gpu.angle", "D3DCompile");
+            ANGLE_TRACE_EVENT0("gpu.angle", "D3DCompile");
             SCOPED_ANGLE_HISTOGRAM_TIMER("GPU.ANGLE.D3DCompileMS");
             result = mD3DCompileFunc(hlsl.c_str(), hlsl.length(), gl::g_fakepath, macros, nullptr,
                                      "main", profile.c_str(), configs[i].flags, 0, &binary,
diff --git a/src/libANGLE/renderer/d3d/d3d11/Blit11.cpp b/src/libANGLE/renderer/d3d/d3d11/Blit11.cpp
index e56fb79..6878ce8 100644
--- a/src/libANGLE/renderer/d3d/d3d11/Blit11.cpp
+++ b/src/libANGLE/renderer/d3d/d3d11/Blit11.cpp
@@ -19,7 +19,7 @@
 #include "libANGLE/renderer/d3d/d3d11/formatutils11.h"
 #include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h"
 #include "libANGLE/renderer/d3d/d3d11/texture_format_table.h"
-#include "third_party/trace_event/trace_event.h"
+#include "libANGLE/trace.h"
 
 namespace rx
 {
@@ -576,7 +576,7 @@
         return angle::Result::Continue;
     }
 
-    TRACE_EVENT0("gpu.angle", "Blit11::initResources");
+    ANGLE_TRACE_EVENT0("gpu.angle", "Blit11::initResources");
 
     D3D11_BUFFER_DESC vbDesc;
     vbDesc.ByteWidth =
diff --git a/src/libANGLE/renderer/d3d/d3d11/Clear11.cpp b/src/libANGLE/renderer/d3d/d3d11/Clear11.cpp
index a95bdb0..6e92c8f 100644
--- a/src/libANGLE/renderer/d3d/d3d11/Clear11.cpp
+++ b/src/libANGLE/renderer/d3d/d3d11/Clear11.cpp
@@ -19,7 +19,7 @@
 #include "libANGLE/renderer/d3d/d3d11/Renderer11.h"
 #include "libANGLE/renderer/d3d/d3d11/formatutils11.h"
 #include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h"
-#include "third_party/trace_event/trace_event.h"
+#include "libANGLE/trace.h"
 
 // Precompiled shaders
 #include "libANGLE/renderer/d3d/d3d11/shaders/compiled/clear11_fl9vs.h"
@@ -234,7 +234,7 @@
         return angle::Result::Continue;
     }
 
-    TRACE_EVENT0("gpu.angle", "Clear11::ensureResourcesInitialized");
+    ANGLE_TRACE_EVENT0("gpu.angle", "Clear11::ensureResourcesInitialized");
 
     static_assert((sizeof(RtvDsvClearInfo<float>) == sizeof(RtvDsvClearInfo<int>)),
                   "Size of rx::RtvDsvClearInfo<float> is not equal to rx::RtvDsvClearInfo<int>");
diff --git a/src/libANGLE/renderer/d3d/d3d11/Renderer11.cpp b/src/libANGLE/renderer/d3d/d3d11/Renderer11.cpp
index 224b715..124f1ab 100644
--- a/src/libANGLE/renderer/d3d/d3d11/Renderer11.cpp
+++ b/src/libANGLE/renderer/d3d/d3d11/Renderer11.cpp
@@ -60,7 +60,7 @@
 #include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h"
 #include "libANGLE/renderer/d3d/d3d11/texture_format_table.h"
 #include "libANGLE/renderer/renderer_utils.h"
-#include "third_party/trace_event/trace_event.h"
+#include "libANGLE/trace.h"
 
 #ifdef ANGLE_ENABLE_WINDOWS_STORE
 #    include "libANGLE/renderer/d3d/d3d11/winrt/NativeWindow11WinRT.h"
@@ -516,7 +516,7 @@
 #if !defined(ANGLE_ENABLE_WINDOWS_STORE)
 #    if !ANGLE_SKIP_DXGI_1_2_CHECK
     {
-        TRACE_EVENT0("gpu.angle", "Renderer11::initialize (DXGICheck)");
+        ANGLE_TRACE_EVENT0("gpu.angle", "Renderer11::initialize (DXGICheck)");
         // In order to create a swap chain for an HWND owned by another process, DXGI 1.2 is
         // required.
         // The easiest way to check is to query for a IDXGIDevice2.
@@ -550,7 +550,7 @@
 #endif
 
     {
-        TRACE_EVENT0("gpu.angle", "Renderer11::initialize (ComQueries)");
+        ANGLE_TRACE_EVENT0("gpu.angle", "Renderer11::initialize (ComQueries)");
         // Cast the DeviceContext to a DeviceContext1 and DeviceContext3.
         // This could fail on Windows 7 without the Platform Update.
         // Don't error in this case- just don't use mDeviceContext1 or mDeviceContext3.
@@ -629,7 +629,7 @@
     // Disable some spurious D3D11 debug warnings to prevent them from flooding the output log
     if (mCreateDebugDevice)
     {
-        TRACE_EVENT0("gpu.angle", "Renderer11::initialize (HideWarnings)");
+        ANGLE_TRACE_EVENT0("gpu.angle", "Renderer11::initialize (HideWarnings)");
         ID3D11InfoQueue *infoQueue;
         result = mDevice->QueryInterface(__uuidof(ID3D11InfoQueue), (void **)&infoQueue);
 
@@ -678,7 +678,7 @@
         PFN_D3D11_CREATE_DEVICE D3D11CreateDevice = nullptr;
         {
             SCOPED_ANGLE_HISTOGRAM_TIMER("GPU.ANGLE.Renderer11InitializeDLLsMS");
-            TRACE_EVENT0("gpu.angle", "Renderer11::initialize (Load DLLs)");
+            ANGLE_TRACE_EVENT0("gpu.angle", "Renderer11::initialize (Load DLLs)");
             mDxgiModule  = LoadLibrary(TEXT("dxgi.dll"));
             mD3d11Module = LoadLibrary(TEXT("d3d11.dll"));
             mDCompModule = LoadLibrary(TEXT("dcomp.dll"));
@@ -704,7 +704,7 @@
 
         if (mCreateDebugDevice)
         {
-            TRACE_EVENT0("gpu.angle", "D3D11CreateDevice (Debug)");
+            ANGLE_TRACE_EVENT0("gpu.angle", "D3D11CreateDevice (Debug)");
             result = callD3D11CreateDevice(D3D11CreateDevice, true);
 
             if (result == E_INVALIDARG && mAvailableFeatureLevels.size() > 1u &&
@@ -726,7 +726,7 @@
         if (!mDevice || FAILED(result))
         {
             SCOPED_ANGLE_HISTOGRAM_TIMER("GPU.ANGLE.D3D11CreateDeviceMS");
-            TRACE_EVENT0("gpu.angle", "D3D11CreateDevice");
+            ANGLE_TRACE_EVENT0("gpu.angle", "D3D11CreateDevice");
 
             result = callD3D11CreateDevice(D3D11CreateDevice, false);
 
@@ -794,7 +794,7 @@
 egl::Error Renderer11::initializeDevice()
 {
     SCOPED_ANGLE_HISTOGRAM_TIMER("GPU.ANGLE.Renderer11InitializeDeviceMS");
-    TRACE_EVENT0("gpu.angle", "Renderer11::initializeDevice");
+    ANGLE_TRACE_EVENT0("gpu.angle", "Renderer11::initializeDevice");
 
     populateRenderer11DeviceCaps();
 
diff --git a/src/libANGLE/renderer/d3d/d3d11/SwapChain11.cpp b/src/libANGLE/renderer/d3d/d3d11/SwapChain11.cpp
index fe4def6..023e205 100644
--- a/src/libANGLE/renderer/d3d/d3d11/SwapChain11.cpp
+++ b/src/libANGLE/renderer/d3d/d3d11/SwapChain11.cpp
@@ -17,7 +17,7 @@
 #include "libANGLE/renderer/d3d/d3d11/formatutils11.h"
 #include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h"
 #include "libANGLE/renderer/d3d/d3d11/texture_format_table.h"
-#include "third_party/trace_event/trace_event.h"
+#include "libANGLE/trace.h"
 
 // Precompiled shaders
 #include "libANGLE/renderer/d3d/d3d11/shaders/compiled/passthrough2d11vs.h"
@@ -186,7 +186,7 @@
 {
     ASSERT(mNeedsOffscreenTexture);
 
-    TRACE_EVENT0("gpu.angle", "SwapChain11::resetOffscreenTexture");
+    ANGLE_TRACE_EVENT0("gpu.angle", "SwapChain11::resetOffscreenTexture");
     ID3D11Device *device = mRenderer->getDevice();
 
     ASSERT(device != nullptr);
@@ -452,7 +452,7 @@
 
 EGLint SwapChain11::resize(DisplayD3D *displayD3D, EGLint backbufferWidth, EGLint backbufferHeight)
 {
-    TRACE_EVENT0("gpu.angle", "SwapChain11::resize");
+    ANGLE_TRACE_EVENT0("gpu.angle", "SwapChain11::resize");
     ID3D11Device *device = mRenderer->getDevice();
 
     if (device == nullptr)
@@ -582,7 +582,7 @@
         return resize(displayD3D, backbufferWidth, backbufferHeight);
     }
 
-    TRACE_EVENT0("gpu.angle", "SwapChain11::reset");
+    ANGLE_TRACE_EVENT0("gpu.angle", "SwapChain11::reset");
     ID3D11Device *device = mRenderer->getDevice();
 
     if (device == nullptr)
@@ -663,7 +663,7 @@
         return angle::Result::Continue;
     }
 
-    TRACE_EVENT0("gpu.angle", "SwapChain11::initPassThroughResources");
+    ANGLE_TRACE_EVENT0("gpu.angle", "SwapChain11::initPassThroughResources");
     ID3D11Device *device = mRenderer->getDevice();
 
     ASSERT(device != nullptr);
diff --git a/src/libANGLE/renderer/d3d/d3d9/Renderer9.cpp b/src/libANGLE/renderer/d3d/d3d9/Renderer9.cpp
index d179a20..121e7dd 100644
--- a/src/libANGLE/renderer/d3d/d3d9/Renderer9.cpp
+++ b/src/libANGLE/renderer/d3d/d3d9/Renderer9.cpp
@@ -51,7 +51,7 @@
 #include "libANGLE/renderer/d3d/d3d9/VertexBuffer9.h"
 #include "libANGLE/renderer/d3d/d3d9/formatutils9.h"
 #include "libANGLE/renderer/d3d/d3d9/renderer9_utils.h"
-#include "third_party/trace_event/trace_event.h"
+#include "libANGLE/trace.h"
 
 #if !defined(ANGLE_COMPILE_OPTIMIZATION_LEVEL)
 #    define ANGLE_COMPILE_OPTIMIZATION_LEVEL D3DCOMPILE_OPTIMIZATION_LEVEL3
@@ -193,7 +193,7 @@
 
 egl::Error Renderer9::initialize()
 {
-    TRACE_EVENT0("gpu.angle", "GetModuleHandle_d3d9");
+    ANGLE_TRACE_EVENT0("gpu.angle", "GetModuleHandle_d3d9");
     mD3d9Module = ::LoadLibrary(TEXT("d3d9.dll"));
 
     if (mD3d9Module == nullptr)
@@ -212,14 +212,14 @@
     if (ANGLE_D3D9EX == ANGLE_ENABLED && Direct3DCreate9ExPtr &&
         SUCCEEDED(Direct3DCreate9ExPtr(D3D_SDK_VERSION, &mD3d9Ex)))
     {
-        TRACE_EVENT0("gpu.angle", "D3d9Ex_QueryInterface");
+        ANGLE_TRACE_EVENT0("gpu.angle", "D3d9Ex_QueryInterface");
         ASSERT(mD3d9Ex);
         mD3d9Ex->QueryInterface(__uuidof(IDirect3D9), reinterpret_cast<void **>(&mD3d9));
         ASSERT(mD3d9);
     }
     else
     {
-        TRACE_EVENT0("gpu.angle", "Direct3DCreate9");
+        ANGLE_TRACE_EVENT0("gpu.angle", "Direct3DCreate9");
         mD3d9 = Direct3DCreate9(D3D_SDK_VERSION);
     }
 
@@ -238,7 +238,7 @@
 
     // Give up on getting device caps after about one second.
     {
-        TRACE_EVENT0("gpu.angle", "GetDeviceCaps");
+        ANGLE_TRACE_EVENT0("gpu.angle", "GetDeviceCaps");
         for (int i = 0; i < 10; ++i)
         {
             result = mD3d9->GetDeviceCaps(mAdapter, mDeviceType, &mDeviceCaps);
@@ -282,7 +282,7 @@
     }
 
     {
-        TRACE_EVENT0("gpu.angle", "GetAdapterIdentifier");
+        ANGLE_TRACE_EVENT0("gpu.angle", "GetAdapterIdentifier");
         mD3d9->GetAdapterIdentifier(mAdapter, 0, &mAdapterIdentifier);
     }
 
@@ -290,7 +290,7 @@
     static const TCHAR className[]  = TEXT("STATIC");
 
     {
-        TRACE_EVENT0("gpu.angle", "CreateWindowEx");
+        ANGLE_TRACE_EVENT0("gpu.angle", "CreateWindowEx");
         mDeviceWindow =
             CreateWindowEx(WS_EX_NOACTIVATE, className, windowName, WS_DISABLED | WS_POPUP, 0, 0, 1,
                            1, HWND_MESSAGE, nullptr, GetModuleHandle(nullptr), nullptr);
@@ -301,7 +301,7 @@
         D3DCREATE_FPU_PRESERVE | D3DCREATE_NOWINDOWCHANGES | D3DCREATE_MULTITHREADED;
 
     {
-        TRACE_EVENT0("gpu.angle", "D3d9_CreateDevice");
+        ANGLE_TRACE_EVENT0("gpu.angle", "D3d9_CreateDevice");
         result = mD3d9->CreateDevice(
             mAdapter, mDeviceType, mDeviceWindow,
             behaviorFlags | D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE,
@@ -315,7 +315,7 @@
 
     if (FAILED(result))
     {
-        TRACE_EVENT0("gpu.angle", "D3d9_CreateDevice2");
+        ANGLE_TRACE_EVENT0("gpu.angle", "D3d9_CreateDevice2");
         result = mD3d9->CreateDevice(mAdapter, mDeviceType, mDeviceWindow,
                                      behaviorFlags | D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                                      &presentParameters, &mDevice);
@@ -331,13 +331,13 @@
 
     if (mD3d9Ex)
     {
-        TRACE_EVENT0("gpu.angle", "mDevice_QueryInterface");
+        ANGLE_TRACE_EVENT0("gpu.angle", "mDevice_QueryInterface");
         result = mDevice->QueryInterface(__uuidof(IDirect3DDevice9Ex), (void **)&mDeviceEx);
         ASSERT(SUCCEEDED(result));
     }
 
     {
-        TRACE_EVENT0("gpu.angle", "ShaderCache initialize");
+        ANGLE_TRACE_EVENT0("gpu.angle", "ShaderCache initialize");
         mVertexShaderCache.initialize(mDevice);
         mPixelShaderCache.initialize(mDevice);
     }
diff --git a/src/libANGLE/renderer/vulkan/BufferVk.cpp b/src/libANGLE/renderer/vulkan/BufferVk.cpp
index 3e15fc8..897780c 100644
--- a/src/libANGLE/renderer/vulkan/BufferVk.cpp
+++ b/src/libANGLE/renderer/vulkan/BufferVk.cpp
@@ -14,7 +14,7 @@
 #include "libANGLE/Context.h"
 #include "libANGLE/renderer/vulkan/ContextVk.h"
 #include "libANGLE/renderer/vulkan/RendererVk.h"
-#include "third_party/trace_event/trace_event.h"
+#include "libANGLE/trace.h"
 
 namespace rx
 {
@@ -255,7 +255,7 @@
         return angle::Result::Continue;
     }
 
-    TRACE_EVENT0("gpu.angle", "BufferVk::getIndexRange");
+    ANGLE_TRACE_EVENT0("gpu.angle", "BufferVk::getIndexRange");
     // Needed before reading buffer or we could get stale data.
     ANGLE_TRY(contextVk->finishImpl());
 
diff --git a/src/libANGLE/renderer/vulkan/CommandGraph.cpp b/src/libANGLE/renderer/vulkan/CommandGraph.cpp
index 027b7da..6fe91ef 100644
--- a/src/libANGLE/renderer/vulkan/CommandGraph.cpp
+++ b/src/libANGLE/renderer/vulkan/CommandGraph.cpp
@@ -17,7 +17,7 @@
 #include "libANGLE/renderer/vulkan/vk_format_utils.h"
 #include "libANGLE/renderer/vulkan/vk_helpers.h"
 
-#include "third_party/trace_event/trace_event.h"
+#include "libANGLE/trace.h"
 
 namespace rx
 {
diff --git a/src/libANGLE/renderer/vulkan/ContextVk.cpp b/src/libANGLE/renderer/vulkan/ContextVk.cpp
index 51f92b9..5c5a778 100644
--- a/src/libANGLE/renderer/vulkan/ContextVk.cpp
+++ b/src/libANGLE/renderer/vulkan/ContextVk.cpp
@@ -38,7 +38,7 @@
 #include "libANGLE/renderer/vulkan/TransformFeedbackVk.h"
 #include "libANGLE/renderer/vulkan/VertexArrayVk.h"
 
-#include "third_party/trace_event/trace_event.h"
+#include "libANGLE/trace.h"
 
 namespace rx
 {
@@ -187,7 +187,7 @@
       mGpuClockSync{std::numeric_limits<double>::max(), std::numeric_limits<double>::max()},
       mGpuEventTimestampOrigin(0)
 {
-    TRACE_EVENT0("gpu.angle", "ContextVk::ContextVk");
+    ANGLE_TRACE_EVENT0("gpu.angle", "ContextVk::ContextVk");
     memset(&mClearColorValue, 0, sizeof(mClearColorValue));
     memset(&mClearDepthStencilValue, 0, sizeof(mClearDepthStencilValue));
 
@@ -273,7 +273,7 @@
 
 angle::Result ContextVk::initialize()
 {
-    TRACE_EVENT0("gpu.angle", "ContextVk::initialize");
+    ANGLE_TRACE_EVENT0("gpu.angle", "ContextVk::initialize");
 
     VkDescriptorPoolSize driverSetSize = {VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 1};
     ANGLE_TRY(mDriverUniformsDescriptorPool.init(this, &driverSetSize, 1));
@@ -656,7 +656,7 @@
 angle::Result ContextVk::submitFrame(const VkSubmitInfo &submitInfo,
                                      vk::PrimaryCommandBuffer &&commandBuffer)
 {
-    TRACE_EVENT0("gpu.angle", "RendererVk::submitFrame");
+    ANGLE_TRACE_EVENT0("gpu.angle", "RendererVk::submitFrame");
     VkFenceCreateInfo fenceInfo = {};
     fenceInfo.sType             = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
     fenceInfo.flags             = 0;
@@ -841,7 +841,7 @@
     // Make sure nothing is running
     ASSERT(mCommandGraph.empty());
 
-    TRACE_EVENT0("gpu.angle", "RendererVk::synchronizeCpuGpuTime");
+    ANGLE_TRACE_EVENT0("gpu.angle", "RendererVk::synchronizeCpuGpuTime");
 
     // Create a query used to receive the GPU timestamp
     vk::QueryHelper timestampQuery;
@@ -1096,7 +1096,7 @@
         // for.
         static long long eventId = 1;
         static const unsigned char *categoryEnabled =
-            TRACE_EVENT_API_GET_CATEGORY_ENABLED("gpu.angle.gpu");
+            TRACE_EVENT_API_GET_CATEGORY_ENABLED(platform, "gpu.angle.gpu");
         platform->addTraceEvent(platform, event.phase, categoryEnabled, event.name, eventId++,
                                 gpuTimestampS, 0, nullptr, nullptr, nullptr, TRACE_EVENT_FLAG_NONE);
     }
@@ -2080,7 +2080,7 @@
         return angle::Result::Continue;
     }
 
-    TRACE_EVENT0("gpu.angle", "ContextVk::flush");
+    ANGLE_TRACE_EVENT0("gpu.angle", "ContextVk::flush");
 
     vk::Scoped<vk::PrimaryCommandBuffer> commandBatch(getDevice());
     if (!mCommandGraph.empty())
@@ -2110,7 +2110,7 @@
 
 angle::Result ContextVk::finishImpl()
 {
-    TRACE_EVENT0("gpu.angle", "ContextVk::finish");
+    ANGLE_TRACE_EVENT0("gpu.angle", "ContextVk::finish");
 
     ANGLE_TRY(flushImpl(nullptr));
 
@@ -2165,7 +2165,7 @@
         mLastCompletedQueueSerial = batch.serial;
 
         batch.fence.reset(device);
-        TRACE_EVENT0("gpu.angle", "commandPool.destroy");
+        ANGLE_TRACE_EVENT0("gpu.angle", "commandPool.destroy");
         batch.commandPool.destroy(device);
         ++finishedCount;
     }
diff --git a/src/libANGLE/renderer/vulkan/DisplayVk.cpp b/src/libANGLE/renderer/vulkan/DisplayVk.cpp
index 3907781..af5ed60 100644
--- a/src/libANGLE/renderer/vulkan/DisplayVk.cpp
+++ b/src/libANGLE/renderer/vulkan/DisplayVk.cpp
@@ -17,7 +17,7 @@
 #include "libANGLE/renderer/vulkan/RendererVk.h"
 #include "libANGLE/renderer/vulkan/SurfaceVk.h"
 #include "libANGLE/renderer/vulkan/SyncVk.h"
-#include "third_party/trace_event/trace_event.h"
+#include "libANGLE/trace.h"
 
 namespace rx
 {
@@ -83,7 +83,7 @@
 
 egl::Error DisplayVk::waitClient(const gl::Context *context)
 {
-    TRACE_EVENT0("gpu.angle", "DisplayVk::waitClient");
+    ANGLE_TRACE_EVENT0("gpu.angle", "DisplayVk::waitClient");
     ContextVk *contextVk = vk::GetImpl(context);
     return angle::ToEGL(contextVk->finishImpl(), this, EGL_BAD_ACCESS);
 }
diff --git a/src/libANGLE/renderer/vulkan/FramebufferVk.cpp b/src/libANGLE/renderer/vulkan/FramebufferVk.cpp
index d73e2f2..ee031a6 100644
--- a/src/libANGLE/renderer/vulkan/FramebufferVk.cpp
+++ b/src/libANGLE/renderer/vulkan/FramebufferVk.cpp
@@ -24,7 +24,7 @@
 #include "libANGLE/renderer/vulkan/RendererVk.h"
 #include "libANGLE/renderer/vulkan/SurfaceVk.h"
 #include "libANGLE/renderer/vulkan/vk_format_utils.h"
-#include "third_party/trace_event/trace_event.h"
+#include "libANGLE/trace.h"
 
 namespace rx
 {
@@ -1311,7 +1311,7 @@
                                             RenderTargetVk *renderTarget,
                                             void *pixels)
 {
-    TRACE_EVENT0("gpu.angle", "FramebufferVk::readPixelsImpl");
+    ANGLE_TRACE_EVENT0("gpu.angle", "FramebufferVk::readPixelsImpl");
 
     RendererVk *renderer = contextVk->getRenderer();
 
diff --git a/src/libANGLE/renderer/vulkan/RendererVk.cpp b/src/libANGLE/renderer/vulkan/RendererVk.cpp
index f93c321..5649408 100644
--- a/src/libANGLE/renderer/vulkan/RendererVk.cpp
+++ b/src/libANGLE/renderer/vulkan/RendererVk.cpp
@@ -30,8 +30,8 @@
 #include "libANGLE/renderer/vulkan/VertexArrayVk.h"
 #include "libANGLE/renderer/vulkan/vk_caps_utils.h"
 #include "libANGLE/renderer/vulkan/vk_format_utils.h"
+#include "libANGLE/trace.h"
 #include "platform/Platform.h"
-#include "third_party/trace_event/trace_event.h"
 
 // Consts
 namespace
diff --git a/src/libANGLE/renderer/vulkan/SurfaceVk.cpp b/src/libANGLE/renderer/vulkan/SurfaceVk.cpp
index 12babea..2cd7250 100644
--- a/src/libANGLE/renderer/vulkan/SurfaceVk.cpp
+++ b/src/libANGLE/renderer/vulkan/SurfaceVk.cpp
@@ -18,7 +18,7 @@
 #include "libANGLE/renderer/vulkan/FramebufferVk.h"
 #include "libANGLE/renderer/vulkan/RendererVk.h"
 #include "libANGLE/renderer/vulkan/vk_format_utils.h"
-#include "third_party/trace_event/trace_event.h"
+#include "libANGLE/trace.h"
 
 namespace rx
 {
@@ -869,7 +869,7 @@
     // Throttle the submissions to avoid getting too far ahead of the GPU.
     SwapHistory &swap = mSwapHistory[mCurrentSwapHistoryIndex];
     {
-        TRACE_EVENT0("gpu.angle", "WindowSurfaceVk::present: Throttle CPU");
+        ANGLE_TRACE_EVENT0("gpu.angle", "WindowSurfaceVk::present: Throttle CPU");
         ANGLE_TRY(swap.waitFence(contextVk));
         swap.destroy(contextVk->getDevice());
     }
@@ -996,7 +996,7 @@
     {
         // Note: TRACE_EVENT0 is put here instead of inside the function to workaround this issue:
         // http://anglebug.com/2927
-        TRACE_EVENT0("gpu.angle", "nextSwapchainImage");
+        ANGLE_TRACE_EVENT0("gpu.angle", "nextSwapchainImage");
         // Get the next available swapchain image.
 
         VkResult result = nextSwapchainImage(contextVk);
diff --git a/src/libANGLE/renderer/vulkan/TextureVk.cpp b/src/libANGLE/renderer/vulkan/TextureVk.cpp
index bab7285..f47f5a1 100644
--- a/src/libANGLE/renderer/vulkan/TextureVk.cpp
+++ b/src/libANGLE/renderer/vulkan/TextureVk.cpp
@@ -23,7 +23,7 @@
 #include "libANGLE/renderer/vulkan/RendererVk.h"
 #include "libANGLE/renderer/vulkan/SurfaceVk.h"
 #include "libANGLE/renderer/vulkan/vk_format_utils.h"
-#include "third_party/trace_event/trace_event.h"
+#include "libANGLE/trace.h"
 
 namespace rx
 {
@@ -926,7 +926,7 @@
                                                const gl::Rectangle &sourceArea,
                                                uint8_t **outDataPtr)
 {
-    TRACE_EVENT0("gpu.angle", "TextureVk::copyImageDataToBuffer");
+    ANGLE_TRACE_EVENT0("gpu.angle", "TextureVk::copyImageDataToBuffer");
     // Make sure the source is initialized and it's images are flushed.
     ANGLE_TRY(ensureImageInitialized(contextVk));
 
diff --git a/src/libANGLE/renderer/vulkan/VertexArrayVk.cpp b/src/libANGLE/renderer/vulkan/VertexArrayVk.cpp
index 31fbed6..3e0757f 100644
--- a/src/libANGLE/renderer/vulkan/VertexArrayVk.cpp
+++ b/src/libANGLE/renderer/vulkan/VertexArrayVk.cpp
@@ -18,7 +18,7 @@
 #include "libANGLE/renderer/vulkan/FramebufferVk.h"
 #include "libANGLE/renderer/vulkan/RendererVk.h"
 #include "libANGLE/renderer/vulkan/vk_format_utils.h"
-#include "third_party/trace_event/trace_event.h"
+#include "libANGLE/trace.h"
 
 namespace rx
 {
@@ -280,7 +280,7 @@
                                                     const vk::Format &vertexFormat,
                                                     ConversionBuffer *conversion)
 {
-    TRACE_EVENT0("gpu.angle", "VertexArrayVk::convertVertexBufferCpu");
+    ANGLE_TRACE_EVENT0("gpu.angle", "VertexArrayVk::convertVertexBufferCpu");
     // Needed before reading buffer or we could get stale data.
     ANGLE_TRY(contextVk->finishImpl());
 
diff --git a/src/libANGLE/renderer/vulkan/vk_helpers.cpp b/src/libANGLE/renderer/vulkan/vk_helpers.cpp
index b6fe557..8e4d831 100644
--- a/src/libANGLE/renderer/vulkan/vk_helpers.cpp
+++ b/src/libANGLE/renderer/vulkan/vk_helpers.cpp
@@ -17,7 +17,7 @@
 #include "libANGLE/renderer/vulkan/FramebufferVk.h"
 #include "libANGLE/renderer/vulkan/RendererVk.h"
 #include "libANGLE/renderer/vulkan/vk_utils.h"
-#include "third_party/trace_event/trace_event.h"
+#include "libANGLE/trace.h"
 
 namespace rx
 {
@@ -1045,7 +1045,7 @@
     if (glIndexType == gl::DrawElementsType::UnsignedByte ||
         contextVk->getState().isPrimitiveRestartEnabled())
     {
-        TRACE_EVENT0("gpu.angle", "LineLoopHelper::getIndexBufferForElementArrayBuffer");
+        ANGLE_TRACE_EVENT0("gpu.angle", "LineLoopHelper::getIndexBufferForElementArrayBuffer");
         // Needed before reading buffer or we could get stale data.
         ANGLE_TRY(contextVk->finishImpl());
 
diff --git a/src/libANGLE/trace.h b/src/libANGLE/trace.h
new file mode 100644
index 0000000..831fef6
--- /dev/null
+++ b/src/libANGLE/trace.h
@@ -0,0 +1,24 @@
+//
+// Copyright 2019 The ANGLE Project Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+// trace.h: Wrappers for ANGLE trace event functions.
+//
+
+#ifndef LIBANGLE_TRACE_H_
+#define LIBANGLE_TRACE_H_
+
+#include <platform/Platform.h>
+#include "third_party/trace_event/trace_event.h"
+
+// TODO: Pass platform directly to these methods. http://anglebug.com/1892
+#define ANGLE_TRACE_EVENT_BEGIN0(CATEGORY, EVENT) \
+    TRACE_EVENT_BEGIN0(ANGLEPlatformCurrent(), CATEGORY, EVENT)
+#define ANGLE_TRACE_EVENT_END0(CATEGORY, EVENT) \
+    TRACE_EVENT_END0(ANGLEPlatformCurrent(), CATEGORY, EVENT)
+#define ANGLE_TRACE_EVENT_INSTANT0(CATEGORY, EVENT) \
+    TRACE_EVENT_INSTANT0(ANGLEPlatformCurrent(), CATEGORY, EVENT)
+#define ANGLE_TRACE_EVENT0(CATEGORY, EVENT) TRACE_EVENT0(ANGLEPlatformCurrent(), CATEGORY, EVENT)
+
+#endif  // LIBANGLE_TRACE_H_
diff --git a/src/libGLESv2.gni b/src/libGLESv2.gni
index d99cbd2..8d3fbe7 100644
--- a/src/libGLESv2.gni
+++ b/src/libGLESv2.gni
@@ -26,6 +26,8 @@
   "src/common/bitset_utils.h",
   "src/common/debug.cpp",
   "src/common/debug.h",
+  "src/common/event_tracer.cpp",
+  "src/common/event_tracer.h",
   "src/common/hash_utils.h",
   "src/common/mathutil.cpp",
   "src/common/mathutil.h",
@@ -161,8 +163,6 @@
 ]
 
 libangle_sources = [
-  "src/common/event_tracer.cpp",
-  "src/common/event_tracer.h",
   "src/libANGLE/AttributeMap.cpp",
   "src/libANGLE/AttributeMap.h",
   "src/libANGLE/BinaryStream.h",
@@ -289,6 +289,7 @@
   "src/libANGLE/queryconversions.h",
   "src/libANGLE/queryutils.cpp",
   "src/libANGLE/queryutils.h",
+  "src/libANGLE/trace.h",
   "src/libANGLE/renderer/BufferImpl.h",
   "src/libANGLE/renderer/CompilerImpl.h",
   "src/libANGLE/renderer/ContextImpl.cpp",
diff --git a/src/third_party/trace_event/trace_event.h b/src/third_party/trace_event/trace_event.h
index 040580e..a29e708 100644
--- a/src/third_party/trace_event/trace_event.h
+++ b/src/third_party/trace_event/trace_event.h
@@ -155,101 +155,110 @@
 // enabled, then this does nothing.
 // - category and name strings must have application lifetime (statics or
 //   literals). They may not include " chars.
-#define TRACE_EVENT0(category, name) INTERNAL_TRACE_EVENT_ADD_SCOPED(category, name)
-#define TRACE_EVENT1(category, name, arg1_name, arg1_val) \
-    INTERNAL_TRACE_EVENT_ADD_SCOPED(category, name, arg1_name, arg1_val)
-#define TRACE_EVENT2(category, name, arg1_name, arg1_val, arg2_name, arg2_val) \
-    INTERNAL_TRACE_EVENT_ADD_SCOPED(category, name, arg1_name, arg1_val, arg2_name, arg2_val)
+#define TRACE_EVENT0(platform, category, name) \
+    INTERNAL_TRACE_EVENT_ADD_SCOPED(platform, category, name)
+#define TRACE_EVENT1(platform, category, name, arg1_name, arg1_val) \
+    INTERNAL_TRACE_EVENT_ADD_SCOPED(platform, category, name, arg1_name, arg1_val)
+#define TRACE_EVENT2(category, name, arg1_name, arg1_val, arg2_name, arg2_val)                \
+    INTERNAL_TRACE_EVENT_ADD_SCOPED(platform, category, name, arg1_name, arg1_val, arg2_name, \
+                                    arg2_val)
 
 // Records a single event called "name" immediately, with 0, 1 or 2
 // associated arguments. If the category is not enabled, then this
 // does nothing.
 // - category and name strings must have application lifetime (statics or
 //   literals). They may not include " chars.
-#define TRACE_EVENT_INSTANT0(category, name) \
-    INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, category, name, TRACE_EVENT_FLAG_NONE)
-#define TRACE_EVENT_INSTANT1(category, name, arg1_name, arg1_val)                              \
-    INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, category, name, TRACE_EVENT_FLAG_NONE, \
-                             arg1_name, arg1_val)
-#define TRACE_EVENT_INSTANT2(category, name, arg1_name, arg1_val, arg2_name, arg2_val)         \
-    INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, category, name, TRACE_EVENT_FLAG_NONE, \
-                             arg1_name, arg1_val, arg2_name, arg2_val)
-#define TRACE_EVENT_COPY_INSTANT0(category, name) \
-    INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, category, name, TRACE_EVENT_FLAG_COPY)
-#define TRACE_EVENT_COPY_INSTANT1(category, name, arg1_name, arg1_val)                         \
-    INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, category, name, TRACE_EVENT_FLAG_COPY, \
-                             arg1_name, arg1_val)
-#define TRACE_EVENT_COPY_INSTANT2(category, name, arg1_name, arg1_val, arg2_name, arg2_val)    \
-    INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, category, name, TRACE_EVENT_FLAG_COPY, \
-                             arg1_name, arg1_val, arg2_name, arg2_val)
+#define TRACE_EVENT_INSTANT0(platform, category, name)                            \
+    INTERNAL_TRACE_EVENT_ADD(platform, TRACE_EVENT_PHASE_INSTANT, category, name, \
+                             TRACE_EVENT_FLAG_NONE)
+#define TRACE_EVENT_INSTANT1(platform, category, name, arg1_name, arg1_val)       \
+    INTERNAL_TRACE_EVENT_ADD(platform, TRACE_EVENT_PHASE_INSTANT, category, name, \
+                             TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
+#define TRACE_EVENT_INSTANT2(platform, category, name, arg1_name, arg1_val, arg2_name, arg2_val) \
+    INTERNAL_TRACE_EVENT_ADD(platform, TRACE_EVENT_PHASE_INSTANT, category, name,                \
+                             TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, arg2_name, arg2_val)
+#define TRACE_EVENT_COPY_INSTANT0(platform, category, name)                       \
+    INTERNAL_TRACE_EVENT_ADD(platform, TRACE_EVENT_PHASE_INSTANT, category, name, \
+                             TRACE_EVENT_FLAG_COPY)
+#define TRACE_EVENT_COPY_INSTANT1(platform, category, name, arg1_name, arg1_val)  \
+    INTERNAL_TRACE_EVENT_ADD(platform, TRACE_EVENT_PHASE_INSTANT, category, name, \
+                             TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val)
+#define TRACE_EVENT_COPY_INSTANT2(platform, category, name, arg1_name, arg1_val, arg2_name, \
+                                  arg2_val)                                                 \
+    INTERNAL_TRACE_EVENT_ADD(platform, TRACE_EVENT_PHASE_INSTANT, category, name,           \
+                             TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, arg2_name, arg2_val)
 
 // Records a single BEGIN event called "name" immediately, with 0, 1 or 2
 // associated arguments. If the category is not enabled, then this
 // does nothing.
 // - category and name strings must have application lifetime (statics or
 //   literals). They may not include " chars.
-#define TRACE_EVENT_BEGIN0(category, name) \
-    INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, category, name, TRACE_EVENT_FLAG_NONE)
-#define TRACE_EVENT_BEGIN1(category, name, arg1_name, arg1_val)                              \
-    INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, category, name, TRACE_EVENT_FLAG_NONE, \
-                             arg1_name, arg1_val)
-#define TRACE_EVENT_BEGIN2(category, name, arg1_name, arg1_val, arg2_name, arg2_val)         \
-    INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, category, name, TRACE_EVENT_FLAG_NONE, \
-                             arg1_name, arg1_val, arg2_name, arg2_val)
-#define TRACE_EVENT_COPY_BEGIN0(category, name) \
-    INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, category, name, TRACE_EVENT_FLAG_COPY)
-#define TRACE_EVENT_COPY_BEGIN1(category, name, arg1_name, arg1_val)                         \
-    INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, category, name, TRACE_EVENT_FLAG_COPY, \
-                             arg1_name, arg1_val)
-#define TRACE_EVENT_COPY_BEGIN2(category, name, arg1_name, arg1_val, arg2_name, arg2_val)    \
-    INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, category, name, TRACE_EVENT_FLAG_COPY, \
-                             arg1_name, arg1_val, arg2_name, arg2_val)
+#define TRACE_EVENT_BEGIN0(platform, category, name)                            \
+    INTERNAL_TRACE_EVENT_ADD(platform, TRACE_EVENT_PHASE_BEGIN, category, name, \
+                             TRACE_EVENT_FLAG_NONE)
+#define TRACE_EVENT_BEGIN1(platform, category, name, arg1_name, arg1_val)       \
+    INTERNAL_TRACE_EVENT_ADD(platform, TRACE_EVENT_PHASE_BEGIN, category, name, \
+                             TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
+#define TRACE_EVENT_BEGIN2(platform, category, name, arg1_name, arg1_val, arg2_name, arg2_val) \
+    INTERNAL_TRACE_EVENT_ADD(platform, TRACE_EVENT_PHASE_BEGIN, category, name,                \
+                             TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, arg2_name, arg2_val)
+#define TRACE_EVENT_COPY_BEGIN0(platform, category, name)                       \
+    INTERNAL_TRACE_EVENT_ADD(platform, TRACE_EVENT_PHASE_BEGIN, category, name, \
+                             TRACE_EVENT_FLAG_COPY)
+#define TRACE_EVENT_COPY_BEGIN1(platform, category, name, arg1_name, arg1_val)  \
+    INTERNAL_TRACE_EVENT_ADD(platform, TRACE_EVENT_PHASE_BEGIN, category, name, \
+                             TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val)
+#define TRACE_EVENT_COPY_BEGIN2(platform, category, name, arg1_name, arg1_val, arg2_name, \
+                                arg2_val)                                                 \
+    INTERNAL_TRACE_EVENT_ADD(platform, TRACE_EVENT_PHASE_BEGIN, category, name,           \
+                             TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, arg2_name, arg2_val)
 
 // Records a single END event for "name" immediately. If the category
 // is not enabled, then this does nothing.
 // - category and name strings must have application lifetime (statics or
 //   literals). They may not include " chars.
-#define TRACE_EVENT_END0(category, name) \
-    INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, category, name, TRACE_EVENT_FLAG_NONE)
-#define TRACE_EVENT_END1(category, name, arg1_name, arg1_val)                              \
-    INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, category, name, TRACE_EVENT_FLAG_NONE, \
-                             arg1_name, arg1_val)
-#define TRACE_EVENT_END2(category, name, arg1_name, arg1_val, arg2_name, arg2_val)         \
-    INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, category, name, TRACE_EVENT_FLAG_NONE, \
-                             arg1_name, arg1_val, arg2_name, arg2_val)
-#define TRACE_EVENT_COPY_END0(category, name) \
-    INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, category, name, TRACE_EVENT_FLAG_COPY)
-#define TRACE_EVENT_COPY_END1(category, name, arg1_name, arg1_val)                         \
-    INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, category, name, TRACE_EVENT_FLAG_COPY, \
-                             arg1_name, arg1_val)
-#define TRACE_EVENT_COPY_END2(category, name, arg1_name, arg1_val, arg2_name, arg2_val)    \
-    INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, category, name, TRACE_EVENT_FLAG_COPY, \
-                             arg1_name, arg1_val, arg2_name, arg2_val)
+#define TRACE_EVENT_END0(platform, category, name) \
+    INTERNAL_TRACE_EVENT_ADD(platform, TRACE_EVENT_PHASE_END, category, name, TRACE_EVENT_FLAG_NONE)
+#define TRACE_EVENT_END1(platform, category, name, arg1_name, arg1_val)       \
+    INTERNAL_TRACE_EVENT_ADD(platform, TRACE_EVENT_PHASE_END, category, name, \
+                             TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
+#define TRACE_EVENT_END2(platform, category, name, arg1_name, arg1_val, arg2_name, arg2_val) \
+    INTERNAL_TRACE_EVENT_ADD(platform, TRACE_EVENT_PHASE_END, category, name,                \
+                             TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, arg2_name, arg2_val)
+#define TRACE_EVENT_COPY_END0(platform, category, name) \
+    INTERNAL_TRACE_EVENT_ADD(platform, TRACE_EVENT_PHASE_END, category, name, TRACE_EVENT_FLAG_COPY)
+#define TRACE_EVENT_COPY_END1(platform, category, name, arg1_name, arg1_val)  \
+    INTERNAL_TRACE_EVENT_ADD(platform, TRACE_EVENT_PHASE_END, category, name, \
+                             TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val)
+#define TRACE_EVENT_COPY_END2(platform, category, name, arg1_name, arg1_val, arg2_name, arg2_val) \
+    INTERNAL_TRACE_EVENT_ADD(platform, TRACE_EVENT_PHASE_END, category, name,                     \
+                             TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, arg2_name, arg2_val)
 
 // Records the value of a counter called "name" immediately. Value
 // must be representable as a 32 bit integer.
 // - category and name strings must have application lifetime (statics or
 //   literals). They may not include " chars.
-#define TRACE_COUNTER1(category, name, value)                                                  \
-    INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, category, name, TRACE_EVENT_FLAG_NONE, \
-                             "value", static_cast<int>(value))
-#define TRACE_COPY_COUNTER1(category, name, value)                                             \
-    INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, category, name, TRACE_EVENT_FLAG_COPY, \
-                             "value", static_cast<int>(value))
+#define TRACE_COUNTER1(platform, category, name, value)                           \
+    INTERNAL_TRACE_EVENT_ADD(platform, TRACE_EVENT_PHASE_COUNTER, category, name, \
+                             TRACE_EVENT_FLAG_NONE, "value", static_cast<int>(value))
+#define TRACE_COPY_COUNTER1(platform, category, name, value)                      \
+    INTERNAL_TRACE_EVENT_ADD(platform, TRACE_EVENT_PHASE_COUNTER, category, name, \
+                             TRACE_EVENT_FLAG_COPY, "value", static_cast<int>(value))
 
 // Records the values of a multi-parted counter called "name" immediately.
 // The UI will treat value1 and value2 as parts of a whole, displaying their
 // values as a stacked-bar chart.
 // - category and name strings must have application lifetime (statics or
 //   literals). They may not include " chars.
-#define TRACE_COUNTER2(category, name, value1_name, value1_val, value2_name, value2_val)       \
-    INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, category, name, TRACE_EVENT_FLAG_NONE, \
-                             value1_name, static_cast<int>(value1_val), value2_name,           \
-                             static_cast<int>(value2_val))
-#define TRACE_COPY_COUNTER2(category, name, value1_name, value1_val, value2_name, value2_val)  \
-    INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, category, name, TRACE_EVENT_FLAG_COPY, \
-                             value1_name, static_cast<int>(value1_val), value2_name,           \
-                             static_cast<int>(value2_val))
+#define TRACE_COUNTER2(platform, category, name, value1_name, value1_val, value2_name, value2_val) \
+    INTERNAL_TRACE_EVENT_ADD(platform, TRACE_EVENT_PHASE_COUNTER, category, name,                  \
+                             TRACE_EVENT_FLAG_NONE, value1_name, static_cast<int>(value1_val),     \
+                             value2_name, static_cast<int>(value2_val))
+#define TRACE_COPY_COUNTER2(platform, category, name, value1_name, value1_val, value2_name,    \
+                            value2_val)                                                        \
+    INTERNAL_TRACE_EVENT_ADD(platform, TRACE_EVENT_PHASE_COUNTER, category, name,              \
+                             TRACE_EVENT_FLAG_COPY, value1_name, static_cast<int>(value1_val), \
+                             value2_name, static_cast<int>(value2_val))
 
 // Records the value of a counter called "name" immediately. Value
 // must be representable as a 32 bit integer.
@@ -259,11 +268,11 @@
 //   be a pointer or an integer value up to 64 bits. If it's a pointer, the bits
 //   will be xored with a hash of the process ID so that the same pointer on
 //   two different processes will not collide.
-#define TRACE_COUNTER_ID1(category, name, id, value)                                \
-    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_COUNTER, category, name, id, \
+#define TRACE_COUNTER_ID1(platform, category, name, id, value)                                \
+    INTERNAL_TRACE_EVENT_ADD_WITH_ID(platform, TRACE_EVENT_PHASE_COUNTER, category, name, id, \
                                      TRACE_EVENT_FLAG_NONE, "value", static_cast<int>(value))
-#define TRACE_COPY_COUNTER_ID1(category, name, id, value)                           \
-    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_COUNTER, category, name, id, \
+#define TRACE_COPY_COUNTER_ID1(platform, category, name, id, value)                           \
+    INTERNAL_TRACE_EVENT_ADD_WITH_ID(platform, TRACE_EVENT_PHASE_COUNTER, category, name, id, \
                                      TRACE_EVENT_FLAG_COPY, "value", static_cast<int>(value))
 
 // Records the values of a multi-parted counter called "name" immediately.
@@ -275,15 +284,16 @@
 //   be a pointer or an integer value up to 64 bits. If it's a pointer, the bits
 //   will be xored with a hash of the process ID so that the same pointer on
 //   two different processes will not collide.
-#define TRACE_COUNTER_ID2(category, name, id, value1_name, value1_val, value2_name, value2_val) \
-    INTERNAL_TRACE_EVENT_ADD_WITH_ID(                                                           \
-        TRACE_EVENT_PHASE_COUNTER, category, name, id, TRACE_EVENT_FLAG_NONE, value1_name,      \
-        static_cast<int>(value1_val), value2_name, static_cast<int>(value2_val))
-#define TRACE_COPY_COUNTER_ID2(category, name, id, value1_name, value1_val, value2_name,   \
-                               value2_val)                                                 \
-    INTERNAL_TRACE_EVENT_ADD_WITH_ID(                                                      \
-        TRACE_EVENT_PHASE_COUNTER, category, name, id, TRACE_EVENT_FLAG_COPY, value1_name, \
-        static_cast<int>(value1_val), value2_name, static_cast<int>(value2_val))
+#define TRACE_COUNTER_ID2(platform, category, name, id, value1_name, value1_val, value2_name, \
+                          value2_val)                                                         \
+    INTERNAL_TRACE_EVENT_ADD_WITH_ID(                                                         \
+        platform, TRACE_EVENT_PHASE_COUNTER, category, name, id, TRACE_EVENT_FLAG_NONE,       \
+        value1_name, static_cast<int>(value1_val), value2_name, static_cast<int>(value2_val))
+#define TRACE_COPY_COUNTER_ID2(platform, category, name, id, value1_name, value1_val, value2_name, \
+                               value2_val)                                                         \
+    INTERNAL_TRACE_EVENT_ADD_WITH_ID(                                                              \
+        platform, TRACE_EVENT_PHASE_COUNTER, category, name, id, TRACE_EVENT_FLAG_COPY,            \
+        value1_name, static_cast<int>(value1_val), value2_name, static_cast<int>(value2_val))
 
 // Records a single ASYNC_BEGIN event called "name" immediately, with 0, 1 or 2
 // associated arguments. If the category is not enabled, then this
@@ -301,26 +311,27 @@
 // An async operation can span threads and processes, but all events in that
 // operation must use the same |name| and |id|. Each event can have its own
 // args.
-#define TRACE_EVENT_ASYNC_BEGIN0(category, name, id)                                    \
-    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, category, name, id, \
+#define TRACE_EVENT_ASYNC_BEGIN0(platform, category, name, id)                                    \
+    INTERNAL_TRACE_EVENT_ADD_WITH_ID(platform, TRACE_EVENT_PHASE_ASYNC_BEGIN, category, name, id, \
                                      TRACE_EVENT_FLAG_NONE)
-#define TRACE_EVENT_ASYNC_BEGIN1(category, name, id, arg1_name, arg1_val)               \
-    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, category, name, id, \
+#define TRACE_EVENT_ASYNC_BEGIN1(platform, category, name, id, arg1_name, arg1_val)               \
+    INTERNAL_TRACE_EVENT_ADD_WITH_ID(platform, TRACE_EVENT_PHASE_ASYNC_BEGIN, category, name, id, \
                                      TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
-#define TRACE_EVENT_ASYNC_BEGIN2(category, name, id, arg1_name, arg1_val, arg2_name, arg2_val) \
-    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, category, name, id,        \
-                                     TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, arg2_name,    \
+#define TRACE_EVENT_ASYNC_BEGIN2(platform, category, name, id, arg1_name, arg1_val, arg2_name,    \
+                                 arg2_val)                                                        \
+    INTERNAL_TRACE_EVENT_ADD_WITH_ID(platform, TRACE_EVENT_PHASE_ASYNC_BEGIN, category, name, id, \
+                                     TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, arg2_name,       \
                                      arg2_val)
-#define TRACE_EVENT_COPY_ASYNC_BEGIN0(category, name, id)                               \
-    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, category, name, id, \
+#define TRACE_EVENT_COPY_ASYNC_BEGIN0(platform, category, name, id)                               \
+    INTERNAL_TRACE_EVENT_ADD_WITH_ID(platform, TRACE_EVENT_PHASE_ASYNC_BEGIN, category, name, id, \
                                      TRACE_EVENT_FLAG_COPY)
-#define TRACE_EVENT_COPY_ASYNC_BEGIN1(category, name, id, arg1_name, arg1_val)          \
-    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, category, name, id, \
+#define TRACE_EVENT_COPY_ASYNC_BEGIN1(platform, category, name, id, arg1_name, arg1_val)          \
+    INTERNAL_TRACE_EVENT_ADD_WITH_ID(platform, TRACE_EVENT_PHASE_ASYNC_BEGIN, category, name, id, \
                                      TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val)
-#define TRACE_EVENT_COPY_ASYNC_BEGIN2(category, name, id, arg1_name, arg1_val, arg2_name,   \
-                                      arg2_val)                                             \
-    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, category, name, id,     \
-                                     TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, arg2_name, \
+#define TRACE_EVENT_COPY_ASYNC_BEGIN2(platform, category, name, id, arg1_name, arg1_val,          \
+                                      arg2_name, arg2_val)                                        \
+    INTERNAL_TRACE_EVENT_ADD_WITH_ID(platform, TRACE_EVENT_PHASE_ASYNC_BEGIN, category, name, id, \
+                                     TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, arg2_name,       \
                                      arg2_val)
 
 // Records a single ASYNC_STEP event for |step| immediately. If the category
@@ -328,39 +339,41 @@
 // ASYNC_BEGIN event above. The |step| param identifies this step within the
 // async event. This should be called at the beginning of the next phase of an
 // asynchronous operation.
-#define TRACE_EVENT_ASYNC_STEP0(category, name, id, step)                              \
-    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_STEP, category, name, id, \
+#define TRACE_EVENT_ASYNC_STEP0(platform, category, name, id, step)                              \
+    INTERNAL_TRACE_EVENT_ADD_WITH_ID(platform, TRACE_EVENT_PHASE_ASYNC_STEP, category, name, id, \
                                      TRACE_EVENT_FLAG_NONE, "step", step)
-#define TRACE_EVENT_ASYNC_STEP1(category, name, id, step, arg1_name, arg1_val)         \
-    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_STEP, category, name, id, \
+#define TRACE_EVENT_ASYNC_STEP1(platform, category, name, id, step, arg1_name, arg1_val)         \
+    INTERNAL_TRACE_EVENT_ADD_WITH_ID(platform, TRACE_EVENT_PHASE_ASYNC_STEP, category, name, id, \
                                      TRACE_EVENT_FLAG_NONE, "step", step, arg1_name, arg1_val)
-#define TRACE_EVENT_COPY_ASYNC_STEP0(category, name, id, step)                         \
-    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_STEP, category, name, id, \
+#define TRACE_EVENT_COPY_ASYNC_STEP0(platform, category, name, id, step)                         \
+    INTERNAL_TRACE_EVENT_ADD_WITH_ID(platform, TRACE_EVENT_PHASE_ASYNC_STEP, category, name, id, \
                                      TRACE_EVENT_FLAG_COPY, "step", step)
-#define TRACE_EVENT_COPY_ASYNC_STEP1(category, name, id, step, arg1_name, arg1_val)    \
-    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_STEP, category, name, id, \
+#define TRACE_EVENT_COPY_ASYNC_STEP1(platform, category, name, id, step, arg1_name, arg1_val)    \
+    INTERNAL_TRACE_EVENT_ADD_WITH_ID(platform, TRACE_EVENT_PHASE_ASYNC_STEP, category, name, id, \
                                      TRACE_EVENT_FLAG_COPY, "step", step, arg1_name, arg1_val)
 
 // Records a single ASYNC_END event for "name" immediately. If the category
 // is not enabled, then this does nothing.
-#define TRACE_EVENT_ASYNC_END0(category, name, id)                                    \
-    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, category, name, id, \
+#define TRACE_EVENT_ASYNC_END0(platform, category, name, id)                                    \
+    INTERNAL_TRACE_EVENT_ADD_WITH_ID(platform, TRACE_EVENT_PHASE_ASYNC_END, category, name, id, \
                                      TRACE_EVENT_FLAG_NONE)
-#define TRACE_EVENT_ASYNC_END1(category, name, id, arg1_name, arg1_val)               \
-    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, category, name, id, \
+#define TRACE_EVENT_ASYNC_END1(platform, category, name, id, arg1_name, arg1_val)               \
+    INTERNAL_TRACE_EVENT_ADD_WITH_ID(platform, TRACE_EVENT_PHASE_ASYNC_END, category, name, id, \
                                      TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
-#define TRACE_EVENT_ASYNC_END2(category, name, id, arg1_name, arg1_val, arg2_name, arg2_val) \
-    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, category, name, id,        \
-                                     TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, arg2_name,  \
+#define TRACE_EVENT_ASYNC_END2(platform, category, name, id, arg1_name, arg1_val, arg2_name,    \
+                               arg2_val)                                                        \
+    INTERNAL_TRACE_EVENT_ADD_WITH_ID(platform, TRACE_EVENT_PHASE_ASYNC_END, category, name, id, \
+                                     TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, arg2_name,     \
                                      arg2_val)
-#define TRACE_EVENT_COPY_ASYNC_END0(category, name, id)                               \
-    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, category, name, id, \
+#define TRACE_EVENT_COPY_ASYNC_END0(platform, category, name, id)                               \
+    INTERNAL_TRACE_EVENT_ADD_WITH_ID(platform, TRACE_EVENT_PHASE_ASYNC_END, category, name, id, \
                                      TRACE_EVENT_FLAG_COPY)
-#define TRACE_EVENT_COPY_ASYNC_END1(category, name, id, arg1_name, arg1_val)          \
-    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, category, name, id, \
+#define TRACE_EVENT_COPY_ASYNC_END1(platform, category, name, id, arg1_name, arg1_val)          \
+    INTERNAL_TRACE_EVENT_ADD_WITH_ID(platform, TRACE_EVENT_PHASE_ASYNC_END, category, name, id, \
                                      TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val)
-#define TRACE_EVENT_COPY_ASYNC_END2(category, name, id, arg1_name, arg1_val, arg2_name, arg2_val) \
-    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, category, name, id,             \
+#define TRACE_EVENT_COPY_ASYNC_END2(platform, category, name, id, arg1_name, arg1_val, arg2_name, \
+                                    arg2_val)                                                     \
+    INTERNAL_TRACE_EVENT_ADD_WITH_ID(platform, TRACE_EVENT_PHASE_ASYNC_END, category, name, id,   \
                                      TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, arg2_name,       \
                                      arg2_val)
 
@@ -441,52 +454,53 @@
 #define INTERNALTRACEEVENTUID(name_prefix) INTERNAL_TRACE_EVENT_UID2(name_prefix, __LINE__)
 
 // Implementation detail: internal macro to create static category.
-#define INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category)              \
+#define INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(platform, category)    \
     static const unsigned char *INTERNALTRACEEVENTUID(catstatic) = 0; \
     if (!INTERNALTRACEEVENTUID(catstatic))                            \
-        INTERNALTRACEEVENTUID(catstatic) = TRACE_EVENT_API_GET_CATEGORY_ENABLED(category);
+        INTERNALTRACEEVENTUID(catstatic) = TRACE_EVENT_API_GET_CATEGORY_ENABLED(platform, category);
 
 // Implementation detail: internal macro to create static category and add
 // event if the category is enabled.
-#define INTERNAL_TRACE_EVENT_ADD(phase, category, name, flags, ...)                         \
-    do                                                                                      \
-    {                                                                                       \
-        INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category);                                   \
-        if (*INTERNALTRACEEVENTUID(catstatic))                                              \
-        {                                                                                   \
-            gl::TraceEvent::addTraceEvent(phase, INTERNALTRACEEVENTUID(catstatic), name,    \
-                                          gl::TraceEvent::noEventId, flags, ##__VA_ARGS__); \
-        }                                                                                   \
+#define INTERNAL_TRACE_EVENT_ADD(platform, phase, category, name, flags, ...)                      \
+    do                                                                                             \
+    {                                                                                              \
+        INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(platform, category);                                \
+        if (*INTERNALTRACEEVENTUID(catstatic))                                                     \
+        {                                                                                          \
+            gl::TraceEvent::addTraceEvent(platform, phase, INTERNALTRACEEVENTUID(catstatic), name, \
+                                          gl::TraceEvent::noEventId, flags, ##__VA_ARGS__);        \
+        }                                                                                          \
     } while (0)
 
 // Implementation detail: internal macro to create static category and add begin
 // event if the category is enabled. Also adds the end event when the scope
 // ends.
-#define INTERNAL_TRACE_EVENT_ADD_SCOPED(category, name, ...)                                     \
-    INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category);                                            \
-    gl::TraceEvent::TraceEndOnScopeClose INTERNALTRACEEVENTUID(profileScope);                    \
-    if (*INTERNALTRACEEVENTUID(catstatic))                                                       \
-    {                                                                                            \
-        gl::TraceEvent::addTraceEvent(TRACE_EVENT_PHASE_BEGIN, INTERNALTRACEEVENTUID(catstatic), \
-                                      name, gl::TraceEvent::noEventId, TRACE_EVENT_FLAG_NONE,    \
-                                      ##__VA_ARGS__);                                            \
-        INTERNALTRACEEVENTUID(profileScope).initialize(INTERNALTRACEEVENTUID(catstatic), name);  \
+#define INTERNAL_TRACE_EVENT_ADD_SCOPED(platform, category, name, ...)                 \
+    INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(platform, category);                        \
+    gl::TraceEvent::TraceEndOnScopeClose INTERNALTRACEEVENTUID(profileScope);          \
+    if (*INTERNALTRACEEVENTUID(catstatic))                                             \
+    {                                                                                  \
+        gl::TraceEvent::addTraceEvent(                                                 \
+            platform, TRACE_EVENT_PHASE_BEGIN, INTERNALTRACEEVENTUID(catstatic), name, \
+            gl::TraceEvent::noEventId, TRACE_EVENT_FLAG_NONE, ##__VA_ARGS__);          \
+        INTERNALTRACEEVENTUID(profileScope)                                            \
+            .initialize(platform, INTERNALTRACEEVENTUID(catstatic), name);             \
     }
 
 // Implementation detail: internal macro to create static category and add
 // event if the category is enabled.
-#define INTERNAL_TRACE_EVENT_ADD_WITH_ID(phase, category, name, id, flags, ...)          \
-    do                                                                                   \
-    {                                                                                    \
-        INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category);                                \
-        if (*INTERNALTRACEEVENTUID(catstatic))                                           \
-        {                                                                                \
-            unsigned char traceEventFlags = flags | TRACE_EVENT_FLAG_HAS_ID;             \
-            gl::TraceEvent::TraceID traceEventTraceID(id, &traceEventFlags);             \
-            gl::TraceEvent::addTraceEvent(phase, INTERNALTRACEEVENTUID(catstatic), name, \
-                                          traceEventTraceID.data(), traceEventFlags,     \
-                                          ##__VA_ARGS__);                                \
-        }                                                                                \
+#define INTERNAL_TRACE_EVENT_ADD_WITH_ID(platform, phase, category, name, id, flags, ...)          \
+    do                                                                                             \
+    {                                                                                              \
+        INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(platform, category);                                \
+        if (*INTERNALTRACEEVENTUID(catstatic))                                                     \
+        {                                                                                          \
+            unsigned char traceEventFlags = flags | TRACE_EVENT_FLAG_HAS_ID;                       \
+            gl::TraceEvent::TraceID traceEventTraceID(id, &traceEventFlags);                       \
+            gl::TraceEvent::addTraceEvent(platform, phase, INTERNALTRACEEVENTUID(catstatic), name, \
+                                          traceEventTraceID.data(), traceEventFlags,               \
+                                          ##__VA_ARGS__);                                          \
+        }                                                                                          \
     } while (0)
 
 // Notes regarding the following definitions:
@@ -653,18 +667,20 @@
 // store pointers to the internal c_str and pass through to the tracing API, the
 // arg values must live throughout these procedures.
 
-static inline angle::TraceEventHandle addTraceEvent(char phase,
+static inline angle::TraceEventHandle addTraceEvent(angle::PlatformMethods *platform,
+                                                    char phase,
                                                     const unsigned char *categoryEnabled,
                                                     const char *name,
                                                     unsigned long long id,
                                                     unsigned char flags)
 {
-    return TRACE_EVENT_API_ADD_TRACE_EVENT(phase, categoryEnabled, name, id, zeroNumArgs, 0, 0, 0,
-                                           flags);
+    return TRACE_EVENT_API_ADD_TRACE_EVENT(platform, phase, categoryEnabled, name, id, zeroNumArgs,
+                                           0, 0, 0, flags);
 }
 
 template <class ARG1_TYPE>
-static inline angle::TraceEventHandle addTraceEvent(char phase,
+static inline angle::TraceEventHandle addTraceEvent(angle::PlatformMethods *platform,
+                                                    char phase,
                                                     const unsigned char *categoryEnabled,
                                                     const char *name,
                                                     unsigned long long id,
@@ -676,12 +692,13 @@
     unsigned char argTypes[1];
     unsigned long long argValues[1];
     setTraceValue(arg1Val, &argTypes[0], &argValues[0]);
-    return TRACE_EVENT_API_ADD_TRACE_EVENT(phase, categoryEnabled, name, id, numArgs, &arg1Name,
-                                           argTypes, argValues, flags);
+    return TRACE_EVENT_API_ADD_TRACE_EVENT(platform, phase, categoryEnabled, name, id, numArgs,
+                                           &arg1Name, argTypes, argValues, flags);
 }
 
 template <class ARG1_TYPE, class ARG2_TYPE>
-static inline angle::TraceEventHandle addTraceEvent(char phase,
+static inline angle::TraceEventHandle addTraceEvent(angle::PlatformMethods *platform,
+                                                    char phase,
                                                     const unsigned char *categoryEnabled,
                                                     const char *name,
                                                     unsigned long long id,
@@ -697,8 +714,8 @@
     unsigned long long argValues[2];
     setTraceValue(arg1Val, &argTypes[0], &argValues[0]);
     setTraceValue(arg2Val, &argTypes[1], &argValues[1]);
-    return TRACE_EVENT_API_ADD_TRACE_EVENT(phase, categoryEnabled, name, id, numArgs, argNames,
-                                           argTypes, argValues, flags);
+    return TRACE_EVENT_API_ADD_TRACE_EVENT(platform, phase, categoryEnabled, name, id, numArgs,
+                                           argNames, argTypes, argValues, flags);
 }
 
 // Used by TRACE_EVENTx macro. Do not use directly.
@@ -713,8 +730,11 @@
             addEventIfEnabled();
     }
 
-    void initialize(const unsigned char *categoryEnabled, const char *name)
+    void initialize(angle::PlatformMethods *platform,
+                    const unsigned char *categoryEnabled,
+                    const char *name)
     {
+        m_data.platform        = platform;
         m_data.categoryEnabled = categoryEnabled;
         m_data.name            = name;
         m_pdata                = &m_data;
@@ -727,9 +747,9 @@
         // Only called when m_pdata is non-null.
         if (*m_pdata->categoryEnabled)
         {
-            TRACE_EVENT_API_ADD_TRACE_EVENT(TRACE_EVENT_PHASE_END, m_pdata->categoryEnabled,
-                                            m_pdata->name, noEventId, zeroNumArgs, 0, 0, 0,
-                                            TRACE_EVENT_FLAG_NONE);
+            TRACE_EVENT_API_ADD_TRACE_EVENT(m_pdata->platform, TRACE_EVENT_PHASE_END,
+                                            m_pdata->categoryEnabled, m_pdata->name, noEventId,
+                                            zeroNumArgs, 0, 0, 0, TRACE_EVENT_FLAG_NONE);
         }
     }
 
@@ -740,6 +760,7 @@
     // uninitialized accesses.
     struct Data
     {
+        angle::PlatformMethods *platform;
         const unsigned char *categoryEnabled;
         const char *name;
     };