20 {
21 TRACE();
23
24 const MInt padSize = 50;
26 std::vector<MString> topConsumers;
27 std::vector<MLong> consumption(N);
28 for(
MInt k = 0; k < N; k++) {
29 consumption[k] = 0;
30 topConsumers.emplace_back("-");
31 }
34 MLong size = (*i)->getElementSize();
36 auto j = i + 1;
37 while((j !=
g_allocatedObjects.end()) && ((*j)->getObjectId() == (*i)->getObjectId())) {
38 size += (*j)->getElementSize();
39 j++;
40 i++;
41 }
42 count++;
43 for(
MInt k = 0; k < N; k++) {
44 if(size > consumption[k]) {
45 for(
MInt l = N - 1; l > k; l--) {
46 consumption[l] = consumption[l - 1];
47 }
48 consumption[k] = size;
49 topConsumers.insert(topConsumers.begin() + k, name);
50 topConsumers.pop_back();
51 k = N;
52 }
53 }
54 }
55
57
58 for(
MInt k = 0; k < padSize + 24; k++) {
60 }
62 m_log <<
"Freeing allocated memory...";
63
65
66 for(auto& g_allocatedObject : g_allocatedObjects) {
67#ifdef MAIA_EXTRA_DEBUG
68 m_log <<
"Deallocating " << g_allocatedObject->getName() <<
" " << std::endl;
70#endif
71 delete g_allocatedObject;
72 }
74
75 m_log <<
" finished" << endl;
77 m_log << endl <<
"Top " << N <<
" (out of " << count <<
") memory consumers are:" << endl;
78 MChar buffer[100 + padSize];
80 for(
MInt k = 0; k < N; k++) {
81 sum += consumption[k];
82 MString name(topConsumers[k], 0,
mMin(std::size_t(padSize - 2), topConsumers[k].size()));
83 name += ":";
84 if(padSize > (signed)name.size()) {
85 name.insert(name.end(), padSize - name.size(), ' ');
86 }
90 sprintf(buffer, "%3d%s %s %s %s%6.2f%s", k + 1, ".", buf0.c_str(), buf1.c_str(), "=", perc, "%");
91 m_log << buffer << endl;
92 }
94 tmp.insert(tmp.end(), padSize + 6, ' ');
95 tmp.insert(tmp.end(), 18, '-');
98 if(padSize > (signed)name.size()) {
99 name.insert(name.end(), padSize - name.size(), ' ');
100 }
104 sprintf(buffer, "%s%s %s %s %s%6.2f%s", " ", " ", buf0.c_str(), buf1.c_str(), "=", perc, "%");
105 m_log << buffer << endl;
106
107 topConsumers.clear();
108
111 } else {
112 m_log <<
"All memory cleared." << endl;
113 }
114 for(
MInt k = 0; k < padSize + 24; k++) {
116 }
117 m_log << endl << endl << endl;
118}
MLong maxAllocatedBytes()
Return the maximum number of allocated bytes.
MLong allocatedBytes()
Return the number of allocated bytes.
constexpr T mMin(const T &x, const T &y)
MString getMemorySize(MLong noBytes)
Returns memory size in KB, MB or GB.
std::basic_string< char > MString
std::vector< GenericObject * > g_allocatedObjects