Stroika Library 3.0d23x
 
Loading...
Searching...
No Matches
InstrumentHelpers.h
Go to the documentation of this file.
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2026. 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
16#include "Stroika/Frameworks/SystemPerformance/Instrument.h"
17
18/**
19 * \file
20 *
21 * \note Code-Status: <a href="Code-Status.md#Beta">Beta</a>
22 */
23
24namespace Stroika::Frameworks::SystemPerformance::Support {
25
26 /**
27 * Optional utility used internally in building Instruments - no need to use it (except if using InstrumentRep_COMMON)
28 */
30 optional<Time::TimePointSeconds> fCaptureContextAt{};
31 };
32
33 /**
34 * Optional utility used internally in building Instruments - no need to use it.
35 */
36 template <typename OPTIONS, derived_from<Context> CONTEXT>
38 protected:
39 using _Context = CONTEXT;
40
41 protected:
42 const OPTIONS _fOptions;
43
44 protected:
46
47 private:
48 // Before Stroika v3.0d5, tickcount startedat zero, so we could assume that when context fCaptureContextAt missing;
49 // but no longer. Could save this more compactly perhaps (redefineing meaning of fCaptureContextAt) but no apparent need.
50 const Time::TimePointSeconds fInstrumentCreatedAt_{Time::GetTickCount ()};
51
52 protected:
53 InstrumentRep_COMMON (const OPTIONS& options, const shared_ptr<CONTEXT>& context = Memory::MakeSharedPtr<CONTEXT> ());
54
55 protected:
56 /**
57 * If any stored context information was captured (like for averaging over an interval) - this is the start of that interval.
58 */
60
61 protected:
62 // @todo redo docs
63 // return true iff actually capture context
64 // This looks at the fMinimumAveragingInterval field of fOptions, which obviously must exist for this to be called
65 // and if not enuf time has elapsed, just returns false and doesnt update capture time (and caller should then
66 // not update the _fContext data used for computing future references / averages)
67 nonvirtual void _NoteCompletedCapture (Time::TimePointSeconds at = Time::GetTickCount ());
68
69 protected:
70 template <typename INFO_TYPE>
71 nonvirtual INFO_TYPE Do_Capture_Raw (function<INFO_TYPE ()> internalCapture, Range<Time::TimePointSeconds>* outMeasuredAt)
72 {
73 // Timerange returned is from time of last context capture, til now. NOTE: this COULD produce overlapping measurement intervals.
74 auto before = _GetCaptureContextTime ();
75 INFO_TYPE rawMeasurement = internalCapture ();
76 if (outMeasuredAt != nullptr) {
78 *outMeasuredAt = Range<Time::TimePointSeconds> (before, _GetCaptureContextTime (), Openness::eClosed, Openness::eClosed);
79 }
80 return rawMeasurement;
81 }
82
83 public:
84 virtual shared_ptr<Instrument::ICaptureContext> GetContext () const override
85 {
86 EnsureNotNull (_fContext.load ());
87 return _fContext.load ();
88 }
89 virtual void SetContext (const shared_ptr<Instrument::ICaptureContext>& context) override
90 {
91 _fContext.store ((context == nullptr) ? Memory::MakeSharedPtr<CONTEXT> () : dynamic_pointer_cast<CONTEXT> (context));
92 }
93 };
94
95}
96
97/*
98 ********************************************************************************
99 ***************************** Implementation Details ***************************
100 ********************************************************************************
101 */
102#include "InstrumentHelpers.inl"
103
104#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,...