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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
#include "drape/utils/gpu_mem_tracker.hpp"
#include "std/tuple.hpp"
#include "std/sstream.hpp"
namespace dp
{
GPUMemTracker & GPUMemTracker::Inst()
{
static GPUMemTracker s_inst;
return s_inst;
}
string GPUMemTracker::Report()
{
uint32_t summaryUsed = 0;
uint32_t summaryAllocated = 0;
typedef tuple<size_t, uint32_t, uint32_t> TTagStat;
map<string, TTagStat> tagStats;
for (auto const it : m_memTracker)
{
TTagStat & stat = tagStats[it.first.first];
get<0>(stat)++;
get<1>(stat) += it.second.first;
get<2>(stat) += it.second.second;
summaryAllocated += it.second.first;
summaryUsed += it.second.second;
}
float byteToMb = static_cast<float>(1024 * 1024);
ostringstream ss;
ss << " ===== Mem Report ===== \n";
ss << " Summary Allocated = " << summaryAllocated / byteToMb << "\n";
ss << " Summary Used = " << summaryUsed / byteToMb << "\n";
ss << " Tags registered = " << tagStats.size() << "\n";
for (auto const it : tagStats)
{
ss << " Tag = " << it.first << " \n";
ss << " Object count = " << get<0>(it.second) << "\n";
ss << " Allocated = " << get<1>(it.second) / byteToMb << "\n";
ss << " Used = " << get<2>(it.second) / byteToMb << "\n";
}
ss << " ===== Mem Report ===== \n";
return ss.str();
}
void GPUMemTracker::AddAllocated(string const & tag, uint32_t id, uint32_t size)
{
threads::MutexGuard g(m_mutex);
m_memTracker[make_pair(tag, id)].first = size;
}
void GPUMemTracker::SetUsed(string const & tag, uint32_t id, uint32_t size)
{
threads::MutexGuard g(m_mutex);
TAlocUsedMem & node = m_memTracker[make_pair(tag, id)];
node.second = size;
ASSERT_LESS_OR_EQUAL(node.second, node.first, ("Can't use more then allocated"));
}
void GPUMemTracker::RemoveDeallocated(string const & tag, uint32_t id)
{
threads::MutexGuard g(m_mutex);
m_memTracker.erase(make_pair(tag, id));
}
} // namespace dp
|