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.Collections.Generic;
2using System.Text;
3
5{
9 public class FileStatistics
10 {
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;
43
49 {
50 this.blockSize = BlockSize;
51 this.nrBlockLoads = NrBlockLoads;
52 this.nrCacheLoads = NrCacheLoads;
53 this.nrBlockSaves = NrBlockSaves;
54 this.nrBlobBlockLoads = NrBlobBlockLoads;
55 this.nrBlobBlockSaves = NrBlobBlockSaves;
56 this.nrFullFileScans = NrFullFileScans;
57 this.nrSearches = NrSearches;
58 }
59
63 public uint BlockSize => this.blockSize;
64
68 public ulong NrSearches => this.nrSearches;
69
73 public ulong NrFullFileScans => this.nrFullFileScans;
74
78 public uint NrBlocks
79 {
80 get
81 {
82 lock (this.synchObject)
83 {
84 return this.nrBlocks;
85 }
86 }
87 }
88
92 public ulong NrBytesUsed
93 {
94 get
95 {
96 lock (this.synchObject)
97 {
98 return this.nrBytesUsed;
99 }
100 }
101 }
102
106 public ulong NrBytesUnused
107 {
108 get
109 {
110 lock (this.synchObject)
111 {
112 return this.nrBytesUnused;
113 }
114 }
115 }
116
120 public ulong NrBytesTotal
121 {
122 get
123 {
124 lock (this.synchObject)
125 {
126 return this.nrBytesTotal;
127 }
128 }
129 }
130
134 public uint NrBlobBlocks
135 {
136 get
137 {
138 lock (this.synchObject)
139 {
140 return this.nrBlobBlocks;
141 }
142 }
143 }
144
148 public ulong NrBlobBytesUsed
149 {
150 get
151 {
152 lock (this.synchObject)
153 {
154 return this.nrBlobBytesUsed;
155 }
156 }
157 }
158
162 public ulong NrBlobBytesUnused
163 {
164 get
165 {
166 lock (this.synchObject)
167 {
168 return this.nrBlobBytesUnused;
169 }
170 }
171 }
172
176 public ulong NrBlobBytesTotal
177 {
178 get
179 {
180 lock (this.synchObject)
181 {
182 return this.nrBlobBytesTotal;
183 }
184 }
185 }
186
190 public double Usage
191 {
192 get
193 {
194 lock (this.synchObject)
195 {
196 return (100.0 * (this.nrBytesUsed + this.nrBlobBytesUsed)) / (this.nrBytesTotal + this.nrBlobBytesTotal);
197 }
198 }
199 }
200
204 public uint NrObjects
205 {
206 get
207 {
208 lock (this.synchObject)
209 {
210 return this.nrObjects;
211 }
212 }
213 }
214
218 public uint MinObjectSize
219 {
220 get
221 {
222 lock (this.synchObject)
223 {
224 return this.minObjSize;
225 }
226 }
227
228 internal set
229 {
230 lock (this.synchObject)
231 {
232 this.minObjSize = value;
233 }
234 }
235 }
236
240 public uint MaxObjectSize
241 {
242 get
243 {
244 lock (this.synchObject)
245 {
246 return this.maxObjSize;
247 }
248 }
249 }
250
255 {
256 get
257 {
258 lock (this.synchObject)
259 {
260 return this.minObjPerBlock;
261 }
262 }
263 }
264
269 {
270 get
271 {
272 lock (this.synchObject)
273 {
274 return this.maxObjPerBlock;
275 }
276 }
277 }
278
283 {
284 get
285 {
286 lock (this.synchObject)
287 {
288 return this.minBytesUsedPerBlock;
289 }
290 }
291 }
292
297 {
298 get
299 {
300 lock (this.synchObject)
301 {
302 return this.maxBytesUsedPerBlock;
303 }
304 }
305 }
306
310 public double AverageObjectSize
311 {
312 get
313 {
314 lock (this.synchObject)
315 {
316 return ((double)this.sumObjSize) / this.nrObjects;
317 }
318 }
319 }
320
325 {
326 get
327 {
328 lock (this.synchObject)
329 {
330 return ((double)this.nrObjects) / this.nrBlocks;
331 }
332 }
333 }
334
339 {
340 get
341 {
342 lock (this.synchObject)
343 {
344 return ((double)this.nrBytesUsed) / this.nrBlocks;
345 }
346 }
347 }
348
352 public uint MinDepth
353 {
354 get
355 {
356 lock (this.synchObject)
357 {
358 return this.minDepth;
359 }
360 }
361 }
362
366 public uint MaxDepth
367 {
368 get
369 {
370 lock (this.synchObject)
371 {
372 return this.maxDepth;
373 }
374 }
375 }
376
380 public ulong NrBlockLoads
381 {
382 get
383 {
384 lock (this.synchObject)
385 {
386 return this.nrBlockLoads;
387 }
388 }
389 }
390
394 public ulong NrCacheLoads
395 {
396 get
397 {
398 lock (this.synchObject)
399 {
400 return this.nrCacheLoads;
401 }
402 }
403 }
404
408 public ulong NrBlockSaves
409 {
410 get
411 {
412 lock (this.synchObject)
413 {
414 return this.nrBlockSaves;
415 }
416 }
417 }
418
422 public ulong NrBlobBlockLoads
423 {
424 get
425 {
426 lock (this.synchObject)
427 {
428 return this.nrBlobBlockLoads;
429 }
430 }
431 }
432
436 public ulong NrBlobBlockSaves
437 {
438 get
439 {
440 lock (this.synchObject)
441 {
442 return this.nrBlobBlockSaves;
443 }
444 }
445 }
446
450 public bool IsCorrupt
451 {
452 get
453 {
454 lock (this.synchObject)
455 {
456 return this.isCorrupt;
457 }
458 }
459 }
460
464 public bool IsBalanced
465 {
466 get
467 {
468 lock (this.synchObject)
469 {
470 return this.isBalanced && this.minDepth == this.maxDepth;
471 }
472 }
473
474 internal set
475 {
476 lock (this.synchObject)
477 {
478 this.isBalanced = value;
479 }
480 }
481 }
482
486 public string[] Comments
487 {
488 get
489 {
490 lock (this.synchObject)
491 {
492 if (this.comments is null)
493 return new string[0];
494 else
495 return this.comments.ToArray();
496 }
497 }
498 }
499
503 public bool HasComments
504 {
505 get
506 {
507 lock (this.synchObject)
508 {
509 return !(this.comments is null);
510 }
511 }
512 }
513
518 {
519 get => this.unreferencedBlocks;
520 internal set => this.unreferencedBlocks = value;
521 }
522
527 {
528 get => this.unreferencedBlobBlocks;
529 internal set => this.unreferencedBlobBlocks = value;
530 }
531
532 internal void ReportBlockStatistics(uint NrBytesUsed, uint NrBytesUnused, uint NrObjects)
533 {
534 lock (this.synchObject)
535 {
536 this.nrBlocks++;
537 this.nrBytesUsed += NrBytesUsed;
538 this.nrBytesUnused += NrBytesUnused;
539 this.nrBytesTotal += NrBytesUsed + NrBytesUnused;
540
541 if (NrObjects < this.minObjPerBlock)
542 this.minObjPerBlock = NrObjects;
543
544 if (NrObjects > this.maxObjPerBlock)
545 this.maxObjPerBlock = NrObjects;
546
547 if (NrBytesUsed < this.minBytesUsedPerBlock)
548 this.minBytesUsedPerBlock = NrBytesUsed;
549
550 if (NrBytesUsed > this.maxBytesUsedPerBlock)
551 this.maxBytesUsedPerBlock = NrBytesUsed;
552 }
553 }
554
555 internal void ReportBlobBlockStatistics(uint NrBytesUsed, uint NrBytesUnused)
556 {
557 lock (this.synchObject)
558 {
559 this.nrBlobBlocks++;
560 this.nrBlobBytesUsed += NrBytesUsed;
561 this.nrBlobBytesUnused += NrBytesUnused;
562 this.nrBlobBytesTotal += NrBytesUsed + NrBytesUnused;
563
564 if (NrBytesUsed < this.minBytesUsedPerBlock)
565 this.minBytesUsedPerBlock = NrBytesUsed;
566
567 if (NrBytesUsed > this.maxBytesUsedPerBlock)
568 this.maxBytesUsedPerBlock = NrBytesUsed;
569 }
570 }
571
572 internal void ReportObjectStatistics(uint ObjectSize)
573 {
574 lock (this.synchObject)
575 {
576 if (ObjectSize < this.minObjSize)
577 this.minObjSize = ObjectSize;
578
579 if (ObjectSize > this.maxObjSize)
580 this.maxObjSize = ObjectSize;
581
582 this.sumObjSize += ObjectSize;
583 this.nrObjects++;
584 }
585 }
586
587 internal void ReportDepthStatistics(uint Depth)
588 {
589 lock (this.synchObject)
590 {
591 if (Depth < this.minDepth)
592 this.minDepth = Depth;
593
594 if (Depth > this.maxDepth)
595 this.maxDepth = Depth;
596 }
597 }
598
599 internal void LogError(string Message)
600 {
601 lock (this.synchObject)
602 {
603 this.isCorrupt = true;
604
605 if (this.comments is null)
606 this.comments = new List<string>();
607
608 this.comments.Add(Message);
609 }
610 }
611
612 internal void LogComment(string Message)
613 {
614 lock (this.synchObject)
615 {
616 if (this.comments is null)
617 this.comments = new List<string>();
618
619 this.comments.Add(Message);
620 }
621 }
622
628 public void ToString(StringBuilder Output, bool WriteStat)
629 {
630 lock (this.synchObject)
631 {
632 if (WriteStat)
633 {
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());
651 Output.AppendLine("Average object: " + this.AverageObjectSize.ToString("F1"));
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());
657 Output.AppendLine("Avg(Objects/Block): " + this.AverageObjectsPerBlock.ToString("F1"));
658 Output.AppendLine("Min(Bytes Used/Block): " + this.minBytesUsedPerBlock.ToString());
659 Output.AppendLine("Max(Bytes Used/Block): " + this.maxBytesUsedPerBlock.ToString());
660 Output.AppendLine("Avg(Bytes Used/Block): " + this.AverageBytesUsedPerBlock.ToString("F1"));
661 Output.AppendLine("Is Corrupt: " + this.isCorrupt.ToString());
662 Output.AppendLine("Is Balanced: " + this.isBalanced.ToString());
663 Output.AppendLine("Has Comments: " + this.HasComments.ToString());
664 }
665
666 if (this.HasComments)
667 {
668 Output.AppendLine();
669 foreach (string Comment in this.Comments)
670 Output.AppendLine(Comment);
671 }
672 }
673 }
674
675 }
676}
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.