aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/actors/util/memory_tracker.h
blob: e74508191b10e669986bdbde240e147b61cbde53 (plain) (blame)
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
#pragma once

#include "memory_track.h"

#include <map>
#include <unordered_map>
#include <unordered_set>

#include <util/system/rwlock.h>

namespace NActors {
namespace NMemory {

namespace NPrivate {

class TMemoryTracker {
public:
    static TMemoryTracker* Instance();

    void Initialize();

    const std::map<TString, size_t>& GetMetricIndices() const;
    const std::unordered_set<size_t>& GetSensors() const;
    TString GetName(size_t index) const;
    size_t GetCount() const;

    void GatherMetrics(std::vector<TMetric>& metrics) const;

private:
    size_t RegisterStaticMemoryLabel(const char* name, bool hasSensor);

    void OnCreateThread(TThreadLocalInfo* info);
    void OnDestroyThread(TThreadLocalInfo* info);

private:
    std::map<TString, size_t> Indices;
    std::vector<TString> Names;

    std::vector<TMetric> GlobalMetrics;

    std::unordered_set<size_t> Sensors;

    std::unordered_set<TThreadLocalInfo*> ThreadInfo;
    TRWMutex LockThreadInfo;

    friend class TThreadLocalInfo;
    friend class TBaseLabel;
};

}

}
}