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

Scene paint fixes and optimization

This commit is contained in:
Victor Zarubkin 2016-07-27 21:50:11 +03:00
parent 9a616fc693
commit 03fb3f271f
4 changed files with 293 additions and 119 deletions

View File

@ -27,6 +27,9 @@ along with this program.If not, see <http://www.gnu.org/licenses/>.
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//#define PROFILER_COUNT_TOTAL_CHILDREN_NUMBER
#define PROFILER_COUNT_DEPTH
namespace profiler { namespace profiler {
typedef uint32_t calls_number_t; typedef uint32_t calls_number_t;
@ -96,10 +99,25 @@ struct BlocksTree
::profiler::SerilizedBlock* node; ::profiler::SerilizedBlock* node;
::profiler::BlockStatistics* frame_statistics; ///< Pointer to statistics for this block within the parent (may be nullptr for top-level blocks) ::profiler::BlockStatistics* frame_statistics; ///< Pointer to statistics for this block within the parent (may be nullptr for top-level blocks)
::profiler::BlockStatistics* total_statistics; ///< Pointer to statistics for this block within the bounds of all frames per current thread ::profiler::BlockStatistics* total_statistics; ///< Pointer to statistics for this block within the bounds of all frames per current thread
unsigned int total_children_number; ///< Number of all children including number of grandchildren (and so on)
unsigned short sublevels; ///< Maximum number of sublevels (maximum children depth)
BlocksTree() : node(nullptr), frame_statistics(nullptr), total_statistics(nullptr), total_children_number(0), sublevels(0) #ifdef PROFILER_COUNT_TOTAL_CHILDREN_NUMBER
unsigned int total_children_number; ///< Number of all children including number of grandchildren (and so on)
#endif
#ifdef PROFILER_COUNT_DEPTH
unsigned short depth; ///< Maximum number of sublevels (maximum children depth)
#endif
BlocksTree()
: node(nullptr)
, frame_statistics(nullptr)
, total_statistics(nullptr)
#ifdef PROFILER_COUNT_TOTAL_CHILDREN_NUMBER
, total_children_number(0)
#endif
#ifdef PROFILER_COUNT_DEPTH
, depth(0)
#endif
{ {
} }
@ -158,8 +176,14 @@ private:
node = that.node; node = that.node;
frame_statistics = that.frame_statistics; frame_statistics = that.frame_statistics;
total_statistics = that.total_statistics; total_statistics = that.total_statistics;
#ifdef PROFILER_COUNT_TOTAL_CHILDREN_NUMBER
total_children_number = that.total_children_number; total_children_number = that.total_children_number;
sublevels = that.sublevels; #endif
#ifdef PROFILER_COUNT_DEPTH
depth = that.depth;
#endif
that.node = nullptr; that.node = nullptr;
that.frame_statistics = nullptr; that.frame_statistics = nullptr;

View File

@ -35,50 +35,50 @@
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const qreal GRAPHICS_ROW_SIZE = 16; const unsigned short GRAPHICS_ROW_SIZE = 16;
const qreal GRAPHICS_ROW_SIZE_FULL = GRAPHICS_ROW_SIZE + 2; const unsigned short GRAPHICS_ROW_SIZE_FULL = GRAPHICS_ROW_SIZE + 2;
const qreal ROW_SPACING = 10; const unsigned short ROW_SPACING = 10;
const QRgb DEFAULT_COLOR = 0x00f0e094; const QRgb DEFAULT_COLOR = 0x00f0e094;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
QRgb toRgb(unsigned int _red, unsigned int _green, unsigned int _blue) QRgb toRgb(unsigned int _red, unsigned int _green, unsigned int _blue)
{ {
if (_red == _green == _blue == 0) if (_red == 0 && _green == 0 && _blue == 0)
return DEFAULT_COLOR; return DEFAULT_COLOR;
return (_red << 16) + (_green << 8) + _blue; return (_red << 16) + (_green << 8) + _blue;
} }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void ProfBlockItem::setRect(preal _x, preal _y, preal _w, preal _h) { void ProfBlockItem::setRect(qreal _x, float _y, float _w, float _h) {
x = _x; x = _x;
y = _y; y = _y;
w = _w; w = _w;
h = _h; h = _h;
} }
preal ProfBlockItem::left() const { qreal ProfBlockItem::left() const {
return x; return x;
} }
preal ProfBlockItem::top() const { float ProfBlockItem::top() const {
return y; return y;
} }
preal ProfBlockItem::width() const { float ProfBlockItem::width() const {
return w; return w;
} }
preal ProfBlockItem::height() const { float ProfBlockItem::height() const {
return h; return h;
} }
preal ProfBlockItem::right() const { qreal ProfBlockItem::right() const {
return x + w; return x + w;
} }
preal ProfBlockItem::bottom() const { float ProfBlockItem::bottom() const {
return y + h; return y + h;
} }
@ -139,8 +139,8 @@ void ProfGraphicsItem::paint(QPainter* _painter, const QStyleOptionGraphicsItem*
QRgb previousColor = 0; QRgb previousColor = 0;
for (auto& item : m_items) for (auto& item : m_items)
{ {
item.draw = !(item.left() > sceneRight || item.right() < sceneLeft); item.state = !(item.left() > sceneRight || item.right() < sceneLeft);
if (!item.draw) if (!item.state)
{ {
// this item is fully out of scene visible rect // this item is fully out of scene visible rect
continue; continue;
@ -164,7 +164,7 @@ void ProfGraphicsItem::paint(QPainter* _painter, const QStyleOptionGraphicsItem*
{ {
for (auto& item : m_items) for (auto& item : m_items)
{ {
if (!item.draw) if (!item.state)
continue; continue;
auto w = item.width() * currentScale; auto w = item.width() * currentScale;
@ -181,7 +181,7 @@ void ProfGraphicsItem::paint(QPainter* _painter, const QStyleOptionGraphicsItem*
previousColor = 0; previousColor = 0;
for (auto& item : m_items) for (auto& item : m_items)
{ {
if (!item.draw) if (!item.state)
continue; continue;
auto w = item.width() * currentScale; auto w = item.width() * currentScale;
@ -220,28 +220,30 @@ void ProfGraphicsItem::paint(QPainter* _painter, const QStyleOptionGraphicsItem*
return; return;
} }
const auto selfX = x(); const auto self_x = x();
const auto view = static_cast<ProfGraphicsView*>(scene()->parent()); const auto view = static_cast<ProfGraphicsView*>(scene()->parent());
const auto visibleSceneRect = view->visibleSceneRect(); // Current visible scene rect
const auto sceneLeft = visibleSceneRect.left() - selfX, sceneRight = visibleSceneRect.right() - selfX;
const auto currentScale = view->currentScale(); // Current GraphicsView scale const auto currentScale = view->currentScale(); // Current GraphicsView scale
const auto scaleRevert = 1.0 / currentScale; // Multiplier for reverting current GraphicsView scale const auto scaleRevert = 1.0 / currentScale; // Multiplier for reverting current GraphicsView scale
const auto visibleSceneRect = view->visibleSceneRect(); // Current visible scene rect
const auto sceneLeft = visibleSceneRect.left() - self_x, sceneRight = visibleSceneRect.right() - self_x;
QRectF rect; QRectF rect;
QBrush brush; QBrush brush;
QPen pen = _painter->pen();
QRgb previousColor = 0; QRgb previousColor = 0;
brush.setStyle(Qt::SolidPattern); brush.setStyle(Qt::SolidPattern);
_painter->save(); _painter->save();
//_painter->setPen(Qt::NoPen); _painter->setPen(Qt::NoPen);
_painter->setTransform(QTransform::fromScale(scaleRevert, 1), true);
const int levelsNumber = static_cast<int>(m_levels.size());
for (int i = 1; i < levelsNumber; ++i) // Reset indices of first visible item for each layer
const auto levelsNumber = levels();
for (unsigned short i = 1; i < levelsNumber; ++i)
m_levelsIndexes[i] = -1; m_levelsIndexes[i] = -1;
// Searching for first visible top item
// Search for first visible top item
auto& level0 = m_levels[0]; auto& level0 = m_levels[0];
auto first = ::std::lower_bound(level0.begin(), level0.end(), sceneLeft, [](const ProfBlockItem& _item, double _value) auto first = ::std::lower_bound(level0.begin(), level0.end(), sceneLeft, [](const ProfBlockItem& _item, double _value)
{ {
@ -259,51 +261,99 @@ void ProfGraphicsItem::paint(QPainter* _painter, const QStyleOptionGraphicsItem*
m_levelsIndexes[0] = level0.size() - 1; m_levelsIndexes[0] = level0.size() - 1;
} }
// Iterating through levels and draw visible items
for (int l = 0; l < levelsNumber; ++l) // STUB! --------------------------------------------------------
//
// This is to make _painter->drawText() work properly
// (it seems there is a bug in Qt5.6 when drawText called for big coordinates,
// drawRect at the same time called for actually same coordinates
// works fine without using this additional transform fromTranslate)
const auto dx = m_levels[0][m_levelsIndexes[0]].left();
_painter->setTransform(QTransform::fromTranslate(dx, -y()), true);
//
// END STUB! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_painter->setTransform(QTransform::fromScale(scaleRevert, 1), true);
//printf("SCALE=%0.4lf // LEFT=%0.2lf // RIGHT=%0.2lf // self_x=%0.2lf\n", currentScale, sceneLeft, sceneRight, self_x);
// Iterate through layers and draw visible items
for (unsigned short l = 0; l < levelsNumber; ++l)
{ {
auto& level = m_levels[l]; auto& level = m_levels[l];
const auto next_level = l + 1; const auto next_level = l + 1;
char state = 1;
//bool changebrush = false;
for (unsigned int i = m_levelsIndexes[l], end = level.size(); i < end; ++i) for (unsigned int i = m_levelsIndexes[l], end = level.size(); i < end; ++i)
{ {
auto& item = level[i]; auto& item = level[i];
if (item.state != 0) state = item.state;
if (item.right() < sceneLeft) if (item.right() < sceneLeft || state == -1)
{ {
++m_levelsIndexes[l]; ++m_levelsIndexes[l];
continue; continue;
} }
auto w = item.width() * currentScale; auto w = ::std::max(item.width() * currentScale, 1.0);
if (l == 0)
if (w < 20)
{ {
if (w < 20) // Items which width is less than 20 will be painted as big rectangles which are hiding it's children
{ if (item.left() > sceneRight)
// Items which width is less than 20 will be painted as big rectangles which are hiding it's children break;
if (item.left() > sceneRight)
break;
if (previousColor != item.color) auto x = (item.left() - dx) * currentScale;
{ //if (previousColor != item.color)
previousColor = item.color; //{
brush.setColor(previousColor); // changebrush = true;
_painter->setBrush(brush); // previousColor = item.color;
} // QLinearGradient gradient(x, item.top(), x, item.top() + item.totalHeight);
// gradient.setColorAt(0, item.color);
// gradient.setColorAt(1, 0x00ffffff);
// brush = QBrush(gradient);
// _painter->setBrush(brush);
//}
//rect.setRect(selfX + item.left(), item.top(), item.width(), item.totalHeight); if (previousColor != item.color)
rect.setRect((selfX + item.left()) * currentScale, item.top(), w, item.totalHeight); {
_painter->drawRect(rect); previousColor = item.color;
continue; brush.setColor(previousColor);
_painter->setBrush(brush);
} }
//rect.setRect(item.left(), item.top(), item.width(), item.totalHeight);
//rect.setRect(item.left() * currentScale, item.top(), w, item.totalHeight);
rect.setRect(x, item.top(), w, item.totalHeight);
_painter->drawRect(rect);
if (next_level < levelsNumber && item.children_begin != -1)
m_levels[next_level][item.children_begin].state = -1;
continue;
} }
if (next_level < levelsNumber && m_levelsIndexes[next_level] == -1) if (next_level < levelsNumber && item.children_begin != -1)
m_levelsIndexes[next_level] = item.children_begin; {
if (m_levelsIndexes[next_level] == -1)
m_levelsIndexes[next_level] = item.children_begin;
m_levels[next_level][item.children_begin].state = 1;
}
if (item.left() > sceneRight) if (item.left() > sceneRight)
break; break;
//if (changebrush)
//{
// changebrush = false;
// previousColor = item.color;
// brush = QBrush(previousColor);
// _painter->setBrush(brush);
//} else
if (previousColor != item.color) if (previousColor != item.color)
{ {
previousColor = item.color; previousColor = item.color;
@ -311,32 +361,35 @@ void ProfGraphicsItem::paint(QPainter* _painter, const QStyleOptionGraphicsItem*
_painter->setBrush(brush); _painter->setBrush(brush);
} }
if (w < 20) //rect.setRect(item.left(), item.top(), item.width(), item.height());
_painter->setPen(Qt::NoPen); //rect.setRect(item.left() * currentScale, item.top(), w, item.height());
rect.setRect((item.left() - dx) * currentScale, item.top(), w, item.height());
//rect.setRect(selfX + item.left(), item.top(), item.width(), item.height());
rect.setRect((selfX + item.left()) * currentScale, item.top(), w, item.height());
_painter->drawRect(rect); _painter->drawRect(rect);
if (w < 20) //if (w < 20)
{ // continue;
_painter->setPen(Qt::SolidLine);
continue;
}
if (m_bTest) auto xtext = 0;
{ if (item.left() < sceneLeft)
auto xtext = item.left(); {
if (xtext < sceneLeft) w += (item.left() - sceneLeft) * currentScale;
{ xtext = sceneLeft - dx;
w += xtext - sceneLeft; }
xtext = sceneLeft; else
} {
xtext += selfX; xtext = item.left() - dx;
}
rect.setRect(xtext * currentScale, item.top(), w, item.height()); //w = item.width();
_painter->drawText(rect, 0, "NOT VERY LONG TEST TEXT"); rect.setRect(xtext * currentScale, item.top(), w, item.height());
}
auto textColor = 0x00ffffff - previousColor;
if (textColor == previousColor) textColor = 0;
pen.setColor(textColor); // Text is painted with inverse color
_painter->setPen(pen);
auto text = m_bTest ? "NOT VERY LONG TEST TEXT" : item.block->node->getBlockName();
_painter->drawText(rect, 0, text);
_painter->setPen(Qt::NoPen); // restore pen for rectangle painting
} }
} }
@ -396,6 +449,11 @@ size_t ProfGraphicsItem::addItem(ProfBlockItem&& _item)
#else #else
unsigned short ProfGraphicsItem::levels() const
{
return static_cast<unsigned short>(m_levels.size());
}
void ProfGraphicsItem::setLevels(unsigned short _levels) void ProfGraphicsItem::setLevels(unsigned short _levels)
{ {
m_levels.resize(_levels); m_levels.resize(_levels);
@ -545,23 +603,24 @@ void fillChildren(ProfGraphicsItem* _item, int _level, qreal _x, qreal _y, size_
size_t j = _item->addItem(_level); size_t j = _item->addItem(_level);
auto& b = _item->getItem(_level, j); auto& b = _item->getItem(_level, j);
b.color = toRgb(30 + rand() % 225, 30 + rand() % 225, 30 + rand() % 225); b.color = toRgb(30 + rand() % 225, 30 + rand() % 225, 30 + rand() % 225);
b.state = 0;
if (_childrenNumber > 0) if (_childrenNumber > 0)
{ {
const auto& children = _item->items(_level + 1); const auto& children = _item->items(_level + 1);
b.children_begin = static_cast<unsigned int>(children.size()); b.children_begin = static_cast<unsigned int>(children.size());
fillChildren(_item, _level + 1, _x, _y + GRAPHICS_ROW_SIZE + 2, _childrenNumber, _total_items); fillChildren(_item, _level + 1, _x, _y + GRAPHICS_ROW_SIZE_FULL, _childrenNumber, _total_items);
const auto& last = children.back(); const auto& last = children.back();
b.setRect(_x, _y, last.right() - _x, GRAPHICS_ROW_SIZE); b.setRect(_x, _y, last.right() - _x, GRAPHICS_ROW_SIZE);
b.totalHeight = GRAPHICS_ROW_SIZE + last.totalHeight + 2; b.totalHeight = GRAPHICS_ROW_SIZE_FULL + last.totalHeight;
} }
else else
{ {
b.setRect(_x, _y, 10 + rand() % 40, GRAPHICS_ROW_SIZE); b.setRect(_x, _y, 10 + rand() % 40, GRAPHICS_ROW_SIZE);
b.totalHeight = GRAPHICS_ROW_SIZE; b.totalHeight = GRAPHICS_ROW_SIZE;
b.children_begin = 0; b.children_begin = -1;
} }
_x = b.right(); _x = b.right();
@ -571,11 +630,14 @@ void fillChildren(ProfGraphicsItem* _item, int _level, qreal _x, qreal _y, size_
void ProfGraphicsScene::test(size_t _frames_number, size_t _total_items_number_estimate, int _depth) void ProfGraphicsScene::test(size_t _frames_number, size_t _total_items_number_estimate, int _depth)
{ {
static const qreal X_BEGIN = 50;
static const qreal Y_BEGIN = 0;
const auto children_per_frame = _total_items_number_estimate / _frames_number; const auto children_per_frame = _total_items_number_estimate / _frames_number;
const size_t first_level_children_count = sqrt(pow(2, _depth - 1)) * pow(children_per_frame, 1.0 / double(_depth)) + 0.5; const size_t first_level_children_count = sqrt(pow(2, _depth - 1)) * pow(children_per_frame, 1.0 / double(_depth)) + 0.5;
auto item = new ProfGraphicsItem(true); auto item = new ProfGraphicsItem(true);
item->setPos(0, 0); item->setPos(X_BEGIN, Y_BEGIN);
item->setLevels(_depth + 1); item->setLevels(_depth + 1);
item->reserve(0, _frames_number); item->reserve(0, _frames_number);
@ -589,36 +651,33 @@ void ProfGraphicsScene::test(size_t _frames_number, size_t _total_items_number_e
} }
size_t total_items = 0; size_t total_items = 0;
qreal x = 0, y = 0, h = 0; qreal x = X_BEGIN;
for (unsigned int i = 0; i < _frames_number; ++i) for (unsigned int i = 0; i < _frames_number; ++i)
{ {
size_t j = item->addItem(0); size_t j = item->addItem(0);
auto& b = item->getItem(0, j); auto& b = item->getItem(0, j);
b.color = toRgb(30 + rand() % 225, 30 + rand() % 225, 30 + rand() % 225); b.color = toRgb(30 + rand() % 225, 30 + rand() % 225, 30 + rand() % 225);
b.state = 0;
const auto& children = item->items(1); const auto& children = item->items(1);
b.children_begin = static_cast<unsigned int>(children.size()); b.children_begin = static_cast<unsigned int>(children.size());
fillChildren(item, 1, x, y + GRAPHICS_ROW_SIZE + 2, first_level_children_count, total_items); fillChildren(item, 1, x, Y_BEGIN + GRAPHICS_ROW_SIZE_FULL, first_level_children_count, total_items);
const auto& last = children.back(); const auto& last = children.back();
b.setRect(x, 0, last.right() - x, GRAPHICS_ROW_SIZE); b.setRect(x, Y_BEGIN, last.right() - x, GRAPHICS_ROW_SIZE);
b.totalHeight = GRAPHICS_ROW_SIZE + last.totalHeight + 2; b.totalHeight = GRAPHICS_ROW_SIZE_FULL + last.totalHeight;
x += b.width() + 500; x += b.width() + 500;
if (last.bottom() > h)
{
h = last.bottom();
}
++total_items; ++total_items;
} }
item->setBoundingRect(0, 0, x, item->getItem(0, 0).totalHeight); const auto h = item->getItem(0, 0).totalHeight;
item->setBoundingRect(0, 0, x - X_BEGIN, h);
addItem(item); addItem(item);
setSceneRect(0, 0, x, h); setSceneRect(0, 0, x, Y_BEGIN + h);
} }
#endif #endif
@ -635,7 +694,7 @@ void ProfGraphicsScene::setTree(const thread_blocks_tree_t& _blocksTree)
{ {
// calculate scene size and fill it with items // calculate scene size and fill it with items
::profiler::timestamp_t finish = 0; ::profiler::timestamp_t finish = 0;
qreal y = ROW_SPACING; qreal y = 0;// ROW_SPACING;
for (const auto& threadTree : _blocksTree) for (const auto& threadTree : _blocksTree)
{ {
const auto timestart = threadTree.second.children.front().node->block()->getBegin(); const auto timestart = threadTree.second.children.front().node->block()->getBegin();
@ -644,13 +703,19 @@ void ProfGraphicsScene::setTree(const thread_blocks_tree_t& _blocksTree)
if (finish < timefinish) finish = timefinish; if (finish < timefinish) finish = timefinish;
// fill scene with new items // fill scene with new items
qreal h = 0; qreal h = 0, x = time2position(timestart);
#if DRAW_METHOD == 0 #if DRAW_METHOD == 0
setTree(threadTree.second.children, h, y); setTree(threadTree.second.children, h, y);
#else #else
auto item = new ProfGraphicsItem(); auto item = new ProfGraphicsItem();
item->setLevels(threadTree.second.sublevels); item->setLevels(threadTree.second.depth);
//item->setPos(x, y);
const auto children_duration = setTree(item, threadTree.second.children, h, y, 0); const auto children_duration = setTree(item, threadTree.second.children, h, y, 0);
item->setBoundingRect(0, 0, children_duration, h);
item->setPos(x, y);
addItem(item); addItem(item);
#endif #endif
y += h + ROW_SPACING; y += h + ROW_SPACING;
@ -658,6 +723,13 @@ void ProfGraphicsScene::setTree(const thread_blocks_tree_t& _blocksTree)
const qreal endX = time2position(finish + 1000000); const qreal endX = time2position(finish + 1000000);
setSceneRect(0, 0, endX, y + ROW_SPACING); setSceneRect(0, 0, endX, y + ROW_SPACING);
auto rect = sceneRect();
auto itms = items();
for (auto item : itms)
{
static_cast<ProfGraphicsItem*>(item)->setBoundingRect(rect);
}
} }
qreal ProfGraphicsScene::setTree(const BlocksTree::children_t& _children, qreal& _height, qreal _y) qreal ProfGraphicsScene::setTree(const BlocksTree::children_t& _children, qreal& _height, qreal _y)
@ -721,7 +793,7 @@ qreal ProfGraphicsScene::setTree(const BlocksTree::children_t& _children, qreal&
#endif #endif
} }
qreal ProfGraphicsScene::setTree(ProfGraphicsItem* _item, const BlocksTree::children_t& _children, qreal& _height, qreal _y, unsigned int _level) qreal ProfGraphicsScene::setTree(ProfGraphicsItem* _item, const BlocksTree::children_t& _children, qreal& _height, qreal _y, unsigned short _level)
{ {
if (_children.empty()) if (_children.empty())
{ {
@ -732,7 +804,9 @@ qreal ProfGraphicsScene::setTree(ProfGraphicsItem* _item, const BlocksTree::chil
_item->reserve(_level, _children.size()); _item->reserve(_level, _children.size());
#endif #endif
const auto next_level = _level + 1;
qreal total_duration = 0, prev_end = 0, maxh = 0; qreal total_duration = 0, prev_end = 0, maxh = 0;
//size_t num = 0;
for (const auto& child : _children) for (const auto& child : _children)
{ {
qreal xbegin = time2position(child.node->block()->getBegin()); qreal xbegin = time2position(child.node->block()->getBegin());
@ -754,10 +828,20 @@ qreal ProfGraphicsScene::setTree(ProfGraphicsItem* _item, const BlocksTree::chil
auto i = _item->addItem(); auto i = _item->addItem();
#else #else
auto i = _item->addItem(_level); auto i = _item->addItem(_level);
auto& b = _item->getItem(_level, i);
if (next_level < _item->levels() && !child.children.empty())
{
b.children_begin = static_cast<unsigned int>(_item->items(next_level).size());
}
else
{
b.children_begin = -1;
}
#endif #endif
qreal h = 0; qreal h = 0;
const auto children_duration = setTree(_item, child.children, h, _y + GRAPHICS_ROW_SIZE_FULL, _level + 1); const auto children_duration = setTree(_item, child.children, h, _y + GRAPHICS_ROW_SIZE_FULL, next_level);
if (duration < children_duration) if (duration < children_duration)
{ {
duration = children_duration; duration = children_duration;
@ -771,17 +855,17 @@ qreal ProfGraphicsScene::setTree(ProfGraphicsItem* _item, const BlocksTree::chil
const auto color = child.node->block()->getColor(); const auto color = child.node->block()->getColor();
#if DRAW_METHOD == 0 #if DRAW_METHOD == 0
auto& b = _item->getItem(i); auto& b = _item->getItem(i);
#else
auto& b = _item->getItem(_level, i);
#endif #endif
b.block = &child; b.block = &child;
b.color = toRgb(::profiler::colors::get_red(color), ::profiler::colors::get_green(color), ::profiler::colors::get_blue(color)); b.color = toRgb(::profiler::colors::get_red(color), ::profiler::colors::get_green(color), ::profiler::colors::get_blue(color));
b.setRect(xbegin - _item->x(), _y - _item->y(), duration, GRAPHICS_ROW_SIZE); b.setRect(xbegin, _y, duration, GRAPHICS_ROW_SIZE);
b.totalHeight = GRAPHICS_ROW_SIZE + h; b.totalHeight = GRAPHICS_ROW_SIZE + h;
total_duration += duration; total_duration += duration;
prev_end = xbegin + duration; prev_end = xbegin + duration;
//if (_level == 0 && ++num > 20) break;
} }
_height += GRAPHICS_ROW_SIZE_FULL + maxh; _height += GRAPHICS_ROW_SIZE_FULL + maxh;

View File

@ -36,29 +36,33 @@
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define DRAW_METHOD 2 #define DRAW_METHOD 2
typedef float preal;
#pragma pack(push, 1) #pragma pack(push, 1)
struct ProfBlockItem struct ProfBlockItem
{ {
const BlocksTree* block; const BlocksTree* block;
preal x, y, w, h; qreal x;
float w;
float totalHeight; float y;
QRgb color; float h;
QRgb color;
#if DRAW_METHOD > 0 #if DRAW_METHOD > 0
unsigned int children_begin; unsigned int children_begin;
#endif
unsigned short totalHeight;
#if DRAW_METHOD > 0
char state;
#else #else
bool draw; bool state;
#endif #endif
void setRect(preal _x, preal _y, preal _w, preal _h); void setRect(qreal _x, float _y, float _w, float _h);
preal left() const; qreal left() const;
preal top() const; float top() const;
preal width() const; float width() const;
preal height() const; float height() const;
preal right() const; qreal right() const;
preal bottom() const; float bottom() const;
}; };
#pragma pack(pop) #pragma pack(pop)
@ -99,6 +103,7 @@ public:
size_t addItem(const ProfBlockItem& _item); size_t addItem(const ProfBlockItem& _item);
size_t addItem(ProfBlockItem&& _item); size_t addItem(ProfBlockItem&& _item);
#else #else
unsigned short levels() const;
void setLevels(unsigned short _levels); void setLevels(unsigned short _levels);
void reserve(unsigned short _level, size_t _items); void reserve(unsigned short _level, size_t _items);
const Children& items(unsigned short _level) const; const Children& items(unsigned short _level) const;
@ -140,7 +145,7 @@ private:
void setTree(const thread_blocks_tree_t& _blocksTree); void setTree(const thread_blocks_tree_t& _blocksTree);
qreal setTree(const BlocksTree::children_t& _children, qreal& _height, qreal _y); qreal setTree(const BlocksTree::children_t& _children, qreal& _height, qreal _y);
qreal setTree(ProfGraphicsItem* _item, const BlocksTree::children_t& _children, qreal& _height, qreal _y, unsigned int _level); qreal setTree(ProfGraphicsItem* _item, const BlocksTree::children_t& _children, qreal& _height, qreal _y, unsigned short _level);
inline qreal time2position(const profiler::timestamp_t& _time) const inline qreal time2position(const profiler::timestamp_t& _time) const
{ {

View File

@ -272,16 +272,51 @@ extern "C"{
for (auto& child : tree.children) for (auto& child : tree.children)
{ {
#ifdef PROFILER_COUNT_TOTAL_CHILDREN_NUMBER
tree.total_children_number += child.total_children_number; tree.total_children_number += child.total_children_number;
#endif
update_statistics(frame_statistics, child.node, child.frame_statistics); update_statistics(frame_statistics, child.node, child.frame_statistics);
if (tree.sublevels < child.sublevels)
tree.sublevels = child.sublevels; #ifdef PROFILER_COUNT_DEPTH
if (tree.depth < child.depth)
tree.depth = child.depth;
#endif
} }
#ifdef PROFILER_COUNT_TOTAL_CHILDREN_NUMBER
tree.total_children_number += static_cast<unsigned int>(tree.children.size()); tree.total_children_number += static_cast<unsigned int>(tree.children.size());
++tree.sublevels; #endif
#ifdef PROFILER_COUNT_DEPTH
++tree.depth;
#endif
}
#if defined(PROFILER_COUNT_TOTAL_CHILDREN_NUMBER) || defined(PROFILER_COUNT_DEPTH)
else
{
for (auto& child : tree.children)
{
#ifdef PROFILER_COUNT_TOTAL_CHILDREN_NUMBER
tree.total_children_number += child.total_children_number;
#endif
#ifdef PROFILER_COUNT_DEPTH
if (tree.depth < child.depth)
tree.depth = child.depth;
#endif
}
#ifdef PROFILER_COUNT_TOTAL_CHILDREN_NUMBER
tree.total_children_number += static_cast<unsigned int>(tree.children.size());
#endif
#ifdef PROFILER_COUNT_DEPTH
++tree.depth;
#endif
} }
} }
#endif
} }
root.children.push_back(std::move(tree)); root.children.push_back(std::move(tree));
@ -299,6 +334,7 @@ extern "C"{
} }
} }
PROFILER_BEGIN_BLOCK("Gather statistic for roots") PROFILER_BEGIN_BLOCK("Gather statistic for roots")
if (gather_statistics) if (gather_statistics)
{ {
@ -309,15 +345,28 @@ extern "C"{
frame_statistics.clear(); frame_statistics.clear();
for (auto& frame : root.children) for (auto& frame : root.children)
{ {
#ifdef PROFILER_COUNT_TOTAL_CHILDREN_NUMBER
root.total_children_number += frame.total_children_number; root.total_children_number += frame.total_children_number;
#endif
update_statistics(frame_statistics, frame.node, frame.frame_statistics); update_statistics(frame_statistics, frame.node, frame.frame_statistics);
if (root.sublevels < frame.sublevels)
root.sublevels = frame.sublevels; #ifdef PROFILER_COUNT_DEPTH
if (root.depth < frame.depth)
root.depth = frame.depth;
#endif
} }
#ifdef PROFILER_COUNT_TOTAL_CHILDREN_NUMBER
root.total_children_number += static_cast<unsigned int>(root.children.size()); root.total_children_number += static_cast<unsigned int>(root.children.size());
++root.sublevels; #endif
#ifdef PROFILER_COUNT_DEPTH
++root.depth;
#endif
} }
} }
#if defined(PROFILER_COUNT_TOTAL_CHILDREN_NUMBER) || defined(PROFILER_COUNT_DEPTH)
else else
{ {
for (auto& root_value : threaded_trees) for (auto& root_value : threaded_trees)
@ -325,14 +374,26 @@ extern "C"{
auto& root = root_value.second; auto& root = root_value.second;
for (auto& frame : root.children) for (auto& frame : root.children)
{ {
#ifdef PROFILER_COUNT_TOTAL_CHILDREN_NUMBER
root.total_children_number += frame.total_children_number; root.total_children_number += frame.total_children_number;
if (root.sublevels < frame.sublevels) #endif
root.sublevels = frame.sublevels;
#ifdef PROFILER_COUNT_DEPTH
if (root.depth < frame.depth)
root.depth = frame.depth;
#endif
} }
#ifdef PROFILER_COUNT_TOTAL_CHILDREN_NUMBER
root.total_children_number += static_cast<unsigned int>(root.children.size()); root.total_children_number += static_cast<unsigned int>(root.children.size());
++root.sublevels; #endif
#ifdef PROFILER_COUNT_DEPTH
++root.depth;
#endif
} }
} }
#endif
PROFILER_END_BLOCK PROFILER_END_BLOCK
// No need to delete BlockStatistics instances - they will be deleted inside BlocksTree destructors // No need to delete BlockStatistics instances - they will be deleted inside BlocksTree destructors