Search results histogram.

This commit is contained in:
Bartosz Taudul 2018-02-15 17:25:16 +01:00
parent ea4863d4bd
commit 5bc145f719

View File

@ -4171,9 +4171,80 @@ void View::DrawFindZone()
FindZones(); FindZones();
} }
if( !m_findZone.result.empty() )
{
ImGui::Separator(); ImGui::Separator();
for( const auto &v : m_findZone.result ) if( ImGui::TreeNode( "Histogram" ) )
{
int64_t tmin = std::numeric_limits<int64_t>::max();
int64_t tmax = std::numeric_limits<int64_t>::min();
for( auto& v : m_findZone.result )
{
for( auto& ev : v->timeline )
{
const auto timeSpan = GetZoneEnd( *ev ) - ev->start;
tmin = std::min( tmin, timeSpan );
tmax = std::max( tmax, timeSpan );
}
}
ImGui::Text( "tMin: %s", TimeToString( tmin ) );
ImGui::Text( "tMax: %s", TimeToString( tmax ) );
const auto dt = double( tmax - tmin );
if( dt > 0 )
{
enum { Height = 200 };
const auto w = ImGui::GetContentRegionAvail().x;
const auto wpos = ImGui::GetCursorScreenPos();
ImGui::InvisibleButton( "##histogram", ImVec2( w, Height ) );
auto draw = ImGui::GetWindowDrawList();
draw->AddRectFilled( wpos, wpos + ImVec2( w, Height ), 0x22FFFFFF );
draw->AddRect( wpos, wpos + ImVec2( w, Height ), 0x88FFFFFF );
const auto numBins = size_t( w - 4 );
auto bins = std::make_unique<uint64_t[]>( numBins );
memset( bins.get(), 0, sizeof( uint64_t ) * numBins );
const auto idt = numBins / dt;
for( auto& v : m_findZone.result )
{
for( auto& ev : v->timeline )
{
const auto timeSpan = GetZoneEnd( *ev ) - ev->start;
const auto bin = std::min( numBins - 1, size_t( ( timeSpan - tmin ) * idt ) );
bins[bin]++;
}
}
auto maxVal = bins[0];
for( int i=1; i<numBins; i++ )
{
maxVal = std::max( maxVal, bins[i] );
}
const auto hAdj = double( Height - 4 ) / maxVal;
for( int i=0; i<numBins; i++ )
{
if( bins[i] > 0 )
{
draw->AddLine( wpos + ImVec2( 2+i, Height-3 ), wpos + ImVec2( 2+i, Height-3 - bins[i] * hAdj ), 0xFF22DDDD );
}
}
}
ImGui::TreePop();
}
ImGui::Separator();
for( auto& v : m_findZone.result )
{ {
const bool expand = ImGui::TreeNode( GetThreadString( v->id ) ); const bool expand = ImGui::TreeNode( GetThreadString( v->id ) );
ImGui::SameLine(); ImGui::SameLine();
@ -4216,6 +4287,7 @@ void View::DrawFindZone()
ImGui::TreePop(); ImGui::TreePop();
} }
} }
}
ImGui::End(); ImGui::End();
} }