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
7 changes: 7 additions & 0 deletions clean/runtime/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -821,8 +821,15 @@ void trace_launch(const std::string& kernel, unsigned grid, unsigned block, cons
return p && *p ? std::fopen(p, "a") : (FILE*)nullptr;
}();
static std::mutex mutex;
static const unsigned long long cap = [] { // WG_LAUNCH_TRACE_MAX=<lines>: stop after that many (0 / unset: no cap)
const char* m = std::getenv("WG_LAUNCH_TRACE_MAX");
return m && *m ? std::strtoull(m, nullptr, 10) : 0ull;
}();
static unsigned long long lines = 0;
if (!fp) return;
std::lock_guard<std::mutex> lock(mutex);
if (cap && lines >= cap) return;
++lines;
if (where)
std::fprintf(fp, "%s %u %u %s\n", kernel.c_str(), grid, block, where);
else
Expand Down
4 changes: 3 additions & 1 deletion clean/runtime/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ std::unique_ptr<Device> make_dx12_device(const std::string& rocm_dir, const std:
// Uses <build_dir>/dx12/manifest.json and WG_D3D12_ARENA_MB (16..4095, default 2560).
std::unique_ptr<Device> make_d3d12_device(const std::string& build_dir, std::string* err);

// Diagnostics: WG_LAUNCH_TRACE=<file> appends one line per kernel launch ("kernel grid block [where]").
// Diagnostics: WG_LAUNCH_TRACE=<file> appends one line per kernel launch ("kernel grid block [where]");
// WG_LAUNCH_TRACE_MAX=<lines> stops it after that many lines. The interop's runtime options launch_trace=<file> and
// launch_trace_max=<lines> set both (a game started by its store launcher does not inherit our environment).
void trace_launch(const std::string& kernel, unsigned grid, unsigned block, const char* where = nullptr);

} // namespace wgrt
6 changes: 6 additions & 0 deletions clean/runtime/interop/backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,12 @@ Options parse_options(const char* text) {
else if (key == "input_copy") o.input_copy = value == "1";
else if (key == "output_copy") o.output_copy = value == "1";
else if (key == "test_view") o.test_view = value == "depth" ? 1 : value == "motion" ? 2 : 0;
#ifdef _WIN32
// diagnostics (a game started by its store launcher does not inherit our environment): launch_trace=<file> sets
// WG_LAUNCH_TRACE (device.cpp trace_launch, one line per kernel launch), launch_trace_max=<lines> caps it
else if (key == "launch_trace") _putenv_s("WG_LAUNCH_TRACE", value.c_str());
else if (key == "launch_trace_max") _putenv_s("WG_LAUNCH_TRACE_MAX", value.c_str());
#endif
else {
o.unknown += (o.unknown.empty() ? "" : ", ") + key;
o.runtime += (o.runtime.empty() ? "" : ";") + key + (eq == std::string::npos ? "" : "=" + value);
Expand Down
Loading