Add label to the trace events for pipeline and shader module creation

This patch adds the object label to the trace events for the creation
of pipeline and shader module so that we can easily know which shader
module or pipeline creation task the trace event belongs to.

BUG=dawn:1167

Change-Id: Ic2de4542d0167437eea2fd600d0f0be3bdd225f9
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/70041
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
This commit is contained in:
Jiawei Shao 2021-11-21 11:18:19 +00:00 committed by Dawn LUCI CQ
parent bd3e042383
commit 4e3ddbd955
5 changed files with 60 additions and 30 deletions

View File

@ -20,6 +20,7 @@
#include "dawn_native/RenderPipeline.h" #include "dawn_native/RenderPipeline.h"
#include "dawn_platform/DawnPlatform.h" #include "dawn_platform/DawnPlatform.h"
#include "dawn_platform/tracing/TraceEvent.h" #include "dawn_platform/tracing/TraceEvent.h"
#include "utils/WGPUHelpers.h"
namespace dawn_native { namespace dawn_native {
@ -114,10 +115,13 @@ namespace dawn_native {
} }
void CreateComputePipelineAsyncTask::Run() { void CreateComputePipelineAsyncTask::Run() {
TRACE_EVENT_FLOW_END0(mComputePipeline->GetDevice()->GetPlatform(), General, const char* eventLabel = utils::GetLabelForTrace(mComputePipeline->GetLabel().c_str());
"CreateComputePipelineAsyncTask::RunAsync", this); TRACE_EVENT_FLOW_END1(mComputePipeline->GetDevice()->GetPlatform(), General,
TRACE_EVENT0(mComputePipeline->GetDevice()->GetPlatform(), General, "CreateComputePipelineAsyncTask::RunAsync", this, "label",
"CreateComputePipelineAsyncTask::Run"); eventLabel);
TRACE_EVENT1(mComputePipeline->GetDevice()->GetPlatform(), General,
"CreateComputePipelineAsyncTask::Run", "label", eventLabel);
MaybeError maybeError = mComputePipeline->Initialize(); MaybeError maybeError = mComputePipeline->Initialize();
std::string errorMessage; std::string errorMessage;
if (maybeError.IsError()) { if (maybeError.IsError()) {
@ -133,6 +137,9 @@ namespace dawn_native {
std::unique_ptr<CreateComputePipelineAsyncTask> task) { std::unique_ptr<CreateComputePipelineAsyncTask> task) {
DeviceBase* device = task->mComputePipeline->GetDevice(); DeviceBase* device = task->mComputePipeline->GetDevice();
const char* eventLabel =
utils::GetLabelForTrace(task->mComputePipeline->GetLabel().c_str());
// Using "taskPtr = std::move(task)" causes compilation error while it should be supported // Using "taskPtr = std::move(task)" causes compilation error while it should be supported
// since C++14: // since C++14:
// https://docs.microsoft.com/en-us/cpp/cpp/lambda-expressions-in-cpp?view=msvc-160 // https://docs.microsoft.com/en-us/cpp/cpp/lambda-expressions-in-cpp?view=msvc-160
@ -140,8 +147,10 @@ namespace dawn_native {
std::unique_ptr<CreateComputePipelineAsyncTask> innnerTaskPtr(taskPtr); std::unique_ptr<CreateComputePipelineAsyncTask> innnerTaskPtr(taskPtr);
innnerTaskPtr->Run(); innnerTaskPtr->Run();
}; };
TRACE_EVENT_FLOW_BEGIN0(device->GetPlatform(), General,
"CreateComputePipelineAsyncTask::RunAsync", task.get()); TRACE_EVENT_FLOW_BEGIN1(device->GetPlatform(), General,
"CreateComputePipelineAsyncTask::RunAsync", task.get(), "label",
eventLabel);
device->GetAsyncTaskManager()->PostTask(std::move(asyncTask)); device->GetAsyncTaskManager()->PostTask(std::move(asyncTask));
} }
@ -156,10 +165,12 @@ namespace dawn_native {
} }
void CreateRenderPipelineAsyncTask::Run() { void CreateRenderPipelineAsyncTask::Run() {
TRACE_EVENT_FLOW_END0(mRenderPipeline->GetDevice()->GetPlatform(), General, const char* eventLabel = utils::GetLabelForTrace(mRenderPipeline->GetLabel().c_str());
"CreateRenderPipelineAsyncTask::RunAsync", this); TRACE_EVENT_FLOW_END1(mRenderPipeline->GetDevice()->GetPlatform(), General,
TRACE_EVENT0(mRenderPipeline->GetDevice()->GetPlatform(), General, "CreateRenderPipelineAsyncTask::RunAsync", this, "label", eventLabel);
"CreateRenderPipelineAsyncTask::Run"); TRACE_EVENT1(mRenderPipeline->GetDevice()->GetPlatform(), General,
"CreateRenderPipelineAsyncTask::Run", "label", eventLabel);
MaybeError maybeError = mRenderPipeline->Initialize(); MaybeError maybeError = mRenderPipeline->Initialize();
std::string errorMessage; std::string errorMessage;
if (maybeError.IsError()) { if (maybeError.IsError()) {
@ -175,6 +186,8 @@ namespace dawn_native {
std::unique_ptr<CreateRenderPipelineAsyncTask> task) { std::unique_ptr<CreateRenderPipelineAsyncTask> task) {
DeviceBase* device = task->mRenderPipeline->GetDevice(); DeviceBase* device = task->mRenderPipeline->GetDevice();
const char* eventLabel = utils::GetLabelForTrace(task->mRenderPipeline->GetLabel().c_str());
// Using "taskPtr = std::move(task)" causes compilation error while it should be supported // Using "taskPtr = std::move(task)" causes compilation error while it should be supported
// since C++14: // since C++14:
// https://docs.microsoft.com/en-us/cpp/cpp/lambda-expressions-in-cpp?view=msvc-160 // https://docs.microsoft.com/en-us/cpp/cpp/lambda-expressions-in-cpp?view=msvc-160
@ -182,8 +195,10 @@ namespace dawn_native {
std::unique_ptr<CreateRenderPipelineAsyncTask> innerTaskPtr(taskPtr); std::unique_ptr<CreateRenderPipelineAsyncTask> innerTaskPtr(taskPtr);
innerTaskPtr->Run(); innerTaskPtr->Run();
}; };
TRACE_EVENT_FLOW_BEGIN0(device->GetPlatform(), General,
"CreateRenderPipelineAsyncTask::RunAsync", task.get()); TRACE_EVENT_FLOW_BEGIN1(device->GetPlatform(), General,
"CreateRenderPipelineAsyncTask::RunAsync", task.get(), "label",
eventLabel);
device->GetAsyncTaskManager()->PostTask(std::move(asyncTask)); device->GetAsyncTaskManager()->PostTask(std::move(asyncTask));
} }
} // namespace dawn_native } // namespace dawn_native

View File

@ -45,6 +45,7 @@
#include "dawn_native/ValidationUtils_autogen.h" #include "dawn_native/ValidationUtils_autogen.h"
#include "dawn_platform/DawnPlatform.h" #include "dawn_platform/DawnPlatform.h"
#include "dawn_platform/tracing/TraceEvent.h" #include "dawn_platform/tracing/TraceEvent.h"
#include "utils/WGPUHelpers.h"
#include <array> #include <array>
#include <mutex> #include <mutex>
@ -911,7 +912,9 @@ namespace dawn_native {
} }
ComputePipelineBase* DeviceBase::APICreateComputePipeline( ComputePipelineBase* DeviceBase::APICreateComputePipeline(
const ComputePipelineDescriptor* descriptor) { const ComputePipelineDescriptor* descriptor) {
TRACE_EVENT0(GetPlatform(), General, "DeviceBase::APICreateComputePipeline"); TRACE_EVENT1(GetPlatform(), General, "DeviceBase::APICreateComputePipeline", "label",
utils::GetLabelForTrace(descriptor->label));
Ref<ComputePipelineBase> result; Ref<ComputePipelineBase> result;
if (ConsumedError(CreateComputePipeline(descriptor), &result, if (ConsumedError(CreateComputePipeline(descriptor), &result,
"calling %s.CreateComputePipeline(%s).", this, descriptor)) { "calling %s.CreateComputePipeline(%s).", this, descriptor)) {
@ -922,7 +925,9 @@ namespace dawn_native {
void DeviceBase::APICreateComputePipelineAsync(const ComputePipelineDescriptor* descriptor, void DeviceBase::APICreateComputePipelineAsync(const ComputePipelineDescriptor* descriptor,
WGPUCreateComputePipelineAsyncCallback callback, WGPUCreateComputePipelineAsyncCallback callback,
void* userdata) { void* userdata) {
TRACE_EVENT0(GetPlatform(), General, "DeviceBase::APICreateComputePipelineAsync"); TRACE_EVENT1(GetPlatform(), General, "DeviceBase::APICreateComputePipelineAsync", "label",
utils::GetLabelForTrace(descriptor->label));
MaybeError maybeResult = CreateComputePipelineAsync(descriptor, callback, userdata); MaybeError maybeResult = CreateComputePipelineAsync(descriptor, callback, userdata);
// Call the callback directly when a validation error has been found in the front-end // Call the callback directly when a validation error has been found in the front-end
@ -962,7 +967,8 @@ namespace dawn_native {
void DeviceBase::APICreateRenderPipelineAsync(const RenderPipelineDescriptor* descriptor, void DeviceBase::APICreateRenderPipelineAsync(const RenderPipelineDescriptor* descriptor,
WGPUCreateRenderPipelineAsyncCallback callback, WGPUCreateRenderPipelineAsyncCallback callback,
void* userdata) { void* userdata) {
TRACE_EVENT0(GetPlatform(), General, "DeviceBase::APICreateRenderPipelineAsync"); TRACE_EVENT1(GetPlatform(), General, "DeviceBase::APICreateRenderPipelineAsync", "label",
utils::GetLabelForTrace(descriptor->label));
// TODO(dawn:563): Add validation error context. // TODO(dawn:563): Add validation error context.
MaybeError maybeResult = CreateRenderPipelineAsync(descriptor, callback, userdata); MaybeError maybeResult = CreateRenderPipelineAsync(descriptor, callback, userdata);
@ -986,7 +992,9 @@ namespace dawn_native {
} }
RenderPipelineBase* DeviceBase::APICreateRenderPipeline( RenderPipelineBase* DeviceBase::APICreateRenderPipeline(
const RenderPipelineDescriptor* descriptor) { const RenderPipelineDescriptor* descriptor) {
TRACE_EVENT0(GetPlatform(), General, "DeviceBase::APICreateRenderPipeline"); TRACE_EVENT1(GetPlatform(), General, "DeviceBase::APICreateRenderPipeline", "label",
utils::GetLabelForTrace(descriptor->label));
Ref<RenderPipelineBase> result; Ref<RenderPipelineBase> result;
if (ConsumedError(CreateRenderPipeline(descriptor), &result, if (ConsumedError(CreateRenderPipeline(descriptor), &result,
"calling %s.CreateRenderPipeline(%s).", this, descriptor)) { "calling %s.CreateRenderPipeline(%s).", this, descriptor)) {
@ -995,7 +1003,9 @@ namespace dawn_native {
return result.Detach(); return result.Detach();
} }
ShaderModuleBase* DeviceBase::APICreateShaderModule(const ShaderModuleDescriptor* descriptor) { ShaderModuleBase* DeviceBase::APICreateShaderModule(const ShaderModuleDescriptor* descriptor) {
TRACE_EVENT0(GetPlatform(), General, "DeviceBase::APICreateShaderModule"); TRACE_EVENT1(GetPlatform(), General, "DeviceBase::APICreateShaderModule", "label",
utils::GetLabelForTrace(descriptor->label));
Ref<ShaderModuleBase> result; Ref<ShaderModuleBase> result;
std::unique_ptr<OwnedCompilationMessages> compilationMessages( std::unique_ptr<OwnedCompilationMessages> compilationMessages(
std::make_unique<OwnedCompilationMessages>()); std::make_unique<OwnedCompilationMessages>());

View File

@ -185,4 +185,8 @@ namespace dawn_native { namespace utils {
return device->CreateBindGroup(&descriptor); return device->CreateBindGroup(&descriptor);
} }
const char* GetLabelForTrace(const char* label) {
return (label == nullptr || strlen(label) == 0) ? "None" : label;
}
}} // namespace dawn_native::utils }} // namespace dawn_native::utils

View File

@ -115,6 +115,9 @@ namespace dawn_native { namespace utils {
DeviceBase* device, DeviceBase* device,
const Ref<BindGroupLayoutBase>& layout, const Ref<BindGroupLayoutBase>& layout,
std::initializer_list<BindingInitializationHelper> entriesInitializer); std::initializer_list<BindingInitializationHelper> entriesInitializer);
const char* GetLabelForTrace(const char* label);
}} // namespace dawn_native::utils }} // namespace dawn_native::utils
#endif // DAWNNATIVE_UTILS_WGPUHELPERS_H_ #endif // DAWNNATIVE_UTILS_WGPUHELPERS_H_

View File

@ -840,20 +840,18 @@ namespace dawn_platform { namespace TraceEvent {
// Define setTraceValue for each allowed type. It stores the type and // Define setTraceValue for each allowed type. It stores the type and
// value in the return arguments. This allows this API to avoid declaring any // value in the return arguments. This allows this API to avoid declaring any
// structures so that it is portable to third_party libraries. // structures so that it is portable to third_party libraries.
#define INTERNAL_DECLARE_SET_TRACE_VALUE(actual_type, union_member, value_type_id) \ #define INTERNAL_DECLARE_SET_TRACE_VALUE(actual_type, union_member, value_type_id) \
static inline void setTraceValue(actual_type arg, unsigned char* type, \ static inline void setTraceValue(actual_type arg, unsigned char* type, uint64_t* value) { \
unsigned long long* value) { \ TraceValueUnion typeValue; \
TraceValueUnion typeValue; \ typeValue.union_member = arg; \
typeValue.union_member = arg; \ *type = value_type_id; \
*type = value_type_id; \ *value = typeValue.m_uint; \
*value = typeValue.m_uint; \
} }
// Simpler form for int types that can be safely casted. // Simpler form for int types that can be safely casted.
#define INTERNAL_DECLARE_SET_TRACE_VALUE_INT(actual_type, value_type_id) \ #define INTERNAL_DECLARE_SET_TRACE_VALUE_INT(actual_type, value_type_id) \
static inline void setTraceValue(actual_type arg, unsigned char* type, \ static inline void setTraceValue(actual_type arg, unsigned char* type, uint64_t* value) { \
unsigned long long* value) { \ *type = value_type_id; \
*type = value_type_id; \ *value = static_cast<unsigned long long>(arg); \
*value = static_cast<unsigned long long>(arg); \
} }
INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned long long, TRACE_VALUE_TYPE_UINT) INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned long long, TRACE_VALUE_TYPE_UINT)
@ -877,7 +875,7 @@ namespace dawn_platform { namespace TraceEvent {
static inline void setTraceValue(const std::string& arg, static inline void setTraceValue(const std::string& arg,
unsigned char* type, unsigned char* type,
unsigned long long* value) { uint64_t* value) {
TraceValueUnion typeValue; TraceValueUnion typeValue;
typeValue.m_string = arg.data(); typeValue.m_string = arg.data();
*type = TRACE_VALUE_TYPE_COPY_STRING; *type = TRACE_VALUE_TYPE_COPY_STRING;