From 74973a93594e4150a827459708895577a795036b Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 2 Jul 2018 11:34:44 -0700 Subject: Added a threadsafe speedometer class. --- src/unstable/speedometer.h | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/unstable/speedometer.h (limited to 'src/unstable/speedometer.h') diff --git a/src/unstable/speedometer.h b/src/unstable/speedometer.h new file mode 100644 index 0000000..84d21ed --- /dev/null +++ b/src/unstable/speedometer.h @@ -0,0 +1,43 @@ +#ifndef BU_SPEEDOMETER_H +#define BU_SPEEDOMETER_H + +#include "bu/mutex.h" + +#include + +namespace Bu +{ + class Speedometer + { + public: + Speedometer( int64_t iBucketMs, int32_t iBucketCount ); + virtual ~Speedometer(); + + void addEvent(); + double getSpeed(); + int32_t getTotalEvents(); + void debug(); + + private: + void _updateBuckets( int64_t iNow ); + /** + * Gets the current time in milliseconds. + */ + int64_t getCurrentTime() const; + + private: + uint32_t *aiBucket; + uint32_t iTotal; + int32_t iCapacity; + int32_t iFill; + int32_t iStart; + int32_t iCurrent; + int64_t iBucketMs; + int64_t iStartTime; + int64_t iWindowSizeMs; + int64_t iLastUpdate; + mutable Bu::Mutex mLock; + }; +} + +#endif -- cgit v1.2.3