aboutsummaryrefslogtreecommitdiff
path: root/src/unstable/profiler.h
blob: df0502399f3d249bcb5c4e62f98fd1258beb7e25 (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
44
45
46
47
48
49
50
51
52
53
54
#ifndef BU_PROFILER_H
#define BU_PROFILER_H

#include "bu/blob.h"
#include "bu/hash.h"
#include "bu/list.h"
#include "bu/mutex.h"
#include "bu/singleton.h"

namespace Bu
{
    class Profiler : public Bu::Singleton<Profiler>
    {
    friend class Bu::Singleton<Profiler>;
    private:
        Profiler();
        virtual ~Profiler();

    public:
        static uint64_t getMicroTime();

        void startEvent( const Bu::Blob &bName );
        void endEvent( const Bu::Blob &bName );

        void printReport() const;

    private:
        class Event
        {
        public:
            Event();
            Event( const Event &rSrc );
            ~Event();

            void end();
            bool hasEnded() const;

            uint64_t getStart() const;
            uint64_t getEnd() const;
            uint64_t getSpan() const;

        private:
            uint64_t iStart;
            uint64_t iStop;
        };

        typedef Bu::List<Event> EventList;
        typedef Bu::Hash<Bu::Blob, EventList> EventListHash;
        EventListHash hEvent;
        mutable Bu::Mutex mLock;
    };
};

#endif