Commit 72267b56 authored by Alexab's avatar Alexab
Browse files

Performance problems has been fixed.

--HG--
branch : MockCompsTest
parent 4bdac79d0e26
......@@ -5,6 +5,24 @@
namespace RDK {
UPerformanceElement::UPerformanceElement(void)
: Duration(0), RegTime(0), Interval(0)
{
}
UPerformanceElement::UPerformanceElement(const UPerformanceElement &copy)
: Duration(copy.Duration), RegTime(copy.RegTime), Interval(copy.Interval)
{
}
UPerformanceElement::UPerformanceElement(long long duration, unsigned long long reg_time, long long interval)
: Duration(duration), RegTime(reg_time), Interval(interval)
{
}
UIntegralPerfomanceResults::UIntegralPerfomanceResults(void)
{
ModelTime=0.0;
......@@ -18,33 +36,65 @@ UIntegralPerfomanceResults::UIntegralPerfomanceResults(void)
UPerfomanceResults::UPerfomanceResults(void)
: AvgDuration(0.0), Percentage(0.0)
: AvgDuration(0.0), Percentage(0.0), MinDuration(0.0), MaxDuration(0.0),
MinInterval(0.0), MaxInterval(0.0), AvgInterval(0.0)
{
}
///
void UPerfomanceData::AddHistory(long long value, int max_values)
void UPerfomanceData::AddHistory(long long value, long long interval, int max_values)
{
CalcDurationHistory.push_back(value);
unsigned long long reg_time(0);
if(!CalcDurationHistory.empty())
reg_time=GetCurrentStartupTime()-CalcDurationHistory.back().RegTime;
UPerformanceElement hist(value,reg_time,interval);
CalcDurationHistory.push_back(hist);
while(int(CalcDurationHistory.size())>max_values)
CalcDurationHistory.erase(CalcDurationHistory.begin());
}
///
//struct RDK_LIB_TYPE UPerfomanceData: public UPerfomanceResults
///
void UPerfomanceData::CalcAverage(void)
///
void UPerfomanceData::CalcMetrics(void)
{
AvgDuration=0;
MinDuration=10e6;
MaxDuration=0;
MinInterval=10e6;
MaxInterval=0;
std::list<long long>::iterator I=CalcDurationHistory.begin();
std::list<UPerformanceElement>::iterator I=CalcDurationHistory.begin();
for(;I!=CalcDurationHistory.end();I++)
AvgDuration+=double(*I);
{
UPerformanceElement &curr=*I;
AvgDuration+=double(curr.Duration);
AvgInterval+=double(curr.Interval);
if(MinDuration>curr.Duration)
MinDuration=curr.Duration;
if(MaxDuration<curr.Duration)
MaxDuration=curr.Duration;
if(MinInterval>curr.Interval)
MinInterval=curr.Interval;
if(MaxInterval<curr.Interval)
MaxInterval=curr.Interval;
}
if(!CalcDurationHistory.empty())
{
AvgDuration/=double(CalcDurationHistory.size())*1000.0;
AvgInterval/=double(CalcDurationHistory.size())*1000.0;
}
MinInterval/=1000.0;
MaxInterval/=1000.0;
MaxDuration/=1000.0;
MinDuration/=1000.0;
}
///
......@@ -278,28 +328,28 @@ void UChannelProfiler::ClearPerfomanceData(void)
}
///
void UChannelProfiler::AddComponentPerfomanceData(int index, long long value)
void UChannelProfiler::AddComponentPerfomanceData(int index, long long value, long long interval)
{
UGenericMutexExclusiveLocker locker(Mutex);
if(index<0 || index>=int(ComponentsPerfomance.size()))
return;
ComponentsPerfomance[index].AddHistory(value,AverageIterations);
ComponentsPerfomance[index].AddHistory(value,interval,AverageIterations);
}
void UChannelProfiler::AddComponentPerfomanceData(const std::string &name, long long value)
void UChannelProfiler::AddComponentPerfomanceData(const std::string &name, long long value, long long interval)
{
AddComponentPerfomanceData(FindComponentIndex(name), value);
AddComponentPerfomanceData(FindComponentIndex(name), value,interval);
}
/// gui
void UChannelProfiler::AddGuiPerfomanceData(int index, long long value)
void UChannelProfiler::AddGuiPerfomanceData(int index, long long value, long long interval)
{
UGenericMutexExclusiveLocker locker(Mutex);
if(index<0 || index>=int(GuiPerfomance.size()))
return;
GuiPerfomance[index].AddHistory(value,AverageIterations);
GuiPerfomance[index].AddHistory(value,interval,AverageIterations);
}
///
......@@ -318,12 +368,12 @@ void UChannelProfiler::LoadCorePerfomanceData(void)
{
UEPtr<UNet> component=model->GetComponentL<UNet>(ComponentsName[i],true);
if(component)
AddComponentPerfomanceData(int(i), component->GetFullStepDuration());
AddComponentPerfomanceData(int(i), component->GetFullStepDuration(), component->GetInterstepsInterval());
}
long long full_step=model->GetFullStepDuration();
long long interstep_interval=model->GetInterstepsInterval();
ModelPerfomance.AddHistory(full_step,AverageIterations);
OtherPerfomance.AddHistory(interstep_interval,AverageIterations);
ModelPerfomance.AddHistory(full_step,0,AverageIterations);
OtherPerfomance.AddHistory(interstep_interval,0,AverageIterations);
UEPtr<UEnvironment> env=GetEnvironment(ChannelIndex);
IntegralPerfomanceResults.ModelTime=env->GetTime().GetDoubleTime();
......@@ -359,18 +409,21 @@ void UChannelProfiler::LoadGuiPerfomanceData(void)
for(size_t i=0;i<GuiPerfomance.size();i++)
{
AddGuiPerfomanceData(int(i), interfaces[i]->GetUpdateTime());
if(interfaces[i]->GetUpdateInterval()>0)
AddGuiPerfomanceData(int(i), interfaces[i]->GetUpdateTime(), interfaces[i]->GetUpdateInterval());
else
AddGuiPerfomanceData(int(i), interfaces[i]->GetUpdateTime(), 0);
}
UGenericMutexExclusiveLocker locker(Mutex);
SummaryGuiPerfomance.AddHistory(RDK::UIVisualControllerStorage::GetUpdateTime(),AverageIterations);
SummaryGuiPerfomance.AddHistory(RDK::UIVisualControllerStorage::GetUpdateTime(),0,AverageIterations);
}
///
void UChannelProfiler::CalcCorePerfomance(void)
{
UGenericMutexExclusiveLocker locker(Mutex);
ModelPerfomance.CalcAverage();
OtherPerfomance.CalcAverage();
ModelPerfomance.CalcMetrics();
OtherPerfomance.CalcMetrics();
double avg_full_step=ModelPerfomance.AvgDuration+OtherPerfomance.AvgDuration;
ModelPerfomance.CalcPercentage(avg_full_step);
OtherPerfomance.CalcPercentage(avg_full_step);
......@@ -387,7 +440,7 @@ void UChannelProfiler::CalcCorePerfomance(void)
for(size_t i=0;i<ComponentsPerfomance.size();i++)
{
ComponentsPerfomance[i].CalcAverage();
ComponentsPerfomance[i].CalcMetrics();
ComponentsPerfomance[i].CalcPercentage(ModelPerfomance.AvgDuration);
}
}
......@@ -397,12 +450,12 @@ void UChannelProfiler::CalcGuiPerfomance(void)
{
UGenericMutexExclusiveLocker locker(Mutex);
SummaryGuiPerfomance.CalcAverage();
SummaryGuiPerfomance.CalcMetrics();
SummaryGuiPerfomance.CalcPercentage(SummaryGuiPerfomance.AvgDuration);
for(size_t i=0;i<GuiPerfomance.size();i++)
{
GuiPerfomance[i].CalcAverage();
GuiPerfomance[i].CalcMetrics();
GuiPerfomance[i].CalcPercentage(SummaryGuiPerfomance.AvgDuration);
}
}
......
......@@ -5,6 +5,23 @@
namespace RDK {
///
struct RDK_LIB_TYPE UPerformanceElement
{
///
long long Duration;
///
unsigned long long RegTime;
///
long long Interval;
UPerformanceElement(void);
UPerformanceElement(const UPerformanceElement &copy);
UPerformanceElement(long long duration, unsigned long long reg_time, long long interval);
};
///
struct RDK_LIB_TYPE UIntegralPerfomanceResults
{
......@@ -35,6 +52,21 @@ UIntegralPerfomanceResults(void);
///
struct RDK_LIB_TYPE UPerfomanceResults
{
/// ,
double MinDuration;
/// ,
double MaxDuration;
/// ,
double MinInterval;
/// ,
double MaxInterval;
/// ,
double AvgInterval;
/// ,
double AvgDuration;
......@@ -47,14 +79,16 @@ UPerfomanceResults(void);
///
struct RDK_LIB_TYPE UPerfomanceData: public UPerfomanceResults
{
/// ,
std::list<long long> CalcDurationHistory;
/// : < (), ()>
std::list<UPerformanceElement> CalcDurationHistory;
///
void AddHistory(long long value, int max_values);
/// value - ,
/// interval -
void AddHistory(long long value, long long interval, int max_values);
///
void CalcAverage(void);
///
void CalcMetrics(void);
///
void CalcPercentage(double full_time);
......@@ -183,11 +217,11 @@ std::string GetGuiName(int index) const;
void ClearPerfomanceData(void);
///
void AddComponentPerfomanceData(int index, long long value);
void AddComponentPerfomanceData(const std::string &name, long long value);
void AddComponentPerfomanceData(int index, long long value, long long interval);
void AddComponentPerfomanceData(const std::string &name, long long value, long long interval);
/// gui
void AddGuiPerfomanceData(int index, long long value);
void AddGuiPerfomanceData(int index, long long value, long long interval);
///
void LoadCorePerfomanceData(void);
......
......@@ -57,7 +57,7 @@ UEngineControlThread::UEngineControlThread(UEngineControl* engine_control, int c
ServerTimeStamp=0.0;
CalculationTimeSource=0;
CalculateMode=0;
MinInterstepsInterval=0;
MinInterstepsInterval=1;
Thread=boost::thread(boost::bind(&UEngineControlThread::Execute, boost::ref(*this)));
Profiler=new UChannelProfiler;
Profiler->SetChannelIndex(channel_index);
......@@ -241,19 +241,20 @@ void UEngineControlThread::Calculate(void)
double diff=(RDK::GetVariantLocalTime()-RealLastCalculationTime)*86400*1000.0;
if(diff<MinInterstepsInterval)
int wait_diff=(MinInterstepsInterval>1)?MinInterstepsInterval:1;
if(diff<wait_diff)
{
CalculationNotInProgress->set();
Sleep(int(static_cast<int>(MinInterstepsInterval)-diff));
Sleep(int(static_cast<int>(wait_diff)-diff));
return;
}
/*
if(CalculateMode == 3 && MinInterstepsInterval == UTime(0) && diff<1)
{
CalculationNotInProgress->set();
Sleep(1);
return;
}
}*/
// ..
UELockPtr<UContainer> model=GetModelLock(EngineIndex);
......
......@@ -12,7 +12,7 @@ UTableInfo::UTableInfo(QWidget *parent, RDK::UApplication *app) :
setAccessibleName("UTableInfo");
ui->setupUi(this);
//
ui->tableWidget->setColumnCount(2);
ui->tableWidget->setColumnCount(6);
//
ui->tableWidget->setRowCount(0);
//
......@@ -26,7 +26,7 @@ UTableInfo::UTableInfo(QWidget *parent, RDK::UApplication *app) :
//
QStringList headers;
headers<<"Component name"<<"Time, ms";
headers<<"Component name"<<"Min, ms"<<"Max, ms"<<"Avg, ms"<<"Min Int., ms"<<"Max Int., ms"<<"Avg Int., ms";
ui->tableWidget->setHorizontalHeaderLabels(headers);
//ui->tableWidget->setItem(0,0, new QTableWidgetItem("Full step"));
//ui->tableWidget->setItem(1,0, new QTableWidgetItem("Model"));
......@@ -45,7 +45,7 @@ UTableInfo::UTableInfo(QWidget *parent, RDK::UApplication *app) :
connect(ui->actionAddGroupComponents, SIGNAL(triggered()), this, SLOT(slotAddGroupComponents()));
//
ui->tableWidget_2->setColumnCount(2);
ui->tableWidget_2->setColumnCount(5);
//
ui->tableWidget_2->setRowCount(0);
//
......@@ -54,11 +54,11 @@ UTableInfo::UTableInfo(QWidget *parent, RDK::UApplication *app) :
ui->tableWidget_2->setSelectionBehavior(QAbstractItemView::SelectRows);
//
ui->tableWidget_2->horizontalHeader()->setStretchLastSection(true);
ui->tableWidget_2->setColumnWidth(0, 200);
ui->tableWidget_2->setColumnWidth(1, 40);
// ui->tableWidget_2->setColumnWidth(0, 200);
// ui->tableWidget_2->setColumnWidth(1, 40);
QStringList headers_gui;
headers<<"Gui Widget name"<<"Time, ms";
headers<<"Gui Widget name"<<"Min, ms"<<"Max, ms"<<"Avg, ms"<<"Interval, ms";
ui->tableWidget_2->setHorizontalHeaderLabels(headers_gui);
}
......@@ -99,7 +99,12 @@ void UTableInfo::AUpdateInterface()
ui->tableWidget->setItem(i,0, new QTableWidgetItem(a));
//ui->tableWidget->setItem(i,0, new QTableWidgetItem(cI->first.c_str()));
ui->tableWidget->setItem(i,1, new QTableWidgetItem(QString::number(cI->second.AvgDuration*1000)));
ui->tableWidget->setItem(i,1, new QTableWidgetItem(QString::number(cI->second.MinDuration*1000)));
ui->tableWidget->setItem(i,2, new QTableWidgetItem(QString::number(cI->second.MaxDuration*1000)));
ui->tableWidget->setItem(i,3, new QTableWidgetItem(QString::number(cI->second.AvgDuration*1000)));
ui->tableWidget->setItem(i,4, new QTableWidgetItem(QString::number(cI->second.MinInterval*1000)));
ui->tableWidget->setItem(i,5, new QTableWidgetItem(QString::number(cI->second.MaxInterval*1000)));
ui->tableWidget->setItem(i,6, new QTableWidgetItem(QString::number(cI->second.AvgInterval*1000)));
}
// Gui
......@@ -122,8 +127,10 @@ void UTableInfo::AUpdateInterface()
a.remove("\r\n");
ui->tableWidget_2->setItem(i,0, new QTableWidgetItem(a));
//ui->tableWidget->setItem(i,0, new QTableWidgetItem(cI->first.c_str()));
ui->tableWidget_2->setItem(i,1, new QTableWidgetItem(QString::number(gI->second.AvgDuration*1000)));
ui->tableWidget_2->setItem(i,1, new QTableWidgetItem(QString::number(gI->second.MinDuration*1000)));
ui->tableWidget_2->setItem(i,2, new QTableWidgetItem(QString::number(gI->second.MaxDuration*1000)));
ui->tableWidget_2->setItem(i,3, new QTableWidgetItem(QString::number(gI->second.AvgDuration*1000)));
ui->tableWidget_2->setItem(i,4, new QTableWidgetItem(QString::number(gI->second.AvgInterval*1000)));
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment