Skip to content

Commit c84ca32

Browse files
committed
Added timer to more node types.
1 parent 9880d03 commit c84ca32

7 files changed

Lines changed: 205 additions & 78 deletions

File tree

‎include/react/common/Timing.h‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ class ConditionalTimer
6161
class ScopedTimer
6262
{
6363
public:
64-
ScopedTimer(const ConditionalTimer&);
64+
// Note:
65+
// Count is passed by ref so it can be set later if it's not known at time of creation
66+
ScopedTimer(const ConditionalTimer&, const size_t& count);
6567
};
6668

6769
bool IsThresholdExceeded() const;
@@ -79,7 +81,7 @@ class ConditionalTimer<threshold,false>
7981
class ScopedTimer
8082
{
8183
public:
82-
ScopedTimer(const ConditionalTimer&) {}
84+
ScopedTimer(const ConditionalTimer&, const size_t& count) {}
8385
};
8486

8587
bool IsThresholdExceeded() const { return false; }
@@ -103,8 +105,9 @@ class ConditionalTimer<threshold,true>
103105
class ScopedTimer
104106
{
105107
public:
106-
ScopedTimer(ConditionalTimer& parent) :
107-
parent_( parent )
108+
ScopedTimer(ConditionalTimer& parent, const size_t& count) :
109+
parent_( parent ),
110+
count_( count )
108111
{
109112
if (!parent_.shouldMeasure_)
110113
return;
@@ -139,18 +142,19 @@ class ConditionalTimer<threshold,true>
139142
durationUS.QuadPart *= 1000000;
140143
durationUS.QuadPart /= GetPerformanceFrequency().QuadPart;
141144

142-
parent_.isThresholdExceeded_ = durationUS.QuadPart > threshold;
145+
parent_.isThresholdExceeded_ = durationUS.QuadPart > (threshold * count_);
143146
#else
144147
using std::chrono::duration_cast;
145148
using std::chrono::microseconds;
146149

147150
parent_.isThresholdExceeded_ =
148-
duration_cast<microseconds>(now() - startTime_).count() > threshold;
151+
duration_cast<microseconds>(now() - startTime_).count() > (threshold * count_);
149152
#endif
150153
}
151154

152155
ConditionalTimer& parent_;
153156
TimestampT startTime_;
157+
const size_t& count_;
154158
};
155159

156160
static TimestampT now()

‎include/react/detail/graph/AlgorithmNodes.h‎

Lines changed: 79 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ template
2929
typename E,
3030
typename TFunc
3131
>
32-
class IterateNode : public SignalNode<D,S>
32+
class IterateNode :
33+
public SignalNode<D,S>,
34+
public UpdateTimingPolicy<D,500>
3335
{
3436
using Engine = typename IterateNode::Engine;
3537

@@ -58,26 +60,40 @@ class IterateNode : public SignalNode<D,S>
5860
REACT_LOG(D::Log().template Append<NodeEvaluateBeginEvent>(
5961
GetObjectId(*this), turn.Id()));
6062

61-
S newValue = this->value_;
62-
for (const auto& e : events_->Events())
63-
newValue = func_(e, newValue);
63+
bool changed = false;
64+
65+
{// timer
66+
using TimerT = typename IterateNode::ScopedUpdateTimer;
67+
TimerT scopedTimer( *this, events_->Events().size() );
68+
69+
S newValue = this->value_;
70+
71+
for (const auto& e : events_->Events())
72+
newValue = func_(e, newValue);
73+
74+
if (! Equals(newValue, this->value_))
75+
{
76+
this->value_ = std::move(newValue);
77+
changed = true;
78+
}
79+
}// ~timer
6480

6581
REACT_LOG(D::Log().template Append<NodeEvaluateEndEvent>(
6682
GetObjectId(*this), turn.Id()));
6783

68-
if (! Equals(newValue, this->value_))
69-
{
70-
this->value_ = std::move(newValue);
84+
if (changed)
7185
Engine::OnNodePulse(*this, turn);
72-
}
7386
else
74-
{
7587
Engine::OnNodeIdlePulse(*this, turn);
76-
}
7788
}
7889

