aboutsummaryrefslogtreecommitdiff
path: root/src/unstable/speedometer.h
blob: 84d21ed75fdcd68167bfe13761efb8891988e32f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#ifndef BU_SPEEDOMETER_H
#define BU_SPEEDOMETER_H

#include "bu/mutex.h"

#include <stdint.h>

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