Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/gpgmm/common/TraceEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,19 @@ namespace gpgmm {
const TraceEventPhase& ignoreMask,
bool flushOnDestruct) {
#if defined(GPGMM_DISABLE_TRACING)
gpgmm::WarningLog() << "Event tracing enabled but unable to record due to GPGMM_DISABLE_TRACING.";
gpgmm::WarningLog()
<< "Event tracing enabled but unable to record due to GPGMM_DISABLE_TRACING.";
#endif

GetInstance()->SetConfiguration(traceFile, ignoreMask, flushOnDestruct);
TRACE_EVENT_METADATA1(TraceEventCategory::Metadata, "thread_name", "name",
"GPGMM_MainThread");
}

void ShutdownEventTrace() {
void FlushEventTraceToDisk() {
if (!IsEventTraceEnabled()) {
return;
}
GetInstance()->FlushQueuedEventsToDisk();
}

Expand Down
2 changes: 1 addition & 1 deletion src/gpgmm/common/TraceEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ namespace gpgmm {
const TraceEventPhase& ignoreMask,
bool flushOnDestruct);

void ShutdownEventTrace();
void FlushEventTraceToDisk();

bool IsEventTraceEnabled();

Expand Down
8 changes: 4 additions & 4 deletions src/gpgmm/d3d12/ResidencyManagerD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ namespace gpgmm::d3d12 {
: descriptor.EvictBatchSize),
mIsUMA(descriptor.IsUMA),
mIsBudgetChangeEventsDisabled(descriptor.UpdateBudgetByPolling),
mShutdownEventTrace(descriptor.RecordOptions.EventScope &
EVENT_RECORD_SCOPE_PER_INSTANCE),
mFlushEventBuffersOnDestruct(descriptor.RecordOptions.EventScope &
EVENT_RECORD_SCOPE_PER_INSTANCE),
mThreadPool(ThreadPool::Create()) {
GPGMM_TRACE_EVENT_OBJECT_NEW(this);

Expand All @@ -236,8 +236,8 @@ namespace gpgmm::d3d12 {
GPGMM_TRACE_EVENT_OBJECT_DESTROY(this);
StopBudgetNotificationUpdates();

if (mShutdownEventTrace) {
ShutdownEventTrace();
if (mFlushEventBuffersOnDestruct) {
FlushEventTraceToDisk();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/gpgmm/d3d12/ResidencyManagerD3D12.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ namespace gpgmm::d3d12 {
const uint64_t mEvictBatchSize;
const bool mIsUMA;
const bool mIsBudgetChangeEventsDisabled;
const bool mShutdownEventTrace;
const bool mFlushEventBuffersOnDestruct;

VideoMemorySegment mLocalVideoMemorySegment;
VideoMemorySegment mNonLocalVideoMemorySegment;
Expand Down
16 changes: 11 additions & 5 deletions src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,13 +340,17 @@ namespace gpgmm::d3d12 {
return E_INVALIDARG;
}

if (!IsEventTraceEnabled() && newDescriptor.RecordOptions.Flags != EVENT_RECORD_FLAG_NONE) {
if (pResidencyManager == nullptr &&
newDescriptor.RecordOptions.Flags != EVENT_RECORD_FLAG_NONE) {
StartupEventTrace(
allocatorDescriptor.RecordOptions.TraceFile,
static_cast<TraceEventPhase>(~newDescriptor.RecordOptions.Flags | 0),
allocatorDescriptor.RecordOptions.EventScope & EVENT_RECORD_SCOPE_PER_PROCESS);

SetEventMessageLevel(GetLogSeverity(newDescriptor.RecordOptions.MinMessageLevel));
} else {
// Do not override the event scope from a event trace already enabled.
newDescriptor.RecordOptions.EventScope = EVENT_RECORD_SCOPE_PER_PROCESS;
}

// Do not override the default min. log level specified by the residency manager.
Expand Down Expand Up @@ -391,8 +395,8 @@ namespace gpgmm::d3d12 {
mIsAlwaysCommitted(descriptor.Flags & ALLOCATOR_FLAG_ALWAYS_COMMITED),
mIsAlwaysInBudget(descriptor.Flags & ALLOCATOR_FLAG_ALWAYS_IN_BUDGET),
mMaxResourceHeapSize(descriptor.MaxResourceHeapSize),
mShutdownEventTrace(descriptor.RecordOptions.EventScope &
EVENT_RECORD_SCOPE_PER_INSTANCE),
mFlushEventBuffersOnDestruct(descriptor.RecordOptions.EventScope &
EVENT_RECORD_SCOPE_PER_INSTANCE),
mUseDetailedTimingEvents(descriptor.RecordOptions.UseDetailedTimingEvents) {
GPGMM_TRACE_EVENT_OBJECT_NEW(this);

Expand Down Expand Up @@ -609,8 +613,10 @@ namespace gpgmm::d3d12 {
#if defined(GPGMM_ENABLE_DEVICE_CHECKS)
ReportLiveDeviceObjects(mDevice);
#endif
if (mShutdownEventTrace) {
ShutdownEventTrace();
mResidencyManager = nullptr;

if (mFlushEventBuffersOnDestruct) {
FlushEventTraceToDisk();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/gpgmm/d3d12/ResourceAllocatorD3D12.h
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ namespace gpgmm::d3d12 {
const bool mIsAlwaysCommitted;
const bool mIsAlwaysInBudget;
const uint64_t mMaxResourceHeapSize;
const bool mShutdownEventTrace;
const bool mFlushEventBuffersOnDestruct;
const bool mUseDetailedTimingEvents;

static constexpr uint64_t kNumOfResourceHeapTypes = 8u;
Expand Down
21 changes: 16 additions & 5 deletions src/tests/capture_replay_tests/D3D12EventTraceReplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,21 @@ class D3D12EventTraceReplay : public D3D12TestBase, public CaptureReplayTestWith
residencyDesc.EvictBatchSize = snapshot["EvictBatchSize"].asUInt64();
residencyDesc.InitialFenceValue = snapshot["InitialFenceValue"].asUInt64();

if (envParams.CaptureEventMask != 0) {
residencyDesc.RecordOptions.Flags |=
static_cast<EVENT_RECORD_FLAGS_TYPE>(envParams.CaptureEventMask);
residencyDesc.RecordOptions.TraceFile = traceFile.path;
residencyDesc.RecordOptions.MinMessageLevel =
GetMessageSeverity(envParams.LogLevel);

// Keep recording across multiple playback iterations to ensure all
// events will be captured instead of overwritten per iteration.
if (envParams.Iterations == 1) {
residencyDesc.RecordOptions.EventScope =
EVENT_RECORD_SCOPE_PER_INSTANCE;
}
}

ComPtr<ResidencyManager> residencyManager;
ASSERT_SUCCEEDED(ResidencyManager::CreateResidencyManager(
residencyDesc, &residencyManager));
Expand Down Expand Up @@ -394,7 +409,6 @@ class D3D12EventTraceReplay : public D3D12TestBase, public CaptureReplayTestWith
if (envParams.CaptureEventMask != 0) {
allocatorDesc.RecordOptions.Flags |=
static_cast<EVENT_RECORD_FLAGS_TYPE>(envParams.CaptureEventMask);
allocatorDesc.RecordOptions.Flags |= EVENT_RECORD_FLAG_CAPTURE;
allocatorDesc.RecordOptions.TraceFile = traceFile.path;
allocatorDesc.RecordOptions.MinMessageLevel =
GetMessageSeverity(envParams.LogLevel);
Expand Down Expand Up @@ -440,7 +454,7 @@ class D3D12EventTraceReplay : public D3D12TestBase, public CaptureReplayTestWith

ComPtr<ResourceAllocator> resourceAllocator;
ASSERT_SUCCEEDED(ResourceAllocator::CreateAllocator(
allocatorDesc, &resourceAllocator, &residencyManager));
allocatorDesc, residencyManager.Get(), &resourceAllocator));

ASSERT_TRUE(
createdAllocatorToID.insert({allocatorID, std::move(resourceAllocator)})
Expand Down Expand Up @@ -578,9 +592,6 @@ TEST_P(D3D12EventTraceReplay, Recapture) {

forceParams.CaptureEventMask = EVENT_RECORD_FLAG_CAPTURE;
RunSingleTest(forceParams);

forceParams.CaptureEventMask = EVENT_RECORD_FLAG_NONE;
RunSingleTest(forceParams);
}

GPGMM_INSTANTIATE_CAPTURE_REPLAY_TEST(D3D12EventTraceReplay);
2 changes: 1 addition & 1 deletion src/tests/unittests/EventTraceWriterTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class EventTraceWriterTests : public testing::Test {
}

void TearDown() override {
ShutdownEventTrace();
FlushEventTraceToDisk();
}
};

Expand Down