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
20 changes: 18 additions & 2 deletions profiler/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,15 @@ static void DrawContents()
ImGui::EndDisabled();
}

ImGui::Spacing();
if( ImGui::Checkbox( "Time limit", &tracy::s_config.timeLimit ) ) tracy::SaveConfig();
ImGui::SameLine();
tracy::DrawHelpMarker( "When enabled, the profiler will stop recording data once the connection duration exceeds the specified value (in seconds). Note that the capture duration itself is not correlated to the connection duration." );
ImGui::SameLine();
ImGui::SetNextItemWidth( 70 * dpiScale );
if( ImGui::InputFloat( "##timelimit", &tracy::s_config.connectionTimeLimitSeconds, 0.f, 0.f, "%.2f" ) ) { tracy::s_config.connectionTimeLimitSeconds = std::max( tracy::s_config.connectionTimeLimitSeconds, 0.f ); tracy::SaveConfig(); }
ImGui::SameLine();
ImGui::TextUnformatted( "s" );
ImGui::Spacing();
if( ImGui::Checkbox( "Enable achievements", &tracy::s_config.achievements ) ) tracy::SaveConfig();
ImGui::Spacing();
Expand Down Expand Up @@ -970,11 +979,18 @@ static void DrawContents()
}
}
}
if( tracy::s_config.memoryLimit )
if( tracy::s_config.memoryLimit || tracy::s_config.timeLimit )
{
ImGui::SameLine();
tracy::TextColoredUnformatted( 0xFF00FFFF, ICON_FA_TRIANGLE_EXCLAMATION );
tracy::TooltipIfHovered( "Memory limit is active" );
if( tracy::s_config.memoryLimit )
{
tracy::TooltipIfHovered( "Memory limit is active" );
}
if( tracy::s_config.timeLimit )
{
tracy::TooltipIfHovered( "Capture duration limit is active" );
}
}
ImGui::SameLine( 0, ImGui::GetTextLineHeight() * 2 );

Expand Down
6 changes: 6 additions & 0 deletions profiler/src/profiler/TracyConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ void LoadConfig()
if( ini_sget( ini, "timeline", "verticalScrollMultiplier", "%lf", &v1 ) && v1 > 0.0 ) s_config.verticalScrollMultiplier = v1;
if( ini_sget( ini, "memory", "limit", "%d", &v ) ) s_config.memoryLimit = v;
if( ini_sget( ini, "memory", "percent", "%d", &v ) && v >= 1 && v < 1000 ) s_config.memoryLimitPercent = v;
if( ini_sget( ini, "connection", "durationLimitEnabled", "%d", &v ) && v >= 1 ) s_config.timeLimit = v;
if( ini_sget( ini, "connection", "durationLimitInSeconds", "%lf", &v1 ) ) s_config.connectionTimeLimitSeconds = v1;
if( ini_sget( ini, "achievements", "enabled", "%d", &v ) ) s_config.achievements = v;
if( ini_sget( ini, "achievements", "asked", "%d", &v ) ) s_config.achievementsAsked = v;
if( ini_sget( ini, "ui", "saveUserScale", "%d", &v ) ) s_config.saveUserScale = v;
Expand Down Expand Up @@ -67,6 +69,10 @@ bool SaveConfig()
fprintf( f, "limit = %i\n", (int)s_config.memoryLimit );
fprintf( f, "percent = %i\n", s_config.memoryLimitPercent );

fprintf( f, "\n[connection]\n" );
fprintf( f, "durationLimitEnabled = %i\n", (int)s_config.timeLimit );
fprintf( f, "durationLimitInSeconds = %f\n", s_config.connectionTimeLimitSeconds );

fprintf( f, "\n[achievements]\n" );
fprintf( f, "enabled = %i\n", (int)s_config.achievements );
fprintf( f, "asked = %i\n", (int)s_config.achievementsAsked );
Expand Down
2 changes: 2 additions & 0 deletions profiler/src/profiler/TracyConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ struct Config
double verticalScrollMultiplier = 1.0;
bool memoryLimit = false;
int memoryLimitPercent = 80;
bool timeLimit = false;
float connectionTimeLimitSeconds = 10.f;
bool achievements = false;
bool achievementsAsked = false;
int dynamicColors = 1;
Expand Down
34 changes: 28 additions & 6 deletions profiler/src/profiler/TracyView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace tracy
double s_time = 0;

