Skip to content

Commit d12084c

Browse files
committed
run clang-format (so CI can pass)
1 parent 0d5d6bf commit d12084c

File tree

4 files changed

+244
-186
lines changed

4 files changed

+244
-186
lines changed

AUTHORS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
# following the format reported by `git shortlog -sen | cut -f 2`.
33

44
Sean Moore <sean@219design.com>
5-
5+
mhoffman <mhoffman@219design.com>
6+
pestophagous <pestophagous@gmail.com>

src/util/performance_counter.cc

Lines changed: 152 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -4,105 +4,137 @@
44

55
#include <QQmlContext>
66

7-
namespace project {
8-
9-
PerformanceCounter::PerformanceCounter(QObject* parent, QQuickWindow* window) : QObject(parent), m_window(window) {
10-
11-
}
12-
13-
void PerformanceCounter::ExportContextPropertiesToQml( QQmlEngine* engine) {
14-
engine->rootContext()->setContextProperty( "performanceCounter", this );
7+
namespace project
8+
{
9+
PerformanceCounter::PerformanceCounter( QObject* parent, QQuickWindow* window )
10+
: QObject( parent ), m_window( window )
11+
{
12+
}
13+
14+
void PerformanceCounter::ExportContextPropertiesToQml( QQmlEngine* engine )
15+
{
16+
engine->rootContext()->setContextProperty( "performanceCounter", this );
17+
}
18+
19+
void PerformanceCounter::ConnectToWindowIfNecessary()
20+
{
21+
if( m_connectedToWindow )
22+
{
23+
return;
1524
}
16-
17-
void PerformanceCounter::ConnectToWindowIfNecessary() {
18-
if (m_connectedToWindow) {
25+
connect( m_window, &QQuickWindow::afterAnimating, this, &PerformanceCounter::AfterAnimating );
26+
connect( m_window, &QQuickWindow::beforeRendering, this, &PerformanceCounter::BeforeRendering );
27+
connect( m_window, &QQuickWindow::afterRendering, this, &PerformanceCounter::AfterRendering );
28+
}
29+
30+
void PerformanceCounter::StartReport( const QString& name )
31+
{
32+
for( auto& reportRequest : m_reports )
33+
{
34+
if( reportRequest.m_name.data() == nullptr )
35+
{
36+
reportRequest = ReportRequest( name );
1937
return;
2038
}
21-
connect(m_window, &QQuickWindow::afterAnimating, this, &PerformanceCounter::AfterAnimating);
22-
connect(m_window, &QQuickWindow::beforeRendering, this, &PerformanceCounter::BeforeRendering);
23-
connect(m_window, &QQuickWindow::afterRendering, this, &PerformanceCounter::AfterRendering);
2439
}
25-
26-
void PerformanceCounter::StartReport(const QString& name) {
27-
for (auto& reportRequest : m_reports) {
28-
if (reportRequest.m_name.data() == nullptr) {
29-
reportRequest = ReportRequest(name);
30-
return;
31-
}
40+
}
41+
42+
void PerformanceCounter::AfterAnimating()
43+
{
44+
for( auto& reportRequest : m_reports )
45+
{
46+
reportRequest.Synchronize();
47+
if( reportRequest.m_report.has_value() )
48+
{
49+
reportRequest.m_report->GetFrameReportToWriteInto().m_afterAnimating = static_cast<qint32>( reportRequest.m_timer.elapsed() );
3250
}
3351
}
34-
35-
void PerformanceCounter::AfterAnimating() {
36-
for (auto& reportRequest : m_reports) {
37-
reportRequest.Synchronize();
38-
if (reportRequest.m_report.has_value()) {
39-
reportRequest.m_report->GetFrameReportToWriteInto().m_afterAnimating = static_cast<qint32>(reportRequest.m_timer.elapsed());
40-
}
52+
}
53+
54+
void PerformanceCounter::BeforeRendering()
55+
{
56+
for( auto& reportRequest : m_reports )
57+
{
58+
if( reportRequest.m_report.has_value() )
59+
{
60+
reportRequest.m_report->GetFrameReportToWriteInto().m_beforeRendering = static_cast<qint32>( reportRequest.m_timer.elapsed() );
4161
}
4262
}
43-
44-
void PerformanceCounter::BeforeRendering() {
45-
for (auto& reportRequest : m_reports) {
46-
if (reportRequest.m_report.has_value()) {
47-
reportRequest.m_report->GetFrameReportToWriteInto().m_beforeRendering = static_cast<qint32>(reportRequest.m_timer.elapsed());
63+
}
64+
65+
void PerformanceCounter::AfterRendering()
66+
{
67+
for( auto& reportRequest : m_reports )
68+
{
69+
if( reportRequest.m_report.has_value() )
70+
{
71+
reportRequest.m_report->GetFrameReportToWriteInto().m_beforeRendering = static_cast<qint32>( reportRequest.m_timer.elapsed() );
72+
reportRequest.m_report->FinishFrame();
73+
if( reportRequest.m_requestedToStopRenderThread )
74+
{
75+
reportRequest.Finalize();
4876
}
4977
}
5078
}
51-
52-
void PerformanceCounter::AfterRendering() {
53-
for (auto& reportRequest : m_reports) {
54-
if (reportRequest.m_report.has_value()) {
55-
reportRequest.m_report->GetFrameReportToWriteInto().m_beforeRendering = static_cast<qint32>(reportRequest.m_timer.elapsed());
56-
reportRequest.m_report->FinishFrame();
57-
if (reportRequest.m_requestedToStopRenderThread) {
58-
reportRequest.Finalize();
59-
}
60-
}
61-
}
62-
}
63-
64-
ReportRequest::ReportRequest() : m_name(), m_timer() {}
65-
ReportRequest::ReportRequest(QString name) : m_name(name), m_timer() {
79+
}
80+
81+
ReportRequest::ReportRequest()
82+
: m_name(), m_timer()
83+
{
84+
}
85+
ReportRequest::ReportRequest( QString name )
86+
: m_name( name ), m_timer()
87+
{
6688
m_timer.start();
67-
}
68-
69-
// Called automatically from the GUI thread while the render thread is waiting
70-
void ReportRequest::Synchronize() {
71-
if (m_finalized) {
72-
*this = ReportRequest();
73-
} else {
74-
if ((m_name.data() != nullptr) && !m_report.has_value()) {
75-
m_report.emplace();
76-
}
77-
m_requestedToStopRenderThread = m_requestedToStopGUIThread;
89+
}
90+
91+
// Called automatically from the GUI thread while the render thread is waiting
92+
void ReportRequest::Synchronize()
93+
{
94+
if( m_finalized )
95+
{
96+
*this = ReportRequest();
97+
}
98+
else
99+
{
100+
if( ( m_name.data() != nullptr ) && !m_report.has_value() )
101+
{
102+
m_report.emplace();
103+
}
104+
m_requestedToStopRenderThread = m_requestedToStopGUIThread;
78105
}
79-
}
106+
}
80107

81-
// Called by users from GUI thread
82-
void ReportRequest::RequestStop() {
108+
// Called by users from GUI thread
109+
void ReportRequest::RequestStop()
110+
{
83111
m_requestedToStopGUIThread = true;
84-
}
112+
}
85113

86-
// Called automatically from the render thread
87-
void ReportRequest::Finalize() {
114+
// Called automatically from the render thread
115+
void ReportRequest::Finalize()
116+
{
88117
ExportReport();
89118
m_finalized = true;
90-
}
119+
}
91120

92-
struct MinMax {
93-
qint32 m_min = std::numeric_limits < qint32 >::max();
94-
qint32 m_max = std::numeric_limits < qint32 >::min();
121+
struct MinMax
122+
{
123+
qint32 m_min = std::numeric_limits<qint32>::max();
124+
qint32 m_max = std::numeric_limits<qint32>::min();
95125

96-
void Update(qint32 val) {
97-
m_min = std::min(m_min, val);
98-
m_max = std::max(m_max, val);
126+
void Update( qint32 val )
127+
{
128+
m_min = std::min( m_min, val );
129+
m_max = std::max( m_max, val );
99130
}
100-
};
131+
};
101132

102-
void ReportRequest::ExportReport() {
133+
void ReportRequest::ExportReport()
134+
{
103135
auto log = qDebug();
104136
log = log << "Exporting report for: " << m_name << Qt::endl;
105-
log = log << Qt::right << qSetFieldWidth(3);
137+
log = log << Qt::right << qSetFieldWidth( 3 );
106138
qint32 previousGuiUpdate = 0;
107139
qint32 previousRenderFinish = 0;
108140

@@ -111,51 +143,56 @@ namespace project {
111143
MinMax synchronizingExtents;
112144
MinMax renderingExtents;
113145

114-
for (const FrameReport& frame : m_report->m_backloggedFrames) {
115-
qint32 guiFrameDuration = frame.m_afterAnimating - previousGuiUpdate;
116-
previousGuiUpdate = frame.m_afterAnimating;
117-
qint32 renderFrameDuration = frame.m_afterRendering - previousRenderFinish;
118-
previousRenderFinish = frame.m_afterRendering;
119-
qint32 synchronizing = frame.m_beforeRendering - frame.m_afterAnimating;
120-
qint32 rendering = frame.m_afterRendering - frame.m_beforeRendering;
121-
log << synchronizing << ", " << rendering << ", " << guiFrameDuration << ", " << renderFrameDuration;
122-
guiFrameDurationExtents.Update(guiFrameDuration);
123-
renderFrameDurationExtents.Update(renderFrameDuration);
124-
synchronizingExtents.Update(synchronizing);
125-
renderingExtents.Update(rendering);
146+
for( const FrameReport& frame : m_report->m_backloggedFrames )
147+
{
148+
qint32 guiFrameDuration = frame.m_afterAnimating - previousGuiUpdate;
149+
previousGuiUpdate = frame.m_afterAnimating;
150+
qint32 renderFrameDuration = frame.m_afterRendering - previousRenderFinish;
151+
previousRenderFinish = frame.m_afterRendering;
152+
qint32 synchronizing = frame.m_beforeRendering - frame.m_afterAnimating;
153+
qint32 rendering = frame.m_afterRendering - frame.m_beforeRendering;
154+
log << synchronizing << ", " << rendering << ", " << guiFrameDuration << ", " << renderFrameDuration;
155+
guiFrameDurationExtents.Update( guiFrameDuration );
156+
renderFrameDurationExtents.Update( renderFrameDuration );
157+
synchronizingExtents.Update( synchronizing );
158+
renderingExtents.Update( rendering );
126159
}
127-
for (size_t i = 0; i < m_report->m_framesFilledCount; i++) {
128-
const FrameReport& frame = m_report->m_frames[i];
129-
qint32 guiFrameDuration = frame.m_afterAnimating - previousGuiUpdate;
130-
previousGuiUpdate = frame.m_afterAnimating;
131-
qint32 renderFrameDuration = frame.m_afterRendering - previousRenderFinish;
132-
previousRenderFinish = frame.m_afterRendering;
133-
qint32 synchronizing = frame.m_beforeRendering - frame.m_afterAnimating;
134-
qint32 rendering = frame.m_afterRendering - frame.m_beforeRendering;
135-
log << synchronizing << ", " << rendering << ", " << guiFrameDuration << ", " << renderFrameDuration;
136-
guiFrameDurationExtents.Update(guiFrameDuration);
137-
renderFrameDurationExtents.Update(renderFrameDuration);
138-
synchronizingExtents.Update(synchronizing);
139-
renderingExtents.Update(rendering);
160+
for( size_t i = 0; i < m_report->m_framesFilledCount; i++ )
161+
{
162+
const FrameReport& frame = m_report->m_frames[ i ];
163+
qint32 guiFrameDuration = frame.m_afterAnimating - previousGuiUpdate;
164+
previousGuiUpdate = frame.m_afterAnimating;
165+
qint32 renderFrameDuration = frame.m_afterRendering - previousRenderFinish;
166+
previousRenderFinish = frame.m_afterRendering;
167+
qint32 synchronizing = frame.m_beforeRendering - frame.m_afterAnimating;
168+
qint32 rendering = frame.m_afterRendering - frame.m_beforeRendering;
169+
log << synchronizing << ", " << rendering << ", " << guiFrameDuration << ", " << renderFrameDuration;
170+
guiFrameDurationExtents.Update( guiFrameDuration );
171+
renderFrameDurationExtents.Update( renderFrameDuration );
172+
synchronizingExtents.Update( synchronizing );
173+
renderingExtents.Update( rendering );
140174
}
141175

142176
log << "GUI Frame Duration Extents " << guiFrameDurationExtents.m_min << ", " << guiFrameDurationExtents.m_max;
143177
log << "Render Frame Duration Extents " << renderFrameDurationExtents.m_min << ", " << renderFrameDurationExtents.m_max;
144178
log << "Synchronizing Extents " << synchronizingExtents.m_min << ", " << synchronizingExtents.m_max;
145179
log << "Rendering Extents " << renderingExtents.m_min << ", " << renderingExtents.m_max;
146-
}
147-
148-
FrameReport& Report::GetFrameReportToWriteInto() {
149-
return m_frames[m_framesFilledCount];
150-
}
151-
152-
void Report::FinishFrame() {
153-
m_framesFilledCount++;
154-
if (m_framesFilledCount == m_frames.size()) {
155-
size_t currentBacklogSize = m_backloggedFrames.size();
156-
m_backloggedFrames.resize(currentBacklogSize + m_frames.size());
157-
memcpy(m_frames.data(), m_backloggedFrames.data() + currentBacklogSize, sizeof(FrameReport) * m_frames.size());
158-
m_framesFilledCount = 0;
159-
}
180+
}
181+
182+
FrameReport& Report::GetFrameReportToWriteInto()
183+
{
184+
return m_frames[ m_framesFilledCount ];
185+
}
186+
187+
void Report::FinishFrame()
188+
{
189+
m_framesFilledCount++;
190+
if( m_framesFilledCount == m_frames.size() )
191+
{
192+
size_t currentBacklogSize = m_backloggedFrames.size();
193+
m_backloggedFrames.resize( currentBacklogSize + m_frames.size() );
194+
memcpy( m_frames.data(), m_backloggedFrames.data() + currentBacklogSize, sizeof( FrameReport ) * m_frames.size() );
195+
m_framesFilledCount = 0;
160196
}
161-
}
197+
}
198+
} // namespace project

0 commit comments

Comments
 (0)