Skip to content

Commit

Permalink
Tracy Profiler: attempt to fix infrequent crash w/ fiber zones
Browse files Browse the repository at this point in the history
  • Loading branch information
sharkautarch committed Jul 22, 2024
1 parent 0657cb5 commit ea52f5d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/commit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void commit_t::OnPollIn()
{
std::unique_lock lock( m_WaitableCommitStateMutex );
if ( !CloseFenceInternal() ) {
TRACY_FIBER_ZONE_END(g_cZone_img_waiter);
TRACY_FIBER_ZONE_END(g_zone_img_waiter);
TracyFiberLeave;
return;
}
Expand All @@ -68,7 +68,7 @@ void commit_t::OnPollIn()
Signal();

nudge_steamcompmgr();
TRACY_FIBER_ZONE_END(g_cZone_img_waiter);
TRACY_FIBER_ZONE_END(g_zone_img_waiter);
TracyFiberLeave;
}

Expand Down
2 changes: 1 addition & 1 deletion src/steamcompmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6288,7 +6288,7 @@ void update_wayland_res(CommitDoneList_t *doneCommits, steamcompmgr_win_t *w, Re
else {
ZoneScopedN("g_ImageWaiter.AddWaitable()");
TracyFiberEnter(sl_img_waiter_fiber);
TRACY_FIBER_ZONE_START(g_cZone_img_waiter, ctx, "wait for commit");
TRACY_FIBER_ZONE_START(g_zone_img_waiter, ctx, "wait for commit");
g_ImageWaiter.AddWaitable( newCommit.get() );
TracyFiberLeave;
}
Expand Down
8 changes: 4 additions & 4 deletions src/tracy_include.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
#include "tracy/Tracy.hpp"
#include "tracy/TracyC.h"


// (from 3.4.6 of Tracy manual) Tracy doesn't support exiting within a zone.
// workaround is to throw a custom exception,
// then catch exception at the end of the function

extern const char* const sl_steamcompmgr_name;
extern const char* const sl_vblankFrameName;
extern const char* const sl_img_waiter_fiber;
inline std::optional<TracyCZoneCtx> g_cZone_img_waiter;
inline std::optional<tracy::ScopedZone> g_zone_img_waiter;

#ifdef TRACY_ENABLE
#include <pthread.h>
Expand All @@ -21,8 +20,9 @@ inline std::optional<TracyCZoneCtx> g_cZone_img_waiter;
# define MAYBE_NORETURN
# define TRACY_TRY try
# define TRACY_CATCH catch(const ETracyExit& e) { e.m_bPthreadExit ? pthread_exit(const_cast<void*>(e.m_pStatus)) : exit(e.m_status); }
# define TRACY_FIBER_ZONE_START(oVariable, ctx, name) TracyCZoneN(ctx, name, 1); oVariable.emplace(ctx)
# define TRACY_FIBER_ZONE_END(oVariable) if (oVariable) TracyCZoneEnd(*oVariable); oVariable.reset()
# define TRACY_GET_SRC_LOC [](const std::source_location loc = std::source_location::current()) { return tracy::SourceLocationData(loc.function_name(), loc.function_name(), loc.file_name(), loc.line()); }()
# define TRACY_FIBER_ZONE_START(oVariable, ctx, name) static constexpr auto __attribute__((no_icf,used)) tracy_loc = TRACY_GET_SRC_LOC; oVariable.emplace(&tracy_loc, true)
# define TRACY_FIBER_ZONE_END(oVariable) oVariable.reset()
# define TracyDoubleLockable( type, varname ) tracy::DoubleLockable<type> varname { [] () -> const tracy::SourceLocationData* { static constexpr tracy::SourceLocationData srcloc { nullptr, #type " " #varname, TracyFile, TracyLine, 0 }; return &srcloc; }() }
//pthread lock instrumentation seems to trigger an assert on tracy server, so leaving it commented out for now:
# if 0
Expand Down

0 comments on commit ea52f5d

Please sign in to comment.