mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-10 10:41:50 +00:00
Improve trace saving experience.
This adds additional dialog, which allows selection of compression mode. Also, when a trace cannot be saved, a failure popup will be displayed.
This commit is contained in:
parent
ab830962c8
commit
92ae003308
@ -36,7 +36,6 @@
|
||||
#include "tracy_pdqsort.h"
|
||||
#include "TracyColor.hpp"
|
||||
#include "TracyFileRead.hpp"
|
||||
#include "TracyFileWrite.hpp"
|
||||
#include "TracyFilesystem.hpp"
|
||||
#include "TracyMouse.hpp"
|
||||
#include "TracyPopcnt.hpp"
|
||||
@ -345,6 +344,24 @@ void View::DrawHelpMarker( const char* desc ) const
|
||||
}
|
||||
}
|
||||
|
||||
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" );
|
||||
|
||||
bool View::Draw()
|
||||
{
|
||||
HandshakeStatus status = (HandshakeStatus)s_instance->m_worker.GetHandshakeStatus();
|
||||
@ -606,6 +623,66 @@ bool View::Draw()
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
bool saveFailed = false;
|
||||
if( !s_instance->m_filenameStaging.empty() )
|
||||
{
|
||||
ImGui::OpenPopup( "Save trace" );
|
||||
}
|
||||
if( ImGui::BeginPopupModal( "Save trace", nullptr, ImGuiWindowFlags_AlwaysAutoResize ) )
|
||||
{
|
||||
assert( !s_instance->m_filenameStaging.empty() );
|
||||
auto fn = s_instance->m_filenameStaging.c_str();
|
||||
TextFocused( "Path:", fn );
|
||||
ImGui::Separator();
|
||||
|
||||
static FileWrite::Compression comp = FileWrite::Compression::Fast;
|
||||
static int zlvl = 6;
|
||||
ImGui::TextUnformatted( ICON_FA_FILE_ARCHIVE " 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();
|
||||
ImGui::TextDisabled( 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();
|
||||
ImGui::SliderInt( "##zstd", &zlvl, 1, 22, "%d", ImGuiSliderFlags_AlwaysClamp );
|
||||
ImGui::Unindent();
|
||||
|
||||
ImGui::Separator();
|
||||
if( ImGui::Button( ICON_FA_SAVE " Save trace" ) )
|
||||
{
|
||||
saveFailed = !s_instance->Save( fn, comp, zlvl );
|
||||
s_instance->m_filenameStaging.clear();
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if( ImGui::Button( "Cancel" ) )
|
||||
{
|
||||
s_instance->m_filenameStaging.clear();
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
if( saveFailed ) ImGui::OpenPopup( "Save failed" );
|
||||
if( ImGui::BeginPopupModal( "Save failed", nullptr, ImGuiWindowFlags_AlwaysAutoResize ) )
|
||||
{
|
||||
TextCentered( ICON_FA_EXCLAMATION_TRIANGLE );
|
||||
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();
|
||||
}
|
||||
|
||||
s_time += ImGui::GetIO().DeltaTime;
|
||||
return s_instance->DrawImpl();
|
||||
}
|
||||
@ -1466,33 +1543,16 @@ bool View::DrawConnection()
|
||||
const char* fn = "trace.tracy";
|
||||
#endif
|
||||
{
|
||||
std::unique_ptr<FileWrite> f;
|
||||
const auto sz = strlen( fn );
|
||||
if( sz < 7 || memcmp( fn + sz - 6, ".tracy", 6 ) != 0 )
|
||||
{
|
||||
char tmp[1024];
|
||||
sprintf( tmp, "%s.tracy", fn );
|
||||
f.reset( FileWrite::Open( tmp ) );
|
||||
if( f ) m_filename = tmp;
|
||||
m_filenameStaging = tmp;
|
||||
}
|
||||
else
|
||||
{
|
||||
f.reset( FileWrite::Open( fn ) );
|
||||
if( f ) m_filename = fn;
|
||||
}
|
||||
if( f )
|
||||
{
|
||||
m_userData.StateShouldBePreserved();
|
||||
m_saveThreadState.store( SaveThreadState::Saving, std::memory_order_relaxed );
|
||||
m_saveThread = std::thread( [this, f{std::move( f )}] {
|
||||
std::lock_guard<std::mutex> lock( m_worker.GetDataLock() );
|
||||
m_worker.Write( *f );
|
||||
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 );
|
||||
} );
|
||||
m_filenameStaging = fn;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -17976,4 +18036,24 @@ void View::DrawSourceTooltip( const char* filename, uint32_t srcline, int before
|
||||
if( separateTooltip ) ImGui::EndTooltip();
|
||||
}
|
||||
|
||||
bool View::Save( const char* fn, FileWrite::Compression comp, int zlevel )
|
||||
{
|
||||
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 )}] {
|
||||
std::lock_guard<std::mutex> lock( m_worker.GetDataLock() );
|
||||
m_worker.Write( *f );
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "TracyBadVersion.hpp"
|
||||
#include "TracyBuzzAnim.hpp"
|
||||
#include "TracyDecayValue.hpp"
|
||||
#include "TracyFileWrite.hpp"
|
||||
#include "TracyImGui.hpp"
|
||||
#include "TracyShortPtr.hpp"
|
||||
#include "TracySourceContents.hpp"
|
||||
@ -282,6 +283,7 @@ private:
|
||||
void CalcZoneTimeDataImpl( const V& children, const ContextSwitch* ctx, unordered_flat_map<int16_t, ZoneTimeData>& data, int64_t& ztime, const ZoneEvent& zone );
|
||||
|
||||
void SetPlaybackFrame( uint32_t idx );
|
||||
bool Save( const char* fn, FileWrite::Compression comp, int zlevel );
|
||||
|
||||
unordered_flat_map<const void*, VisData> m_visData;
|
||||
unordered_flat_map<uint64_t, bool> m_visibleMsgThread;
|
||||
@ -323,7 +325,7 @@ private:
|
||||
void AdjustThreadHeight( View::VisData& vis, int oldOffset, int& offset );
|
||||
|
||||
Worker m_worker;
|
||||
std::string m_filename;
|
||||
std::string m_filename, m_filenameStaging;
|
||||
bool m_staticView;
|
||||
ViewMode m_viewMode;
|
||||
bool m_viewModeHeuristicTry = false;
|
||||
|
Loading…
Reference in New Issue
Block a user