<commit_before>/*
 * Copyright(c) Sophist Solutions, Inc. 1990-2021.  All rights reserved
 */
#ifndef _Stroika_Frameworks_SystemPerformance_Instrument_inl_
#define _Stroika_Frameworks_SystemPerformance_Instrument_inl_ 1

/*
 ********************************************************************************
 ***************************** Implementation Details ***************************
 ********************************************************************************
 */

namespace Stroika::Frameworks::SystemPerformance {

    /*
     ********************************************************************************
     ************************ SystemPerformance::Instrument *************************
     ********************************************************************************
     */
    inline MeasurementSet Instrument::Capture ()
    {
        AssertNotNull (fCapFun_.get ());
        return fCapFun_.get ()->Capture ();
    }
    template <>
    inline VariantValue Instrument::CaptureOneMeasurement (Range<DurationSecondsType>* measurementTimeOut)
    {
        MeasurementSet ms = Capture ();
        if (measurementTimeOut != nullptr) {
            *measurementTimeOut = ms.fMeasuredAt;
        }
        for (const auto& ii : ms.fMeasurements) {
            return ii.fValue;
        }
        AssertNotReached (); // only use this on insturments with one result returned
        return VariantValue ();
    }
    template <typename T>
    inline T Instrument::CaptureOneMeasurement (Range<DurationSecondsType>* measurementTimeOut)
    {
        // This function is typically template specialized by Instruments to avoid the round trip through VariantValues, but this is
        // logically correct (just slower).
        return MeasurementAs<T> (CaptureOneMeasurement<VariantValue> (measurementTimeOut));
    }
    template <typename T>
    inline T Instrument::MeasurementAs (const Measurement& m) const
    {
        Require (fType2MeasurementTypes.Contains (type_id (decay_t<T>)));
        return fObjectVariantMapper.ToObject<T> (m.fValue);
    }
    template <typename T>
    T Instrument::MeasurementAs (const MeasurementSet& m) const
    {
        Require (fType2MeasurementTypes.Contains (type_id (decay_t<T>)));
        MeasurementType mt = fType2MeasurementTypes[type_id (decay_t<T>)];
        Require (m.fMeasurements.Any ([=] (const Measurement& m) { return m.fType == mt; }));
        VariantValue vv = m.fMeasurements.FindFirstThat ([=] (const Measurement& m) { return m.fType == mt; })->fValue;
        return fObjectVariantMapper.ToObject<T> (vv);
    }
    inline bool Instrument::operator== (const Instrument& rhs) const
    {
        return fInstrumentName == rhs.fInstrumentName;
    }

}

#endif /*_Stroika_Frameworks_SystemPerformance_Instrument_inl_*/<commit_msg>fixed typeid typo<commit_after>/*
 * Copyright(c) Sophist Solutions, Inc. 1990-2021.  All rights reserved
 */
#ifndef _Stroika_Frameworks_SystemPerformance_Instrument_inl_
#define _Stroika_Frameworks_SystemPerformance_Instrument_inl_ 1

/*
 ********************************************************************************
 ***************************** Implementation Details ***************************
 ********************************************************************************
 */

namespace Stroika::Frameworks::SystemPerformance {

    /*
     ********************************************************************************
     ************************ SystemPerformance::Instrument *************************
     ********************************************************************************
     */
    inline MeasurementSet Instrument::Capture ()
    {
        AssertNotNull (fCapFun_.get ());
        return fCapFun_.get ()->Capture ();
    }
    template <>
    inline VariantValue Instrument::CaptureOneMeasurement (Range<DurationSecondsType>* measurementTimeOut)
    {
        MeasurementSet ms = Capture ();
        if (measurementTimeOut != nullptr) {
            *measurementTimeOut = ms.fMeasuredAt;
        }
        for (const auto& ii : ms.fMeasurements) {
            return ii.fValue;
        }
        AssertNotReached (); // only use this on insturments with one result returned
        return VariantValue ();
    }
    template <typename T>
    inline T Instrument::CaptureOneMeasurement (Range<DurationSecondsType>* measurementTimeOut)
    {
        // This function is typically template specialized by Instruments to avoid the round trip through VariantValues, but this is
        // logically correct (just slower).
        return MeasurementAs<T> (CaptureOneMeasurement<VariantValue> (measurementTimeOut));
    }
    template <typename T>
    inline T Instrument::MeasurementAs (const Measurement& m) const
    {
        Require (fType2MeasurementTypes.Contains (type_id (decay_t<T>)));
        return fObjectVariantMapper.ToObject<T> (m.fValue);
    }
    template <typename T>
    T Instrument::MeasurementAs (const MeasurementSet& m) const
    {
        Require (fType2MeasurementTypes.ContainsKey (typeid (T)));
        MeasurementType mt = fType2MeasurementTypes[typeid (T)];
        Require (m.fMeasurements.Any ([=] (const Measurement& m) { return m.fType == mt; }));
        VariantValue vv = m.fMeasurements.FindFirstThat ([=] (const Measurement& m) { return m.fType == mt; })->fValue;
        return fObjectVariantMapper.ToObject<T> (vv);
    }
    inline bool Instrument::operator== (const Instrument& rhs) const
    {
        return fInstrumentName == rhs.fInstrumentName;
    }

}

#endif /*_Stroika_Frameworks_SystemPerformance_Instrument_inl_*/
{'fraction_non_alphanumeric': 0.2356086259133844, 'fraction_numerical': 0.004277312422028159, 'mean_word_length': 3.9884444444444442, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6100792', 'n_tokens_mistral': 1497, 'n_tokens_neox': 1371, 'n_words': 323}