xref: /haiku/src/add-ons/kernel/file_systems/ramfs/AllocationInfo.cpp (revision 3af8011358bd4c624a0979336d48dabb466171ed)
1 /*
2  * Copyright 2007, Ingo Weinhold, ingo_weinhold@gmx.de.
3  * All rights reserved. Distributed under the terms of the MIT license.
4  */
5 #include "AllocationInfo.h"
6 
7 #include "DebugSupport.h"
8 
9 #include "Attribute.h"
10 #include "Directory.h"
11 #include "Entry.h"
12 #include "File.h"
13 #include "SymLink.h"
14 
15 // constructor
16 AllocationInfo::AllocationInfo()
17 	: fNodeTableArraySize(0),
18 	  fNodeTableVectorSize(0),
19 	  fNodeTableElementCount(0),
20 	  fDirectoryEntryTableArraySize(0),
21 	  fDirectoryEntryTableVectorSize(0),
22 	  fDirectoryEntryTableElementCount(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 // AddAttributeAllocation
74 void
75 AllocationInfo::AddAttributeAllocation(size_t size)
76 {
77 	fAttributeCount++;
78 	fAttributeSize += size;
79 }
80 
81 // AddDirectoryAllocation
82 void
83 AllocationInfo::AddDirectoryAllocation()
84 {
85 	fDirectoryCount++;
86 }
87 
88 // AddEntryAllocation
89 void
90 AllocationInfo::AddEntryAllocation()
91 {
92 	fEntryCount++;
93 }
94 
95 // AddFileAllocation
96 void
97 AllocationInfo::AddFileAllocation(size_t size)
98 {
99 	fFileCount++;
100 	fFileSize += size;
101 }
102 
103 // AddSymLinkAllocation
104 void
105 AllocationInfo::AddSymLinkAllocation(size_t size)
106 {
107 	fSymLinkCount++;
108 	fSymLinkSize += size;
109 }
110 
111 // AddAreaAllocation
112 void
113 AllocationInfo::AddAreaAllocation(size_t size, size_t count)
114 {
115 	fAreaCount += count;
116 	fAreaSize += count * size;
117 }
118 
119 // AddBlockAllocation
120 void
121 AllocationInfo::AddBlockAllocation(size_t size)
122 {
123 	fBlockCount++;
124 	fBlockSize += size;
125 }
126 
127 // AddListAllocation
128 void
129 AllocationInfo::AddListAllocation(size_t capacity, size_t elementSize)
130 {
131 	fListCount += 1;
132 	fListSize += capacity * elementSize;
133 }
134 
135 // AddOtherAllocation
136 void
137 AllocationInfo::AddOtherAllocation(size_t size, size_t count)
138 {
139 	fOtherCount += count;
140 	fOtherSize += size * count;
141 }
142 
143 // AddStringAllocation
144 void
145 AllocationInfo::AddStringAllocation(size_t size)
146 {
147 	fStringCount++;
148 	fStringSize += size;
149 }
150 
151 // Dump
152 void
153 AllocationInfo::Dump() const
154 {
155 	size_t heapCount = 0;
156 	size_t heapSize = 0;
157 	size_t areaCount = 0;
158 	size_t areaSize = 0;
159 
160 	PRINT("  node table:\n");
161 	PRINT("    array size:  %9lu\n", fNodeTableArraySize);
162 	PRINT("    vector size: %9lu\n", fNodeTableVectorSize);
163 	PRINT("    elements:    %9lu\n", fNodeTableElementCount);
164 	areaCount += 2;
165 	areaSize += fNodeTableArraySize * sizeof(int32) + fNodeTableVectorSize;
166 
167 	PRINT("  entry table:\n");
168 	PRINT("    array size:  %9lu\n", fDirectoryEntryTableArraySize);
169 	PRINT("    vector size: %9lu\n", fDirectoryEntryTableVectorSize);
170 	PRINT("    elements:    %9lu\n", fDirectoryEntryTableElementCount);
171 	areaCount += 2;
172 	areaSize += fDirectoryEntryTableArraySize * sizeof(int32)
173 				+ fDirectoryEntryTableVectorSize;
174 
175 	PRINT("  attributes:  %9lu, size: %9lu\n", fAttributeCount, fAttributeSize);
176 	heapCount += fAttributeCount;
177 	heapSize += fAttributeCount * sizeof(Attribute);
178 
179 	PRINT("  directories: %9lu\n", fDirectoryCount);
180 	heapCount += fDirectoryCount;
181 	heapSize += fDirectoryCount * sizeof(Directory);
182 
183 	PRINT("  entries:     %9lu\n", fEntryCount);
184 	heapCount += fEntryCount;
185 	heapSize += fEntryCount * sizeof(Entry);
186 
187 	PRINT("  files:       %9lu, size: %9lu\n", fFileCount, fFileSize);
188 	heapCount += fFileCount;
189 	heapSize += fFileCount * sizeof(File);
190 
191 	PRINT("  symlinks:    %9lu, size: %9lu\n", fSymLinkCount, fSymLinkSize);
192 	heapCount += fSymLinkCount;
193 	heapSize += fSymLinkCount * sizeof(SymLink);
194 
195 	PRINT("  areas:       %9lu, size: %9lu\n", fAreaCount, fAreaSize);
196 	areaCount += fAreaCount;
197 	areaSize += fAreaSize;
198 
199 	PRINT("  blocks:      %9lu, size: %9lu\n", fBlockCount, fBlockSize);
200 
201 	PRINT("  lists:       %9lu, size: %9lu\n", fListCount, fListSize);
202 	heapCount += fListCount;
203 	heapSize += fListSize;
204 
205 	PRINT("  other:       %9lu, size: %9lu\n", fOtherCount, fOtherSize);
206 	heapCount += fOtherCount;
207 	heapSize += fOtherSize;
208 
209 	PRINT("  strings:     %9lu, size: %9lu\n", fStringCount, fStringSize);
210 	heapCount += fStringCount;
211 	heapSize += fStringSize;
212 
213 	PRINT("heap:  %9lu allocations, size: %9lu\n", heapCount, heapSize);
214 	PRINT("areas: %9lu allocations, size: %9lu\n", areaCount, areaSize);
215 }
216 
217