Skip to content

Commit c055690

Browse files
committed
More tests
1 parent eb5febc commit c055690

6 files changed

Lines changed: 586 additions & 14 deletions

File tree

modules/yup_gui/component/yup_Component.cpp

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,15 +1210,10 @@ String Component::getPaintProfileName() const
12101210
return "Component";
12111211
}
12121212

1213-
//==============================================================================
1213+
thread_local std::vector<PaintProfileScopeEntry> Component::paintProfileScopeStack {};
1214+
std::atomic<uint64> Component::globalPaintIndexCounter { 0 };
12141215

1215-
struct PaintProfileScopeEntry
1216-
{
1217-
double childrenMicros = 0.0;
1218-
};
1219-
1220-
thread_local std::vector<PaintProfileScopeEntry> paintProfileScopeStack;
1221-
static std::atomic<uint64> globalPaintIndexCounter { 0 };
1216+
//==============================================================================
12221217

12231218
class PaintProfileScope
12241219
{
@@ -1233,20 +1228,20 @@ class PaintProfileScope
12331228
, selfStartMicros (0.0)
12341229
{
12351230
sample.frameIndex = frameIndex;
1236-
sample.paintIndex = globalPaintIndexCounter.fetch_add (1, std::memory_order_relaxed);
1231+
sample.paintIndex = Component::globalPaintIndexCounter.fetch_add (1, std::memory_order_relaxed);
12371232
sample.repaintArea = repaintArea;
12381233
sample.componentBounds = component.getBoundsRelativeToTopLevelComponent().to<float>();
12391234
sample.renderContinuous = renderContinuous;
12401235

1241-
paintProfileScopeStack.push_back ({});
1236+
Component::paintProfileScopeStack.push_back ({});
12421237
}
12431238

12441239
~PaintProfileScope()
12451240
{
12461241
const double totalEndMicros = ticksToMicros (Time::getHighResolutionTicks());
12471242
sample.totalMicros = totalEndMicros - totalStartMicros;
1248-
sample.childrenMicros = paintProfileScopeStack.back().childrenMicros;
1249-
paintProfileScopeStack.pop_back();
1243+
sample.childrenMicros = Component::paintProfileScopeStack.back().childrenMicros;
1244+
Component::paintProfileScopeStack.pop_back();
12501245

12511246
sample.frameworkMicros = std::max (0.0,
12521247
sample.totalMicros
@@ -1256,8 +1251,8 @@ class PaintProfileScope
12561251
if (auto* stats = component.getPaintProfileStats())
12571252
stats->recordSample (sample);
12581253

1259-
if (! paintProfileScopeStack.empty())
1260-
paintProfileScopeStack.back().childrenMicros += sample.totalMicros;
1254+
if (! Component::paintProfileScopeStack.empty())
1255+
Component::paintProfileScopeStack.back().childrenMicros += sample.totalMicros;
12611256
}
12621257

12631258
void beginSelf()

modules/yup_gui/component/yup_Component.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,7 +1351,10 @@ class YUP_API Component : public MouseListener
13511351
#endif
13521352

13531353
#if YUP_ENABLE_COMPONENT_PAINT_PROFILING
1354+
friend class PaintProfileScope;
13541355
std::unique_ptr<PaintProfileStats> paintProfileStats;
1356+
static thread_local std::vector<PaintProfileScopeEntry> paintProfileScopeStack;
1357+
static std::atomic<uint64> globalPaintIndexCounter;
13551358
#endif
13561359

13571360
YUP_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Component)

modules/yup_gui/profiling/yup_PaintProfileSample.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,21 @@ struct PaintProfileSummary
135135

136136
//==============================================================================
137137

138+
/** A struct used to track the cumulative child time of nested paint calls in the current call stack.
139+
140+
This is stored in a thread_local stack in Component, and each PaintProfileScope pushes a new entry on
141+
construction and pops it on destruction. The self time of a scope is accumulated separately, and the total
142+
time of the scope is added to the parent's childrenMicros when the scope ends, so that the sum of selfMicros
143+
and childrenMicros for a parent scope equals the total time spent in that subtree of the paint call graph.
144+
*/
145+
struct PaintProfileScopeEntry
146+
{
147+
/** Cumulative time spent in child paint calls for the current scope. */
148+
double childrenMicros = 0.0;
149+
};
150+
151+
//==============================================================================
152+
138153
/** A linear histogram of sample values for a single PaintProfileTimeKind field.
139154
140155
The range [rangeMinMicros, rangeMaxMicros] is divided into buckets.size() equal-width

tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ yup_standalone_app (
123123
TARGET_CONSOLE ${target_console}
124124
DEFINITIONS
125125
YUP_USE_CURL=0
126+
YUP_ENABLE_COMPONENT_PAINT_PROFILING=1
126127
YUP_MODAL_LOOPS_PERMITTED=1
127128
PRELOAD_FILES
128129
${target_preloaded}

tests/yup_gui.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "yup_gui/yup_FileChooser.cpp"
2727
#include "yup_gui/yup_Label.cpp"
2828
#include "yup_gui/yup_ListBox.cpp"
29+
#include "yup_gui/yup_PaintProfiler.cpp"
2930
#include "yup_gui/yup_PopupMenu.cpp"
3031
#include "yup_gui/yup_ProgressBar.cpp"
3132
#include "yup_gui/yup_ScrollBar.cpp"

0 commit comments

Comments
 (0)