79-
virtual const char* GetNodeType() const override { return "IterateNode"; }
80-
virtual int DependencyCount() const override { return 1; }
90+
virtual const char* GetNodeType() const override { return "IterateNode"; }
91+
virtual int DependencyCount() const override { return 1; }
92+
93+
virtual bool IsHeavyweight() const override
94+
{
95+
return this->IsUpdateThresholdExceeded();
96+
}
8197

8298
private:
8399
std::shared_ptr<EventStreamNode<D,E>> events_;
@@ -95,7 +111,9 @@ template
95111
typename E,
96112
typename TFunc
97113
>
98-
class IterateByRefNode : public SignalNode<D,S>
114+
class IterateByRefNode :
115+
public SignalNode<D,S>,
116+
public UpdateTimingPolicy<D,500>
99117
{
100118
using Engine = typename IterateByRefNode::Engine;
101119

@@ -124,8 +142,13 @@ class IterateByRefNode : public SignalNode<D,S>
124142
REACT_LOG(D::Log().template Append<NodeEvaluateBeginEvent>(
125143
GetObjectId(*this), turn.Id()));
126144

127-
for (const auto& e : events_->Events())
128-
func_(e, this->value_);
145+
{// timer
146+
using TimerT = typename IterateByRefNode::ScopedUpdateTimer;
147+
TimerT scopedTimer( *this, events_->Events().size() );
148+
149+
for (const auto& e : events_->Events())
150+
func_(e, this->value_);
151+
}// ~timer
129152

130153
REACT_LOG(D::Log().template Append<NodeEvaluateEndEvent>(
131154
GetObjectId(*this), turn.Id()));
@@ -137,6 +160,11 @@ class IterateByRefNode : public SignalNode<D,S>
137160
virtual const char* GetNodeType() const override { return "IterateByRefNode"; }
138161
virtual int DependencyCount() const override { return 1; }
139162

163+
virtual bool IsHeavyweight() const override
164+
{
165+
return this->IsUpdateThresholdExceeded();
166+
}
167+
140168
protected:
141169
TFunc func_;
142170

@@ -154,7 +182,9 @@ template
154182
typename TFunc,
155183
typename ... TDepValues
156184
>
157-
class SyncedIterateNode : public SignalNode<D,S>
185+
class SyncedIterateNode :
186+
public SignalNode<D,S>,
187+
public UpdateTimingPolicy<D,500>
158188
{
159189
using Engine = typename SyncedIterateNode::Engine;
160190

@@ -215,7 +245,10 @@ class SyncedIterateNode : public SignalNode<D,S>
215245
GetObjectId(*this), turn.Id()));
216246

217247
if (! events_->Events().empty())
218-
{
248+
{// timer
249+
using TimerT = typename SyncedIterateNode::ScopedUpdateTimer;
250+
TimerT scopedTimer( *this, events_->Events().size() );
251+
219252
S newValue = this->value_;
220253

221254
for (const auto& e : events_->Events())
@@ -226,7 +259,7 @@ class SyncedIterateNode : public SignalNode<D,S>
226259
changed = true;
227260
this->value_ = std::move(newValue);
228261
}
229-
}
262+
}// ~timer
230263

231264
REACT_LOG(D::Log().template Append<NodeEvaluateEndEvent>(
232265
GetObjectId(*this), turn.Id()));
@@ -240,6 +273,11 @@ class SyncedIterateNode : public SignalNode<D,S>
240273
virtual const char* GetNodeType() const override { return "SyncedIterateNode"; }
241274
virtual int DependencyCount() const override { return 1 + sizeof...(TDepValues); }
242275

276+
virtual bool IsHeavyweight() const override
277+
{
278+
return this->IsUpdateThresholdExceeded();
279+
}
280+
243281
private:
244282
using DepHolderT = std::tuple<std::shared_ptr<SignalNode<D,TDepValues>>...>;
245283

@@ -260,7 +298,9 @@ template
260298
typename TFunc,
261299
typename ... TDepValues
262300
>
263-
class SyncedIterateByRefNode : public SignalNode<D,S>
301+
class SyncedIterateByRefNode :
302+
public SignalNode<D,S>,
303+
public UpdateTimingPolicy<D,500>
264304
{
265305
using Engine = typename SyncedIterateByRefNode::Engine;
266306

@@ -321,12 +361,15 @@ class SyncedIterateByRefNode : public SignalNode<D,S>
321361
GetObjectId(*this), turn.Id()));
322362

