Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
FileStatistics.cs
1using System;
2using System.Text;
4
6{
10 public class FileStatistics
11 {
12 private readonly uint blockSize;
13 private uint nrObjects = 0;
14 private uint nrBlocks = 0;
15 private uint nrBlobBlocks = 0;
16 private uint minObjSize = uint.MaxValue;
17 private uint maxObjSize = uint.MinValue;
18 private uint minDepth = uint.MaxValue;
19 private uint maxDepth = uint.MinValue;
20 private uint minObjPerBlock = uint.MaxValue;
21 private uint maxObjPerBlock = uint.MinValue;
22 private uint minBytesUsedPerBlock = uint.MaxValue;
23 private uint maxBytesUsedPerBlock = uint.MinValue;
24 private ulong sumObjSize = 0;
25 private ulong nrBytesUsed = 0;
26 private ulong nrBytesUnused = 0;
27 private ulong nrBytesTotal = 0;
28 private ulong nrBlobBytesUsed = 0;
29 private ulong nrBlobBytesUnused = 0;
30 private ulong nrBlobBytesTotal = 0;
31 private readonly ulong nrBlockLoads = 0;
32 private readonly ulong nrCacheLoads = 0;
33 private readonly ulong nrBlockSaves = 0;
34 private readonly ulong nrBlobBlockLoads = 0;
35 private readonly ulong nrBlobBlockSaves = 0;
36 private readonly ulong nrFullFileScans;
37 private readonly ulong nrSearches;
38 private bool isCorrupt = false;
39 private bool isBalanced = true;
40 private ChunkedList<string> comments = null;
41 private readonly object synchObject = new object();
42 private int[] unreferencedBlocks = null;
43 private int[] unreferencedBlobBlocks = null;
44
50 {
51 this.blockSize = BlockSize;
52 this.nrBlockLoads = NrBlockLoads;
53 this.nrCacheLoads = NrCacheLoads;
54 this.nrBlockSaves = NrBlockSaves;
55 this.nrBlobBlockLoads = NrBlobBlockLoads;
56 this.nrBlobBlockSaves = NrBlobBlockSaves;
57 this.nrFullFileScans = NrFullFileScans;
58 this.nrSearches = NrSearches;
59 }
60
64 public uint BlockSize => this.blockSize;
65
69 public ulong NrSearches => this.nrSearches;
70
74 public ulong NrFullFileScans => this.nrFullFileScans;
75
79 public uint NrBlocks
80 {
81 get
82 {
83 lock (this.synchObject)
84 {
85 return this.nrBlocks;
86 }
87 }
88 }
89
93 public ulong NrBytesUsed
94 {
95 get
96 {
97 lock (this.synchObject)
98 {
99 return this.nrBytesUsed;
100 }
101 }
102 }
103
107 public ulong NrBytesUnused
108 {
109 get
110 {
111 lock (this.synchObject)
112 {
113 return this.nrBytesUnused;
114 }
115 }
116 }
117
121 public ulong NrBytesTotal
122 {
123 get
124 {
125 lock (this.synchObject)
126 {
127 return this.nrBytesTotal;
128 }
129 }
130 }
131
135 public uint NrBlobBlocks
136 {
137 get
138 {
139 lock (this.synchObject)
140 {
141 return this.nrBlobBlocks;
142 }
143 }
144 }
145
149 public ulong NrBlobBytesUsed
150 {
151 get
152 {
153 lock (this.synchObject)
154 {
155 return this.nrBlobBytesUsed;
156 }
157 }
158 }
159
163 public ulong NrBlobBytesUnused
164 {
165 get
166 {
167 lock (this.synchObject)
168 {
169 return this.nrBlobBytesUnused;
170 }
171 }
172 }
173
177 public ulong NrBlobBytesTotal
178 {
179 get
180 {
181 lock (this.synchObject)
182 {
183 return this.nrBlobBytesTotal;
184 }
185 }
186 }
187
191 public double Usage
192 {
193 get
194 {
195 lock (this.synchObject)
196 {
197 return (100.0 * (this.nrBytesUsed + this.nrBlobBytesUsed)) / (this.nrBytesTotal + this.nrBlobBytesTotal);
198 }
199 }
200 }
201
205 public uint NrObjects
206 {
207 get
208 {
209 lock (this.synchObject)
210 {
211 return this.nrObjects;
212 }
213 }
214 }
215
219 public uint MinObjectSize
220 {
221 get
222 {
223 lock (this.synchObject)
224 {
225 return this.minObjSize;
226 }
227 }
228
229 internal set
230 {
231 lock (this.synchObject)
232 {
233 this.minObjSize = value;
234 }
235 }
236 }
237
241 public uint MaxObjectSize
242 {
243 get
244 {
245 lock (this.synchObject)
246 {
247 return this.maxObjSize;
248 }
249 }
250 }
251
256 {
257 get
258 {
259 lock (this.synchObject)
260 {
261 return this.minObjPerBlock;
262 }
263 }
264 }
265
270 {
271 get
272 {
273 lock (this.synchObject)
274 {
275 return this.maxObjPerBlock;
276 }
277 }
278 }
279
284 {
285 get
286 {
287 lock (this.synchObject)
288 {
289 return this.minBytesUsedPerBlock;
290 }
291 }
292 }
293
298 {
299 get
300 {
301 lock (this.synchObject)
302 {
303 return this.maxBytesUsedPerBlock;
304 }
305 }
306 }
307
311 public double AverageObjectSize
312 {
313 get
314 {
315 lock (this.synchObject)
316 {
317 return ((double)this.sumObjSize) / this.nrObjects;
318 }
319 }
320 }
321
326 {
327 get
328 {
329 lock (this.synchObject)
330 {
331 return ((double)this.nrObjects) / this.nrBlocks;
332 }
333 }
334 }
335
340 {
341 get
342 {
343 lock (this.synchObject)
344 {
345 return ((double)this.nrBytesUsed) / this.nrBlocks;
346 }
347 }
348 }
349
353 public uint MinDepth
354 {
355 get
356 {
357 lock (this.synchObject)
358 {
359 return this.minDepth;
360 }
361 }
362 }
363
367 public uint MaxDepth
368 {
369 get
370 {
371 lock (this.synchObject)
372 {
373 return this.maxDepth;
374 }
375 }
376 }
377
381 public ulong NrBlockLoads
382 {
383 get
384 {
385 lock (this.synchObject)
386 {
387 return this.nrBlockLoads;
388 }
389 }
390 }
391
395 public ulong NrCacheLoads
396 {
397 get
398 {
399 lock (this.synchObject)
400 {
401 return this.nrCacheLoads;
402 }
403 }
404 }
405
409 public ulong NrBlockSaves
410 {
411 get
412 {
413 lock (this.synchObject)
414 {
415 return this.nrBlockSaves;
416 }
417 }
418 }
419
423 public ulong NrBlobBlockLoads
424 {
425 get
426 {
427 lock (this.synchObject)
428 {
429 return this.nrBlobBlockLoads;
430 }
431 }
432 }
433
437 public ulong NrBlobBlockSaves
438 {
439 get
440 {
441 lock (this.synchObject)
442 {
443 return this.nrBlobBlockSaves;
444 }
445 }
446 }
447
451 public bool IsCorrupt
452 {
453 get
454 {
455 lock (this.synchObject)
456 {
457 return this.isCorrupt;
458 }
459 }
460 }
461
465 public bool IsBalanced
466 {
467 get
468 {
469 lock (this.synchObject)
470 {
471 return this.isBalanced && this.minDepth == this.maxDepth;
472 }
473 }
474
475 internal set
476 {
477 lock (this.synchObject)
478 {
479 this.isBalanced = value;
480 }
481 }
482 }
483
487 public string[] Comments
488 {
489 get
490 {
491 lock (this.synchObject)
492 {
493 if (this.comments is null)
494 return Array.Empty<string>();
495 else
496 return this.comments.ToArray();
497 }
498 }
499 }
500
504 public bool HasComments
505 {
506 get
507 {
508 lock (this.synchObject)
509 {
510 return !(this.comments is null);
511 }
512 }
513 }
514
519 {
520 get => this.unreferencedBlocks;
521 internal set => this.unreferencedBlocks = value;
522 }
523
528 {
529 get => this.unreferencedBlobBlocks;
530 internal set => this.unreferencedBlobBlocks = value;
531 }
532
533 internal void ReportBlockStatistics(uint NrBytesUsed, uint NrBytesUnused, uint NrObjects)
534 {
535 lock (this.synchObject)
536 {
537 this.nrBlocks++;
538 this.nrBytesUsed += NrBytesUsed;
539 this.nrBytesUnused += NrBytesUnused;
540 this.nrBytesTotal += NrBytesUsed + NrBytesUnused;
541
542 if (NrObjects < this.minObjPerBlock)
543 this.minObjPerBlock = NrObjects;
544
545 if (NrObjects > this.maxObjPerBlock)
546 this.maxObjPerBlock = NrObjects;
547
548 if (NrBytesUsed < this.minBytesUsedPerBlock)
549 this.minBytesUsedPerBlock = NrBytesUsed;
550
551 if (NrBytesUsed > this.maxBytesUsedPerBlock)
552 this.maxBytesUsedPerBlock = NrBytesUsed;
553 }
554 }
555
556 internal void ReportBlobBlockStatistics(uint NrBytesUsed, uint NrBytesUnused)
557 {
558 lock (this.synchObject)
559 {
560 this.nrBlobBlocks++;
561 this.nrBlobBytesUsed += NrBytesUsed;
562 this.nrBlobBytesUnused += NrBytesUnused;
563 this.nrBlobBytesTotal += NrBytesUsed + NrBytesUnused;
564
565 if (NrBytesUsed < this.minBytesUsedPerBlock)
566 this.minBytesUsedPerBlock = NrBytesUsed;
567
568 if (NrBytesUsed > this.maxBytesUsedPerBlock)
569 this.maxBytesUsedPerBlock = NrBytesUsed;
570 }
571 }
572
573 internal void ReportObjectStatistics(uint ObjectSize)
574 {
575 lock (this.synchObject)
576 {
577 if (ObjectSize < this.minObjSize)
578 this.minObjSize = ObjectSize;
579
580 if (ObjectSize > this.maxObjSize)
581 this.maxObjSize = ObjectSize;
582
583 this.sumObjSize += ObjectSize;
584 this.nrObjects++;
585 }
586 }
587
588 internal void ReportDepthStatistics(uint Depth)
589 {
590 lock (this.synchObject)
591 {
592 if (Depth < this.minDepth)
593 this.minDepth = Depth;
594
595 if (Depth > this.maxDepth)
596 this.maxDepth = Depth;
597 }
598 }
599
600 internal void LogError(string Message)
601 {
602 lock (this.synchObject)
603 {
604 this.isCorrupt = true;
605
606 if (this.comments is null)
607 this.comments = new ChunkedList<string>();
608
609 this.comments.Add(Message);
610 }
611 }
612
613 internal void LogComment(string Message)
614 {
615 lock (this.synchObject)
616 {
617 if (this.comments is null)
618 this.comments = new ChunkedList<string>();
619
620 this.comments.Add(Message);
621 }
622 }
623
629 public void ToString(StringBuilder Output, bool WriteStat)
630 {
631 lock (this.synchObject)
632 {
633 if (WriteStat)
634 {
635 Output.AppendLine("Block Size: " + this.blockSize.ToString());
636 Output.AppendLine("#Blocks: " + this.nrBlocks.ToString());
637 Output.AppendLine("#BLOB Blocks: " + this.nrBlobBlocks.ToString());
638 Output.AppendLine("#Bytes used: " + this.nrBytesUsed.ToString());
639 Output.AppendLine("#Bytes unused: " + this.nrBytesUnused.ToString());
640 Output.AppendLine("#Bytes total: " + this.nrBytesTotal.ToString());
641 Output.AppendLine("#BLOB Bytes used: " + this.nrBlobBytesUsed.ToString());
642 Output.AppendLine("#BLOB Bytes unused: " + this.nrBlobBytesUnused.ToString());
643 Output.AppendLine("#BLOB Bytes total: " + this.nrBlobBytesTotal.ToString());
644 Output.AppendLine("#Block loads: " + this.nrBlockLoads.ToString());
645 Output.AppendLine("#Cache loads: " + this.nrCacheLoads.ToString());
646 Output.AppendLine("#Block saves: " + this.nrBlockSaves.ToString());
647 Output.AppendLine("#BLOB Block loads: " + this.nrBlobBlockLoads.ToString());
648 Output.AppendLine("#BLOB Block saves: " + this.nrBlobBlockSaves.ToString());
649 Output.AppendLine("#Objects: " + this.nrObjects.ToString());
650 Output.AppendLine("Smallest object: " + this.minObjSize.ToString());
651 Output.AppendLine("Largest object: " + this.maxObjSize.ToString());
652 Output.AppendLine("Average object: " + this.AverageObjectSize.ToString("F1"));
653 Output.AppendLine("Usage: " + this.Usage.ToString("F2") + " %");
654 Output.AppendLine("Min(Depth): " + this.minDepth.ToString());
655 Output.AppendLine("Max(Depth): " + this.maxDepth.ToString());
656 Output.AppendLine("Min(Objects/Block): " + this.minObjPerBlock.ToString());
657 Output.AppendLine("Max(Objects/Block): " + this.maxObjPerBlock.ToString());
658 Output.AppendLine("Avg(Objects/Block): " + this.AverageObjectsPerBlock.ToString("F1"));
659 Output.AppendLine("Min(Bytes Used/Block): " + this.minBytesUsedPerBlock.ToString());
660 Output.AppendLine("Max(Bytes Used/Block): " + this.maxBytesUsedPerBlock.ToString());
661 Output.AppendLine("Avg(Bytes Used/Block): " + this.AverageBytesUsedPerBlock.ToString("F1"));
662 Output.AppendLine("Is Corrupt: " + this.isCorrupt.ToString());
663 Output.AppendLine("Is Balanced: " + this.isBalanced.ToString());
664 Output.AppendLine("Has Comments: " + this.HasComments.ToString());
665 }
666
667 if (this.HasComments)
668 {
669 Output.AppendLine();
670 foreach (string Comment in this.Comments)
671 Output.AppendLine(Comment);
672 }
673 }
674 }
675
676 }
677}
Contains information about a file.
ulong NrBlockLoads
Number of blocks load operations performed.
double AverageBytesUsedPerBlock
Average bytes used per block.
uint MaxObjectsPerBlock
Largest number of objects in a block.
uint MaxBytesUsedPerBlock
Largest number of bytes used in a block.
ulong NrBlockSaves
Number of blocks save operations performed.
ulong NrCacheLoads
Number of blocks load operations performed, where result was fetched from internal cache.
ulong NrBlobBlockLoads
Number of BLOB blocks load operations performed.
int[] UnreferencedBlobBlocks
Unreferenced BLOB blocks, if any.
ulong NrBlobBytesUsed
Number of BLOB bytes used.
uint MinBytesUsedPerBlock
Smallest number of bytes used in a block.
string[] Comments
Any comments logged when scanning the file. If no comments, this property is null.
double AverageObjectSize
Average size of object.
ulong NrBlobBytesTotal
Total number of BLOB bytes in file.
ulong NrSearches
Number of searches performed against the file.
int[] UnreferencedBlocks
Unreferenced blocks, if any.
ulong NrFullFileScans
Number of searches performed, resulting in full file scans.
ulong NrBlobBytesUnused
Number of BLOB bytes unused.
uint MinObjectsPerBlock
Smallest number of objects in a block.
bool HasComments
If comments have been logged.
ulong NrBlobBlockSaves
Number of BLOB blocks save operations performed.
ulong NrBytesTotal
Total number of bytes in file.
double AverageObjectsPerBlock
Average number of objects per block.
void ToString(StringBuilder Output, bool WriteStat)
Outputs file statistics to a string.
FileStatistics(uint BlockSize, ulong NrBlockLoads, ulong NrCacheLoads, ulong NrBlockSaves, ulong NrBlobBlockLoads, ulong NrBlobBlockSaves, ulong NrFullFileScans, ulong NrSearches)
Contains information about a file.
A chunked list is a linked list of chunks of objects of type T .
Definition: ChunkedList.cs:54
void Add(T Item)
Adds an item to the collection.
Definition: ChunkedList.cs:272
T[] ToArray()
Returns an array containing all elements of the collection.