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:
Bartosz Taudul 2021-05-15 14:25:45 +02:00
parent ab830962c8
commit 92ae003308
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3
2 changed files with 103 additions and 21 deletions

View File

@ -36,7 +36,6 @@
#include "tracy_pdqsort.h" #include "tracy_pdqsort.h"
#include "TracyColor.hpp" #include "TracyColor.hpp"
#include "TracyFileRead.hpp" #include "TracyFileRead.hpp"
#include "TracyFileWrite.hpp"
#include "TracyFilesystem.hpp" #include "TracyFilesystem.hpp"
#include "TracyMouse.hpp" #include "TracyMouse.hpp"
#include "TracyPopcnt.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() bool View::Draw()
{ {
HandshakeStatus status = (HandshakeStatus)s_instance->m_worker.GetHandshakeStatus(); HandshakeStatus status = (HandshakeStatus)s_instance->m_worker.GetHandshakeStatus();
@ -606,6 +623,66 @@ bool View::Draw()
ImGui::EndPopup(); 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; s_time += ImGui::GetIO().DeltaTime;
return s_instance->DrawImpl(); return s_instance->DrawImpl();
} }
@ -1466,33 +1543,16 @@ bool View::DrawConnection()
const char* fn = "trace.tracy"; const char* fn = "trace.tracy";
#endif #endif
{ {
std::unique_ptr<FileWrite> f;
const auto sz = strlen( fn ); const auto sz = strlen( fn );
if( sz < 7 || memcmp( fn + sz - 6, ".tracy", 6 ) != 0 ) if( sz < 7 || memcmp( fn + sz - 6, ".tracy", 6 ) != 0 )
{ {
char tmp[1024]; char tmp[1024];
sprintf( tmp, "%s.tracy", fn ); sprintf( tmp, "%s.tracy", fn );
f.reset( FileWrite::Open( tmp ) ); m_filenameStaging = tmp;
if( f ) m_filename = tmp;
} }
else else
{ {
f.reset( FileWrite::Open( fn ) ); m_filenameStaging = 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 );
} );
} }
} }
} }
@ -17976,4 +18036,24 @@ void View::DrawSourceTooltip( const char* filename, uint32_t srcline, int before
if( separateTooltip ) ImGui::EndTooltip(); 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;
}
} }

View File

@ -12,6 +12,7 @@
#include "TracyBadVersion.hpp" #include "TracyBadVersion.hpp"
#include "TracyBuzzAnim.hpp" #include "TracyBuzzAnim.hpp"
#include "TracyDecayValue.hpp" #include "TracyDecayValue.hpp"
#include "TracyFileWrite.hpp"
#include "TracyImGui.hpp" #include "TracyImGui.hpp"
#include "TracyShortPtr.hpp" #include "TracyShortPtr.hpp"
#include "TracySourceContents.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 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 ); 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<const void*, VisData> m_visData;
unordered_flat_map<uint64_t, bool> m_visibleMsgThread; unordered_flat_map<uint64_t, bool> m_visibleMsgThread;
@ -323,7 +325,7 @@ private:
void AdjustThreadHeight( View::VisData& vis, int oldOffset, int& offset ); void AdjustThreadHeight( View::VisData& vis, int oldOffset, int& offset );
Worker m_worker; Worker m_worker;
std::string m_filename; std::string m_filename, m_filenameStaging;
bool m_staticView; bool m_staticView;
ViewMode m_viewMode; ViewMode m_viewMode;
bool m_viewModeHeuristicTry = false; bool m_viewModeHeuristicTry = false;