aboutsummaryrefslogtreecommitdiff
path: root/src/unstable/speedometer.h
diff options
context:
space:
mode:
authorMike Buland <mbuland@penny-arcade.com>2018-07-02 11:34:44 -0700
committerMike Buland <mbuland@penny-arcade.com>2018-07-02 11:34:44 -0700
commit74973a93594e4150a827459708895577a795036b (patch)
tree9faff0701bf458144c58f9b9d29ce845dd132aeb /src/unstable/speedometer.h
parent9bcbc8f919fc1c779d3b9c649dcbe3606fdbed32 (diff)
downloadlibbu++-74973a93594e4150a827459708895577a795036b.tar.gz
libbu++-74973a93594e4150a827459708895577a795036b.tar.bz2
libbu++-74973a93594e4150a827459708895577a795036b.tar.xz
libbu++-74973a93594e4150a827459708895577a795036b.zip
Added a threadsafe speedometer class.
Diffstat (limited to '')
-rw-r--r--src/unstable/speedometer.h43
1 files changed, 43 insertions, 0 deletions
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 @@
1#ifndef BU_SPEEDOMETER_H
2#define BU_SPEEDOMETER_H
3
4#include "bu/mutex.h"
5
6#include <stdint.h>
7
8namespace Bu
9{
10 class Speedometer
11 {
12 public:
13 Speedometer( int64_t iBucketMs, int32_t iBucketCount );
14 virtual ~Speedometer();
15
16 void addEvent();
17 double getSpeed();
18 int32_t getTotalEvents();
19 void debug();
20
21 private:
22 void _updateBuckets( int64_t iNow );
23 /**
24 * Gets the current time in milliseconds.
25 */
26 int64_t getCurrentTime() const;
27
28 private:
29 uint32_t *aiBucket;
30 uint32_t iTotal;
31 int32_t iCapacity;
32 int32_t iFill;
33 int32_t iStart;
34 int32_t iCurrent;
35 int64_t iBucketMs;
36 int64_t iStartTime;
37 int64_t iWindowSizeMs;
38 int64_t iLastUpdate;
39 mutable Bu::Mutex mLock;
40 };
41}
42
43#endif