Skip to content

Commit bf7bf10

Browse files
committed
(GUI) Less buggy and more efficient recursive painting algorithm for blocks at diagram. Test mode.
Note: with recursive algorithm it is possible to iterate through blocks in parallel to make painting just more efficient - this is my future todo
1 parent 5a14887 commit bf7bf10

File tree

5 files changed

+516
-160
lines changed

5 files changed

+516
-160
lines changed

profiler_gui/blocks_graphics_view.cpp

+19-4
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,8 @@ void EasyGraphicsView::setTree(const ::profiler::thread_blocks_tree_t& _blocksTr
479479

480480
if (!t.children.empty())
481481
{
482-
children_duration = setTree(item, t.children, h, y, 0);
482+
uint32_t dummy = 0;
483+
children_duration = setTree(item, t.children, h, dummy, y, 0);
483484
}
484485
else
485486
{
@@ -551,7 +552,7 @@ const EasyGraphicsView::Items &EasyGraphicsView::getItems() const
551552
return m_items;
552553
}
553554

554-
qreal EasyGraphicsView::setTree(EasyGraphicsItem* _item, const ::profiler::BlocksTree::children_t& _children, qreal& _height, qreal _y, short _level)
555+
qreal EasyGraphicsView::setTree(EasyGraphicsItem* _item, const ::profiler::BlocksTree::children_t& _children, qreal& _height, uint32_t& _maxDepthChild, qreal _y, short _level)
555556
{
556557
if (_children.empty())
557558
{
@@ -562,6 +563,8 @@ qreal EasyGraphicsView::setTree(EasyGraphicsItem* _item, const ::profiler::Block
562563
const auto n = static_cast<unsigned int>(_children.size());
563564
_item->reserve(level, n);
564565

566+
_maxDepthChild = 0;
567+
uint16_t maxDepth = 0;
565568
const short next_level = _level + 1;
566569
bool warned = false;
567570
qreal total_duration = 0, prev_end = 0, maxh = 0;
@@ -571,6 +574,11 @@ qreal EasyGraphicsView::setTree(EasyGraphicsItem* _item, const ::profiler::Block
571574
{
572575
auto& gui_block = easyBlock(child_index);
573576
const auto& child = gui_block.tree;
577+
if (child.depth > maxDepth)
578+
{
579+
maxDepth = child.depth;
580+
_maxDepthChild = j;
581+
}
574582

575583
auto xbegin = time2position(child.node->begin());
576584
if (start_time < 0)
@@ -609,10 +617,11 @@ qreal EasyGraphicsView::setTree(EasyGraphicsItem* _item, const ::profiler::Block
609617

610618
qreal h = 0;
611619
qreal children_duration = 0;
620+
uint32_t maxDepthChild = 0;
612621

613622
if (next_level < 256)
614623
{
615-
children_duration = setTree(_item, child.children, h, _y + ::profiler_gui::GRAPHICS_ROW_SIZE_FULL, next_level);
624+
children_duration = setTree(_item, child.children, h, maxDepthChild, _y + ::profiler_gui::GRAPHICS_ROW_SIZE_FULL, next_level);
616625
}
617626
else if (!child.children.empty() && !warned)
618627
{
@@ -631,10 +640,16 @@ qreal EasyGraphicsView::setTree(EasyGraphicsItem* _item, const ::profiler::Block
631640
}
632641

633642
b.block = child_index;// &child;
643+
644+
#ifndef EASY_GRAPHICS_ITEM_RECURSIVE_PAINT
634645
b.neighbours = n;
646+
b.state = j > 0 || level == 0 ? 0 : -1;
647+
#else
648+
b.max_depth_child = maxDepthChild;
649+
#endif
650+
635651
b.setPos(xbegin, duration);
636652
//b.totalHeight = ::profiler_gui::GRAPHICS_ROW_SIZE + h;
637-
b.state = j > 0 || level == 0 ? 0 : -1;
638653

639654
prev_end = xbegin + duration;
640655
total_duration = prev_end - start_time;

profiler_gui/blocks_graphics_view.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ class EasyGraphicsView : public QGraphicsView
193193
void scaleTo(qreal _scale);
194194
void scrollTo(const EasyGraphicsItem* _item);
195195
void onWheel(qreal _mouseX, int _wheelDelta);
196-
qreal setTree(EasyGraphicsItem* _item, const ::profiler::BlocksTree::children_t& _children, qreal& _height, qreal _y, short _level);
196+
qreal setTree(EasyGraphicsItem* _item, const ::profiler::BlocksTree::children_t& _children, qreal& _height, uint32_t& _maxDepthChild, qreal _y, short _level);
197197

198198
private slots:
199199

profiler_gui/common_types.h

+9
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,24 @@ inline ::profiler::color_t textColorForRgb(::profiler::color_t _color)
152152

153153
//////////////////////////////////////////////////////////////////////////
154154

155+
#define EASY_GRAPHICS_ITEM_RECURSIVE_PAINT
156+
//#undef EASY_GRAPHICS_ITEM_RECURSIVE_PAINT
157+
155158
#pragma pack(push, 1)
156159
struct EasyBlockItem Q_DECL_FINAL
157160
{
158161
qreal x; ///< x coordinate of the item (this is made qreal=double to avoid mistakes on very wide scene)
159162
float w; ///< Width of the item
160163
::profiler::block_index_t block; ///< Index of profiler block
164+
165+
#ifndef EASY_GRAPHICS_ITEM_RECURSIVE_PAINT
161166
::profiler::block_index_t neighbours; ///< Number of neighbours (parent.children.size())
162167
uint32_t children_begin; ///< Index of first child item on the next sublevel
163168
int8_t state; ///< 0 = no change, 1 = paint, -1 = do not paint
169+
#else
170+
::profiler::block_index_t max_depth_child; ///< Index of child with maximum tree depth
171+
uint32_t children_begin; ///< Index of first child item on the next sublevel
172+
#endif
164173

165174
// Possible optimizations:
166175
// 1) We can save 1 more byte per block if we will use char instead of short + real time calculations for "totalHeight" var;

0 commit comments

Comments
 (0)