0
0
mirror of https://github.com/yse/easy_profiler.git synced 2024-12-27 08:41:02 +08:00

Add percent column

This commit is contained in:
Sergey Yagovtsev 2016-05-06 00:30:31 +03:00
parent dfa583f410
commit 6d94573403

View File

@ -9,7 +9,7 @@ TreeModel::TreeModel(const QByteArray &data, QObject *parent)
: QAbstractItemModel(parent) : QAbstractItemModel(parent)
{ {
QList<QVariant> rootData; QList<QVariant> rootData;
rootData << "Name" << "Duration usec" << "thread id" << "begin"; rootData << "Name" << "Duration ms" << "Percent" <<"thread id";
m_rootItem = new TreeItem(rootData); m_rootItem = new TreeItem(rootData);
setupModelData(data, m_rootItem); setupModelData(data, m_rootItem);
} }
@ -131,7 +131,7 @@ void TreeModel::setupModelData(const QByteArray &lines, TreeItem *parent)
profiler::BaseBlockData* baseData = (profiler::BaseBlockData*)data; profiler::BaseBlockData* baseData = (profiler::BaseBlockData*)data;
blocksList[baseData->getThreadId()].emplace( blocksList[baseData->getThreadId()].emplace(
baseData->getBegin(), baseData->getBegin(),
std::move(profiler::SerilizedBlock(sz, data))); /*std::move(*/profiler::SerilizedBlock(sz, data))/*)*/;
} }
@ -143,22 +143,24 @@ void TreeModel::setupModelData(const QByteArray &lines, TreeItem *parent)
parents.clear(); parents.clear();
parents << parent; parents << parent;
double rootDuration = 0.0;
for (auto& i : threads_list.second){ for (auto& i : threads_list.second){
QList<QVariant> columnData; QList<QVariant> columnData;
double percent = 0.0;
const profiler::BaseBlockData * _block = i.second.block(); const profiler::BaseBlockData * _block = i.second.block();
profiler::timestamp_t _end = _block->getEnd(); profiler::timestamp_t _end = _block->getEnd();
profiler::timestamp_t _begin = _block->getBegin(); profiler::timestamp_t _begin = _block->getBegin();
columnData << i.second.getBlockName(); bool is_root = false;
columnData << QVariant::fromValue(_block->duration()); double duration = _block->duration();
columnData << QVariant::fromValue(_block->getThreadId());
if(parents_blocks.empty()){ if(parents_blocks.empty()){
parents_blocks.push_back(_block); parents_blocks.push_back(_block);
parents << parents.last(); parents << parents.last();
is_root = true;
rootDuration =duration;
}else{ }else{
auto& last_block_in_stack = parents_blocks.back(); auto& last_block_in_stack = parents_blocks.back();
@ -178,40 +180,38 @@ void TreeModel::setupModelData(const QByteArray &lines, TreeItem *parent)
parents.pop_back(); parents.pop_back();
} }
} }
parents_blocks.push_back(_block);
if(parents.size() > 1){
parents << parents.last()->child(parents.last()->childCount()-1);
}else{
parents << parents.last();
}
}else if(_end <= last_block_end){
//child
parents_blocks.push_back(_block);
if(parents.size() > 1){
parents << parents.last()->child(parents.last()->childCount()-1);
}else{
parents << parents.last();
}
} }
} }
if (!is_root){
parents_blocks.push_back(_block);
if(parents.size() > 1){
parents << parents.last()->child(parents.last()->childCount()-1);
}else{
parents << parents.last();
is_root = true;
}
}
if(is_root){
percent = 100.0;
rootDuration =duration;
}else{
percent = duration*100.0/rootDuration;
}
columnData << i.second.getBlockName();
columnData << QVariant::fromValue(duration/1000000.0);
columnData << percent;
columnData << QVariant::fromValue(_block->getThreadId());
columnData << QVariant::fromValue(_block->getBegin() - _begin);
if(_block->getType() == profiler::BLOCK_TYPE_BLOCK){ if(_block->getType() == profiler::BLOCK_TYPE_BLOCK){
parents.last()->appendChild(new TreeItem(columnData, parents.last())); parents.last()->appendChild(new TreeItem(columnData, parents.last()));
}else{ }else{
//parents.last()->appendChild(new TreeItem(columnData, parent)); //parent->appendChild(new TreeItem(columnData, parent));
parents.last()->appendChild(new TreeItem(columnData, parent));
} }
} }