Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
Instrument.cpp
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#include "Stroika/Frameworks/StroikaPreComp.h"
5
6#include "Instrument.h"
7
8using namespace Stroika::Frameworks;
9using namespace Stroika::Frameworks::SystemPerformance;
10
12
13/*
14 ********************************************************************************
15 ******************** SystemPerformance::Instrument *****************************
16 ********************************************************************************
17 */
18Instrument::Instrument (InstrumentNameType instrumentName, unique_ptr<IRep>&& capturer, const Set<MeasurementType>& capturedMeasurements,
19 const Mapping<type_index, MeasurementType>& typeToMeasurementTypeMap, const DataExchange::ObjectVariantMapper& objectVariantMapper)
20 : context{[qStroika_Foundation_Common_Property_ExtraCaptureStuff] ([[maybe_unused]] const auto* property) {
21 const Instrument* thisObj = qStroika_Foundation_Common_Property_OuterObjPtr (property, &Instrument::context);
22 AssertExternallySynchronizedMutex::ReadContext readLock{thisObj->fThisAssertExternallySynchronized_};
23 return thisObj->fCaptureRep_->GetContext ();
24 },
25 [qStroika_Foundation_Common_Property_ExtraCaptureStuff] ([[maybe_unused]] auto* property, const auto& context) {
26 Instrument* thisObj = qStroika_Foundation_Common_Property_OuterObjPtr (property, &Instrument::context);
27 AssertExternallySynchronizedMutex::WriteContext declareContext{thisObj->fThisAssertExternallySynchronized_};
28 thisObj->fCaptureRep_->SetContext (context);
29 }}
30 , instrumentName{[qStroika_Foundation_Common_Property_ExtraCaptureStuff] ([[maybe_unused]] const auto* property) {
31 const Instrument* thisObj = qStroika_Foundation_Common_Property_OuterObjPtr (property, &Instrument::instrumentName);
32 AssertExternallySynchronizedMutex::ReadContext readLock{thisObj->fThisAssertExternallySynchronized_};
33 return thisObj->fInstrumentName_;
34 }}
35 , capturedMeasurementTypes{[qStroika_Foundation_Common_Property_ExtraCaptureStuff] ([[maybe_unused]] const auto* property) {
36 const Instrument* thisObj = qStroika_Foundation_Common_Property_OuterObjPtr (property, &Instrument::capturedMeasurementTypes);
37 AssertExternallySynchronizedMutex::ReadContext readLock{thisObj->fThisAssertExternallySynchronized_};
38 return thisObj->fCapturedMeasurementTypes_;
39 }}
40 , objectVariantMapper{[qStroika_Foundation_Common_Property_ExtraCaptureStuff] ([[maybe_unused]] const auto* property) {
41 const Instrument* thisObj = qStroika_Foundation_Common_Property_OuterObjPtr (property, &Instrument::objectVariantMapper);
42 AssertExternallySynchronizedMutex::ReadContext readLock{thisObj->fThisAssertExternallySynchronized_};
43 return thisObj->fObjectVariantMapper_;
44 }}
45 , type2MeasurementTypes{[qStroika_Foundation_Common_Property_ExtraCaptureStuff] ([[maybe_unused]] const auto* property) {
46 const Instrument* thisObj = qStroika_Foundation_Common_Property_OuterObjPtr (property, &Instrument::type2MeasurementTypes);
47 AssertExternallySynchronizedMutex::ReadContext readLock{thisObj->fThisAssertExternallySynchronized_};
48 return thisObj->fType2MeasurementTypes_;
49 }}
50 , fInstrumentName_{instrumentName}
51 , fType2MeasurementTypes_{typeToMeasurementTypeMap}
52 , fCapturedMeasurementTypes_{capturedMeasurements}
53 , fObjectVariantMapper_{objectVariantMapper}
54 , fCaptureRep_{move (capturer)}
55{
56}
57
58Instrument& Instrument::operator= (Instrument&& rhs) noexcept
59{
60 AssertExternallySynchronizedMutex::WriteContext declareContext{fThisAssertExternallySynchronized_};
61 AssertExternallySynchronizedMutex::WriteContext declareWriteContext2{rhs.fThisAssertExternallySynchronized_};
62 fInstrumentName_ = move (rhs.fInstrumentName_);
63 fCaptureRep_ = move (rhs.fCaptureRep_);
64 fType2MeasurementTypes_ = move (rhs.fType2MeasurementTypes_);
65 fCapturedMeasurementTypes_ = move (rhs.fCapturedMeasurementTypes_);
66 fObjectVariantMapper_ = move (rhs.fObjectVariantMapper_);
67 return *this;
68}
69
70Instrument& Instrument::operator= (const Instrument& rhs)
71{
72 AssertExternallySynchronizedMutex::WriteContext declareContext{fThisAssertExternallySynchronized_};
73 AssertExternallySynchronizedMutex::ReadContext readLock{rhs.fThisAssertExternallySynchronized_};
74 fInstrumentName_ = rhs.fInstrumentName_;
75 fCaptureRep_ = rhs.fCaptureRep_->Clone ();
76 fType2MeasurementTypes_ = rhs.fType2MeasurementTypes_;
77 fCapturedMeasurementTypes_ = rhs.fCapturedMeasurementTypes_;
78 fObjectVariantMapper_ = rhs.fObjectVariantMapper_;
79 return *this;
80}
Set<T> is a container of T, where once an item is added, additionally adds () do nothing.
Definition Set.h:105
An Atom is like a String, except that its much cheaper to copy/store/compare, and the semantics of co...
Definition Atom.h:133
ObjectVariantMapper can be used to map C++ types to and from variant-union types, which can be transp...
NOT a real mutex - just a debugging infrastructure support tool so in debug builds can be assured thr...
shared_lock< const AssertExternallySynchronizedMutex > ReadContext
Instantiate AssertExternallySynchronizedMutex::ReadContext to designate an area of code where protect...
unique_lock< AssertExternallySynchronizedMutex > WriteContext
Instantiate AssertExternallySynchronizedMutex::WriteContext to designate an area of code where protec...
An Instrument is a stateful object from which you can Capture () a series of measurements about a sys...
Definition Instrument.h:69
Common::ReadOnlyProperty< Mapping< type_index, MeasurementType > > type2MeasurementTypes
Many (all) instruments will have corresponding c++ objects to represent what is captured....
Definition Instrument.h:174
Common::ReadOnlyProperty< DataExchange::ObjectVariantMapper > objectVariantMapper
mapper for all the types listed in type2MeasurementTypes().Values (), as well as any required support...
Definition Instrument.h:166
Common::ReadOnlyProperty< Set< MeasurementType > > capturedMeasurementTypes
the set of MeasurementTypes measured by this instrument (often just one)
Definition Instrument.h:160
Common::Property< shared_ptr< ICaptureContext > > context
Definition Instrument.h:146
Common::ReadOnlyProperty< InstrumentNameType > instrumentName
Instruments all have a displayable name which can be used for reference. Each (type) instrument shoul...
Definition Instrument.h:152