1using System.Collections.Generic;
9 public class FileStatistics
11 private readonly uint blockSize;
12 private uint nrObjects = 0;
13 private uint nrBlocks = 0;
14 private uint nrBlobBlocks = 0;
15 private uint minObjSize = uint.MaxValue;
16 private uint maxObjSize = uint.MinValue;
17 private uint minDepth = uint.MaxValue;
18 private uint maxDepth = uint.MinValue;
19 private uint minObjPerBlock = uint.MaxValue;
20 private uint maxObjPerBlock = uint.MinValue;
21 private uint minBytesUsedPerBlock = uint.MaxValue;
22 private uint maxBytesUsedPerBlock = uint.MinValue;
23 private ulong sumObjSize = 0;
24 private ulong nrBytesUsed = 0;
25 private ulong nrBytesUnused = 0;
26 private ulong nrBytesTotal = 0;
27 private ulong nrBlobBytesUsed = 0;
28 private ulong nrBlobBytesUnused = 0;
29 private ulong nrBlobBytesTotal = 0;
30 private readonly ulong nrBlockLoads = 0;
31 private readonly ulong nrCacheLoads = 0;
32 private readonly ulong nrBlockSaves = 0;
33 private readonly ulong nrBlobBlockLoads = 0;
34 private readonly ulong nrBlobBlockSaves = 0;
35 private readonly ulong nrFullFileScans;
36 private readonly ulong nrSearches;
37 private bool isCorrupt =
false;
38 private bool isBalanced =
true;
39 private List<string> comments =
null;
40 private readonly
object synchObject =
new object();
41 private int[] unreferencedBlocks =
null;
42 private int[] unreferencedBlobBlocks =
null;
82 lock (this.synchObject)
96 lock (this.synchObject)
98 return this.nrBytesUsed;
110 lock (this.synchObject)
112 return this.nrBytesUnused;
124 lock (this.synchObject)
126 return this.nrBytesTotal;
138 lock (this.synchObject)
140 return this.nrBlobBlocks;
152 lock (this.synchObject)
154 return this.nrBlobBytesUsed;
166 lock (this.synchObject)
168 return this.nrBlobBytesUnused;
180 lock (this.synchObject)
182 return this.nrBlobBytesTotal;
194 lock (this.synchObject)
196 return (100.0 * (this.nrBytesUsed + this.nrBlobBytesUsed)) / (this.nrBytesTotal + this.nrBlobBytesTotal);
208 lock (this.synchObject)
210 return this.nrObjects;
222 lock (this.synchObject)
224 return this.minObjSize;
230 lock (this.synchObject)
232 this.minObjSize = value;
244 lock (this.synchObject)
246 return this.maxObjSize;
258 lock (this.synchObject)
260 return this.minObjPerBlock;
272 lock (this.synchObject)
274 return this.maxObjPerBlock;
286 lock (this.synchObject)
288 return this.minBytesUsedPerBlock;
300 lock (this.synchObject)
302 return this.maxBytesUsedPerBlock;
314 lock (this.synchObject)
316 return ((
double)this.sumObjSize) / this.nrObjects;
328 lock (this.synchObject)
330 return ((
double)this.nrObjects) / this.nrBlocks;
342 lock (this.synchObject)
344 return ((
double)this.nrBytesUsed) / this.nrBlocks;
356 lock (this.synchObject)
358 return this.minDepth;
370 lock (this.synchObject)
372 return this.maxDepth;
384 lock (this.synchObject)
386 return this.nrBlockLoads;
398 lock (this.synchObject)
400 return this.nrCacheLoads;
412 lock (this.synchObject)
414 return this.nrBlockSaves;
426 lock (this.synchObject)
428 return this.nrBlobBlockLoads;
440 lock (this.synchObject)
442 return this.nrBlobBlockSaves;
454 lock (this.synchObject)
456 return this.isCorrupt;
468 lock (this.synchObject)
470 return this.isBalanced && this.minDepth == this.maxDepth;
476 lock (this.synchObject)
478 this.isBalanced = value;
490 lock (this.synchObject)
492 if (this.comments is
null)
493 return new string[0];
495 return this.comments.ToArray();
507 lock (this.synchObject)
509 return !(this.comments is
null);
519 get => this.unreferencedBlocks;
520 internal set => this.unreferencedBlocks = value;
528 get => this.unreferencedBlobBlocks;
529 internal set => this.unreferencedBlobBlocks = value;
534 lock (this.synchObject)
557 lock (this.synchObject)
572 internal void ReportObjectStatistics(uint ObjectSize)
574 lock (this.synchObject)
576 if (ObjectSize < this.minObjSize)
577 this.minObjSize = ObjectSize;
579 if (ObjectSize > this.maxObjSize)
580 this.maxObjSize = ObjectSize;
582 this.sumObjSize += ObjectSize;
587 internal void ReportDepthStatistics(uint Depth)
589 lock (this.synchObject)
591 if (Depth < this.minDepth)
592 this.minDepth = Depth;
594 if (Depth > this.maxDepth)
595 this.maxDepth = Depth;
599 internal void LogError(
string Message)
601 lock (this.synchObject)
603 this.isCorrupt =
true;
605 if (this.comments is
null)
606 this.comments =
new List<string>();
608 this.comments.Add(Message);
612 internal void LogComment(
string Message)
614 lock (this.synchObject)
616 if (this.comments is
null)
617 this.comments =
new List<string>();
619 this.comments.Add(Message);
628 public void ToString(StringBuilder Output,
bool WriteStat)
630 lock (this.synchObject)
634 Output.AppendLine(
"Block Size: " + this.blockSize.ToString());
635 Output.AppendLine(
"#Blocks: " + this.nrBlocks.ToString());
636 Output.AppendLine(
"#BLOB Blocks: " + this.nrBlobBlocks.ToString());
637 Output.AppendLine(
"#Bytes used: " + this.nrBytesUsed.ToString());
638 Output.AppendLine(
"#Bytes unused: " + this.nrBytesUnused.ToString());
639 Output.AppendLine(
"#Bytes total: " + this.nrBytesTotal.ToString());
640 Output.AppendLine(
"#BLOB Bytes used: " + this.nrBlobBytesUsed.ToString());
641 Output.AppendLine(
"#BLOB Bytes unused: " + this.nrBlobBytesUnused.ToString());
642 Output.AppendLine(
"#BLOB Bytes total: " + this.nrBlobBytesTotal.ToString());
643 Output.AppendLine(
"#Block loads: " + this.nrBlockLoads.ToString());
644 Output.AppendLine(
"#Cache loads: " + this.nrCacheLoads.ToString());
645 Output.AppendLine(
"#Block saves: " + this.nrBlockSaves.ToString());
646 Output.AppendLine(
"#BLOB Block loads: " + this.nrBlobBlockLoads.ToString());
647 Output.AppendLine(
"#BLOB Block saves: " + this.nrBlobBlockSaves.ToString());
648 Output.AppendLine(
"#Objects: " + this.nrObjects.ToString());
649 Output.AppendLine(
"Smallest object: " + this.minObjSize.ToString());
650 Output.AppendLine(
"Largest object: " + this.maxObjSize.ToString());
652 Output.AppendLine(
"Usage: " + this.
Usage.ToString(
"F2") +
" %");
653 Output.AppendLine(
"Min(Depth): " + this.minDepth.ToString());
654 Output.AppendLine(
"Max(Depth): " + this.maxDepth.ToString());
655 Output.AppendLine(
"Min(Objects/Block): " + this.minObjPerBlock.ToString());
656 Output.AppendLine(
"Max(Objects/Block): " + this.maxObjPerBlock.ToString());
658 Output.AppendLine(
"Min(Bytes Used/Block): " + this.minBytesUsedPerBlock.ToString());
659 Output.AppendLine(
"Max(Bytes Used/Block): " + this.maxBytesUsedPerBlock.ToString());
661 Output.AppendLine(
"Is Corrupt: " + this.isCorrupt.ToString());
662 Output.AppendLine(
"Is Balanced: " + this.isBalanced.ToString());
663 Output.AppendLine(
"Has Comments: " + this.
HasComments.ToString());
669 foreach (
string Comment
in this.
Comments)
670 Output.AppendLine(Comment);
ulong NrBlockLoads
Number of blocks load operations performed.
double AverageBytesUsedPerBlock
Average bytes used per block.
ulong NrBytesUnused
Number of bytes unused.
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.
uint MinObjectSize
Size of smallest object.
bool IsCorrupt
If the file is corrupt.
uint NrObjects
Number of objects stored.
uint MaxDepth
Depth of deepest leaf.
ulong NrCacheLoads
Number of blocks load operations performed, where result was fetched from internal cache.
ulong NrBytesUsed
Number of bytes used.
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.
uint MinDepth
Depth of most shallow leaf.
string[] Comments
Any comments logged when scanning the file. If no comments, this property is null.
uint MaxObjectSize
Size of largest object.
uint NrBlobBlocks
Number of BLOB blocks
double Usage
Usage, in percent.
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 NrBlocks
Number of blocks
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.
bool IsBalanced
If the file is balanced.
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.