From 73d5bb57e64faafd857b3d6d3c580e3f57a992d3 Mon Sep 17 00:00:00 2001 From: Austin Eng Date: Mon, 28 Oct 2019 23:15:40 +0000 Subject: [PATCH] Use enums for trace event categories Explicit enums are simpler to use in Dawn and allow only specific categories which the perf tests understand. Also adds trace events around command recording and validation on all backends. Bug: dawn:208 Change-Id: I7859ffd6668b20893780c6081bf2c9019a7115e0 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/12781 Commit-Queue: Austin Eng Reviewed-by: Kai Ninomiya --- src/dawn_native/CommandEncoder.cpp | 4 +- src/dawn_native/Queue.cpp | 4 +- src/dawn_native/RenderBundleEncoder.cpp | 4 ++ src/dawn_native/d3d12/QueueD3D12.cpp | 6 +++ src/dawn_native/metal/DeviceMTL.mm | 12 ++--- src/dawn_native/metal/QueueMTL.mm | 7 ++- src/dawn_native/opengl/QueueGL.cpp | 4 ++ src/dawn_native/vulkan/QueueVk.cpp | 5 ++ src/dawn_platform/tracing/EventTracer.cpp | 4 +- src/dawn_platform/tracing/EventTracer.h | 4 +- src/dawn_platform/tracing/TraceEvent.h | 44 ++++++++--------- src/include/dawn_platform/DawnPlatform.h | 9 +++- src/tests/perf_tests/DawnPerfTest.cpp | 25 ++++++++-- src/tests/perf_tests/DawnPerfTestPlatform.cpp | 48 ++++++++++++------- src/tests/perf_tests/DawnPerfTestPlatform.h | 13 ++--- 15 files changed, 121 insertions(+), 72 deletions(-) diff --git a/src/dawn_native/CommandEncoder.cpp b/src/dawn_native/CommandEncoder.cpp index 09a6d7f248..365c7fe63f 100644 --- a/src/dawn_native/CommandEncoder.cpp +++ b/src/dawn_native/CommandEncoder.cpp @@ -27,6 +27,7 @@ #include "dawn_native/PassResourceUsageTracker.h" #include "dawn_native/RenderPassEncoder.h" #include "dawn_native/RenderPipeline.h" +#include "dawn_platform/DawnPlatform.h" #include "dawn_platform/tracing/TraceEvent.h" #include @@ -706,8 +707,6 @@ namespace dawn_native { } CommandBufferBase* CommandEncoderBase::Finish(const CommandBufferDescriptor* descriptor) { - TRACE_EVENT0(GetDevice()->GetPlatform(), TRACE_DISABLED_BY_DEFAULT("gpu.dawn"), - "CommandEncoderBase::Finish"); if (GetDevice()->ConsumedError(ValidateFinish(descriptor))) { // Even if finish validation fails, it is now invalid to call any encoding commands on // this object, so we set its state to finished. @@ -721,6 +720,7 @@ namespace dawn_native { // Implementation of the command buffer validation that can be precomputed before submit MaybeError CommandEncoderBase::ValidateFinish(const CommandBufferDescriptor*) { + TRACE_EVENT0(GetDevice()->GetPlatform(), Validation, "CommandEncoderBase::ValidateFinish"); DAWN_TRY(GetDevice()->ValidateObject(this)); // Even if Finish() validation fails, calling it will mutate the internal state of the diff --git a/src/dawn_native/Queue.cpp b/src/dawn_native/Queue.cpp index f13079a137..4552fdd476 100644 --- a/src/dawn_native/Queue.cpp +++ b/src/dawn_native/Queue.cpp @@ -22,6 +22,7 @@ #include "dawn_native/Fence.h" #include "dawn_native/FenceSignalTracker.h" #include "dawn_native/Texture.h" +#include "dawn_platform/DawnPlatform.h" #include "dawn_platform/tracing/TraceEvent.h" namespace dawn_native { @@ -33,7 +34,7 @@ namespace dawn_native { void QueueBase::Submit(uint32_t commandCount, CommandBufferBase* const* commands) { DeviceBase* device = GetDevice(); - TRACE_EVENT0(device->GetPlatform(), TRACE_DISABLED_BY_DEFAULT("gpu.dawn"), "Queue::Submit"); + TRACE_EVENT0(device->GetPlatform(), General, "Queue::Submit"); if (device->ConsumedError(ValidateSubmit(commandCount, commands))) { return; } @@ -69,6 +70,7 @@ namespace dawn_native { MaybeError QueueBase::ValidateSubmit(uint32_t commandCount, CommandBufferBase* const* commands) { + TRACE_EVENT0(GetDevice()->GetPlatform(), Validation, "Queue::ValidateSubmit"); DAWN_TRY(GetDevice()->ValidateObject(this)); for (uint32_t i = 0; i < commandCount; ++i) { diff --git a/src/dawn_native/RenderBundleEncoder.cpp b/src/dawn_native/RenderBundleEncoder.cpp index 60598dd5ef..5c90a4b8c7 100644 --- a/src/dawn_native/RenderBundleEncoder.cpp +++ b/src/dawn_native/RenderBundleEncoder.cpp @@ -20,6 +20,8 @@ #include "dawn_native/Format.h" #include "dawn_native/RenderPipeline.h" #include "dawn_native/ValidationUtils_autogen.h" +#include "dawn_platform/DawnPlatform.h" +#include "dawn_platform/tracing/TraceEvent.h" namespace dawn_native { @@ -111,6 +113,8 @@ namespace dawn_native { } MaybeError RenderBundleEncoderBase::ValidateFinish(const RenderBundleDescriptor* descriptor) { + TRACE_EVENT0(GetDevice()->GetPlatform(), Validation, + "RenderBundleEncoderBase::ValidateFinish"); DAWN_TRY(GetDevice()->ValidateObject(this)); // Even if Finish() validation fails, calling it will mutate the internal state of the diff --git a/src/dawn_native/d3d12/QueueD3D12.cpp b/src/dawn_native/d3d12/QueueD3D12.cpp index 0043fda407..c563c5028b 100644 --- a/src/dawn_native/d3d12/QueueD3D12.cpp +++ b/src/dawn_native/d3d12/QueueD3D12.cpp @@ -17,6 +17,8 @@ #include "dawn_native/d3d12/CommandBufferD3D12.h" #include "dawn_native/d3d12/D3D12Error.h" #include "dawn_native/d3d12/DeviceD3D12.h" +#include "dawn_platform/DawnPlatform.h" +#include "dawn_platform/tracing/TraceEvent.h" namespace dawn_native { namespace d3d12 { @@ -31,9 +33,13 @@ namespace dawn_native { namespace d3d12 { CommandRecordingContext* commandContext; DAWN_TRY_ASSIGN(commandContext, device->GetPendingCommandContext()); + TRACE_EVENT_BEGIN0(GetDevice()->GetPlatform(), Recording, + "CommandBufferD3D12::RecordCommands"); for (uint32_t i = 0; i < commandCount; ++i) { DAWN_TRY(ToBackend(commands[i])->RecordCommands(commandContext, i)); } + TRACE_EVENT_END0(GetDevice()->GetPlatform(), Recording, + "CommandBufferD3D12::RecordCommands"); DAWN_TRY(device->ExecutePendingCommandContext()); diff --git a/src/dawn_native/metal/DeviceMTL.mm b/src/dawn_native/metal/DeviceMTL.mm index bacc529ab0..a63c5214cd 100644 --- a/src/dawn_native/metal/DeviceMTL.mm +++ b/src/dawn_native/metal/DeviceMTL.mm @@ -29,6 +29,7 @@ #include "dawn_native/metal/StagingBufferMTL.h" #include "dawn_native/metal/SwapChainMTL.h" #include "dawn_native/metal/TextureMTL.h" +#include "dawn_platform/DawnPlatform.h" #include "dawn_platform/tracing/TraceEvent.h" #include @@ -180,8 +181,7 @@ namespace dawn_native { namespace metal { } id Device::GetPendingCommandBuffer() { - TRACE_EVENT0(GetPlatform(), TRACE_DISABLED_BY_DEFAULT("gpu.dawn"), - "DeviceMTL::GetPendingCommandBuffer"); + TRACE_EVENT0(GetPlatform(), General, "DeviceMTL::GetPendingCommandBuffer"); if (mPendingCommands == nil) { mPendingCommands = [mCommandQueue commandBuffer]; [mPendingCommands retain]; @@ -228,14 +228,14 @@ namespace dawn_native { namespace metal { // mLastSubmittedSerial so it is captured by value. Serial pendingSerial = mLastSubmittedSerial; [mPendingCommands addCompletedHandler:^(id) { - TRACE_EVENT_ASYNC_END0(GetPlatform(), TRACE_DISABLED_BY_DEFAULT("gpu.dawn"), - "DeviceMTL::SubmitPendingCommandBuffer", pendingSerial); + TRACE_EVENT_ASYNC_END0(GetPlatform(), GPUWork, "DeviceMTL::SubmitPendingCommandBuffer", + pendingSerial); ASSERT(pendingSerial > mCompletedSerial.load()); this->mCompletedSerial = pendingSerial; }]; - TRACE_EVENT_ASYNC_BEGIN0(GetPlatform(), TRACE_DISABLED_BY_DEFAULT("gpu.dawn"), - "DeviceMTL::SubmitPendingCommandBuffer", pendingSerial); + TRACE_EVENT_ASYNC_BEGIN0(GetPlatform(), GPUWork, "DeviceMTL::SubmitPendingCommandBuffer", + pendingSerial); [mPendingCommands commit]; mPendingCommands = nil; } diff --git a/src/dawn_native/metal/QueueMTL.mm b/src/dawn_native/metal/QueueMTL.mm index d815c6e56c..dd360e970b 100644 --- a/src/dawn_native/metal/QueueMTL.mm +++ b/src/dawn_native/metal/QueueMTL.mm @@ -16,6 +16,7 @@ #include "dawn_native/metal/CommandBufferMTL.h" #include "dawn_native/metal/DeviceMTL.h" +#include "dawn_platform/DawnPlatform.h" #include "dawn_platform/tracing/TraceEvent.h" namespace dawn_native { namespace metal { @@ -28,13 +29,11 @@ namespace dawn_native { namespace metal { device->Tick(); id commandBuffer = device->GetPendingCommandBuffer(); - TRACE_EVENT_BEGIN0(GetDevice()->GetPlatform(), TRACE_DISABLED_BY_DEFAULT("gpu.dawn"), - "CommandBufferMTL::FillCommands"); + TRACE_EVENT_BEGIN0(GetDevice()->GetPlatform(), Recording, "CommandBufferMTL::FillCommands"); for (uint32_t i = 0; i < commandCount; ++i) { ToBackend(commands[i])->FillCommands(commandBuffer); } - TRACE_EVENT_END0(GetDevice()->GetPlatform(), TRACE_DISABLED_BY_DEFAULT("gpu.dawn"), - "CommandBufferMTL::FillCommands"); + TRACE_EVENT_END0(GetDevice()->GetPlatform(), Recording, "CommandBufferMTL::FillCommands"); device->SubmitPendingCommandBuffer(); return {}; diff --git a/src/dawn_native/opengl/QueueGL.cpp b/src/dawn_native/opengl/QueueGL.cpp index fde06c853a..9e08f6ae45 100644 --- a/src/dawn_native/opengl/QueueGL.cpp +++ b/src/dawn_native/opengl/QueueGL.cpp @@ -16,6 +16,8 @@ #include "dawn_native/opengl/CommandBufferGL.h" #include "dawn_native/opengl/DeviceGL.h" +#include "dawn_platform/DawnPlatform.h" +#include "dawn_platform/tracing/TraceEvent.h" namespace dawn_native { namespace opengl { @@ -25,9 +27,11 @@ namespace dawn_native { namespace opengl { MaybeError Queue::SubmitImpl(uint32_t commandCount, CommandBufferBase* const* commands) { Device* device = ToBackend(GetDevice()); + TRACE_EVENT_BEGIN0(GetDevice()->GetPlatform(), Recording, "CommandBufferGL::Execute"); for (uint32_t i = 0; i < commandCount; ++i) { ToBackend(commands[i])->Execute(); } + TRACE_EVENT_END0(GetDevice()->GetPlatform(), Recording, "CommandBufferGL::Execute"); device->SubmitFenceSync(); return {}; diff --git a/src/dawn_native/vulkan/QueueVk.cpp b/src/dawn_native/vulkan/QueueVk.cpp index 558927c52a..19ab88c7e3 100644 --- a/src/dawn_native/vulkan/QueueVk.cpp +++ b/src/dawn_native/vulkan/QueueVk.cpp @@ -17,6 +17,8 @@ #include "dawn_native/vulkan/CommandBufferVk.h" #include "dawn_native/vulkan/CommandRecordingContext.h" #include "dawn_native/vulkan/DeviceVk.h" +#include "dawn_platform/DawnPlatform.h" +#include "dawn_platform/tracing/TraceEvent.h" namespace dawn_native { namespace vulkan { @@ -33,10 +35,13 @@ namespace dawn_native { namespace vulkan { device->Tick(); + TRACE_EVENT_BEGIN0(GetDevice()->GetPlatform(), Recording, + "CommandBufferVk::RecordCommands"); CommandRecordingContext* recordingContext = device->GetPendingRecordingContext(); for (uint32_t i = 0; i < commandCount; ++i) { DAWN_TRY(ToBackend(commands[i])->RecordCommands(recordingContext)); } + TRACE_EVENT_END0(GetDevice()->GetPlatform(), Recording, "CommandBufferVk::RecordCommands"); DAWN_TRY(device->SubmitPendingCommands()); diff --git a/src/dawn_platform/tracing/EventTracer.cpp b/src/dawn_platform/tracing/EventTracer.cpp index 2727576939..a110340f58 100644 --- a/src/dawn_platform/tracing/EventTracer.cpp +++ b/src/dawn_platform/tracing/EventTracer.cpp @@ -18,13 +18,13 @@ namespace dawn_platform { namespace tracing { - const unsigned char* GetTraceCategoryEnabledFlag(Platform* platform, const char* name) { + const unsigned char* GetTraceCategoryEnabledFlag(Platform* platform, TraceCategory category) { static unsigned char disabled = 0; if (platform == nullptr) { return &disabled; } - const unsigned char* categoryEnabledFlag = platform->GetTraceCategoryEnabledFlag(name); + const unsigned char* categoryEnabledFlag = platform->GetTraceCategoryEnabledFlag(category); if (categoryEnabledFlag != nullptr) { return categoryEnabledFlag; } diff --git a/src/dawn_platform/tracing/EventTracer.h b/src/dawn_platform/tracing/EventTracer.h index f99423b227..114a743d79 100644 --- a/src/dawn_platform/tracing/EventTracer.h +++ b/src/dawn_platform/tracing/EventTracer.h @@ -20,12 +20,14 @@ namespace dawn_platform { class Platform; + enum class TraceCategory; namespace tracing { using TraceEventHandle = uint64_t; - const unsigned char* GetTraceCategoryEnabledFlag(Platform* platform, const char* name); + const unsigned char* GetTraceCategoryEnabledFlag(Platform* platform, + TraceCategory category); // TODO(enga): Simplify this API. TraceEventHandle AddTraceEvent(Platform* platform, diff --git a/src/dawn_platform/tracing/TraceEvent.h b/src/dawn_platform/tracing/TraceEvent.h index f8d4d9e98d..159e91b1d0 100644 --- a/src/dawn_platform/tracing/TraceEvent.h +++ b/src/dawn_platform/tracing/TraceEvent.h @@ -156,12 +156,6 @@ #include "dawn_platform/tracing/EventTracer.h" -#define TRACE_DISABLED_BY_DEFAULT(name) "disabled-by-default-" name - -// By default, const char* argument values are assumed to have long-lived scope -// and will not be copied. Use this macro to force a const char* to be copied. -#define TRACE_STR_COPY(str) WebCore::TraceEvent::TraceStringWithCopy(str) - // Records a pair of begin and end events called "name" for the current // scope, with 0, 1 or 2 associated arguments. If the category is not // enabled, then this does nothing. @@ -679,35 +673,37 @@ // Implementation detail: internal macro to create static category and add // event if the category is enabled. -#define INTERNAL_TRACE_EVENT_ADD(platform, phase, category, name, flags, ...) \ - do { \ - INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(platform, category); \ - if (*INTERNALTRACEEVENTUID(catstatic)) { \ - dawn_platform::TraceEvent::addTraceEvent( \ - platform, phase, INTERNALTRACEEVENTUID(catstatic), name, \ - dawn_platform::TraceEvent::noEventId, flags, ##__VA_ARGS__); \ - } \ +#define INTERNAL_TRACE_EVENT_ADD(platform, phase, category, name, flags, ...) \ + do { \ + INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(platform, \ + ::dawn_platform::TraceCategory::category); \ + if (*INTERNALTRACEEVENTUID(catstatic)) { \ + dawn_platform::TraceEvent::addTraceEvent( \ + platform, phase, INTERNALTRACEEVENTUID(catstatic), name, \ + dawn_platform::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(platform, category, name, ...) \ - INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(platform, category); \ - dawn_platform::TraceEvent::TraceEndOnScopeClose INTERNALTRACEEVENTUID(profileScope); \ - if (*INTERNALTRACEEVENTUID(catstatic)) { \ - dawn_platform::TraceEvent::addTraceEvent( \ - platform, TRACE_EVENT_PHASE_BEGIN, INTERNALTRACEEVENTUID(catstatic), name, \ - dawn_platform::TraceEvent::noEventId, TRACE_EVENT_FLAG_NONE, ##__VA_ARGS__); \ - INTERNALTRACEEVENTUID(profileScope) \ - .initialize(platform, INTERNALTRACEEVENTUID(catstatic), name); \ +#define INTERNAL_TRACE_EVENT_ADD_SCOPED(platform, category, name, ...) \ + INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(platform, ::dawn_platform::TraceCategory::category); \ + dawn_platform::TraceEvent::TraceEndOnScopeClose INTERNALTRACEEVENTUID(profileScope); \ + if (*INTERNALTRACEEVENTUID(catstatic)) { \ + dawn_platform::TraceEvent::addTraceEvent( \ + platform, TRACE_EVENT_PHASE_BEGIN, INTERNALTRACEEVENTUID(catstatic), name, \ + dawn_platform::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(platform, phase, category, name, id, flags, ...) \ do { \ - INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(platform, category); \ + INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(platform, \ + ::dawn_platform::TraceCategory::category); \ if (*INTERNALTRACEEVENTUID(catstatic)) { \ unsigned char traceEventFlags = flags | TRACE_EVENT_FLAG_HAS_ID; \ dawn_platform::TraceEvent::TraceID traceEventTraceID(id, &traceEventFlags); \ diff --git a/src/include/dawn_platform/DawnPlatform.h b/src/include/dawn_platform/DawnPlatform.h index 7d3af270e0..61b029e986 100644 --- a/src/include/dawn_platform/DawnPlatform.h +++ b/src/include/dawn_platform/DawnPlatform.h @@ -21,11 +21,18 @@ namespace dawn_platform { + enum class TraceCategory { + General, // General trace events + Validation, // Dawn validation + Recording, // Native command recording + GPUWork, // Actual GPU work + }; + class DAWN_NATIVE_EXPORT Platform { public: virtual ~Platform() { } - virtual const unsigned char* GetTraceCategoryEnabledFlag(const char* name) = 0; + virtual const unsigned char* GetTraceCategoryEnabledFlag(TraceCategory category) = 0; virtual double MonotonicallyIncreasingTime() = 0; diff --git a/src/tests/perf_tests/DawnPerfTest.cpp b/src/tests/perf_tests/DawnPerfTest.cpp index a49bc7a74d..c39b4da2cb 100644 --- a/src/tests/perf_tests/DawnPerfTest.cpp +++ b/src/tests/perf_tests/DawnPerfTest.cpp @@ -14,6 +14,7 @@ #include "tests/perf_tests/DawnPerfTest.h" +#include "common/Assert.h" #include "dawn_platform/tracing/TraceEvent.h" #include "tests/perf_tests/DawnPerfTestPlatform.h" #include "utils/Timer.h" @@ -47,7 +48,22 @@ namespace { char phase[2] = {traceEvent.phase, '\0'}; value["name"] = traceEvent.name; - value["cat"] = traceEvent.categoryName; + switch (traceEvent.category) { + case dawn_platform::TraceCategory::General: + value["cat"] = "general"; + break; + case dawn_platform::TraceCategory::Validation: + value["cat"] = "validation"; + break; + case dawn_platform::TraceCategory::Recording: + value["cat"] = "recording"; + break; + case dawn_platform::TraceCategory::GPUWork: + value["cat"] = "gpu"; + break; + default: + UNREACHABLE(); + } value["ph"] = &phase[0]; value["id"] = traceEvent.id; value["ts"] = microseconds; @@ -102,7 +118,6 @@ DawnPerfTestEnvironment::DawnPerfTestEnvironment(int argc, char** argv) << " --calibration: Only run calibration. Calibration allows the perf test" " runner script to save some time.\n" << " --override-steps: Set a fixed number of steps to run for each test\n" - << " --enable-tracing: Enable tracing of Dawn's internals.\n" << " --trace-file: The file to dump trace results.\n" << std::endl; continue; @@ -208,9 +223,9 @@ void DawnPerfTestBase::RunTest() { // We don't care about trace events during warmup and calibration. platform->EnableTraceEventRecording(true); { - TRACE_EVENT0(platform, "dawn.perf_test", testName); + TRACE_EVENT0(platform, General, testName); for (unsigned int trial = 0; trial < kNumTrials; ++trial) { - TRACE_EVENT0(platform, "dawn.perf_test", "Trial"); + TRACE_EVENT0(platform, General, "Trial"); DoRunLoop(kMaximumRunTimeSeconds); OutputResults(); } @@ -236,7 +251,7 @@ void DawnPerfTestBase::DoRunLoop(double maxRunTime) { while (signaledFenceValue - fence.GetCompletedValue() >= mMaxStepsInFlight) { mTest->WaitABit(); } - TRACE_EVENT0(platform, "dawn.perf_test", "Step"); + TRACE_EVENT0(platform, General, "Step"); Step(); mTest->queue.Signal(fence, ++signaledFenceValue); diff --git a/src/tests/perf_tests/DawnPerfTestPlatform.cpp b/src/tests/perf_tests/DawnPerfTestPlatform.cpp index 880d5e9cf8..850b9302b1 100644 --- a/src/tests/perf_tests/DawnPerfTestPlatform.cpp +++ b/src/tests/perf_tests/DawnPerfTestPlatform.cpp @@ -14,23 +14,30 @@ #include "tests/perf_tests/DawnPerfTestPlatform.h" +#include "common/Assert.h" #include "dawn_platform/tracing/TraceEvent.h" #include "tests/perf_tests/DawnPerfTest.h" #include "utils/Timer.h" namespace { - struct TraceCategory { + struct TraceCategoryInfo { unsigned char enabled; - const char* name; + dawn_platform::TraceCategory category; }; - constexpr TraceCategory gTraceCategories[2] = { - // TODO(enga): Remove the use of this macro, but keep it disabled by default in Chromium. - {1, TRACE_DISABLED_BY_DEFAULT("gpu.dawn")}, - {1, "dawn.perf_test"}, + constexpr TraceCategoryInfo gTraceCategories[4] = { + {1, dawn_platform::TraceCategory::General}, + {1, dawn_platform::TraceCategory::Validation}, + {1, dawn_platform::TraceCategory::Recording}, + {1, dawn_platform::TraceCategory::GPUWork}, }; + static_assert(static_cast(dawn_platform::TraceCategory::General) == 0, ""); + static_assert(static_cast(dawn_platform::TraceCategory::Validation) == 1, ""); + static_assert(static_cast(dawn_platform::TraceCategory::Recording) == 2, ""); + static_assert(static_cast(dawn_platform::TraceCategory::GPUWork) == 3, ""); + } // anonymous namespace DawnPerfTestPlatform::DawnPerfTestPlatform() @@ -39,15 +46,18 @@ DawnPerfTestPlatform::DawnPerfTestPlatform() DawnPerfTestPlatform::~DawnPerfTestPlatform() = default; -const unsigned char* DawnPerfTestPlatform::GetTraceCategoryEnabledFlag(const char* name) { - for (const TraceCategory& category : gTraceCategories) { - if (strcmp(category.name, name) == 0) { - return &category.enabled; - } +const unsigned char* DawnPerfTestPlatform::GetTraceCategoryEnabledFlag( + dawn_platform::TraceCategory category) { + switch (category) { + case dawn_platform::TraceCategory::General: + case dawn_platform::TraceCategory::Validation: + case dawn_platform::TraceCategory::Recording: + case dawn_platform::TraceCategory::GPUWork: + break; + default: + UNREACHABLE(); } - - constexpr static unsigned char kZero = 0; - return &kZero; + return &gTraceCategories[static_cast(category)].enabled; } double DawnPerfTestPlatform::MonotonicallyIncreasingTime() { @@ -74,11 +84,13 @@ uint64_t DawnPerfTestPlatform::AddTraceEvent(char phase, // Discover the category name based on categoryGroupEnabled. This flag comes from the first // parameter of TraceCategory, and corresponds to one of the entries in gTraceCategories. - static_assert(offsetof(TraceCategory, enabled) == 0, - "|enabled| must be the first field of the TraceCategory class."); - const TraceCategory* category = reinterpret_cast(categoryGroupEnabled); + static_assert(offsetof(TraceCategoryInfo, enabled) == 0, + "|enabled| must be the first field of the TraceCategoryInfo class."); - mTraceEventBuffer.emplace_back(phase, category->name, name, id, timestamp); + const TraceCategoryInfo* info = + reinterpret_cast(categoryGroupEnabled); + + mTraceEventBuffer.emplace_back(phase, info->category, name, id, timestamp); return static_cast(mTraceEventBuffer.size()); } diff --git a/src/tests/perf_tests/DawnPerfTestPlatform.h b/src/tests/perf_tests/DawnPerfTestPlatform.h index 9baef91f52..b835e3480e 100644 --- a/src/tests/perf_tests/DawnPerfTestPlatform.h +++ b/src/tests/perf_tests/DawnPerfTestPlatform.h @@ -33,19 +33,15 @@ class DawnPerfTestPlatform : public dawn_platform::Platform { TraceEvent() { } TraceEvent(char phaseIn, - const char* categoryNameIn, + dawn_platform::TraceCategory categoryIn, const char* nameIn, uint64_t idIn, double timestampIn) - : phase(phaseIn), - categoryName(categoryNameIn), - name(nameIn), - id(idIn), - timestamp(timestampIn) { + : phase(phaseIn), category(categoryIn), name(nameIn), id(idIn), timestamp(timestampIn) { } char phase = 0; - const char* categoryName = nullptr; + dawn_platform::TraceCategory category; const char* name = nullptr; uint64_t id = 0; double timestamp = 0; @@ -58,7 +54,8 @@ class DawnPerfTestPlatform : public dawn_platform::Platform { std::vector AcquireTraceEventBuffer(); private: - const unsigned char* GetTraceCategoryEnabledFlag(const char* name) override; + const unsigned char* GetTraceCategoryEnabledFlag( + dawn_platform::TraceCategory category) override; double MonotonicallyIncreasingTime() override;