Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hook up optional tracy profiler integration #1328

Open
wants to merge 37 commits into
base: master
Choose a base branch
from

Conversation

sharkautarch
Copy link

Shouldn't add any runtime overhead when compiling gamescope w/ tracy disabled (the default)

Advantage of profiling w/ Tracy compared to other sampling profilers is that Tracy's profiling info is way more precise, and Tracy can track slowdowns for (an) individual [delayed] frame(s).

In the current state of this PR, when compiling gamescope w/ tracy enabled, instruments some places with ZoneScoped. profiles frame timings w/ FrameMarkStart/FrameMarkEnd

Also has a default-disabled option (tracy_collect_callstacks) for collecting callstacks in some places: paint_all() and xwayland_ctx_t::Dispatch
I might add additional places to optionally collect callstacks from in the future...

Next Tracy TODO will be to hook up Tracy's vulkan profiling stuff...
(also sorry about the two closed PRs I made accidentily... I had done a git push -f after forgetting to first do git commit...)

@sharkautarch
Copy link
Author

sharkautarch commented Jul 10, 2024

UPDATE:
I've now added code that tracks the vblank timings from vblankmanager.
Here's an example of what it looks like:
gamescope_tracy_screenshot
Note the two parallel horizontal timeline bars in the screenshot
The frame timings for gamescope-xwm (aka steamcompmgr) are shown w/ timeline-bar above the bars labeled 'vblankmanager`

@Joshua-Ashton
Does the tracing code I added to vblankmanager seem ok?
I had decided to keep the code outside of the lock to ensure the profiling code doesn't increase the time spent holding the lock.
EDIT: I just edited the tracy integration for vblankmanager because I realized I should only be doing FrameMarkEnd() in CVBlankTimer::OnPollIn(). The screenshot I originally posted was from before this edit
EDIT 2: after further edits, I moved my code that was outside the lock to being inside the lock. So now it works similar to how gpuvis tracing works inside vblankmanager

@sharkautarch sharkautarch force-pushed the tracy_profiling branch 4 times, most recently from 50e05d0 to 54fccb7 Compare July 10, 2024 16:06
@sharkautarch sharkautarch force-pushed the tracy_profiling branch 5 times, most recently from 4099bad to 9acbbad Compare July 12, 2024 20:59
@sharkautarch
Copy link
Author

sharkautarch commented Jul 14, 2024

UPDATE:
I have now hooked up tracy's vulkan/gpu profiling:
gamescope_tracy_vulkan_screenshot

also set TRACY_LIBBACKTRACE_ELF_DYNLOAD_SUPPORT define for dynamic lib symbol resolution
@matte-schwartz
Copy link

@sharkautarch I've got your tracy_profiling branch merged into master and set up on my dev rig. Gamescope integration seems pretty solid so far, nice work.

I still need to figure out how to make heads or tails of what I see in there, along with setting it up remotely so I can capture drm backend tracing live but that's just a skill issue on my end... time to read the docs.

@sharkautarch
Copy link
Author

sharkautarch commented Jul 21, 2024

@matte-schwartz
For testing drm backend, since it’d be awkward to try to have gamescope and the profiler gui up on the same device
I suggest you build gamescope w/ meson flags: -Dtracy_only_localhost=false -Dtracy_enable=true
Then you should be able to run the Tracy profiler on another device, capturing the stats over the network.
I’m not entirely sure if you’ll need to change any firewall settings.
The profiler gui is designed so that it’s technically a server that the async profiling code in gamescope will connect to, so you might not need to change any firewall settings on your steam deck.
again, I’m not entirely sure. I’ve only tested running gamescope (nested/desktop mode) + the profiler gui on the same device…

Oh also note that the Tracy profiler gui comes with a 'tutorial' mode that teaches you how to use it.

@sharkautarch
Copy link
Author

@matte-schwartz
I added a new commit that records gamescopectl commands w/ tracy.
It actually logs the command before the command executes, which means that you'll always see the effects of a command at some point after wherever the message shows up in tracy profiler gui.
Note that you can search for messages by clicking on the messages button at the top of the gui, and then typing the command (ex: adaptive_sync) into the box next to where it says Filter messages

I made sure that when you do something like gamescopectl adaptive_sync 0, tracy logs adaptive_sync 0, and not just adaptive_sync

@matte-schwartz
Copy link

Seems like tracy profiling may introduce some instability within gamescope-session, not sure if it's from the profiler running out of memory or something like that, but it only happened while I was hammering gamescope with continuous rendering + full mangohud for an extended period of time with tracy profiling connected remotely.

Journal logs of the crash + backtrace of the coredump w/ each thread:
tracy-gamescope-coredump.log

@sharkautarch
Copy link
Author

Oh I think the crash might be due to weirdness w/ static variables, and/or maybe a race condition
I’ll see if I can fix it soon…
Definitely a rare edgecase scenario

@sharkautarch
Copy link
Author

@matte-schwartz
Just pushed out a commit that may fix the issue, tho I'm not entirely sure if it actually fixes it...

…oubleLockable. Markup locks used by the drm and wayland backends

also fix compiler/linker error when building w/ tracy profiler disabled
also add some extra misc details, including some window & commit details previously only shown by gpuvis
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants