Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
InstrumentHelpers.h
Go to the documentation of this file.
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#ifndef _Stroika_Framework_SystemPerformance_Support_InstrumentHelpers_h_
5#define _Stroika_Framework_SystemPerformance_Support_InstrumentHelpers_h_ 1
6
7#include "Stroika/Frameworks/StroikaPreComp.h"
8
9#include <memory>
10#include <optional>
11
15#include "Stroika/Frameworks/SystemPerformance/Instrument.h"
16
17/**
18 * \file
19 *
20 * \note Code-Status: <a href="Code-Status.md#Beta">Beta</a>
21 */
22
23namespace Stroika::Frameworks::SystemPerformance::Support {
24
25 /**
26 * Optional utility used internally in building Instruments - no need to use it (except if using InstrumentRep_COMMON)
27 */
29 optional<Time::TimePointSeconds> fCaptureContextAt{};
30 };
31
32 /**
33 * Optional utility used internally in building Instruments - no need to use it.
34 */
35 template <typename OPTIONS, derived_from<Context> CONTEXT>
37 protected:
38 using _Context = CONTEXT;
39
40 protected:
41 const OPTIONS _fOptions;
42
43 protected:
45
46 private:
47 // Before Stroika v3.0d5, tickcount startedat zero, so we could assume that when context fCaptureContextAt missing;
48 // but no longer. Could save this more compactly perhaps (redefineing meaning of fCaptureContextAt) but no apparent need.
49 const Time::TimePointSeconds fInstrumentCreatedAt_{Time::GetTickCount ()};
50
51 protected:
52 InstrumentRep_COMMON (const OPTIONS& options, const shared_ptr<CONTEXT>& context = make_shared<CONTEXT> ());
53
54 protected:
55 /**
56 * If any stored context information was captured (like for averaging over an interval) - this is the start of that interval.
57 */
59
60 protected:
61 // @todo redo docs
62 // return true iff actually capture context
63 // This looks at the fMinimumAveragingInterval field of fOptions, which obviously must exist for this to be called
64 // and if not enuf time has elapsed, just returns false and doesnt update capture time (and caller should then
65 // not update the _fContext data used for computing future references / averages)
66 nonvirtual void _NoteCompletedCapture (Time::TimePointSeconds at = Time::GetTickCount ());
67
68 protected:
69 template <typename INFO_TYPE>
70 nonvirtual INFO_TYPE Do_Capture_Raw (function<INFO_TYPE ()> internalCapture, Range<Time::TimePointSeconds>* outMeasuredAt)
71 {
72 // Timerange returned is from time of last context capture, til now. NOTE: this COULD produce overlapping measurement intervals.
73 auto before = _GetCaptureContextTime ();
74 INFO_TYPE rawMeasurement = internalCapture ();
75 if (outMeasuredAt != nullptr) {
77 *outMeasuredAt = Range<Time::TimePointSeconds> (before, _GetCaptureContextTime (), Openness::eClosed, Openness::eClosed);
78 }
79 return rawMeasurement;
80 }
81
82 public:
83 virtual shared_ptr<Instrument::ICaptureContext> GetContext () const override
84 {
85 EnsureNotNull (_fContext.load ());
86 return _fContext.load ();
87 }
88 virtual void SetContext (const shared_ptr<Instrument::ICaptureContext>& context) override
89 {
90 _fContext.store ((context == nullptr) ? make_shared<CONTEXT> () : dynamic_pointer_cast<CONTEXT> (context));
91 }
92 };
93
94}
95
96/*
97 ********************************************************************************
98 ***************************** Implementation Details ***************************
99 ********************************************************************************
100 */
101#include "InstrumentHelpers.inl"
102
103#endif /*_Stroika_Framework_SystemPerformance_Support_InstrumentHelpers_h_*/
#define EnsureNotNull(p)
Definition Assertions.h:340
time_point< RealtimeClock, DurationSeconds > TimePointSeconds
TimePointSeconds is a simpler approach to chrono::time_point, which doesn't require using templates e...
Definition Realtime.h:82
NOT a real mutex - just a debugging infrastructure support tool so in debug builds can be assured thr...
Wrap any object with Synchronized<> and it can be used similarly to the base type,...