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
5 changes: 5 additions & 0 deletions src/gpgmm/EventTraceWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "gpgmm/EventTraceWriter.h"

#include "gpgmm/common/Assert.h"
#include "gpgmm/common/Log.h"
#include "gpgmm/common/PlatformTime.h"
#include "gpgmm/common/PlatformUtils.h"
#include "gpgmm/common/Utils.h"
Expand Down Expand Up @@ -154,6 +155,10 @@ namespace gpgmm {

std::ofstream outFile;
outFile.open(mTraceFile);
if (!outFile.fail()) {
WarningLog() << mTraceFile + " exists and will be overwritten.";
}

outFile << traceData.ToString();
outFile.flush();
outFile.close();
Expand Down
4 changes: 4 additions & 0 deletions src/gpgmm/TraceEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ namespace gpgmm {
skipInstantEvents);
}

void ShutdownEventTrace() {
GetInstance()->FlushQueuedEventsToDisk();
}

bool IsEventTraceEnabled() {
return (GetInstance() != nullptr);
}
Expand Down
2 changes: 2 additions & 0 deletions src/gpgmm/TraceEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ namespace gpgmm {
bool skipObjectEvents,
bool skipInstantEvents);

void ShutdownEventTrace();

bool IsEventTraceEnabled();

class TraceEventID {
Expand Down
7 changes: 6 additions & 1 deletion src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,9 @@ namespace gpgmm { namespace d3d12 {
mResourceHeapTier(descriptor.ResourceHeapTier),
mIsAlwaysCommitted(descriptor.Flags & ALLOCATOR_FLAG_ALWAYS_COMMITED),
mIsAlwaysInBudget(descriptor.Flags & ALLOCATOR_FLAG_ALWAYS_IN_BUDGET),
mMaxResourceHeapSize(descriptor.MaxResourceHeapSize) {
mMaxResourceHeapSize(descriptor.MaxResourceHeapSize),
mShutdownEventTrace(descriptor.RecordOptions.EventScope &
ALLOCATOR_RECORD_SCOPE_PER_INSTANCE) {
GPGMM_TRACE_EVENT_OBJECT_NEW(this);

#if defined(GPGMM_ENABLE_ALLOCATOR_CHECKS)
Expand Down Expand Up @@ -577,6 +579,9 @@ namespace gpgmm { namespace d3d12 {
#if defined(GPGMM_ENABLE_DEVICE_CHECKS)
ReportLiveDeviceObjects(mDevice);
#endif
if (mShutdownEventTrace) {
ShutdownEventTrace();
}
}

const char* ResourceAllocator::GetTypename() const {
Expand Down
16 changes: 16 additions & 0 deletions src/gpgmm/d3d12/ResourceAllocatorD3D12.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ namespace gpgmm { namespace d3d12 {
using ALLOCATOR_RECORD_FLAGS_TYPE = Flags<ALLOCATOR_RECORD_FLAGS>;
DEFINE_OPERATORS_FOR_FLAGS(ALLOCATOR_RECORD_FLAGS_TYPE)

enum ALLOCATOR_RECORD_SCOPE {

// Record events per process (or multiple allocators).
ALLOCATOR_RECORD_SCOPE_PER_PROCESS = 0x0,

// Record events per allocator object.
ALLOCATOR_RECORD_SCOPE_PER_INSTANCE = 0x1,
};

using ALLOCATOR_RECORD_SCOPE_TYPE = Flags<ALLOCATOR_RECORD_SCOPE>;
DEFINE_OPERATORS_FOR_FLAGS(ALLOCATOR_RECORD_SCOPE_TYPE)

struct ALLOCATOR_RECORD_OPTIONS {
// Flags used to decide what to record.
ALLOCATOR_RECORD_FLAGS_TYPE Flags = ALLOCATOR_RECORD_FLAG_NONE;
Expand All @@ -107,6 +119,9 @@ namespace gpgmm { namespace d3d12 {
// will be ignored.
ALLOCATOR_MESSAGE_SEVERITY MinMessageLevel = ALLOCATOR_MESSAGE_SEVERITY_WARNING;

// Specifies the scope of the events. By default, recording is per process.
ALLOCATOR_RECORD_SCOPE EventScope = ALLOCATOR_RECORD_SCOPE_PER_PROCESS;

// Path to trace file. Default is trace.json.
std::string TraceFile;
};
Expand Down Expand Up @@ -329,6 +344,7 @@ namespace gpgmm { namespace d3d12 {
const bool mIsAlwaysCommitted;
const bool mIsAlwaysInBudget;
const uint64_t mMaxResourceHeapSize;
const bool mShutdownEventTrace;

static constexpr uint64_t kNumOfResourceHeapTypes = 8u;

Expand Down
2 changes: 2 additions & 0 deletions src/tests/capture_replay_tests/D3D12EventTraceReplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,8 @@ class D3D12EventTraceReplay : public D3D12TestBase, public CaptureReplayTestWith
allocatorDesc.RecordOptions.TraceFile = traceFile.path;
allocatorDesc.RecordOptions.MinMessageLevel =
static_cast<ALLOCATOR_MESSAGE_SEVERITY>(envParams.RecordLevel);
allocatorDesc.RecordOptions.EventScope =
ALLOCATOR_RECORD_SCOPE_PER_INSTANCE;
}

allocatorDesc.MinLogLevel =
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.