jp7677 / dxvk-nvapi

Alternative NVAPI implementation on top of DXVK.
MIT License
353 stars 32 forks source link

Add tracing #182

Closed jp7677 closed 1 month ago

jp7677 commented 1 month ago

~just briefly tested and for actual tracing we should also log all input parameters (wine like, thus only primitives and pointer addresses). Have to think about how to do this elegantly without wasting cycles when tracing is disabled.~

Closes #180

cc: @SveSop

SveSop commented 1 month ago

Seems to work fine, although i am a bit unsure if info should also log this Enter bit? Nice for catching time spent in a function for sure, but do we need it for info logging?

jp7677 commented 1 month ago

Seems to work fine, although i am a bit unsure if info should also log this Enter bit? Nice for catching time spent in a function for sure, but do we need it for info logging?

The idea was to catch situations where a crash occurred within an nvapi call. In that case we obviously don't log an exit code, so those function calls were invisible in the former logs. But I agree, if we have a trace level, putting logging of entering a function behind the trace level sounds sensible.

jp7677 commented 1 month ago

I have to split and clean up the commits, but functionally/code wise this is fine imho. Probably a bit overkill but you never know when all the details might become useful.

jp7677 commented 1 month ago

FYI, I initially I looked at integrating fmt (https://github.com/fmtlib/fmt) for the formatting of the trace statements. Adding it to the project is rather simple, just three headers (fmt/core.h, fmt/format.h, fmt/format-inl.h) and a compile flag (-DFMT_HEADER_ONLY) to indicate header only. But eventually I discarded that idea because of the burden of a new external dependency and it also requires pointers to be wrapped (https://fmt.dev/latest/api.html#_CPPv4I0EN3fmt3ptrEPKv1T), so actual trace statements wouldn't be that shorter.

Saancreed commented 1 month ago

How much we could achieve with just C++20 std::format and some custom formatters? Or is Proton Runtime's compiler too old to support this?

jp7677 commented 1 month ago

How much we could achieve with just C++20 std::format and some custom formatters? Or is Proton Runtime's compiler too old to support this?

I wasn't keen to try out :), also dunno about MSVC support (GitLab CI).

SveSop commented 1 month ago

Seems to be running fine with this. Takes a bit getting used to, but it will be a LOT easier to spot functions that uses too much time, and see if some weird parameters is passed. 👍