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 <enga@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
This commit is contained in:
Austin Eng
2019-10-28 23:15:40 +00:00
committed by Commit Bot service account
parent 7a7d547381
commit 73d5bb57e6
15 changed files with 121 additions and 72 deletions

View File

@@ -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);

View File

@@ -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<uint32_t>(dawn_platform::TraceCategory::General) == 0, "");
static_assert(static_cast<uint32_t>(dawn_platform::TraceCategory::Validation) == 1, "");
static_assert(static_cast<uint32_t>(dawn_platform::TraceCategory::Recording) == 2, "");
static_assert(static_cast<uint32_t>(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<uint32_t>(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<const TraceCategory*>(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<const TraceCategoryInfo*>(categoryGroupEnabled);
mTraceEventBuffer.emplace_back(phase, info->category, name, id, timestamp);
return static_cast<uint64_t>(mTraceEventBuffer.size());
}

View File

@@ -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<TraceEvent> AcquireTraceEventBuffer();
private:
const unsigned char* GetTraceCategoryEnabledFlag(const char* name) override;
const unsigned char* GetTraceCategoryEnabledFlag(
dawn_platform::TraceCategory category) override;
double MonotonicallyIncreasingTime() override;