4#include "Stroika/Frameworks/StroikaPreComp.h"
6#include "Stroika/Foundation/Containers/SortedMapping.h"
7#include "Stroika/Foundation/Debug/Main.h"
16using namespace Stroika::Frameworks;
17using namespace Stroika::Frameworks::SystemPerformance;
25 : pMostRecentMeasurements{[qStroika_Foundation_Common_Property_ExtraCaptureStuff] ([[maybe_unused]] const auto* property) ->
MeasurementSet {
26 const
Capturer* thisObj = qStroika_Foundation_Common_Property_OuterObjPtr (property, &
Capturer::pMostRecentMeasurements);
27 return thisObj->fCurrentMeasurementSet_.load ();
29 , captureSets{[qStroika_Foundation_Common_Property_ExtraCaptureStuff] ([[maybe_unused]]
const auto* property) ->
Collection<CaptureSet> {
30 const Capturer* thisObj = qStroika_Foundation_Common_Property_OuterObjPtr (property, &Capturer::captureSets);
31 return thisObj->fCaptureSets_.load ();
33 [qStroika_Foundation_Common_Property_ExtraCaptureStuff] ([[maybe_unused]]
auto* property,
const auto& captureSets) {
34 Capturer* thisObj = qStroika_Foundation_Common_Property_OuterObjPtr (property, &Capturer::captureSets);
35 thisObj->fCaptureSets_ = captureSets;
38 Require (Debug::AppearsDuringMainLifetime ());
49 return fCallbacks_.Add (cb);
54 fCallbacks_.Remove (cb);
57void Capturer::AddCaptureSet (
const CaptureSet& cs)
60 auto rwLock = fCaptureSets_.rwget ();
62 ++fCaptureSetChangeCount_;
66void Capturer::ManageRunner_ (
bool on)
70 if (not threadPoolRunning) {
71 fThreadPool_.
AddTask ([
this] () { Runner_ (); });
76 if (threadPoolRunning) {
83void Capturer::Runner_ ()
94 uint64_t changeCountForCaptureSet{0};
101 auto recomputeSortOrder = [&] () {
103 auto lock = fCaptureSets_.cget ();
110 for (
const auto& i : lock.load ()) {
111 runQueue.
Add (now + i.runPeriod (), i);
113 changeCountForCaptureSet = fCaptureSetChangeCount_;
118 if (changeCountForCaptureSet < fCaptureSetChangeCount_) {
119 recomputeSortOrder ();
122 Assert (not runQueue.
empty ());
126 auto iterator = runQueue.
begin ();
127 Assert (iterator != runQueue.
end ());
130 RunnerOnce_ (runNext.fValue);
131 runQueue.
erase (iterator);
132 runQueue.
Add (runNext.fKey + runNext.fValue.runPeriod (), runNext.fValue);
136void Capturer::RunnerOnce_ (
const CaptureSet& cs)
143 catch (
const Thread::AbortException&) {
147 using namespace Characters::Literals;
148 DbgTrace (
"Eating exception '{}' in Capturer runner"_f, current_exception ());
151 UpdateMeasurementSet_ (measurements);
156 fCurrentMeasurementSet_.rwget ().rwref ().MergeAdditions (ms);
157 fCallbacks_.Call (ms);
time_point< RealtimeClock, DurationSeconds > TimePointSeconds
TimePointSeconds is a simpler approach to chrono::time_point, which doesn't require using templates e...
A Collection<T> is a container to manage an un-ordered collection of items, without equality defined ...
nonvirtual bool Add(ArgByValueType< key_type > key, ArgByValueType< mapped_type > newElt, AddReplaceMode addReplaceMode=AddReplaceMode::eAddReplaces)
nonvirtual void erase(ArgByValueType< key_type > key)
nonvirtual void AbortTasks(Time::DurationSeconds timeout=Time::kInfinity)
nonvirtual TaskID AddTask(const TaskType &task, const optional< Characters::String > &name=nullopt)
nonvirtual size_t GetTasksCount() const
return total number of tasks, either pending, or currently running.
nonvirtual void SetPoolSize(unsigned int poolSize)
nonvirtual Iterator< T > begin() const
Support for ranged for, and STL syntax in general.
nonvirtual bool empty() const
Returns true iff size() == 0.
static constexpr default_sentinel_t end() noexcept
Support for ranged for, and STL syntax in general.
void SleepUntil(Time::TimePointSeconds untilTickCount)