Skip to content
Open
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
62 changes: 62 additions & 0 deletions profiler/src/profiler/TracyImGui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# pragma warning( disable: 4244 ) // conversion from don't care to whatever, possible loss of data
#endif

#include <array>
#include <math.h>
#include <stdint.h>
#include <vector>
Expand Down Expand Up @@ -191,6 +192,67 @@ static constexpr const uint32_t AsmSyntaxColors[] = {
}
}

// Replay toolbars expose three user-visible states: start from the beginning, resume from a
// paused midpoint, or pause an actively running replay.
enum class ReplayButtonAction
{
Replay,
Continue,
Pause
};

[[maybe_unused]] static inline ReplayButtonAction GetReplayButtonAction( bool active, bool paused, int currentFrame, int endFrameExclusive )
{
if( active && !paused ) return ReplayButtonAction::Pause;
if( active && paused && currentFrame < endFrameExclusive - 1 ) return ReplayButtonAction::Continue;
return ReplayButtonAction::Replay;
}

[[maybe_unused]] static inline const char* GetReplayButtonLabel( ReplayButtonAction action )
{
switch( action )
{
case ReplayButtonAction::Replay: return ICON_FA_PLAY " Replay";
case ReplayButtonAction::Continue: return ICON_FA_PLAY " Continue";
case ReplayButtonAction::Pause: return ICON_FA_PAUSE " Pause";
default:
IM_ASSERT( false );
return "";
}
}

[[maybe_unused]] static inline float GetReplaySpeedComboWidth( float scale )
{
return ImGui::CalcTextSize( "100x" ).x + ImGui::GetFrameHeight() + scale * 16;
}

// Small helper for combo boxes backed by a fixed label array and a byte-sized selection index.
template<size_t N>
[[maybe_unused]] static inline bool StringArrayCombo( const char* id, const std::array<const char*, N>& labels, uint8_t& selected )
{
IM_ASSERT( selected < labels.size() );

bool changed = false;
if( ImGui::BeginCombo( id, labels[selected] ) )
{
for( uint8_t i = 0; i < labels.size(); i++ )
{
const bool isSelected = selected == i;
if( ImGui::Selectable( labels[i], isSelected ) )
{
selected = i;
changed = true;
}
if( isSelected )
{
ImGui::SetItemDefaultFocus();
}
}
ImGui::EndCombo();
}
return changed;
}

[[maybe_unused]] static inline void DrawTextContrast( ImDrawList* draw, const ImVec2& pos, uint32_t color, const char* text )
{
const auto scale = round( GetScale() );
Expand Down
13 changes: 8 additions & 5 deletions profiler/src/profiler/TracyView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1498,11 +1498,14 @@ void View::SelectThread( uint64_t thread )
bool View::WasActive() const
{
return m_wasActive.load( std::memory_order_acquire ) ||
m_zoomAnim.active ||
m_notificationTime > 0 ||
!m_playback.pause ||
m_worker.IsConnected() ||
!m_worker.IsBackgroundDone();
m_zoomAnim.active ||
m_notificationTime > 0 ||
// Keep refreshing while statistics replays are actively advancing.
( m_showInfo && m_frameSortData.playback.active && !m_frameSortData.playback.pause ) ||
( m_findZone.show && m_findZone.playback.active && !m_findZone.playback.pause ) ||
!m_playback.pause ||
m_worker.IsConnected() ||
!m_worker.IsBackgroundDone();
}

void View::AddLlmAttachment( const nlohmann::json& json )
Expand Down
50 changes: 50 additions & 0 deletions profiler/src/profiler/TracyView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ constexpr const char* GpuContextNames[] = {
"Rocprof"
};

static constexpr std::array<float, 6> StatisticsReplaySpeeds = { 1.f, 5.f, 10.f, 20.f, 50.f, 100.f };
static constexpr std::array<const char*, 6> StatisticsReplaySpeedLabels = { "1x", "5x", "10x", "20x", "50x", "100x" };
static constexpr uint8_t StatisticsReplayDefaultSpeed = 4;

struct MemoryPage;
class FileRead;
class SourceView;
Expand Down Expand Up @@ -393,6 +397,10 @@ class View
void DrawCallstackCalls( const CallstackFrameId* data, size_t size, uint16_t limit ) const;
nlohmann::json GetCallstackJson( const CallstackFrameId* data, size_t size ) const;
void SetViewToLastFrames();
void ResetFindZonePlayback();
void ResetFindZonePlaybackData();
void SetFindZonePlaybackFrame( int idx );
void StartFindZonePlayback( std::pair<int, int> range );
int64_t GetZoneChildTime( const ZoneEvent& zone );
int64_t GetZoneChildTime( const GpuEvent& zone );
int64_t GetZoneChildTimeFast( const ZoneEvent& zone );
Expand All @@ -410,6 +418,11 @@ class View
template<typename Adapter, typename V>
void CalcZoneTimeDataImpl( const V& children, const ContextSwitch* ctx, unordered_flat_map<int16_t, ZoneTimeData>& data, int64_t& ztime );

void ResetFrameSortData();
void ResetFrameSortPlayback();
void SetFrameSortPlaybackFrame( int idx );
void StartFrameSortPlayback( std::pair<int, int> range );

void SetPlaybackFrame( uint32_t idx );
bool Save( const char* fn, FileCompression comp, int zlevel, bool buildDict, int streams );

Expand Down Expand Up @@ -733,6 +746,23 @@ class View
bool showZoneInFrames = false;
Range range;
RangeSlim rangeSlim;
struct
{
const FrameData* frameSet = nullptr;
// Final replay span selected by the UI; the live replay range only exposes a prefix of it.
std::pair<int, int> targetFrameRange = { 0, 0 };
// Full replay-range data used to keep histogram axes fixed while replay advances.
std::vector<int64_t> fullSorted;
// Effective time range shown by the current replay frame.
RangeSlim currentRange;
// Last replay range that accumulated find-zone statistics were built against.
RangeSlim rangeSlim;
int currentFrame = 0;
float timeLeft = 0;
uint8_t speed = StatisticsReplayDefaultSpeed;
bool active = false;
bool pause = true;
} playback;

struct
{
Expand All @@ -749,6 +779,9 @@ class View

void Reset()
{
const auto playbackSpeed = playback.speed;
playback = {};
playback.speed = playbackSpeed;
ResetMatch();
match.clear();
selMatch = 0;
Expand All @@ -760,6 +793,9 @@ class View

void ResetMatch()
{
const auto playbackSpeed = playback.speed;
playback = {};
playback.speed = playbackSpeed;
ResetGroups();
sorted.clear();
sortedNum = 0;
Expand Down Expand Up @@ -909,6 +945,20 @@ class View
bool limitToView = false;
std::pair<int, int> limitRange = { -1, 0 };
int minBinVal = 1;
struct
{
const FrameData* frameSet = nullptr;
// Final replay span selected by the UI; the live replay range only exposes a prefix of it.
std::pair<int, int> targetRange = { 0, 0 };
// Full replay-range frame times used to keep histogram axes fixed while replay advances.
std::vector<int64_t> fullData;
int currentFrame = 0;
float timeLeft = 0;
uint8_t speed = StatisticsReplayDefaultSpeed;
bool active = false;
bool pause = true;
bool limitToView = false;
} playback;
} m_frameSortData;

struct {
Expand Down
Loading
Loading