Calculate compare traces average, median.

This commit is contained in:
Bartosz Taudul 2018-09-03 20:34:07 +02:00
parent b485aad2a3
commit fc40c7bbf6
2 changed files with 54 additions and 3 deletions

View File

@ -5552,7 +5552,7 @@ void View::DrawCompare()
ImGui::Separator();
ImGui::NextColumn();
auto prev = m_compare.selMatch[0];
const auto prev0 = m_compare.selMatch[0];
int idx = 0;
for( auto& v : m_compare.match[0] )
{
@ -5566,7 +5566,7 @@ void View::DrawCompare()
}
ImGui::NextColumn();
prev = m_compare.selMatch[1];
const auto prev1 = m_compare.selMatch[1];
idx = 0;
for( auto& v : m_compare.match[1] )
{
@ -5579,9 +5579,13 @@ void View::DrawCompare()
ImGui::PopID();
}
ImGui::NextColumn();
ImGui::EndColumns();
ImGui::TreePop();
if( prev0 != m_compare.selMatch[0] || prev1 != m_compare.selMatch[1] )
{
m_compare.ResetSelection();
}
}
ImGui::Separator();
@ -5605,6 +5609,35 @@ void View::DrawCompare()
auto tmin = std::min( zoneData0.min, zoneData1.min );
auto tmax = std::max( zoneData0.max, zoneData1.max );;
const size_t zsz[2] = { zones0.size(), zones1.size() };
for( int k=0; k<2; k++ )
{
if( m_compare.sortedNum[k] != zsz[k] )
{
auto& zones = k == 0 ? zones0 : zones1;
auto& vec = m_compare.sorted[k];
vec.reserve( zsz[k] );
int64_t total = m_compare.total[k];
size_t i;
for( i=m_compare.sortedNum[k]; i<zsz[k]; i++ )
{
auto& zone = *zones[i].zone;
if( zone.end < 0 ) break;
const auto t = zone.end - zone.start;
vec.emplace_back( t );
total += t;
}
auto mid = vec.begin() + m_compare.sortedNum[k];
pdqsort_branchless( mid, vec.end() );
std::inplace_merge( vec.begin(), mid, vec.end() );
m_compare.average[k] = float( total ) / i;
m_compare.median[k] = vec[i/2];
m_compare.total[k] = total;
m_compare.sortedNum[k] = i;
}
}
if( tmin != std::numeric_limits<int64_t>::max() )
{
ImGui::Checkbox( "Log values", &m_compare.logVal );

View File

@ -367,9 +367,27 @@ private:
bool normalize = false;
int64_t numBins = -1;
std::unique_ptr<CompVal[]> bins, binTime;
std::vector<int64_t> sorted[2];
size_t sortedNum[2] = { 0, 0 };
float average[2];
float median[2];
int64_t total[2];
void ResetSelection()
{
for( int i=0; i<2; i++ )
{
sorted[i].clear();
sortedNum[i] = 0;
average[i] = 0;
median[i] = 0;
total[i] = 0;
}
}
void Reset()
{
ResetSelection();
for( int i=0; i<2; i++ )
{
match[i].clear();