xref: /haiku/src/add-ons/kernel/file_systems/ramfs/AllocationInfo.cpp (revision 12dba4e70f831d6d27a7f769cc9dab19c19a155d)
1 // AllocationInfo.cpp
2 
3 #include "AllocationInfo.h"
4 #include "DebugSupport.h"
5 
6 #include "Attribute.h"
7 #include "Directory.h"
8 #include "Entry.h"
9 #include "File.h"
10 #include "SymLink.h"
11 
12 // constructor
13 AllocationInfo::AllocationInfo()
14 	: fNodeTableArraySize(0),
15 	  fNodeTableVectorSize(0),
16 	  fNodeTableElementCount(0),
17 	  fDirectoryEntryTableArraySize(0),
18 	  fDirectoryEntryTableVectorSize(0),
19 	  fDirectoryEntryTableElementCount(0),
20 	  fNodeAttributeTableArraySize(0),
21 	  fNodeAttributeTableVectorSize(0),
22 	  fNodeAttributeTableElementCount(0),
23 
24 	  fAttributeCount(0),
25 	  fAttributeSize(0),
26 	  fDirectoryCount(0),
27 	  fEntryCount(0),
28 	  fFileCount(0),
29 	  fFileSize(0),
30 	  fSymLinkCount(0),
31 	  fSymLinkSize(0),
32 
33 	  fAreaCount(0),
34 	  fAreaSize(0),
35 	  fBlockCount(0),
36 	  fBlockSize(0),
37 	  fListCount(0),
38 	  fListSize(0),
39 	  fOtherCount(0),
40 	  fOtherSize(0),
41 	  fStringCount(0),
42 	  fStringSize(0)
43 {
44 }
45 
46 // destructor
47 AllocationInfo::~AllocationInfo()
48 {
49 }
50 
51 // AddNodeTableAllocation
52 void
53 AllocationInfo::AddNodeTableAllocation(size_t arraySize, size_t vectorSize,
54 									   size_t elementSize, size_t elementCount)
55 {
56 	fNodeTableArraySize += arraySize;
57 	fNodeTableVectorSize += vectorSize * elementSize;
58 	fNodeTableElementCount += elementCount;
59 }
60 
61 // AddDirectoryEntryTableAllocation
62 void
63 AllocationInfo::AddDirectoryEntryTableAllocation(size_t arraySize,
64 												 size_t vectorSize,
65 												 size_t elementSize,
66 												 size_t elementCount)
67 {
68 	fDirectoryEntryTableArraySize += arraySize;
69 	fDirectoryEntryTableVectorSize += vectorSize * elementSize;
70 	fDirectoryEntryTableElementCount += elementCount;
71 }
72 
73 // AddNodeAttributeTableAllocation
74 void
75 AllocationInfo::AddNodeAttributeTableAllocation(size_t arraySize,
76 												size_t vectorSize,
77 												size_t elementSize,
78 												size_t elementCount)
79 {
80 	fNodeAttributeTableArraySize += arraySize;
81 	fNodeAttributeTableVectorSize += vectorSize * elementSize;
82 	fNodeAttributeTableElementCount += elementCount;
83 }
84 
85 // AddAttributeAllocation
86 void
87 AllocationInfo::AddAttributeAllocation(size_t size)
88 {
89 	fAttributeCount++;
90 	fAttributeSize += size;
91 }
92 
93 // AddDirectoryAllocation
94 void
95 AllocationInfo::AddDirectoryAllocation()
96 {
97 	fDirectoryCount++;
98 }
99 
100 // AddEntryAllocation
101 void
102 AllocationInfo::AddEntryAllocation()
103 {
104 	fEntryCount++;
105 }
106 
107 // AddFileAllocation
108 void
109 AllocationInfo::AddFileAllocation(size_t size)
110 {
111 	fFileCount++;
112 	fFileSize += size;
113 }
114 
115 // AddSymLinkAllocation
116 void
117 AllocationInfo::AddSymLinkAllocation(size_t size)
118 {
119 	fSymLinkCount++;
120 	fSymLinkSize += size;
121 }
122 
123 // AddAreaAllocation
124 void
125 AllocationInfo::AddAreaAllocation(size_t size, size_t count)
126 {
127 	fAreaCount += count;
128 	fAreaSize += count * size;
129 }
130 
131 // AddBlockAllocation
132 void
133 AllocationInfo::AddBlockAllocation(size_t size)
134 {
135 	fBlockCount++;
136 	fBlockSize += size;
137 }
138 
139 // AddListAllocation
140 void
141 AllocationInfo::AddListAllocation(size_t capacity, size_t elementSize)
142 {
143 	fListCount += 1;
144 	fListSize += capacity * elementSize;
145 }
146 
147 // AddOtherAllocation
148 void
149 AllocationInfo::AddOtherAllocation(size_t size, size_t count)
150 {
151 	fOtherCount += count;
152 	fOtherSize += size * count;
153 }
154 
155 // AddStringAllocation
156 void
157 AllocationInfo::AddStringAllocation(size_t size)
158 {
159 	fStringCount++;
160 	fStringSize += size;
161 }
162 
163 // Dump
164 void
165 AllocationInfo::Dump() const
166 {
167 	size_t heapCount = 0;
168 	size_t heapSize = 0;
169 	size_t areaCount = 0;
170 	size_t areaSize = 0;
171 
172 	PRINT(("  node table:\n"));
173 	PRINT(("    array size:  %9lu\n", fNodeTableArraySize));
174 	PRINT(("    vector size: %9lu\n", fNodeTableVectorSize));
175 	PRINT(("    elements:    %9lu\n", fNodeTableElementCount));
176 	areaCount += 2;
177 	areaSize += fNodeTableArraySize * sizeof(int32) + fNodeTableVectorSize;
178 
179 	PRINT(("  entry table:\n"));
180 	PRINT(("    array size:  %9lu\n", fDirectoryEntryTableArraySize));
181 	PRINT(("    vector size: %9lu\n", fDirectoryEntryTableVectorSize));
182 	PRINT(("    elements:    %9lu\n", fDirectoryEntryTableElementCount));
183 	areaCount += 2;
184 	areaSize += fDirectoryEntryTableArraySize * sizeof(int32)
185 				+ fDirectoryEntryTableVectorSize;
186 
187 	PRINT(("  attribute table:\n"));
188 	PRINT(("    array size:  %9lu\n", fNodeAttributeTableArraySize));
189 	PRINT(("    vector size: %9lu\n", fNodeAttributeTableVectorSize));
190 	PRINT(("    elements:    %9lu\n", fNodeAttributeTableElementCount));
191 	areaCount += 2;
192 	areaSize += fNodeAttributeTableArraySize * sizeof(int32)
193 				+ fNodeAttributeTableVectorSize;
194 
195 	PRINT(("  attributes:  %9lu, size: %9lu\n", fAttributeCount, fAttributeSize));
196 	heapCount += fAttributeCount;
197 	heapSize += fAttributeCount * sizeof(Attribute);
198 
199 	PRINT(("  directories: %9lu\n", fDirectoryCount));
200 	heapCount += fDirectoryCount;
201 	heapSize += fDirectoryCount * sizeof(Directory);
202 
203 	PRINT(("  entries:     %9lu\n", fEntryCount));
204 	heapCount += fEntryCount;
205 	heapSize += fEntryCount * sizeof(Entry);
206 
207 	PRINT(("  files:       %9lu, size: %9lu\n", fFileCount, fFileSize));
208 	heapCount += fFileCount;
209 	heapSize += fFileCount * sizeof(File);
210 
211 	PRINT(("  symlinks:    %9lu, size: %9lu\n", fSymLinkCount, fSymLinkSize));
212 	heapCount += fSymLinkCount;
213 	heapSize += fSymLinkCount * sizeof(SymLink);
214 
215 	PRINT(("  areas:       %9lu, size: %9lu\n", fAreaCount, fAreaSize));
216 	areaCount += fAreaCount;
217 	areaSize += fAreaSize;
218 
219 	PRINT(("  blocks:      %9lu, size: %9lu\n", fBlockCount, fBlockSize));
220 
221 	PRINT(("  lists:       %9lu, size: %9lu\n", fListCount, fListSize));
222 	heapCount += fListCount;
223 	heapSize += fListSize;
224 
225 	PRINT(("  other:       %9lu, size: %9lu\n", fOtherCount, fOtherSize));
226 	heapCount += fOtherCount;
227 	heapSize += fOtherSize;
228 
229 	PRINT(("  strings:     %9lu, size: %9lu\n", fStringCount, fStringSize));
230 	heapCount += fStringCount;
231 	heapSize += fStringSize;
232 
233 	PRINT(("heap:  %9lu allocations, size: %9lu\n", heapCount, heapSize));
234 	PRINT(("areas: %9lu allocations, size: %9lu\n", areaCount, areaSize));
235 }
236 
237