|
@@ -7,6 +7,43 @@
|
7
|
7
|
|
8
|
8
|
#include <DK.h>
|
9
|
9
|
|
|
10
|
+auto FormatBytes(size_t size, int maxDigits=3)->DKString
|
|
11
|
+{
|
|
12
|
+ if (size > 1)
|
|
13
|
+ {
|
|
14
|
+ maxDigits = Clamp(maxDigits, 1, 4);
|
|
15
|
+
|
|
16
|
+ const char* suffixList[7] = { "Bytes","KB","MB","GB","TB","PB","EB" };
|
|
17
|
+ int suffixIndex = 0;
|
|
18
|
+ while (size >= 1024000 && suffixIndex < 6)
|
|
19
|
+ {
|
|
20
|
+ suffixIndex++;
|
|
21
|
+ size = size >> 10;
|
|
22
|
+ }
|
|
23
|
+ double s = static_cast<double>(size);
|
|
24
|
+ if (size >= 1000 && suffixIndex < 6)
|
|
25
|
+ {
|
|
26
|
+ s = s / 1024.0;
|
|
27
|
+ suffixIndex++;
|
|
28
|
+ }
|
|
29
|
+ if (suffixIndex > 0)
|
|
30
|
+ {
|
|
31
|
+ int numDigits = [](int s)->int
|
|
32
|
+ {
|
|
33
|
+ int n = 0;
|
|
34
|
+ while (s > 0)
|
|
35
|
+ {
|
|
36
|
+ n++;
|
|
37
|
+ s /= 10;
|
|
38
|
+ }
|
|
39
|
+ return Max(n, 1);
|
|
40
|
+ }(s);
|
|
41
|
+ return DKString::Format("%.*f %s", Clamp<int>(maxDigits - numDigits, 0, 3), s, suffixList[suffixIndex]);
|
|
42
|
+ }
|
|
43
|
+ return DKString::Format("%d %s", int(size), suffixList[0]);
|
|
44
|
+ }
|
|
45
|
+ return DKString::Format("%d Byte", int(size));
|
|
46
|
+};
|
10
|
47
|
|
11
|
48
|
class TestApp1 : public DKApplication
|
12
|
49
|
{
|
|
@@ -38,15 +75,15 @@ public:
|
38
|
75
|
{
|
39
|
76
|
if (buckets[i].totalChunks > 0)
|
40
|
77
|
{
|
41
|
|
- DKLogI("--> %lu: allocated:%lu, reserved:%.1fKB. (usage:%.1f%%)",
|
|
78
|
+ DKLogI("--> %lu: allocated:%lu, reserved:%ls. (usage:%.1f%%)",
|
42
|
79
|
buckets[i].chunkSize,
|
43
|
80
|
buckets[i].chunkSize * buckets[i].usedChunks,
|
44
|
|
- double(buckets[i].chunkSize * (buckets[i].totalChunks - buckets[i].usedChunks)) / 1024.0,
|
|
81
|
+ (const wchar_t*)FormatBytes(buckets[i].chunkSize * (buckets[i].totalChunks - buckets[i].usedChunks)),
|
45
|
82
|
double(buckets[i].usedChunks) / double(buckets[i].totalChunks) * 100.0);
|
46
|
83
|
usedBytes += buckets[i].chunkSize * buckets[i].usedChunks;
|
47
|
84
|
}
|
48
|
85
|
}
|
49
|
|
- DKLogI("MemoryPool Usage: %.1fMB / %.1fMB", double(usedBytes) / (1024 * 1024), double(DKMemoryPoolSize()) / (1024 * 1024));
|
|
86
|
+ DKLogI("MemoryPool Usage: %ls / %ls", (const wchar_t*)FormatBytes(usedBytes), (const wchar_t*)FormatBytes(DKMemoryPoolSize()));
|
50
|
87
|
delete[] buckets;
|
51
|
88
|
}
|
52
|
89
|
};
|