4#include "Stroika/Frameworks/StroikaPreComp.h"
7#include "Stroika/Foundation/Common/GUID.h"
8#include "Stroika/Foundation/Common/Property.h"
13#include "OperationalStatistics.h"
21using namespace Stroika::Foundation::Time;
26using namespace Stroika::Samples::HTMLUI;
38OperationalStatisticsMgr::ProcessAPICmd::~ProcessAPICmd ()
41 sThe.Add_ (Rec_{Rec_::Kind::eAPI, now, now - fStart_});
44void OperationalStatisticsMgr::ProcessAPICmd::NoteError ()
47 sThe.Add_ (Rec_{.fKind = Rec_::Kind::eAPIError, .fAt = now, .fDuration = 0s});
55OperationalStatisticsMgr::ProcessDBCmd::~ProcessDBCmd ()
58 sThe.Add_ (Rec_{.fKind = fKind_, .fAt = now, .fDuration = now - fStart_});
61void OperationalStatisticsMgr::ProcessDBCmd::NoteError ()
64 sThe.Add_ (Rec_{.fKind = Rec_::Kind::eDBError, .fAt = now, .fDuration = 0s});
72void OperationalStatisticsMgr::RecordActiveRunningTasksCount (
size_t length)
75 sThe.Add_ (Rec_{.fKind = Rec_::Kind::eAPIActiveRunningTasks, .fAt = now, .fDuration = 0s, .fLength = length});
78void OperationalStatisticsMgr::RecordOpenConnectionCount (
size_t length)
81 sThe.Add_ (Rec_{.fKind = Rec_::Kind::eAPIOpenConnectionCount, .fAt = now, .fDuration = 0s, .fLength = length});
84void OperationalStatisticsMgr::RecordProcessingConnectionCount (
size_t length)
87 sThe.Add_ (Rec_{.fKind = Rec_::Kind::eAPIProcessingConnectionCount, .fAt = now, .fDuration = 0s, .fLength = length});
90auto OperationalStatisticsMgr::GetStatistics () const -> Statistics
99 lock_guard lk{fMutex_};
101 [&] (
const Rec_& r) {
return r.fAt >= skipBefore and r.fKind != Rec_::Kind::eNull; });
106 if (r.fKind == Rec_::Kind::eAPI)
110 if (not apiTimes.
empty ()) {
111 result.fRecentAPI.fMeanDuration =
Duration{Math::Mean (apiTimes)};
112 result.fRecentAPI.fMedianDuration =
Duration{Math::Median (apiTimes)};
113 result.fRecentAPI.fMaxDuration =
Duration{*apiTimes.
Max ()};
115 result.fRecentAPI.fCallsCompleted =
static_cast<unsigned int> (apiTimes.
length ());
116 result.fRecentAPI.fErrors =
117 static_cast<unsigned int> (allApplicable.
Count ([] (
const Rec_& r) {
return r.fKind == Rec_::Kind::eAPIError; }));
121 if (r.fKind == Rec_::Kind::eAPIActiveRunningTasks)
122 return static_cast<float> (r.fLength);
125 if (not activeRunningWSAPITasks.
empty ()) {
126 result.fRecentAPI.fMedianRunningAPITasks = Math::Median (activeRunningWSAPITasks);
131 if (r.fKind == Rec_::Kind::eDBRead)
135 if (not dbReadTimes.
empty ()) {
136 result.fRecentDB.fReadDurationStats =
139 result.fRecentDB.fReads =
static_cast<unsigned int> (dbReadTimes.
length ());
143 if (r.fKind == Rec_::Kind::eDBWrite)
147 if (not dbWriteTimes.
empty ()) {
148 result.fRecentDB.fWriteDurationStats =
151 result.fRecentDB.fWrites =
static_cast<unsigned int> (dbWriteTimes.
length ());
153 result.fRecentDB.fErrors =
static_cast<unsigned int> (allApplicable.
Count ([] (
const Rec_& r) {
return r.fKind == Rec_::Kind::eDBError; }));
time_point< RealtimeClock, DurationSeconds > TimePointSeconds
TimePointSeconds is a simpler approach to chrono::time_point, which doesn't require using templates e...
A generalization of a vector: a container whose elements are keyed by the natural numbers.
nonvirtual RESULT_CONTAINER Where(INCLUDE_PREDICATE &&includeIfTrue) const
Duration is a chrono::duration<double> (=.
Iterable<T> is a base class for containers which easily produce an Iterator<T> to traverse them.
nonvirtual RESULT_TYPE MaxValue(ArgByValueType< RESULT_TYPE > defaultValue={}) const
nonvirtual optional< T > Max() const
nonvirtual RESULT_TYPE MedianValue(ArgByValueType< RESULT_TYPE > defaultValue={}) const
nonvirtual size_t length() const
STL-ish alias for size() - really in STL only used in string, I think, but still makes sense as an al...
nonvirtual RESULT_CONTAINER Map(ELEMENT_MAPPER &&elementMapper) const
functional API which iterates over all members of an Iterable, applies a map function to each element...
nonvirtual size_t Count() const
with no args, same as size, with function filter arg, returns number of items that pass.
nonvirtual bool empty() const
Returns true iff size() == 0.