View::View( void(*cbMainThread)(const std::function<void()>&, bool), const char* addr, uint16_t port, SetTitleCallback stcb, SetScaleCallback sscb, AttentionCallback acb, AchievementsMgr* amgr )
: m_worker( addr, port, s_config.memoryLimit == 0 ? -1 : ( s_config.memoryLimitPercent * tracy::GetPhysicalMemorySize() / 100 ) )
: m_worker( addr, port, s_config.memoryLimit == 0 ? -1 : ( s_config.memoryLimitPercent * tracy::GetPhysicalMemorySize() / 100 ), s_config.timeLimit == 0 ? -1 : s_config.connectionTimeLimitSeconds )
, m_staticView( false )
, m_viewMode( ViewMode::LastFrames )
, m_viewModeHeuristicTry( true )
Expand Down Expand Up @@ -825,9 +825,9 @@ bool View::DrawImpl()
ImGui::SameLine();
if( ImGui::BeginPopup( "TracyConnectionPopup" ) )
{
const bool wasDisconnectIssued = m_disconnectIssued;
const bool wasDisconnectIssued = m_worker.WasDisconnectIssued();
const bool discardData = !DrawConnection();
const bool disconnectIssuedJustNow = m_disconnectIssued != wasDisconnectIssued;
const bool disconnectIssuedJustNow = m_worker.WasDisconnectIssued() != wasDisconnectIssued;
if( discardData ) keepOpen = false;
if( disconnectIssuedJustNow || discardData ) ImGui::CloseCurrentPopup();
ImGui::EndPopup();
Expand Down Expand Up @@ -1079,11 +1079,16 @@ bool View::DrawImpl()
if( dx < targetLabelSize ) ImGui::SameLine( cx + targetLabelSize );
ImGui::Spacing();

const auto timeLimit = m_worker.GetTimeLimit();
const auto timeRemaining = timeLimit - ( std::chrono::steady_clock::now() - m_worker.GetStartTime() );
const bool timeLimitReached = timeLimit.count() > 0 && timeRemaining.count() < 0;
const auto memoryLimit = m_worker.GetMemoryLimit();
if( memoryLimit > 0 )
const auto memoryRemainingBeforeLimit = memoryLimit - memUsage.load( std::memory_order_relaxed );
const bool memoryLimitReached = memoryLimit > 0 && memoryRemainingBeforeLimit < 0;
if( memoryLimit > 0 || timeLimit.count() > 0.f )
{
ImGui::SameLine();
if( memUsage.load( std::memory_order_relaxed ) > memoryLimit )
if( memoryLimitReached || timeLimitReached )
{
TextColoredUnformatted( 0xFF2222FF, ICON_FA_TRIANGLE_EXCLAMATION );
}
Expand All @@ -1094,7 +1099,24 @@ bool View::DrawImpl()
if( ImGui::IsItemHovered() )
{
ImGui::BeginTooltip();
ImGui::Text( "Memory limit: %s", MemSizeToString( memoryLimit ) );
if( memoryLimit > 0 )
{
ImGui::Text( "Memory limit: %s", MemSizeToString( memoryLimit ) );
if( !memoryLimitReached )
{
ImGui::SameLine();
ImGui::Text( " (%s remaining)", MemSizeToString( memoryRemainingBeforeLimit ) );
}
}
if( timeLimit.count() > 0.f )
{
ImGui::Text( "Capture time limit: %.2f s", timeLimit.count() );
if( !timeLimitReached )
{
ImGui::SameLine();
ImGui::Text( " (%.2f s remaining)", std::chrono::duration<double>( timeRemaining ).count() );
}
}
ImGui::EndTooltip();
}
}
Expand Down
1 change: 0 additions & 1 deletion profiler/src/profiler/TracyView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,6 @@ class View
size_t m_prevMessages = 0;
bool m_messagesShowCallstack = false;
Vector<uint32_t> m_msgList;
bool m_disconnectIssued = false;
uint64_t m_selectedThread = 0;
DecayValue<uint64_t> m_drawThreadMigrations = 0;
DecayValue<uint64_t> m_drawThreadHighlight = 0;
Expand Down
3 changes: 1 addition & 2 deletions profiler/src/profiler/TracyView_ConnectionState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,11 @@ bool View::DrawConnection()
ImGui::SameLine( 0, 2 * ty );
const char* stopStr = ICON_FA_PLUG " Stop";
Worker::MainThreadDataLockGuard lock = m_worker.ObtainLockForMainThread();
if( !m_disconnectIssued && m_worker.IsConnected() )
if( !m_worker.WasDisconnectIssued() && m_worker.IsConnected() )
{
if( ImGui::Button( stopStr ) )
{
m_worker.Disconnect();
m_disconnectIssued = true;
}
}
else
Expand Down
9 changes: 7 additions & 2 deletions server/TracyWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ static bool IsQueryPrio( ServerQuery type )

LoadProgress Worker::s_loadProgress;

Worker::Worker( const char* addr, uint16_t port, int64_t memoryLimit )
Worker::Worker( const char* addr, uint16_t port, int64_t memoryLimit, float timeLimit )
: m_addr( addr )
, m_port( port )
, m_hasData( false )
Expand All @@ -272,6 +272,7 @@ Worker::Worker( const char* addr, uint16_t port, int64_t memoryLimit )
, m_pendingCallstackSubframes( 0 )
, m_pendingSymbolCode( 0 )
, m_memoryLimit( memoryLimit )
, m_timeLimit( timeLimit )
, m_callstackFrameStaging( nullptr )
, m_traceVersion( CurrentVersion )
, m_loadTime( 0 )
Expand Down Expand Up @@ -313,6 +314,7 @@ Worker::Worker( const char* name, const char* program, const std::vector<ImportE
, m_onDemand( false )
, m_inconsistentSamples( false )
, m_memoryLimit( -1 )
, m_timeLimit( -1 )
, m_traceVersion( CurrentVersion )
{
m_data.sourceLocationExpand.push_back( 0 );
Expand Down Expand Up @@ -2762,6 +2764,7 @@ void Worker::Exec()
switch( handshake )
{
case HandshakeWelcome:
m_data.startTime = std::chrono::steady_clock::now();
break;
case HandshakeProtocolMismatch:
case HandshakeNotAvailable:
Expand Down Expand Up @@ -2848,7 +2851,9 @@ void Worker::Exec()

for(;;)
{
if( m_shutdown.load( std::memory_order_relaxed ) || ( m_memoryLimit > 0 && memUsage.load( std::memory_order_relaxed ) > m_memoryLimit ) )
if( m_shutdown.load( std::memory_order_relaxed )
|| ( m_memoryLimit > 0 && memUsage.load( std::memory_order_relaxed ) > m_memoryLimit )
|| ( m_timeLimit.count() > 0.f && std::chrono::steady_clock::now() > m_data.startTime + m_timeLimit ) )
{
QueryTerminate();
goto close;
Expand Down
7 changes: 6 additions & 1 deletion server/TracyWorker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,8 @@ class Worker
bool hasBranchRetirement = false;

unordered_flat_map<uint64_t, uint64_t> fiberToThreadMap;

std::chrono::time_point<std::chrono::steady_clock> startTime;
};

struct MbpsBlock
Expand Down Expand Up @@ -455,7 +457,7 @@ class Worker
NUM_FAILURES
};

Worker( const char* addr, uint16_t port, int64_t memoryLimit );
Worker( const char* addr, uint16_t port, int64_t memoryLimit, float timeLimit );
Worker( const char* name, const char* program, const std::vector<ImportEventTimeline>& timeline, const std::vector<ImportEventMessages>& messages, const std::vector<ImportEventPlots>& plots, const std::unordered_map<uint64_t, std::string>& threadNames );
Worker( FileRead& f, EventType::Type eventMask = EventType::All, bool bgTasks = true, bool allowStringModification = false);
~Worker();
Expand Down Expand Up @@ -671,6 +673,8 @@ class Worker
void Disconnect();
bool WasDisconnectIssued() const { return m_disconnect; }
int64_t GetMemoryLimit() const { return m_memoryLimit; }
std::chrono::duration<float> GetTimeLimit() const { return m_timeLimit; }
std::chrono::steady_clock::time_point GetStartTime() const { return m_data.startTime; }

void Write( FileWrite& f, bool fiDict );
int GetTraceVersion() const { return m_traceVersion; }
Expand Down Expand Up @@ -1068,6 +1072,7 @@ class Worker

Slab<64*1024*1024> m_slab;
int64_t m_memoryLimit;
std::chrono::duration<float> m_timeLimit;

DataBlock m_data;
MbpsBlock m_mbpsData;
Expand Down
Loading