mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-12 19:31:47 +00:00
Change file selector to work with callbacks.
This commit is contained in:
parent
a4e39f3d5f
commit
ec0757c03a
@ -575,12 +575,10 @@ static void DrawContents()
|
|||||||
#ifndef TRACY_NO_FILESELECTOR
|
#ifndef TRACY_NO_FILESELECTOR
|
||||||
if( ImGui::Button( ICON_FA_FOLDER_OPEN " Open saved trace" ) && !loadThread.joinable() )
|
if( ImGui::Button( ICON_FA_FOLDER_OPEN " Open saved trace" ) && !loadThread.joinable() )
|
||||||
{
|
{
|
||||||
auto fn = tracy::Fileselector::OpenFile( "tracy", "Tracy Profiler trace file" );
|
tracy::Fileselector::OpenFile( "tracy", "Tracy Profiler trace file", []( const char* fn ) {
|
||||||
if( !fn.empty() )
|
|
||||||
{
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
auto f = std::shared_ptr<tracy::FileRead>( tracy::FileRead::Open( fn.c_str() ) );
|
auto f = std::shared_ptr<tracy::FileRead>( tracy::FileRead::Open( fn ) );
|
||||||
if( f )
|
if( f )
|
||||||
{
|
{
|
||||||
loadThread = std::thread( [f] {
|
loadThread = std::thread( [f] {
|
||||||
@ -609,7 +607,7 @@ static void DrawContents()
|
|||||||
{
|
{
|
||||||
badVer.state = tracy::BadVersionState::ReadError;
|
badVer.state = tracy::BadVersionState::ReadError;
|
||||||
}
|
}
|
||||||
}
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( badVer.state != tracy::BadVersionState::Ok )
|
if( badVer.state != tracy::BadVersionState::Ok )
|
||||||
|
@ -21,34 +21,30 @@ void Shutdown()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string OpenFile( const char* ext, const char* desc )
|
void OpenFile( const char* ext, const char* desc, std::function<void(const char*)> callback )
|
||||||
{
|
{
|
||||||
std::string ret;
|
|
||||||
#ifndef TRACY_NO_FILESELECTOR
|
#ifndef TRACY_NO_FILESELECTOR
|
||||||
nfdu8filteritem_t filter = { desc, ext };
|
nfdu8filteritem_t filter = { desc, ext };
|
||||||
nfdu8char_t* fn;
|
nfdu8char_t* fn;
|
||||||
if( NFD_OpenDialogU8( &fn, &filter, 1, nullptr ) == NFD_OKAY )
|
if( NFD_OpenDialogU8( &fn, &filter, 1, nullptr ) == NFD_OKAY )
|
||||||
{
|
{
|
||||||
ret.assign( fn );
|
callback( (const char*)fn );
|
||||||
NFD_FreePathU8( fn );
|
NFD_FreePathU8( fn );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string SaveFile( const char* ext, const char* desc )
|
void SaveFile( const char* ext, const char* desc, std::function<void(const char*)> callback )
|
||||||
{
|
{
|
||||||
std::string ret;
|
|
||||||
#ifndef TRACY_NO_FILESELECTOR
|
#ifndef TRACY_NO_FILESELECTOR
|
||||||
nfdu8filteritem_t filter = { desc, ext };
|
nfdu8filteritem_t filter = { desc, ext };
|
||||||
nfdu8char_t* fn;
|
nfdu8char_t* fn;
|
||||||
if( NFD_SaveDialogU8( &fn, &filter, 1, nullptr, nullptr ) == NFD_OKAY )
|
if( NFD_SaveDialogU8( &fn, &filter, 1, nullptr, nullptr ) == NFD_OKAY )
|
||||||
{
|
{
|
||||||
ret.assign( fn );
|
callback( (const char*)fn );
|
||||||
NFD_FreePathU8( fn );
|
NFD_FreePathU8( fn );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#ifndef __TRACYFILESELECTOR_HPP__
|
#ifndef __TRACYFILESELECTOR_HPP__
|
||||||
#define __TRACYFILESELECTOR_HPP__
|
#define __TRACYFILESELECTOR_HPP__
|
||||||
|
|
||||||
#include <string>
|
#include <functional>
|
||||||
|
|
||||||
namespace tracy::Fileselector
|
namespace tracy::Fileselector
|
||||||
{
|
{
|
||||||
@ -9,8 +9,8 @@ namespace tracy::Fileselector
|
|||||||
void Init();
|
void Init();
|
||||||
void Shutdown();
|
void Shutdown();
|
||||||
|
|
||||||
std::string OpenFile( const char* ext, const char* desc );
|
void OpenFile( const char* ext, const char* desc, std::function<void(const char*)> callback );
|
||||||
std::string SaveFile( const char* ext, const char* desc );
|
void SaveFile( const char* ext, const char* desc, std::function<void(const char*)> callback );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5356,81 +5356,77 @@ void SourceView::Save( const Worker& worker, size_t start, size_t stop )
|
|||||||
assert( start < m_asm.size() );
|
assert( start < m_asm.size() );
|
||||||
assert( start < stop );
|
assert( start < stop );
|
||||||
|
|
||||||
auto fn = Fileselector::SaveFile( "asm", "Assembly file" );
|
Fileselector::SaveFile( "asm", "Assembly file", [this, &worker, start, stop]( const char* fn ) {
|
||||||
if( !fn.empty() )
|
|
||||||
{
|
|
||||||
FILE* f = nullptr;
|
FILE* f = nullptr;
|
||||||
const auto sz = fn.size();
|
const auto sz = strlen( fn );
|
||||||
if( sz < 5 || memcmp( fn.c_str() + sz - 4, ".asm", 4 ) != 0 )
|
if( sz < 5 || memcmp( fn + sz - 4, ".asm", 4 ) != 0 )
|
||||||
{
|
{
|
||||||
char tmp[1024];
|
char tmp[1024];
|
||||||
sprintf( tmp, "%s.asm", fn.c_str() );
|
sprintf( tmp, "%s.asm", fn );
|
||||||
f = fopen( tmp, "wb" );
|
f = fopen( tmp, "wb" );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
f = fopen( fn.c_str(), "wb" );
|
f = fopen( fn, "wb" );
|
||||||
}
|
}
|
||||||
if( f )
|
if( !f ) return;
|
||||||
|
char tmp[16];
|
||||||
|
auto sym = worker.GetSymbolData( m_symAddr );
|
||||||
|
assert( sym );
|
||||||
|
const char* symName;
|
||||||
|
if( sym->isInline )
|
||||||
{
|
{
|
||||||
char tmp[16];
|
auto parent = worker.GetSymbolData( m_baseAddr );
|
||||||
auto sym = worker.GetSymbolData( m_symAddr );
|
if( parent )
|
||||||
assert( sym );
|
|
||||||
const char* symName;
|
|
||||||
if( sym->isInline )
|
|
||||||
{
|
{
|
||||||
auto parent = worker.GetSymbolData( m_baseAddr );
|
symName = worker.GetString( parent->name );
|
||||||
if( parent )
|
|
||||||
{
|
|
||||||
symName = worker.GetString( parent->name );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sprintf( tmp, "0x%" PRIx64, m_baseAddr );
|
|
||||||
symName = tmp;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
symName = worker.GetString( sym->name );
|
sprintf( tmp, "0x%" PRIx64, m_baseAddr );
|
||||||
|
symName = tmp;
|
||||||
}
|
}
|
||||||
fprintf( f, "; Tracy Profiler disassembly of symbol %s [%s]\n\n", symName, worker.GetCaptureProgram().c_str() );
|
|
||||||
if( !m_atnt ) fprintf( f, ".intel_syntax\n\n" );
|
|
||||||
|
|
||||||
const auto end = m_asm.size() < stop ? m_asm.size() : stop;
|
|
||||||
for( size_t i=start; i<end; i++ )
|
|
||||||
{
|
|
||||||
const auto& v = m_asm[i];
|
|
||||||
auto it = m_locMap.find( v.addr );
|
|
||||||
if( it != m_locMap.end() )
|
|
||||||
{
|
|
||||||
fprintf( f, ".L%" PRIu32 ":\n", it->second );
|
|
||||||
}
|
|
||||||
bool hasJump = false;
|
|
||||||
if( v.jumpAddr != 0 )
|
|
||||||
{
|
|
||||||
auto lit = m_locMap.find( v.jumpAddr );
|
|
||||||
if( lit != m_locMap.end() )
|
|
||||||
{
|
|
||||||
fprintf( f, "\t%-*s.L%" PRIu32 "\n", m_maxMnemonicLen, v.mnemonic.c_str(), lit->second );
|
|
||||||
hasJump = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if( !hasJump )
|
|
||||||
{
|
|
||||||
if( v.operands.empty() )
|
|
||||||
{
|
|
||||||
fprintf( f, "\t%s\n", v.mnemonic.c_str() );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fprintf( f, "\t%-*s%s\n", m_maxMnemonicLen, v.mnemonic.c_str(), v.operands.c_str() );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fclose( f );
|
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
|
{
|
||||||
|
symName = worker.GetString( sym->name );
|
||||||
|
}
|
||||||
|
fprintf( f, "; Tracy Profiler disassembly of symbol %s [%s]\n\n", symName, worker.GetCaptureProgram().c_str() );
|
||||||
|
if( !m_atnt ) fprintf( f, ".intel_syntax\n\n" );
|
||||||
|
|
||||||
|
const auto end = m_asm.size() < stop ? m_asm.size() : stop;
|
||||||
|
for( size_t i=start; i<end; i++ )
|
||||||
|
{
|
||||||
|
const auto& v = m_asm[i];
|
||||||
|
auto it = m_locMap.find( v.addr );
|
||||||
|
if( it != m_locMap.end() )
|
||||||
|
{
|
||||||
|
fprintf( f, ".L%" PRIu32 ":\n", it->second );
|
||||||
|
}
|
||||||
|
bool hasJump = false;
|
||||||
|
if( v.jumpAddr != 0 )
|
||||||
|
{
|
||||||
|
auto lit = m_locMap.find( v.jumpAddr );
|
||||||
|
if( lit != m_locMap.end() )
|
||||||
|
{
|
||||||
|
fprintf( f, "\t%-*s.L%" PRIu32 "\n", m_maxMnemonicLen, v.mnemonic.c_str(), lit->second );
|
||||||
|
hasJump = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if( !hasJump )
|
||||||
|
{
|
||||||
|
if( v.operands.empty() )
|
||||||
|
{
|
||||||
|
fprintf( f, "\t%s\n", v.mnemonic.c_str() );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fprintf( f, "\t%-*s%s\n", m_maxMnemonicLen, v.mnemonic.c_str(), v.operands.c_str() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fclose( f );
|
||||||
|
} );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -149,12 +149,10 @@ void View::DrawCompare()
|
|||||||
ImGui::TextWrapped( "Please load a second trace to compare results." );
|
ImGui::TextWrapped( "Please load a second trace to compare results." );
|
||||||
if( ImGui::Button( ICON_FA_FOLDER_OPEN " Open second trace" ) && !m_compare.loadThread.joinable() )
|
if( ImGui::Button( ICON_FA_FOLDER_OPEN " Open second trace" ) && !m_compare.loadThread.joinable() )
|
||||||
{
|
{
|
||||||
auto fn = Fileselector::OpenFile( "tracy", "Tracy Profiler trace file" );
|
Fileselector::OpenFile( "tracy", "Tracy Profiler trace file", [this]( const char* fn ) {
|
||||||
if( !fn.empty() )
|
|
||||||
{
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
auto f = std::shared_ptr<tracy::FileRead>( tracy::FileRead::Open( fn.c_str() ) );
|
auto f = std::shared_ptr<tracy::FileRead>( tracy::FileRead::Open( fn ) );
|
||||||
if( f )
|
if( f )
|
||||||
{
|
{
|
||||||
m_compare.loadThread = std::thread( [this, f] {
|
m_compare.loadThread = std::thread( [this, f] {
|
||||||
@ -168,7 +166,7 @@ void View::DrawCompare()
|
|||||||
m_compare.badVer.state = BadVersionState::UnsupportedVersion;
|
m_compare.badVer.state = BadVersionState::UnsupportedVersion;
|
||||||
m_compare.badVer.version = e.version;
|
m_compare.badVer.version = e.version;
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch( const tracy::NotTracyDump& )
|
catch( const tracy::NotTracyDump& )
|
||||||
@ -179,7 +177,7 @@ void View::DrawCompare()
|
|||||||
{
|
{
|
||||||
m_compare.badVer.state = BadVersionState::ReadError;
|
m_compare.badVer.state = BadVersionState::ReadError;
|
||||||
}
|
}
|
||||||
}
|
} );
|
||||||
}
|
}
|
||||||
tracy::BadVersion( m_compare.badVer, m_bigFont );
|
tracy::BadVersion( m_compare.badVer, m_bigFont );
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
@ -121,25 +121,25 @@ bool View::DrawConnection()
|
|||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
if( ImGui::Button( ICON_FA_FLOPPY_DISK " Save trace" ) && m_saveThreadState.load( std::memory_order_relaxed ) == SaveThreadState::Inert )
|
if( ImGui::Button( ICON_FA_FLOPPY_DISK " Save trace" ) && m_saveThreadState.load( std::memory_order_relaxed ) == SaveThreadState::Inert )
|
||||||
{
|
{
|
||||||
#ifndef TRACY_NO_FILESELECTOR
|
auto cb = [this]( const char* fn ) {
|
||||||
auto fn = Fileselector::SaveFile( "tracy", "Tracy Profiler trace file" );
|
const auto sz = strlen( fn );
|
||||||
if( !fn.empty() )
|
if( sz < 7 || memcmp( fn + sz - 6, ".tracy", 6 ) != 0 )
|
||||||
#else
|
|
||||||
std::string fn = "trace.tracy";
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
const auto sz = fn.size();
|
|
||||||
if( sz < 7 || memcmp( fn.c_str() + sz - 6, ".tracy", 6 ) != 0 )
|
|
||||||
{
|
{
|
||||||
char tmp[1024];
|
char tmp[1024];
|
||||||
sprintf( tmp, "%s.tracy", fn.c_str() );
|
sprintf( tmp, "%s.tracy", fn );
|
||||||
m_filenameStaging = tmp;
|
m_filenameStaging = tmp;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_filenameStaging = std::move( fn );
|
m_filenameStaging = fn;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
|
#ifndef TRACY_NO_FILESELECTOR
|
||||||
|
Fileselector::SaveFile( "tracy", "Tracy Profiler trace file", cb );
|
||||||
|
#else
|
||||||
|
cb( "trace.tracy" );
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::SameLine( 0, 2 * ty );
|
ImGui::SameLine( 0, 2 * ty );
|
||||||
|
Loading…
Reference in New Issue
Block a user