323363
if (! events_->Events().empty())
324-
{
364+
{// timer
365+
using TimerT = typename SyncedIterateByRefNode::ScopedUpdateTimer;
366+
TimerT scopedTimer( *this, events_->Events().size() );
367+
325368
for (const auto& e : events_->Events())
326369
apply(EvalFunctor_( e, this->value_, func_ ), deps_);
327370

328371
changed = true;
329-
}
372+
}// ~timer
330373

331374
REACT_LOG(D::Log().template Append<NodeEvaluateEndEvent>(
332375
GetObjectId(*this), turn.Id()));
@@ -340,6 +383,11 @@ class SyncedIterateByRefNode : public SignalNode<D,S>
340383
virtual const char* GetNodeType() const override { return "SyncedIterateByRefNode"; }
341384
virtual int DependencyCount() const override { return 1 + sizeof...(TDepValues); }
342385

386+
virtual bool IsHeavyweight() const override
387+
{
388+
return this->IsUpdateThresholdExceeded();
389+
}
390+
343391
private:
344392
using DepHolderT = std::tuple<std::shared_ptr<SignalNode<D,TDepValues>>...>;
345393

@@ -409,7 +457,7 @@ class HoldNode : public SignalNode<D,S>
409457
Engine::OnNodeIdlePulse(*this, turn);
410458
}
411459

412-
virtual int DependencyCount() const override { return 1; }
460+
virtual int DependencyCount() const override { return 1; }
413461

414462
private:
415463
const std::shared_ptr<EventStreamNode<D,S>> events_;
@@ -447,9 +495,6 @@ class SnapshotNode : public SignalNode<D,S>
447495
Engine::OnNodeDestroy(*this);
448496
}
449497

450-
virtual const char* GetNodeType() const override { return "SnapshotNode"; }
451-
virtual int DependencyCount() const override { return 2; }
452-
453498
virtual void Tick(void* turnPtr) override
454499
{
455500
using TurnT = typename D::Engine::TurnT;
@@ -482,6 +527,9 @@ class SnapshotNode : public SignalNode<D,S>
482527
Engine::OnNodeIdlePulse(*this, turn);
483528
}
484529

530+
virtual const char* GetNodeType() const override { return "SnapshotNode"; }
531+
virtual int DependencyCount() const override { return 2; }
532+
485533
private:
486534
const std::shared_ptr<SignalNode<D,S>> target_;
487535
const std::shared_ptr<EventStreamNode<D,E>> trigger_;
@@ -514,9 +562,6 @@ class MonitorNode : public EventStreamNode<D,E>
514562
Engine::OnNodeDestroy(*this);
515563
}
516564

517-
virtual const char* GetNodeType() const override { return "MonitorNode"; }
518-
virtual int DependencyCount() const override { return 1; }
519-
520565
virtual void Tick(void* turnPtr) override
521566
{
522567
using TurnT = typename D::Engine::TurnT;
@@ -538,6 +583,9 @@ class MonitorNode : public EventStreamNode<D,E>
538583
Engine::OnNodeIdlePulse(*this, turn);
539584
}
540585

586+
virtual const char* GetNodeType() const override { return "MonitorNode"; }
587+
virtual int DependencyCount() const override { return 1; }
588+
541589
private:
542590
const std::shared_ptr<SignalNode<D,E>> target_;
543591
};
@@ -574,9 +622,6 @@ class PulseNode : public EventStreamNode<D,S>
574622
Engine::OnNodeDestroy(*this);
575623
}
576624

577-
virtual const char* GetNodeType() const override { return "PulseNode"; }
578-
virtual int DependencyCount() const override { return 2; }
579-
580625
virtual void Tick(void* turnPtr) override
581626
{
582627
typedef typename D::Engine::TurnT TurnT;
@@ -600,6 +645,9 @@ class PulseNode : public EventStreamNode<D,S>
600645
Engine::OnNodeIdlePulse(*this, turn);
601646
}
602647

648+
virtual const char* GetNodeType() const override { return "PulseNode"; }
649+
virtual int DependencyCount() const override { return 2; }
650+
603651
private:
604652
const std::shared_ptr<SignalNode<D,S>> target_;
605653
const std::shared_ptr<EventStreamNode<D,E>> trigger_;

0 commit comments

Comments
 (0)