From 73f09de29db76b9ca5d93904d15698ff9fe336e5 Mon Sep 17 00:00:00 2001 From: Martijn Courteaux Date: Tue, 21 May 2024 15:25:23 +0200 Subject: [PATCH 1/7] Fix savings calculation. --- profiler/src/profiler/TracyView_Compare.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/profiler/src/profiler/TracyView_Compare.cpp b/profiler/src/profiler/TracyView_Compare.cpp index 61338963..57fba756 100644 --- a/profiler/src/profiler/TracyView_Compare.cpp +++ b/profiler/src/profiler/TracyView_Compare.cpp @@ -968,7 +968,7 @@ void View::DrawCompare() TextFocused( "Savings:", TimeToString( total1 * adj1 - total0 * adj0 ) ); ImGui::SameLine(); char buf[64]; - PrintStringPercent( buf, ( total0 * adj0 ) / ( total1 * adj1 ) * 100 ); + PrintStringPercent( buf, (1.0 - ( total0 * adj0 ) / ( total1 * adj1 )) * 100 ); TextDisabledUnformatted( buf ); TextFocused( "Max counts:", cumulateTime ? TimeToString( maxVal ) : RealToString( floor( maxVal ) ) ); From f704c57f98d385f2e9607aff48f800208a114435 Mon Sep 17 00:00:00 2001 From: Martijn Courteaux Date: Tue, 21 May 2024 17:10:48 +0200 Subject: [PATCH 2/7] Clearer and more detailed comparison in terms of slow down or speed up of times when comparing traces. --- profiler/src/profiler/TracyView_Compare.cpp | 51 ++++++++++++++++++--- 1 file changed, 45 insertions(+), 6 deletions(-) diff --git a/profiler/src/profiler/TracyView_Compare.cpp b/profiler/src/profiler/TracyView_Compare.cpp index 57fba756..1976a81f 100644 --- a/profiler/src/profiler/TracyView_Compare.cpp +++ b/profiler/src/profiler/TracyView_Compare.cpp @@ -185,6 +185,44 @@ static void PrintDiff( const std::string& diff ) } } +static void PrintSpeedupOrSlowdown( double time_this, double time_external ) +{ + const char *label, *label2; + const char *time_diff = TimeToString( abs( time_external - time_this ) ); + ImVec4 color; + double factor; + if( time_external >= time_this ) + { + label = "Speedup:", label2 = "faster"; + color = ImVec4( 0.1f, 0.6f, 0.1f, 1.0f); + factor = time_external / time_this; + } else { + label = "Slowdown:", label2 = "slower"; + color = ImVec4( 0.8f, 0.1f, 0.1f, 1.0f ); + factor = time_this / time_external; + } + TextColoredUnformatted( color, label ); + ImGui::SameLine(); + TextColoredUnformatted(color, time_diff ); + ImGui::SameLine(); + TextColoredUnformatted( color, label2 ); + ImGui::SameLine(); + ImGui::Spacing(); + ImGui::SameLine(); + char buf[64]; + memcpy( buf, "( ", 2 ); + char *ptr = &buf[2]; + ptr = PrintFloat( ptr, buf + sizeof(buf), factor, 3 ); + memcpy( ptr, "x ", 2 ); + ptr += 2; + int ssz = strlen( label2 ); + memcpy( ptr, label2, ssz ); + ptr += ssz; + memcpy( ptr, " )", 3 ); + TextDisabledUnformatted( buf ); + +} + void View::DrawCompare() { const auto scale = GetScale(); @@ -796,7 +834,7 @@ void View::DrawCompare() ImGui::SameLine(); SmallCheckbox( "Normalize values", &m_compare.normalize ); ImGui::SameLine(); - DrawHelpMarker( "Normalization will fudge reported data values!" ); + DrawHelpMarker( "Normalization will rescale the total time of the external trace to match the count of this trace. This will skew reported total values!" ); const auto cumulateTime = m_compare.cumulateTime; @@ -965,11 +1003,9 @@ void View::DrawCompare() TextColoredUnformatted( ImVec4( 0xDD/511.f, 0x22/511.f, 0x22/511.f, 1.f ), ICON_FA_GEM ); ImGui::SameLine(); TextFocused( "Total time (ext.):", TimeToString( total1 * adj1 ) ); - TextFocused( "Savings:", TimeToString( total1 * adj1 - total0 * adj0 ) ); - ImGui::SameLine(); - char buf[64]; - PrintStringPercent( buf, (1.0 - ( total0 * adj0 ) / ( total1 * adj1 )) * 100 ); - TextDisabledUnformatted( buf ); + ImGui::Indent(); + PrintSpeedupOrSlowdown( total0 * adj0, total1 * adj1 ); + ImGui::Unindent(); TextFocused( "Max counts:", cumulateTime ? TimeToString( maxVal ) : RealToString( floor( maxVal ) ) ); TextColoredUnformatted( ImVec4( 0xDD/511.f, 0xDD/511.f, 0x22/511.f, 1.f ), ICON_FA_LEMON ); @@ -1022,6 +1058,9 @@ void View::DrawCompare() TextFocused( "\xcf\x83 (ext.):", TimeToString( sd ) ); TooltipIfHovered( "Standard deviation" ); } + ImGui::Indent(); + PrintSpeedupOrSlowdown( m_compare.average[0], m_compare.average[1] ); + ImGui::Unindent(); ImGui::PushStyleColor( ImGuiCol_Text, ImVec4( 0xDD/511.f, 0xDD/511.f, 0x22/511.f, 1.f ) ); ImGui::PushStyleColor( ImGuiCol_Button, ImVec4( 0xDD/255.f, 0xDD/255.f, 0x22/255.f, 1.f ) ); From 717e545158e6bf756e8c04b6b959faa7d81cb511 Mon Sep 17 00:00:00 2001 From: Martijn Courteaux Date: Tue, 21 May 2024 19:08:16 +0200 Subject: [PATCH 3/7] Improve time comparing display. --- profiler/src/profiler/TracyView_Compare.cpp | 34 +++++++++------------ 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/profiler/src/profiler/TracyView_Compare.cpp b/profiler/src/profiler/TracyView_Compare.cpp index 1976a81f..9de14d90 100644 --- a/profiler/src/profiler/TracyView_Compare.cpp +++ b/profiler/src/profiler/TracyView_Compare.cpp @@ -185,42 +185,35 @@ static void PrintDiff( const std::string& diff ) } } -static void PrintSpeedupOrSlowdown( double time_this, double time_external ) +static void PrintSpeedupOrSlowdown( double time_this, double time_external, const char *metric ) { const char *label, *label2; const char *time_diff = TimeToString( abs( time_external - time_this ) ); ImVec4 color; - double factor; + double factor = time_this / time_external; if( time_external >= time_this ) { - label = "Speedup:", label2 = "faster"; - color = ImVec4( 0.1f, 0.6f, 0.1f, 1.0f); - factor = time_external / time_this; + label = "less than external", label2 = "faster"; + color = ImVec4( 0.1f, 0.6f, 0.1f, 1.0f ); } else { - label = "Slowdown:", label2 = "slower"; + label = "more than external", label2 = "slower"; color = ImVec4( 0.8f, 0.1f, 0.1f, 1.0f ); - factor = time_this / time_external; } - TextColoredUnformatted( color, label ); + TextColoredUnformatted( color, metric ); ImGui::SameLine(); TextColoredUnformatted(color, time_diff ); ImGui::SameLine(); - TextColoredUnformatted( color, label2 ); + TextColoredUnformatted( color, label ); ImGui::SameLine(); ImGui::Spacing(); ImGui::SameLine(); char buf[64]; - memcpy( buf, "( ", 2 ); - char *ptr = &buf[2]; + memcpy( buf, "(Time factor compared to external: ", 35 ); + char *ptr = &buf[35]; ptr = PrintFloat( ptr, buf + sizeof(buf), factor, 3 ); - memcpy( ptr, "x ", 2 ); - ptr += 2; - int ssz = strlen( label2 ); - memcpy( ptr, label2, ssz ); - ptr += ssz; - memcpy( ptr, " )", 3 ); + memcpy( ptr, ")", 2 ); + ptr += 23; TextDisabledUnformatted( buf ); - } void View::DrawCompare() @@ -1004,7 +997,7 @@ void View::DrawCompare() ImGui::SameLine(); TextFocused( "Total time (ext.):", TimeToString( total1 * adj1 ) ); ImGui::Indent(); - PrintSpeedupOrSlowdown( total0 * adj0, total1 * adj1 ); + PrintSpeedupOrSlowdown( total0 * adj0, total1 * adj1, "Total time" ); ImGui::Unindent(); TextFocused( "Max counts:", cumulateTime ? TimeToString( maxVal ) : RealToString( floor( maxVal ) ) ); @@ -1059,7 +1052,8 @@ void View::DrawCompare() TooltipIfHovered( "Standard deviation" ); } ImGui::Indent(); - PrintSpeedupOrSlowdown( m_compare.average[0], m_compare.average[1] ); + PrintSpeedupOrSlowdown( m_compare.average[0], m_compare.average[1], "Mean time" ); + PrintSpeedupOrSlowdown( m_compare.median[0], m_compare.median[1], "Median time" ); ImGui::Unindent(); ImGui::PushStyleColor( ImGuiCol_Text, ImVec4( 0xDD/511.f, 0xDD/511.f, 0x22/511.f, 1.f ) ); From ec7fc9ffb6e376e183bfc8d3b81f0a3180dea283 Mon Sep 17 00:00:00 2001 From: Martijn Courteaux Date: Tue, 21 May 2024 19:08:54 +0200 Subject: [PATCH 4/7] Cleanup --- profiler/src/profiler/TracyView_Compare.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/profiler/src/profiler/TracyView_Compare.cpp b/profiler/src/profiler/TracyView_Compare.cpp index 9de14d90..de99f987 100644 --- a/profiler/src/profiler/TracyView_Compare.cpp +++ b/profiler/src/profiler/TracyView_Compare.cpp @@ -187,16 +187,16 @@ static void PrintDiff( const std::string& diff ) static void PrintSpeedupOrSlowdown( double time_this, double time_external, const char *metric ) { - const char *label, *label2; + const char *label; const char *time_diff = TimeToString( abs( time_external - time_this ) ); ImVec4 color; double factor = time_this / time_external; if( time_external >= time_this ) { - label = "less than external", label2 = "faster"; + label = "less than external"; color = ImVec4( 0.1f, 0.6f, 0.1f, 1.0f ); } else { - label = "more than external", label2 = "slower"; + label = "more than external"; color = ImVec4( 0.8f, 0.1f, 0.1f, 1.0f ); } TextColoredUnformatted( color, metric ); From 86717de6e155718e218f3e01bc82f7f048eb4f3f Mon Sep 17 00:00:00 2001 From: Martijn Courteaux Date: Tue, 21 May 2024 19:24:04 +0200 Subject: [PATCH 5/7] Improve time comparing display. --- profiler/src/profiler/TracyView_Compare.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/profiler/src/profiler/TracyView_Compare.cpp b/profiler/src/profiler/TracyView_Compare.cpp index de99f987..2e0eaac6 100644 --- a/profiler/src/profiler/TracyView_Compare.cpp +++ b/profiler/src/profiler/TracyView_Compare.cpp @@ -207,12 +207,10 @@ static void PrintSpeedupOrSlowdown( double time_this, double time_external, cons ImGui::SameLine(); ImGui::Spacing(); ImGui::SameLine(); - char buf[64]; - memcpy( buf, "(Time factor compared to external: ", 35 ); - char *ptr = &buf[35]; - ptr = PrintFloat( ptr, buf + sizeof(buf), factor, 3 ); - memcpy( ptr, ")", 2 ); - ptr += 23; + char buf[128]; + sprintf(buf, "(this %s %c%s is %.2f%% of external %s %c%s)", + ICON_FA_LEMON, tolower( metric[0] ), metric + 1, factor * 100, + ICON_FA_GEM, tolower( metric[0] ), metric + 1 ); TextDisabledUnformatted( buf ); } From abdbaed7377c8eb3c2799ab2b65926253ca8687f Mon Sep 17 00:00:00 2001 From: Martijn Courteaux Date: Tue, 21 May 2024 19:32:43 +0200 Subject: [PATCH 6/7] Simplify time comparing display. --- profiler/src/profiler/TracyView_Compare.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/profiler/src/profiler/TracyView_Compare.cpp b/profiler/src/profiler/TracyView_Compare.cpp index 2e0eaac6..f6f1c779 100644 --- a/profiler/src/profiler/TracyView_Compare.cpp +++ b/profiler/src/profiler/TracyView_Compare.cpp @@ -207,10 +207,8 @@ static void PrintSpeedupOrSlowdown( double time_this, double time_external, cons ImGui::SameLine(); ImGui::Spacing(); ImGui::SameLine(); - char buf[128]; - sprintf(buf, "(this %s %c%s is %.2f%% of external %s %c%s)", - ICON_FA_LEMON, tolower( metric[0] ), metric + 1, factor * 100, - ICON_FA_GEM, tolower( metric[0] ), metric + 1 ); + char buf[64]; + sprintf(buf, "(%s = %.2f%% %s)", ICON_FA_LEMON, factor * 100, ICON_FA_GEM ); TextDisabledUnformatted( buf ); } From bd00c6a4ee14f7592d650acc88962eabb1317117 Mon Sep 17 00:00:00 2001 From: Martijn Courteaux Date: Tue, 21 May 2024 19:47:19 +0200 Subject: [PATCH 7/7] Improve time comparing display with better colors. --- profiler/src/profiler/TracyView_Compare.cpp | 23 ++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/profiler/src/profiler/TracyView_Compare.cpp b/profiler/src/profiler/TracyView_Compare.cpp index f6f1c779..b3dc3513 100644 --- a/profiler/src/profiler/TracyView_Compare.cpp +++ b/profiler/src/profiler/TracyView_Compare.cpp @@ -193,23 +193,32 @@ static void PrintSpeedupOrSlowdown( double time_this, double time_external, cons double factor = time_this / time_external; if( time_external >= time_this ) { - label = "less than external"; + label = "less"; color = ImVec4( 0.1f, 0.6f, 0.1f, 1.0f ); } else { - label = "more than external"; + label = "more"; color = ImVec4( 0.8f, 0.1f, 0.1f, 1.0f ); } - TextColoredUnformatted( color, metric ); + ImGui::TextDisabled( "%s:", metric ); ImGui::SameLine(); - TextColoredUnformatted(color, time_diff ); + TextColoredUnformatted( color, time_diff ); ImGui::SameLine(); TextColoredUnformatted( color, label ); ImGui::SameLine(); + ImGui::TextUnformatted( "than external" ); + ImGui::SameLine(); ImGui::Spacing(); ImGui::SameLine(); - char buf[64]; - sprintf(buf, "(%s = %.2f%% %s)", ICON_FA_LEMON, factor * 100, ICON_FA_GEM ); - TextDisabledUnformatted( buf ); + + TextDisabledUnformatted("("); + ImGui::SameLine(); + TextColoredUnformatted( ImVec4( 0xDD/511.f, 0xDD/511.f, 0x22/511.f, 1.f ), ICON_FA_LEMON ); + ImGui::SameLine(); + ImGui::TextDisabled("= %.2f%%", factor * 100 ); + ImGui::SameLine(); + TextColoredUnformatted( ImVec4( 0xDD/511.f, 0x22/511.f, 0x22/511.f, 1.f ), ICON_FA_GEM ); + ImGui::SameLine(); + TextDisabledUnformatted(")"); } void View::DrawCompare()