tracy/server/TracyView.cpp

1393 lines
49 KiB
C++
Raw Normal View History

2019-06-22 11:40:00 +00:00
#ifdef _MSC_VER
2020-09-23 13:04:59 +00:00
# pragma warning( disable: 4267 ) // conversion from don't care to whatever, possible loss of data
2019-06-22 11:40:00 +00:00
#endif
2019-01-19 11:03:30 +00:00
#ifdef __MINGW32__
# define __STDC_FORMAT_MACROS
#endif
2017-09-14 19:28:40 +00:00
#include <algorithm>
2017-09-12 23:33:50 +00:00
#include <assert.h>
2017-09-22 20:11:30 +00:00
#include <inttypes.h>
#include <math.h>
2017-11-15 20:49:41 +00:00
#include <mutex>
2022-07-02 15:00:08 +00:00
#include "imgui.h"
2018-04-21 22:52:33 +00:00
#include "TracyFileRead.hpp"
2018-08-17 12:54:28 +00:00
#include "TracyFilesystem.hpp"
2022-07-02 15:00:08 +00:00
#include "TracyImGui.hpp"
2019-06-18 18:43:28 +00:00
#include "TracyPrint.hpp"
#include "TracySourceView.hpp"
2022-07-02 15:00:08 +00:00
#include "TracyTexture.hpp"
2017-09-12 23:33:50 +00:00
#include "TracyView.hpp"
#include "../public/common/TracyStackFrames.hpp"
2017-09-12 23:33:50 +00:00
2021-05-17 10:09:14 +00:00
#include "imgui_internal.h"
#ifdef _WIN32
# include <windows.h>
#elif defined __linux__
# include <sys/sysinfo.h>
#elif defined __APPLE__ || defined BSD
# include <sys/types.h>
# include <sys/sysctl.h>
#endif
#include "IconsFontAwesome6.h"
2018-08-17 21:22:13 +00:00
2018-07-13 21:41:12 +00:00
#ifndef M_PI_2
#define M_PI_2 1.57079632679489661923
#endif
2017-09-12 23:33:50 +00:00
namespace tracy
{
double s_time = 0;
2023-05-01 12:41:38 +00:00
View::View( void(*cbMainThread)(const std::function<void()>&, bool), const char* addr, uint16_t port, ImFont* fixedWidth, ImFont* smallFont, ImFont* bigFont, SetTitleCallback stcb, SetScaleCallback sscb, AttentionCallback acb, const Config& config )
: m_worker( addr, port )
2017-09-30 14:58:02 +00:00
, m_staticView( false )
, m_viewMode( ViewMode::LastFrames )
, m_viewModeHeuristicTry( true )
, m_forceConnectionPopup( true, true )
, m_tc( *this, m_worker, config.threadedRendering )
2018-08-04 17:47:09 +00:00
, m_frames( nullptr )
2019-07-12 23:25:37 +00:00
, m_messagesScrollBottom( true )
2020-08-15 00:26:35 +00:00
, m_reactToCrash( true )
2020-11-18 00:23:46 +00:00
, m_reactToLostConnection( true )
2019-08-16 14:02:57 +00:00
, m_smallFont( smallFont )
2019-07-12 17:16:56 +00:00
, m_bigFont( bigFont )
2021-03-27 12:16:19 +00:00
, m_fixedFont( fixedWidth )
, m_stcb( stcb )
, m_sscb( sscb )
2022-10-13 17:31:47 +00:00
, m_acb( acb )
2019-07-26 21:05:24 +00:00
, m_userData()
, m_cbMainThread( cbMainThread )
2017-09-21 00:10:20 +00:00
{
InitMemory();
InitTextEditor();
2023-05-01 17:07:49 +00:00
m_vd.frameTarget = config.targetFps;
}
2023-05-01 12:41:38 +00:00
View::View( void(*cbMainThread)(const std::function<void()>&, bool), FileRead& f, ImFont* fixedWidth, ImFont* smallFont, ImFont* bigFont, SetTitleCallback stcb, SetScaleCallback sscb, AttentionCallback acb, const Config& config )
: m_worker( f )
2019-10-07 19:34:10 +00:00
, m_filename( f.GetFilename() )
, m_staticView( true )
, m_viewMode( ViewMode::Paused )
, m_tc( *this, m_worker, config.threadedRendering )
2018-08-04 17:47:09 +00:00
, m_frames( m_worker.GetFramesBase() )
2019-07-12 23:25:37 +00:00
, m_messagesScrollBottom( false )
2019-08-16 14:02:57 +00:00
, m_smallFont( smallFont )
2019-07-12 17:16:56 +00:00
, m_bigFont( bigFont )
2021-03-27 12:16:19 +00:00
, m_fixedFont( fixedWidth )
, m_stcb( stcb )
, m_sscb( sscb )
2022-10-13 17:31:47 +00:00
, m_acb( acb )
2019-07-26 21:05:24 +00:00
, m_userData( m_worker.GetCaptureProgram().c_str(), m_worker.GetCaptureTime() )
, m_cbMainThread( cbMainThread )
{
2019-01-06 18:20:17 +00:00
m_notificationTime = 4;
m_notificationText = std::string( "Trace loaded in " ) + TimeToString( m_worker.GetLoadTime() );
InitMemory();
InitTextEditor();
m_vd.zvStart = m_worker.GetFirstTime();
m_vd.zvEnd = m_worker.GetLastTime();
m_userData.StateShouldBePreserved();
2019-08-28 17:45:22 +00:00
m_userData.LoadState( m_vd );
2019-10-13 14:29:24 +00:00
m_userData.LoadAnnotations( m_annotations );
2020-04-18 12:25:04 +00:00
m_sourceRegexValid = m_userData.LoadSourceSubstitutions( m_sourceSubstitutions );
if( m_worker.GetCallstackFrameCount() == 0 ) m_showUnknownFrames = false;
if( m_worker.GetCallstackSampleCount() == 0 ) m_showAllSymbols = true;
2023-05-01 17:07:49 +00:00
m_vd.frameTarget = config.targetFps;
}
View::~View()
2017-09-21 23:30:57 +00:00
{
m_worker.Shutdown();
2020-04-18 12:25:04 +00:00
2019-08-28 17:45:22 +00:00
m_userData.SaveState( m_vd );
2019-10-13 14:29:24 +00:00
m_userData.SaveAnnotations( m_annotations );
2020-04-18 12:25:04 +00:00
m_userData.SaveSourceSubstitutions( m_sourceSubstitutions );
2017-09-21 23:30:57 +00:00
if( m_compare.loadThread.joinable() ) m_compare.loadThread.join();
if( m_saveThread.joinable() ) m_saveThread.join();
if( m_frameTexture ) FreeTexture( m_frameTexture, m_cbMainThread );
if( m_playback.texture ) FreeTexture( m_playback.texture, m_cbMainThread );
}
void View::InitMemory()
{
#ifdef _WIN32
MEMORYSTATUSEX statex;
statex.dwLength = sizeof( statex );
GlobalMemoryStatusEx( &statex );
m_totalMemory = statex.ullTotalPhys;
#elif defined __linux__
struct sysinfo sysInfo;
sysinfo( &sysInfo );
m_totalMemory = sysInfo.totalram;
#elif defined __APPLE__
size_t memSize;
size_t sz = sizeof( memSize );
sysctlbyname( "hw.memsize", &memSize, &sz, nullptr, 0 );
m_totalMemory = memSize;
#elif defined BSD
size_t memSize;
size_t sz = sizeof( memSize );
sysctlbyname( "hw.physmem", &memSize, &sz, nullptr, 0 );
m_totalMemory = memSize;
#else
m_totalMemory = 0;
#endif
}
void View::InitTextEditor()
2018-08-17 12:44:41 +00:00
{
m_sourceView = std::make_unique<SourceView>();
m_sourceViewFile = nullptr;
2018-08-17 12:54:28 +00:00
}
void View::ViewSource( const char* fileName, int line )
{
assert( fileName );
m_sourceViewFile = fileName;
2020-05-23 13:14:57 +00:00
m_sourceView->OpenSource( fileName, line, *this, m_worker );
}
void View::ViewSource( const char* fileName, int line, const char* functionName )
{
assert( functionName );
uint64_t addr = 0;
uint64_t base = 0;
const auto fnsz = strlen( functionName );
auto& symMap = m_worker.GetSymbolMap();
for( auto& sym : symMap )
{
const auto name = m_worker.GetString( sym.second.name );
const auto ptr = strstr( name, functionName );
if( ptr &&
( ptr[fnsz] == 0 || ptr[fnsz] == '(' || ptr[fnsz] == '<' ) &&
( ptr == name || ( ptr[-1] == ' ' || ptr[-1] == ':' ) ) )
{
if( addr != 0 )
{
// Ambiguous function name. Bail out.
ViewSource( fileName, line );
return;
}
else
{
addr = sym.first;
if( sym.second.isInline )
{
base = m_worker.GetSymbolForAddress( addr );
if( base == 0 )
{
addr = 0;
}
}
else
{
base = addr;
}
}
}
}
if( addr != 0 && base != 0 )
{
ViewSymbol( fileName, line, base, addr );
}
else
{
ViewSource( fileName, line );
}
}
void View::ViewSourceCheckKeyMod( const char* fileName, int line, const char* functionName )
{
if( ImGui::GetIO().KeyCtrl )
{
ViewSource( fileName, line );
}
else
{
ViewSource( fileName, line, functionName );
}
}
void View::ViewSymbol( const char* fileName, int line, uint64_t baseAddr, uint64_t symAddr )
2018-08-17 12:54:28 +00:00
{
assert( fileName || symAddr );
m_sourceViewFile = fileName ? fileName : (const char*)~uint64_t( 0 );
m_sourceView->OpenSymbol( fileName, line, baseAddr, symAddr, m_worker, *this );
2018-08-17 12:44:41 +00:00
}
bool View::ViewDispatch( const char* fileName, int line, uint64_t symAddr )
{
if( line == 0 )
{
fileName = nullptr;
}
else
{
2020-05-23 13:14:57 +00:00
if( !SourceFileValid( fileName, m_worker.GetCaptureTime(), *this, m_worker ) )
{
fileName = nullptr;
line = 0;
}
}
if( symAddr == 0 )
{
if( line != 0 )
{
ViewSource( fileName, line );
return true;
}
return false;
}
else
{
uint64_t baseAddr = 0;
if( m_worker.HasSymbolCode( symAddr ) )
{
baseAddr = symAddr;
}
else
{
2020-04-08 14:55:49 +00:00
const auto parentAddr = m_worker.GetSymbolForAddress( symAddr );
2022-05-01 22:51:46 +00:00
if( parentAddr != 0 && m_worker.HasSymbolCode( parentAddr ) )
{
2022-05-01 22:51:46 +00:00
baseAddr = parentAddr;
}
}
if( baseAddr != 0 || line != 0 )
{
ViewSymbol( fileName, line, baseAddr, symAddr );
return true;
}
return false;
}
}
static const char* CompressionName[] = {
"LZ4",
"LZ4 HC",
"LZ4 HC extreme",
"Zstd",
nullptr
};
static const char* CompressionDesc[] = {
"Fastest save, fast load time, big file size",
"Slow save, fastest load time, reasonable file size",
"Very slow save, fastest load time, file smaller than LZ4 HC",
"Configurable save time (fast-slowest), reasonable load time, smallest file size",
nullptr
};
static_assert( sizeof( CompressionName ) == sizeof( CompressionDesc ), "Unmatched compression names and descriptions" );
2022-10-13 18:39:43 +00:00
2018-04-29 23:16:08 +00:00
bool View::Draw()
2017-09-15 00:30:22 +00:00
{
2022-10-13 17:50:35 +00:00
HandshakeStatus status = (HandshakeStatus)m_worker.GetHandshakeStatus();
switch( status )
{
case HandshakeProtocolMismatch:
2022-10-13 18:39:43 +00:00
Attention( m_attnProtoMismatch );
ImGui::OpenPopup( "Protocol mismatch" );
break;
case HandshakeNotAvailable:
2022-10-13 18:39:43 +00:00
Attention( m_attnNotAvailable );
ImGui::OpenPopup( "Client not ready" );
break;
case HandshakeDropped:
2022-10-13 18:39:43 +00:00
Attention( m_attnDropped );
ImGui::OpenPopup( "Client disconnected" );
break;
default:
break;
}
2022-10-13 17:50:35 +00:00
const auto& failure = m_worker.GetFailureType();
2019-01-14 22:42:58 +00:00
if( failure != Worker::Failure::None )
{
2022-10-13 18:39:43 +00:00
Attention( m_attnFailure );
2019-01-14 22:42:58 +00:00
ImGui::OpenPopup( "Instrumentation failure" );
}
if( ImGui::BeginPopupModal( "Protocol mismatch", nullptr, ImGuiWindowFlags_AlwaysAutoResize ) )
{
2022-10-13 17:50:35 +00:00
ImGui::PushFont( m_bigFont );
TextCentered( ICON_FA_TRIANGLE_EXCLAMATION );
ImGui::PopFont();
ImGui::TextUnformatted( "The client you are trying to connect to uses incompatible protocol version.\nMake sure you are using the same Tracy version on both client and server." );
ImGui::Separator();
if( ImGui::Button( "My bad" ) )
{
ImGui::CloseCurrentPopup();
ImGui::EndPopup();
2022-10-13 18:39:43 +00:00
m_attnProtoMismatch = false;
return false;
}
ImGui::SameLine();
if( ImGui::Button( "Reconnect" ) )
{
ImGui::CloseCurrentPopup();
ImGui::EndPopup();
2022-10-13 17:50:35 +00:00
m_reconnectRequested = true;
2022-10-13 18:39:43 +00:00
m_attnProtoMismatch = false;
return false;
}
ImGui::EndPopup();
}
if( ImGui::BeginPopupModal( "Client not ready", nullptr, ImGuiWindowFlags_AlwaysAutoResize ) )
{
2022-10-13 17:50:35 +00:00
ImGui::PushFont( m_bigFont );
TextCentered( ICON_FA_LIGHTBULB );
ImGui::PopFont();
ImGui::TextUnformatted( "The client you are trying to connect to is no longer able to sent profiling data,\nbecause another server was already connected to it.\nYou can do the following:\n\n 1. Restart the client application.\n 2. Rebuild the client application with on-demand mode enabled." );
ImGui::Separator();
if( ImGui::Button( "I understand" ) )
{
ImGui::CloseCurrentPopup();
ImGui::EndPopup();
2022-10-13 18:39:43 +00:00
m_attnNotAvailable = false;
return false;
}
ImGui::SameLine();
if( ImGui::Button( "Reconnect" ) )
{
ImGui::CloseCurrentPopup();
ImGui::EndPopup();
2022-10-13 17:50:35 +00:00
m_reconnectRequested = true;
2022-10-13 18:39:43 +00:00
m_attnNotAvailable = false;
return false;
}
ImGui::EndPopup();
}
if( ImGui::BeginPopupModal( "Client disconnected", nullptr, ImGuiWindowFlags_AlwaysAutoResize ) )
{
2022-10-13 17:50:35 +00:00
ImGui::PushFont( m_bigFont );
TextCentered( ICON_FA_HANDSHAKE );
ImGui::PopFont();
ImGui::TextUnformatted( "The client you are trying to connect to has disconnected during the initial\nconnection handshake. Please check your network configuration." );
ImGui::Separator();
if( ImGui::Button( "Will do" ) )
{
ImGui::CloseCurrentPopup();
ImGui::EndPopup();
2022-10-13 18:39:43 +00:00
m_attnDropped = false;
return false;
}
ImGui::SameLine();
if( ImGui::Button( "Reconnect" ) )
{
ImGui::CloseCurrentPopup();
ImGui::EndPopup();
2022-10-13 17:50:35 +00:00
m_reconnectRequested = true;
2022-10-13 18:39:43 +00:00
m_attnDropped = false;
return false;
}
ImGui::EndPopup();
}
2019-01-14 22:42:58 +00:00
if( ImGui::BeginPopupModal( "Instrumentation failure", nullptr, ImGuiWindowFlags_AlwaysAutoResize ) )
{
2022-10-13 17:50:35 +00:00
const auto& data = m_worker.GetFailureData();
ImGui::PushFont( m_bigFont );
2019-01-14 22:42:58 +00:00
TextCentered( ICON_FA_SKULL );
ImGui::PopFont();
ImGui::TextUnformatted( "Profiling session terminated due to improper instrumentation.\nPlease correct your program and try again." );
ImGui::TextUnformatted( "Reason:" );
2019-01-14 22:42:58 +00:00
ImGui::SameLine();
ImGui::TextUnformatted( Worker::GetFailureString( failure ) );
2019-01-14 22:42:58 +00:00
ImGui::Separator();
if( data.srcloc != 0 )
2019-01-14 22:42:58 +00:00
{
2022-10-13 17:50:35 +00:00
const auto& srcloc = m_worker.GetSourceLocation( data.srcloc );
if( srcloc.name.active )
{
2022-10-13 17:50:35 +00:00
TextFocused( "Zone name:", m_worker.GetString( srcloc.name ) );
}
2022-10-13 17:50:35 +00:00
TextFocused( "Function:", m_worker.GetString( srcloc.function ) );
TextDisabledUnformatted( "Location:" );
ImGui::SameLine();
2022-10-13 17:50:35 +00:00
ImGui::TextUnformatted( LocationToString( m_worker.GetString( srcloc.file ), srcloc.line ) );
2019-01-14 22:42:58 +00:00
}
if( data.thread != 0 )
{
2022-10-13 17:50:35 +00:00
TextFocused( "Thread:", m_worker.GetThreadName( data.thread ) );
ImGui::SameLine();
ImGui::TextDisabled( "(%s)", RealToString( data.thread ) );
2022-10-13 17:50:35 +00:00
if( m_worker.IsThreadFiber( data.thread ) )
2021-11-06 18:18:33 +00:00
{
ImGui::SameLine();
TextColoredUnformatted( ImVec4( 0.2f, 0.6f, 0.2f, 1.f ), "Fiber" );
}
}
2021-10-10 12:12:13 +00:00
if( !data.message.empty() )
{
TextFocused( "Context:", data.message.c_str() );
}
2020-09-30 14:32:34 +00:00
if( data.callstack != 0 )
{
if( ImGui::TreeNode( "Call stack" ) )
{
ImGui::BeginChild( "##callstackFailure", ImVec2( 1200, 500 ) );
2020-12-08 01:03:23 +00:00
if( ImGui::BeginTable( "##callstack", 4, ImGuiTableFlags_Resizable | ImGuiTableFlags_Borders ) )
2020-09-30 14:32:34 +00:00
{
ImGui::TableSetupColumn( "Frame", ImGuiTableColumnFlags_WidthFixed | ImGuiTableColumnFlags_NoResize );
ImGui::TableSetupColumn( "Function" );
ImGui::TableSetupColumn( "Location" );
ImGui::TableSetupColumn( "Image" );
ImGui::TableHeadersRow();
2022-10-13 17:50:35 +00:00
auto& cs = m_worker.GetCallstack( data.callstack );
int fidx = 0;
for( auto& entry : cs )
2020-09-30 14:32:34 +00:00
{
2022-10-13 17:50:35 +00:00
auto frameData = m_worker.GetCallstackFrame( entry );
if( !frameData )
2020-09-30 14:32:34 +00:00
{
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::Text( "%i", fidx++ );
ImGui::TableNextColumn();
char buf[32];
2022-10-13 17:50:35 +00:00
sprintf( buf, "%p", (void*)m_worker.GetCanonicalPointer( entry ) );
ImGui::TextUnformatted( buf );
if( ImGui::IsItemHovered() )
{
ImGui::BeginTooltip();
ImGui::TextUnformatted( "Click on entry to copy it to clipboard." );
ImGui::EndTooltip();
if( ImGui::IsItemClicked() )
{
ImGui::SetClipboardText( buf );
}
}
2020-09-30 14:32:34 +00:00
}
else
2020-09-30 14:32:34 +00:00
{
const auto fsz = frameData->size;
for( uint8_t f=0; f<fsz; f++ )
2020-09-30 14:32:34 +00:00
{
const auto& frame = frameData->data[f];
2022-10-13 17:50:35 +00:00
auto txt = m_worker.GetString( frame.name );
if( fidx == 0 && f != fsz-1 )
2020-09-30 14:32:34 +00:00
{
auto test = s_tracyStackFrames;
bool match = false;
do
2020-09-30 14:32:34 +00:00
{
if( strcmp( txt, *test ) == 0 )
{
match = true;
break;
}
2020-09-30 14:32:34 +00:00
}
while( *++test );
if( match ) continue;
2020-09-30 14:32:34 +00:00
}
ImGui::TableNextRow();
ImGui::TableNextColumn();
if( f == fsz-1 )
{
ImGui::Text( "%i", fidx++ );
}
else
{
TextDisabledUnformatted( "inline" );
}
ImGui::TableNextColumn();
{
ImGui::PushTextWrapPos( 0.0f );
if( txt[0] == '[' )
{
TextDisabledUnformatted( txt );
}
else
{
ImGui::TextUnformatted( txt );
}
ImGui::PopTextWrapPos();
}
if( ImGui::IsItemHovered() )
{
ImGui::BeginTooltip();
ImGui::TextUnformatted( "Click on entry to copy it to clipboard." );
ImGui::EndTooltip();
if( ImGui::IsItemClicked() )
{
ImGui::SetClipboardText( txt );
}
}
ImGui::TableNextColumn();
2020-09-30 14:32:34 +00:00
ImGui::PushTextWrapPos( 0.0f );
2022-10-13 17:50:35 +00:00
txt = m_worker.GetString( frame.file );
TextDisabledUnformatted( LocationToString( txt, frame.line ) );
if( ImGui::IsItemHovered() )
{
ImGui::BeginTooltip();
ImGui::TextUnformatted( "Click on entry to copy it to clipboard." );
ImGui::EndTooltip();
if( ImGui::IsItemClicked() )
{
ImGui::SetClipboardText( txt );
}
2020-09-30 14:32:34 +00:00
}
ImGui::PopTextWrapPos();
ImGui::TableNextColumn();
if( frameData->imageName.Active() )
{
2022-10-13 17:50:35 +00:00
TextDisabledUnformatted( m_worker.GetString( frameData->imageName ) );
}
2020-09-30 14:32:34 +00:00
}
}
}
ImGui::EndTable();
2020-09-30 14:32:34 +00:00
}
ImGui::EndChild();
ImGui::TreePop();
}
}
2019-01-14 22:42:58 +00:00
ImGui::Separator();
if( ImGui::Button( "I understand" ) )
{
ImGui::CloseCurrentPopup();
2022-10-13 17:50:35 +00:00
m_worker.ClearFailure();
2022-10-13 18:39:43 +00:00
m_attnFailure = false;
2019-01-14 22:42:58 +00:00
}
ImGui::EndPopup();
}
bool saveFailed = false;
2022-10-13 17:50:35 +00:00
if( !m_filenameStaging.empty() )
{
ImGui::OpenPopup( "Save trace" );
}
if( ImGui::BeginPopupModal( "Save trace", nullptr, ImGuiWindowFlags_AlwaysAutoResize ) )
{
2022-10-13 17:50:35 +00:00
assert( !m_filenameStaging.empty() );
auto fn = m_filenameStaging.c_str();
ImGui::PushFont( m_bigFont );
TextFocused( "Path:", fn );
2022-05-01 11:04:16 +00:00
ImGui::PopFont();
ImGui::Separator();
static FileWrite::Compression comp = FileWrite::Compression::Fast;
static int zlvl = 6;
ImGui::TextUnformatted( ICON_FA_FILE_ZIPPER " Trace compression" );
ImGui::SameLine();
TextDisabledUnformatted( "Can be changed later with the upgrade utility" );
ImGui::Indent();
int idx = 0;
while( CompressionName[idx] )
{
if( ImGui::RadioButton( CompressionName[idx], (int)comp == idx ) ) comp = (FileWrite::Compression)idx;
ImGui::SameLine();
TextDisabledUnformatted( CompressionDesc[idx] );
idx++;
}
ImGui::Unindent();
ImGui::TextUnformatted( "Zstd level" );
ImGui::SameLine();
TextDisabledUnformatted( "Increasing level decreases file size, but increases save and load times" );
ImGui::Indent();
if( ImGui::SliderInt( "##zstd", &zlvl, 1, 22, "%d", ImGuiSliderFlags_AlwaysClamp ) )
{
comp = FileWrite::Compression::Zstd;
}
ImGui::Unindent();
static bool buildDict = false;
2022-10-13 17:50:35 +00:00
if( m_worker.GetFrameImageCount() != 0 )
{
ImGui::Separator();
ImGui::Checkbox( "Build frame images dictionary", &buildDict );
ImGui::SameLine();
TextDisabledUnformatted( "Decreases run-time memory requirements" );
}
ImGui::Separator();
if( ImGui::Button( ICON_FA_FLOPPY_DISK " Save trace" ) )
{
2022-10-13 17:50:35 +00:00
saveFailed = !Save( fn, comp, zlvl, buildDict );
m_filenameStaging.clear();
ImGui::CloseCurrentPopup();
}
ImGui::SameLine();
if( ImGui::Button( "Cancel" ) )
{
2022-10-13 17:50:35 +00:00
m_filenameStaging.clear();
ImGui::CloseCurrentPopup();
}
ImGui::EndPopup();
}
if( saveFailed ) ImGui::OpenPopup( "Save failed" );
if( ImGui::BeginPopupModal( "Save failed", nullptr, ImGuiWindowFlags_AlwaysAutoResize ) )
{
2022-10-13 17:50:35 +00:00
ImGui::PushFont( m_bigFont );
TextCentered( ICON_FA_TRIANGLE_EXCLAMATION );
ImGui::PopFont();
ImGui::TextUnformatted( "Could not save trace at the specified location. Try again somewhere else." );
ImGui::Separator();
if( ImGui::Button( "Oh well" ) ) ImGui::CloseCurrentPopup();
ImGui::EndPopup();
}
if( !m_staticView &&
( ImGui::IsModKey( ImGuiKey_LeftCtrl ) || ImGui::IsModKey( ImGuiKey_RightCtrl ) ) &&
( ImGui::IsModKey( ImGuiKey_LeftShift ) || ImGui::IsModKey( ImGuiKey_RightShift ) ) &&
( ImGui::IsModKey( ImGuiKey_LeftAlt ) || ImGui::IsModKey( ImGuiKey_RightAlt ) ) &&
ImGui::IsKeyPressed( ImGuiKey_R ) )
{
m_reconnectRequested = true;
return false;
}
2019-03-06 23:57:25 +00:00
s_time += ImGui::GetIO().DeltaTime;
2022-10-13 17:50:35 +00:00
return DrawImpl();
2017-09-15 00:30:22 +00:00
}
static const char* MainWindowButtons[] = {
2018-08-17 21:24:25 +00:00
ICON_FA_PLAY " Resume",
ICON_FA_PAUSE " Pause",
ICON_FA_SQUARE " Stopped"
};
enum { MainWindowButtonsCount = sizeof( MainWindowButtons ) / sizeof( *MainWindowButtons ) };
2018-04-29 23:16:08 +00:00
bool View::DrawImpl()
2017-09-15 00:30:22 +00:00
{
if( !m_worker.HasData() )
{
bool keepOpen = true;
char tmp[2048];
sprintf( tmp, "%s###Connection", m_worker.GetAddr().c_str() );
ImGui::Begin( tmp, &keepOpen, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoCollapse );
ImGui::PushFont( m_bigFont );
TextCentered( ICON_FA_WIFI );
ImGui::PopFont();
ImGui::TextUnformatted( "Waiting for connection..." );
DrawWaitingDots( s_time );
ImGui::End();
return keepOpen;
2017-09-30 14:58:02 +00:00
}
2017-09-30 12:37:21 +00:00
Attention( m_attnWorking );
if( !m_uarchSet )
{
m_uarchSet = true;
m_sourceView->SetCpuId( m_worker.GetCpuId() );
}
2019-07-26 21:05:24 +00:00
if( !m_userData.Valid() ) m_userData.Init( m_worker.GetCaptureProgram().c_str(), m_worker.GetCaptureTime() );
2020-02-08 12:07:02 +00:00
if( m_saveThreadState.load( std::memory_order_acquire ) == SaveThreadState::NeedsJoin )
{
m_saveThread.join();
2020-02-08 12:07:02 +00:00
m_saveThreadState.store( SaveThreadState::Inert, std::memory_order_release );
const auto src = m_srcFileBytes.load( std::memory_order_relaxed );
const auto dst = m_dstFileBytes.load( std::memory_order_relaxed );
m_notificationTime = 4;
char buf[1024];
sprintf( buf, "Trace size %s (%.2f%% ratio)", MemSizeToString( dst ), 100.f * dst / src );
m_notificationText = buf;
2022-10-13 18:42:32 +00:00
m_acb();
}
const auto& io = ImGui::GetIO();
m_wasActive = false;
assert( m_shortcut == ShortcutAction::None );
if( io.KeyCtrl )
{
2022-04-26 23:16:46 +00:00
if( ImGui::IsKeyPressed( ImGuiKey_F ) )
{
m_findZone.show = true;
m_shortcut = ShortcutAction::OpenFind;
}
}
2018-08-04 17:47:09 +00:00
if( !m_frames ) m_frames = m_worker.GetFramesBase();
2018-03-24 22:43:51 +00:00
const auto th = ImGui::GetTextLineHeight();
float bw = 0;
for( int i=0; i<MainWindowButtonsCount; i++ )
{
bw = std::max( bw, ImGui::CalcTextSize( MainWindowButtons[i] ).x );
}
bw += th;
2018-03-24 22:43:51 +00:00
2018-04-29 23:16:08 +00:00
bool keepOpen = true;
bool* keepOpenPtr = nullptr;
2019-06-22 12:04:48 +00:00
(void)keepOpenPtr;
if( m_staticView )
2018-04-29 23:16:08 +00:00
{
keepOpenPtr = &keepOpen;
}
#ifndef TRACY_NO_ROOT_WINDOW
if( !m_titleSet && m_stcb )
{
m_titleSet = true;
UpdateTitle();
}
ImGuiViewport* viewport = ImGui::GetMainViewport();
2020-05-03 11:27:58 +00:00
{
auto& style = ImGui::GetStyle();
const auto wrPrev = style.WindowRounding;
const auto wbsPrev = style.WindowBorderSize;
const auto wpPrev = style.WindowPadding;
style.WindowRounding = 0.f;
style.WindowBorderSize = 0.f;
style.WindowPadding = ImVec2( 4.f, 4.f );
style.Colors[ImGuiCol_WindowBg] = ImVec4( 0.129f, 0.137f, 0.11f, 1.f );
ImGui::SetNextWindowPos( viewport->Pos );
2020-05-03 11:27:58 +00:00
ImGui::SetNextWindowSize( ImVec2( m_rootWidth, m_rootHeight ) );
ImGui::SetNextWindowViewport( viewport->ID );
ImGui::Begin( "Timeline view###Profiler", nullptr, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoNavFocus );
2020-05-03 11:27:58 +00:00
style.WindowRounding = wrPrev;
style.WindowBorderSize = wbsPrev;
style.WindowPadding = wpPrev;
style.Colors[ImGuiCol_WindowBg] = ImVec4( 0.11f, 0.11f, 0.08f, 1.f );
}
#else
char tmp[2048];
sprintf( tmp, "%s###Profiler", m_worker.GetCaptureName().c_str() );
ImGui::SetNextWindowSize( ImVec2( 1550, 800 ), ImGuiCond_FirstUseEver );
ImGui::Begin( tmp, keepOpenPtr, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoBringToFrontOnFocus );
#endif
2019-08-04 13:55:42 +00:00
if( !m_staticView )
{
if( ImGui::Button( ICON_FA_WIFI ) || m_forceConnectionPopup )
2019-08-04 13:55:42 +00:00
{
if( m_forceConnectionPopup )
{
m_forceConnectionPopup.Decay( false );
ImGui::SetNextWindowPos( viewport->Pos + ImGui::GetCursorPos() );
}
2019-08-04 13:55:42 +00:00
ImGui::OpenPopup( "TracyConnectionPopup" );
}
ImGui::SameLine();
if( ImGui::BeginPopup( "TracyConnectionPopup" ) )
{
const bool wasDisconnectIssued = m_disconnectIssued;
const bool discardData = !DrawConnection();
const bool disconnectIssuedJustNow = m_disconnectIssued != wasDisconnectIssued;
if( discardData ) keepOpen = false;
if( disconnectIssuedJustNow || discardData ) ImGui::CloseCurrentPopup();
ImGui::EndPopup();
}
}
std::lock_guard<std::mutex> lock( m_worker.GetDataLock() );
2021-02-07 17:29:29 +00:00
m_worker.DoPostponedWork();
if( !m_worker.IsDataStatic() )
{
if( m_worker.IsConnected() )
{
if( ImGui::Button( m_viewMode == ViewMode::Paused ? MainWindowButtons[0] : MainWindowButtons[1], ImVec2( bw, 0 ) ) )
{
if( m_viewMode != ViewMode::Paused )
{
m_viewMode = ViewMode::Paused;
m_viewModeHeuristicTry = false;
}
else
{
ImGui::OpenPopup( "viewMode" );
}
}
}
else
{
2022-10-13 18:49:30 +00:00
Attention( m_attnDisconnected );
2021-08-20 22:52:30 +00:00
ImGui::BeginDisabled();
ImGui::ButtonEx( MainWindowButtons[2], ImVec2( bw, 0 ) );
ImGui::EndDisabled();
}
if( ImGui::BeginPopup( "viewMode" ) )
{
if( ImGui::Selectable( ICON_FA_MAGNIFYING_GLASS_PLUS " Newest three frames" ) )
{
m_viewMode = ViewMode::LastFrames;
}
if( ImGui::Selectable( ICON_FA_RULER_HORIZONTAL " Use current zoom level" ) )
{
m_viewMode = ViewMode::LastRange;
}
ImGui::EndPopup();
}
else if( m_viewModeHeuristicTry )
{
const auto lastTime = m_worker.GetLastTime() - m_worker.GetFirstTime();
if( lastTime > 5*1000*1000*1000ll )
{
if( m_viewMode == ViewMode::LastFrames && m_worker.GetFrameCount( *m_worker.GetFramesBase() ) <= ( m_worker.IsOnDemand() ? 3 : 2 ) )
{
m_viewMode = ViewMode::LastRange;
ZoomToRange( lastTime - 5*1000*1000*1000ll, lastTime, false );
}
else
{
m_viewModeHeuristicTry = false;
}
}
}
}
else
{
ImGui::PushStyleColor( ImGuiCol_Button, (ImVec4)ImColor::HSV( 0.f, 0.6f, 0.6f) );
ImGui::PushStyleColor( ImGuiCol_ButtonHovered, (ImVec4)ImColor::HSV( 0.f, 0.7f, 0.7f) );
ImGui::PushStyleColor( ImGuiCol_ButtonActive, (ImVec4)ImColor::HSV( 0.f, 0.8f, 0.8f) );
2018-08-17 21:22:13 +00:00
if( ImGui::Button( ICON_FA_POWER_OFF ) ) keepOpen = false;
ImGui::PopStyleColor( 3 );
}
ImGui::SameLine();
ToggleButton( ICON_FA_GEAR " Options", m_showOptions );
2017-09-30 12:37:21 +00:00
ImGui::SameLine();
2018-12-18 15:13:11 +00:00
ToggleButton( ICON_FA_TAGS " Messages", m_showMessages );
2017-10-14 12:36:30 +00:00
ImGui::SameLine();
ToggleButton( ICON_FA_MAGNIFYING_GLASS " Find zone", m_findZone.show );
2018-03-24 13:40:48 +00:00
ImGui::SameLine();
ToggleButton( ICON_FA_ARROW_UP_WIDE_SHORT " Statistics", m_showStatistics );
ImGui::SameLine();
2018-12-18 15:13:11 +00:00
ToggleButton( ICON_FA_MEMORY " Memory", m_memInfo.show );
ImGui::SameLine();
ToggleButton( ICON_FA_SCALE_BALANCED " Compare", m_compare.show );
2018-04-21 22:52:33 +00:00
ImGui::SameLine();
2018-12-18 15:13:11 +00:00
ToggleButton( ICON_FA_FINGERPRINT " Info", m_showInfo );
2018-08-08 17:25:13 +00:00
ImGui::SameLine();
if( ImGui::Button( ICON_FA_SCREWDRIVER_WRENCH ) ) ImGui::OpenPopup( "ToolsPopup" );
if( ImGui::BeginPopup( "ToolsPopup" ) )
{
const auto ficnt = m_worker.GetFrameImageCount();
if( ButtonDisablable( ICON_FA_PLAY " Playback", ficnt == 0 ) )
{
m_showPlayback = true;
}
const auto& ctd = m_worker.GetCpuThreadData();
if( ButtonDisablable( ICON_FA_SLIDERS " CPU data", ctd.empty() ) )
{
m_showCpuDataWindow = true;
}
ToggleButton( ICON_FA_NOTE_STICKY " Annotations", m_showAnnotationList );
2020-08-03 14:07:28 +00:00
ToggleButton( ICON_FA_RULER " Limits", m_showRanges );
2021-11-13 14:58:25 +00:00
const auto cscnt = m_worker.GetContextSwitchSampleCount();
if( ButtonDisablable( ICON_FA_HOURGLASS_HALF " Wait stacks", cscnt == 0 ) )
{
m_showWaitStacks = true;
}
ImGui::EndPopup();
}
2021-11-18 21:48:32 +00:00
if( m_sscb )
{
ImGui::SameLine();
if( ImGui::Button( ICON_FA_MAGNIFYING_GLASS_PLUS ) ) ImGui::OpenPopup( "ZoomPopup" );
2021-11-18 21:48:32 +00:00
if( ImGui::BeginPopup( "ZoomPopup" ) )
{
if( ImGui::Button( "50%" ) ) m_sscb( 1.f/2 );
if( ImGui::Button( "57%" ) ) m_sscb( 1.f/1.75f );
if( ImGui::Button( "66%" ) ) m_sscb( 1.f/1.5f );
if( ImGui::Button( "80%" ) ) m_sscb( 1.f/1.25f );
if( ImGui::Button( "100%" ) ) m_sscb( 1.f );
if( ImGui::Button( "125%" ) ) m_sscb( 1.25f );
if( ImGui::Button( "150%" ) ) m_sscb( 1.5f );
if( ImGui::Button( "175%" ) ) m_sscb( 1.75f );
if( ImGui::Button( "200%" ) ) m_sscb( 2.f );
if( ImGui::Button( "225%" ) ) m_sscb( 2.25f );
if( ImGui::Button( "250%" ) ) m_sscb( 2.5f );
if( ImGui::Button( "275%" ) ) m_sscb( 2.75f );
if( ImGui::Button( "300%" ) ) m_sscb( 3.f );
2021-11-18 21:48:32 +00:00
ImGui::EndPopup();
}
}
if( m_worker.AreFramesUsed() )
{
ImGui::SameLine();
if( ImGui::SmallButton( " " ICON_FA_CARET_LEFT " " ) ) ZoomToPrevFrame();
ImGui::SameLine();
{
const auto vis = Vis( m_frames );
if( !vis )
{
ImGui::PushStyleColor( ImGuiCol_Text, GImGui->Style.Colors[ImGuiCol_TextDisabled] );
}
ImGui::Text( "%s: %s", GetFrameSetName( *m_frames ), RealToString( m_worker.GetFrameCount( *m_frames ) ) );
if( !vis )
{
ImGui::PopStyleColor();
}
if( ImGui::IsItemClicked() ) ImGui::OpenPopup( "GoToFramePopup" );
}
ImGui::SameLine();
if( ImGui::SmallButton( " " ICON_FA_CARET_RIGHT " " ) ) ZoomToNextFrame();
ImGui::SameLine();
if( ImGui::BeginCombo( "##frameCombo", nullptr, ImGuiComboFlags_NoPreview ) )
{
auto& frames = m_worker.GetFrames();
for( auto& fd : frames )
{
bool isSelected = m_frames == fd;
if( ImGui::Selectable( GetFrameSetName( *fd ), isSelected ) )
{
m_frames = fd;
}
if( isSelected )
{
ImGui::SetItemDefaultFocus();
}
ImGui::SameLine();
ImGui::TextDisabled( "(%s)", RealToString( fd->frames.size() ) );
}
ImGui::EndCombo();
}
if( ImGui::BeginPopup( "GoToFramePopup" ) )
{
static int frameNum = 1;
const bool mainFrameSet = m_frames->name == 0;
const auto numFrames = mainFrameSet ? m_frames->frames.size() - 1 : m_frames->frames.size();
const auto frameOffset = mainFrameSet ? 0 : 1;
ImGui::SetNextItemWidth( 120 * GetScale() );
const bool clicked = ImGui::InputInt( "##goToFrame", &frameNum, 1, 100, ImGuiInputTextFlags_EnterReturnsTrue );
frameNum = std::min( std::max( frameNum, 1 ), int( numFrames ) );
if( clicked ) ZoomToRange( m_worker.GetFrameBegin( *m_frames, frameNum - frameOffset ), m_worker.GetFrameEnd( *m_frames, frameNum - frameOffset ) );
ImGui::EndPopup();
}
2020-05-03 11:54:37 +00:00
}
{
ImGui::SameLine();
ImGui::Spacing();
ImGui::SameLine();
const auto targetLabelSize = ImGui::CalcTextSize( "WWWWWWW" ).x;
auto cx = ImGui::GetCursorPosX();
ImGui::Text( ICON_FA_EYE " %s", TimeToString( m_vd.zvEnd - m_vd.zvStart ) );
TooltipIfHovered( "View span" );
ImGui::SameLine();
auto dx = ImGui::GetCursorPosX() - cx;
if( dx < targetLabelSize ) ImGui::SameLine( cx + targetLabelSize );
const auto firstTime = m_worker.GetFirstTime();
const auto lastTime = m_worker.GetLastTime();
cx = ImGui::GetCursorPosX();
ImGui::Text( ICON_FA_DATABASE " %s", TimeToString( lastTime - firstTime ) );
if( ImGui::IsItemHovered() )
{
ImGui::BeginTooltip();
if( firstTime == 0 )
{
ImGui::Text( "Time span" );
}
else
{
TextFocused( "Total time span:", TimeToString( lastTime ) );
}
ImGui::EndTooltip();
if( ImGui::IsItemClicked( 2 ) )
{
ZoomToRange( firstTime, lastTime );
}
}
ImGui::SameLine();
dx = ImGui::GetCursorPosX() - cx;
if( dx < targetLabelSize ) ImGui::SameLine( cx + targetLabelSize );
cx = ImGui::GetCursorPosX();
ImGui::Text( ICON_FA_MEMORY " %s", MemSizeToString( memUsage ) );
TooltipIfHovered( "Profiler memory usage" );
if( m_totalMemory != 0 )
{
ImGui::SameLine();
const auto memUse = float( memUsage ) / m_totalMemory * 100;
if( memUse < 80 )
{
ImGui::TextDisabled( "(%.2f%%)", memUse );
}
else
{
ImGui::TextColored( ImVec4( 1.f, 0.25f, 0.25f, 1.f ), "(%.2f%%)", memUse );
}
}
ImGui::SameLine();
dx = ImGui::GetCursorPosX() - cx;
if( dx < targetLabelSize ) ImGui::SameLine( cx + targetLabelSize );
ImGui::Spacing();
}
DrawNotificationArea();
m_frameHover = -1;
DrawFrames();
2020-05-03 11:23:26 +00:00
const auto dockspaceId = ImGui::GetID( "tracyDockspace" );
2019-03-16 20:11:18 +00:00
ImGui::DockSpace( dockspaceId, ImVec2( 0, 0 ), ImGuiDockNodeFlags_NoDockingInCentralNode );
if( ImGuiDockNode* node = ImGui::DockBuilderGetCentralNode( dockspaceId ) )
{
node->LocalFlags |= ImGuiDockNodeFlags_NoTabBar;
}
2020-05-03 11:23:26 +00:00
ImGui::SetNextWindowDockID( dockspaceId );
2020-05-03 11:27:58 +00:00
{
auto& style = ImGui::GetStyle();
const auto wpPrev = style.WindowPadding;
style.WindowPadding = ImVec2( 1, 0 );
#ifndef TRACY_NO_ROOT_WINDOW
style.Colors[ImGuiCol_WindowBg] = ImVec4( 0.129f, 0.137f, 0.11f, 1.f );
#endif
ImGui::Begin( "Work area", nullptr, ImGuiWindowFlags_NoNavFocus );
2020-05-03 11:27:58 +00:00
style.WindowPadding = wpPrev;
#ifndef TRACY_NO_ROOT_WINDOW
style.Colors[ImGuiCol_WindowBg] = ImVec4( 0.11f, 0.11f, 0.08f, 1.f );
#endif
}
2020-05-03 11:23:26 +00:00
2022-07-02 13:38:10 +00:00
DrawTimeline();
2020-05-03 11:23:26 +00:00
ImGui::End();
ImGui::End();
m_zoneHighlight = nullptr;
m_gpuHighlight = nullptr;
DrawInfoWindow();
if( m_showOptions ) DrawOptions();
if( m_showMessages ) DrawMessages();
if( m_findZone.show ) DrawFindZone();
if( m_showStatistics ) DrawStatistics();
if( m_memInfo.show ) DrawMemory();
if( m_memInfo.showAllocList ) DrawAllocList();
if( m_compare.show ) DrawCompare();
if( m_callstackInfoWindow != 0 ) DrawCallstackWindow();
if( m_memoryAllocInfoWindow >= 0 ) DrawMemoryAllocWindow();
if( m_showInfo ) DrawInfo();
if( m_sourceViewFile ) DrawTextEditor();
if( m_lockInfoWindow != InvalidId ) DrawLockInfoWindow();
if( m_showPlayback ) DrawPlayback();
if( m_showCpuDataWindow ) DrawCpuDataWindow();
2019-10-13 13:50:37 +00:00
if( m_selectedAnnotation ) DrawSelectedAnnotation();
2019-10-14 18:37:24 +00:00
if( m_showAnnotationList ) DrawAnnotationList();
2020-02-29 17:15:59 +00:00
if( m_sampleParents.symAddr != 0 ) DrawSampleParents();
2020-07-31 14:37:47 +00:00
if( m_showRanges ) DrawRanges();
2021-11-13 14:58:25 +00:00
if( m_showWaitStacks ) DrawWaitStacks();
if( m_setRangePopup.active )
{
m_setRangePopup.active = false;
ImGui::OpenPopup( "SetZoneRange" );
}
if( ImGui::BeginPopup( "SetZoneRange" ) )
{
const auto s = std::min( m_setRangePopup.min, m_setRangePopup.max );
const auto e = std::max( m_setRangePopup.min, m_setRangePopup.max );
if( ImGui::Selectable( ICON_FA_MAGNIFYING_GLASS " Limit find zone time range" ) )
{
m_findZone.range.active = true;
m_findZone.range.min = s;
m_findZone.range.max = e;
}
if( ImGui::Selectable( ICON_FA_ARROW_UP_WIDE_SHORT " Limit statistics time range" ) )
2020-08-04 12:31:53 +00:00
{
m_statRange.active = true;
m_statRange.min = s;
m_statRange.max = e;
2020-08-04 12:31:53 +00:00
}
2021-11-29 18:34:43 +00:00
if( ImGui::Selectable( ICON_FA_HOURGLASS_HALF " Limit wait stacks range" ) )
2021-11-13 17:43:55 +00:00
{
m_waitStackRange.active = true;
m_waitStackRange.min = s;
m_waitStackRange.max = e;
}
2021-11-29 17:17:19 +00:00
if( ImGui::Selectable( ICON_FA_MEMORY " Limit memory range" ) )
{
m_memInfo.range.active = true;
m_memInfo.range.min = s;
m_memInfo.range.max = e;
}
ImGui::Separator();
if( ImGui::Selectable( ICON_FA_NOTE_STICKY " Add annotation" ) )
{
AddAnnotation( s, e );
}
ImGui::EndPopup();
}
2020-08-04 14:49:39 +00:00
m_setRangePopupOpen = ImGui::IsPopupOpen( "SetZoneRange" );
if( m_zoomAnim.active )
{
if( m_viewMode == ViewMode::LastRange )
{
const auto delta = m_worker.GetLastTime() - m_vd.zvEnd;
if( delta != 0 )
{
m_zoomAnim.start0 += delta;
m_zoomAnim.start1 += delta;
m_zoomAnim.end0 += delta;
m_zoomAnim.end1 += delta;
}
}
m_zoomAnim.progress += io.DeltaTime * 3.33f;
if( m_zoomAnim.progress >= 1.f )
{
m_zoomAnim.active = false;
m_vd.zvStart = m_zoomAnim.start1;
m_vd.zvEnd = m_zoomAnim.end1;
}
else
{
const auto v = sqrt( sin( M_PI_2 * m_zoomAnim.progress ) );
m_vd.zvStart = int64_t( m_zoomAnim.start0 + ( m_zoomAnim.start1 - m_zoomAnim.start0 ) * v );
m_vd.zvEnd = int64_t( m_zoomAnim.end0 + ( m_zoomAnim.end1 - m_zoomAnim.end0 ) * v );
}
}
m_wasActive |= m_callstackBuzzAnim.Update( io.DeltaTime );
m_wasActive |= m_sampleParentBuzzAnim.Update( io.DeltaTime );
m_wasActive |= m_callstackTreeBuzzAnim.Update( io.DeltaTime );
m_wasActive |= m_zoneinfoBuzzAnim.Update( io.DeltaTime );
m_wasActive |= m_findZoneBuzzAnim.Update( io.DeltaTime );
m_wasActive |= m_optionsLockBuzzAnim.Update( io.DeltaTime );
m_wasActive |= m_lockInfoAnim.Update( io.DeltaTime );
m_wasActive |= m_statBuzzAnim.Update( io.DeltaTime );
if( m_firstFrame )
{
const auto now = std::chrono::high_resolution_clock::now();
if( m_firstFrameTime.time_since_epoch().count() == 0 )
{
m_firstFrameTime = now;
}
else
{
if( std::chrono::duration_cast<std::chrono::milliseconds>( now - m_firstFrameTime ).count() > 500 )
{
m_firstFrame = false;
2022-08-20 15:02:29 +00:00
m_tc.FirstFrameExpired();
}
}
}
2020-05-23 14:40:15 +00:00
if( m_reactToCrash )
{
auto& crash = m_worker.GetCrashEvent();
if( crash.thread != 0 )
{
m_reactToCrash = false;
ImGui::OpenPopup( "Application crashed!" );
}
}
if( ImGui::BeginPopupModal( "Application crashed!", nullptr, ImGuiWindowFlags_AlwaysAutoResize ) )
{
auto& crash = m_worker.GetCrashEvent();
assert( crash.thread != 0 );
ImGui::TextUnformatted( ICON_FA_SKULL );
ImGui::SameLine();
TextColoredUnformatted( 0xFF4444FF, "Application has crashed" );
ImGui::SameLine();
ImGui::TextUnformatted( ICON_FA_SKULL );
ImGui::Separator();
TextFocused( "Time:", TimeToString( crash.time ) );
TextFocused( "Thread:", m_worker.GetThreadName( crash.thread ) );
ImGui::SameLine();
ImGui::TextDisabled( "(%s)", RealToString( crash.thread ) );
2021-11-06 18:18:33 +00:00
if( m_worker.IsThreadFiber( crash.thread ) )
{
ImGui::SameLine();
TextColoredUnformatted( ImVec4( 0.2f, 0.6f, 0.2f, 1.f ), "Fiber" );
}
2020-05-23 14:40:15 +00:00
TextFocused( "Reason:", m_worker.GetString( crash.message ) );
if( crash.callstack != 0 )
{
bool hilite = m_callstackInfoWindow == crash.callstack;
if( hilite )
{
SetButtonHighlightColor();
}
if( ImGui::Button( ICON_FA_ALIGN_JUSTIFY " Call stack" ) )
{
m_callstackInfoWindow = crash.callstack;
}
if( hilite )
{
ImGui::PopStyleColor( 3 );
}
if( ImGui::IsItemHovered() )
{
CallstackTooltip( crash.callstack );
}
}
ImGui::Separator();
if( ImGui::Button( ICON_FA_MICROSCOPE " Focus" ) ) CenterAtTime( crash.time );
ImGui::SameLine();
if( ImGui::Button( "Dismiss" ) ) ImGui::CloseCurrentPopup();
ImGui::EndPopup();
}
2020-11-18 00:23:46 +00:00
if( m_reactToLostConnection && !m_worker.IsConnected() )
{
m_reactToLostConnection = false;
const auto inFlight = m_worker.GetSendInFlight();
if( inFlight > 1 || ( inFlight == 1 && !m_worker.WasDisconnectIssued() ) )
2020-11-18 00:23:46 +00:00
{
ImGui::OpenPopup( "Connection lost!" );
}
}
if( ImGui::BeginPopupModal( "Connection lost!", nullptr, ImGuiWindowFlags_AlwaysAutoResize ) )
{
ImGui::PushFont( m_bigFont );
2020-11-18 00:23:46 +00:00
TextCentered( ICON_FA_PLUG );
ImGui::PopFont();
2020-11-18 00:23:46 +00:00
ImGui::TextUnformatted(
"Connection to the profiled application was lost\n"
"before all required profiling data could be retrieved.\n"
"This will result in missing source locations,\n"
"unresolved stack frames, etc." );
ImGui::Separator();
if( ImGui::Button( "Dismiss" ) ) ImGui::CloseCurrentPopup();
ImGui::EndPopup();
}
return keepOpen;
}
void View::DrawTextEditor()
{
2021-11-18 18:20:45 +00:00
const auto scale = GetScale();
ImGui::SetNextWindowSize( ImVec2( 1800 * scale, 800 * scale ), ImGuiCond_FirstUseEver );
bool show = true;
ImGui::Begin( "Source view", &show, ImGuiWindowFlags_NoScrollbar );
if( !ImGui::GetCurrentWindowRead()->SkipItems )
{
2022-08-15 20:48:00 +00:00
m_sourceView->UpdateFont( m_fixedFont, m_smallFont, m_bigFont );
m_sourceView->Render( m_worker, *this );
}
ImGui::End();
if( !show ) m_sourceViewFile = nullptr;
}
void View::CrashTooltip()
{
auto& crash = m_worker.GetCrashEvent();
ImGui::BeginTooltip();
TextFocused( "Time:", TimeToString( crash.time ) );
TextFocused( "Reason:", m_worker.GetString( crash.message ) );
ImGui::EndTooltip();
}
2021-03-27 12:25:21 +00:00
void View::DrawSourceTooltip( const char* filename, uint32_t srcline, int before, int after, bool separateTooltip )
{
2021-03-27 13:09:18 +00:00
if( !filename ) return;
2021-03-27 12:25:21 +00:00
if( !SourceFileValid( filename, m_worker.GetCaptureTime(), *this, m_worker ) ) return;
m_srcHintCache.Parse( filename, m_worker, *this );
if( m_srcHintCache.empty() ) return;
ImGui::PushStyleVar( ImGuiStyleVar_ItemSpacing, ImVec2( 0, 0 ) );
2021-03-27 12:25:21 +00:00
if( separateTooltip ) ImGui::BeginTooltip();
ImGui::PushFont( m_fixedFont );
2021-03-27 12:25:21 +00:00
auto& lines = m_srcHintCache.get();
const int start = std::max( 0, (int)srcline - ( before+1 ) );
const int end = std::min<int>( m_srcHintCache.get().size(), srcline + after );
bool first = true;
int bottomEmpty = 0;
2021-03-27 12:25:21 +00:00
for( int i=start; i<end; i++ )
{
auto& line = lines[i];
if( line.begin == line.end )
{
if( !first ) bottomEmpty++;
2021-03-27 12:25:21 +00:00
}
else
{
first = false;
while( bottomEmpty > 0 )
{
ImGui::TextUnformatted( "" );
bottomEmpty--;
}
2021-03-27 12:25:21 +00:00
auto ptr = line.begin;
auto it = line.tokens.begin();
while( ptr < line.end )
{
if( it == line.tokens.end() )
{
ImGui::TextUnformatted( ptr, line.end );
ImGui::SameLine( 0, 0 );
break;
}
if( ptr < it->begin )
{
ImGui::TextUnformatted( ptr, it->begin );
ImGui::SameLine( 0, 0 );
}
2022-09-10 22:44:26 +00:00
auto color = SyntaxColors[(int)it->color];
if( i != srcline-1 ) color = ( color & 0xFFFFFF ) | 0x99000000;
TextColoredUnformatted( color, it->begin, it->end );
2021-03-27 12:25:21 +00:00
ImGui::SameLine( 0, 0 );
ptr = it->end;
++it;
}
ImGui::ItemSize( ImVec2( 0, 0 ), 0 );
}
}
ImGui::PopFont();
2021-03-27 12:25:21 +00:00
if( separateTooltip ) ImGui::EndTooltip();
ImGui::PopStyleVar();
2021-03-27 12:25:21 +00:00
}
bool View::Save( const char* fn, FileWrite::Compression comp, int zlevel, bool buildDict )
{
std::unique_ptr<FileWrite> f( FileWrite::Open( fn, comp, zlevel ) );
if( !f ) return false;
m_userData.StateShouldBePreserved();
m_saveThreadState.store( SaveThreadState::Saving, std::memory_order_relaxed );
m_saveThread = std::thread( [this, f{std::move( f )}, buildDict] {
std::lock_guard<std::mutex> lock( m_worker.GetDataLock() );
m_worker.Write( *f, buildDict );
f->Finish();
const auto stats = f->GetCompressionStatistics();
m_srcFileBytes.store( stats.first, std::memory_order_relaxed );
m_dstFileBytes.store( stats.second, std::memory_order_relaxed );
m_saveThreadState.store( SaveThreadState::NeedsJoin, std::memory_order_release );
} );
return true;
}
void View::HighlightThread( uint64_t thread )
{
m_drawThreadMigrations = thread;
m_drawThreadHighlight = thread;
}
bool View::WasActive() const
{
return m_wasActive ||
m_zoomAnim.active ||
m_notificationTime > 0 ||
!m_playback.pause ||
m_worker.IsConnected() ||
!m_worker.IsBackgroundDone();
}
2017-09-12 23:33:50 +00:00
}