@@ -11,6 +11,7 @@ import (
11
11
12
12
"github.com/cockroachdb/pebble/internal/humanize"
13
13
"github.com/cockroachdb/pebble/internal/treeprinter"
14
+ "github.com/cockroachdb/pebble/sstable/block/blockkind"
14
15
"github.com/cockroachdb/redact"
15
16
)
16
17
@@ -365,11 +366,12 @@ func (s SeekLTFlags) DisableRelativeSeek() SeekLTFlags {
365
366
return s &^ (1 << seekLTFlagRelativeSeek )
366
367
}
367
368
368
- // InternalIteratorStats contains miscellaneous stats produced by
369
- // InternalIterators that are part of the InternalIterator tree. Not every
370
- // field is relevant for an InternalIterator implementation. The field values
371
- // are aggregated as one goes up the InternalIterator tree.
372
- type InternalIteratorStats struct {
369
+ // BlockReadStats contains stats about block reads performed by an iterator.
370
+ type BlockReadStats struct {
371
+ // Count is the count of blocks loaded.
372
+ Count uint64
373
+ // CountInCache is the subset of Count that were found in the block cache.
374
+ CountInCache uint64
373
375
// Bytes in the loaded blocks. If the block was compressed, this is the
374
376
// compressed bytes. Currently, only the index blocks, data blocks
375
377
// containing points, and filter blocks are included.
@@ -381,6 +383,26 @@ type InternalIteratorStats struct {
381
383
// TODO(sumeer): this currently excludes the time spent in Reader creation,
382
384
// and in reading the rangedel and rangekey blocks. Fix that.
383
385
BlockReadDuration time.Duration
386
+ }
387
+
388
+ // Add adds the stats in other to the stats in s.
389
+ func (s * BlockReadStats ) Add (other BlockReadStats ) {
390
+ s .Count += other .Count
391
+ s .CountInCache += other .CountInCache
392
+ s .BlockBytes += other .BlockBytes
393
+ s .BlockBytesInCache += other .BlockBytesInCache
394
+ s .BlockReadDuration += other .BlockReadDuration
395
+ }
396
+
397
+ // InternalIteratorStats contains miscellaneous stats produced by
398
+ // InternalIterators that are part of the InternalIterator tree. Not every
399
+ // field is relevant for an InternalIterator implementation. The field values
400
+ // are aggregated as one goes up the InternalIterator tree.
401
+ type InternalIteratorStats struct {
402
+ // BlockReads is the count of block reads performed by the iterator by
403
+ // type.
404
+ BlockReads [blockkind .NumKinds ]BlockReadStats
405
+
384
406
// The following can repeatedly count the same points if they are iterated
385
407
// over multiple times. Additionally, they may count a point twice when
386
408
// switching directions. The latter could be improved if needed.
@@ -424,9 +446,9 @@ type InternalIteratorStats struct {
424
446
425
447
// Merge merges the stats in from into the given stats.
426
448
func (s * InternalIteratorStats ) Merge (from InternalIteratorStats ) {
427
- s . BlockBytes += from . BlockBytes
428
- s . BlockBytesInCache += from .BlockBytesInCache
429
- s . BlockReadDuration += from . BlockReadDuration
449
+ for i := range blockkind . NumKinds {
450
+ s . BlockReads [ i ]. Add ( from .BlockReads [ i ])
451
+ }
430
452
s .KeyBytes += from .KeyBytes
431
453
s .ValueBytes += from .ValueBytes
432
454
s .PointCount += from .PointCount
@@ -440,15 +462,24 @@ func (s *InternalIteratorStats) String() string {
440
462
return redact .StringWithoutMarkers (s )
441
463
}
442
464
465
+ func (s * InternalIteratorStats ) TotalBlockReads () BlockReadStats {
466
+ var total BlockReadStats
467
+ for i := range blockkind .NumKinds {
468
+ total .Add (s .BlockReads [i ])
469
+ }
470
+ return total
471
+ }
472
+
443
473
// SafeFormat implements the redact.SafeFormatter interface.
444
474
func (s * InternalIteratorStats ) SafeFormat (p redact.SafePrinter , verb rune ) {
475
+ total := s .TotalBlockReads ()
445
476
p .Printf ("blocks: %s cached" ,
446
- humanize .Bytes .Uint64 (s .BlockBytesInCache ),
477
+ humanize .Bytes .Uint64 (total .BlockBytesInCache ),
447
478
)
448
- if s .BlockBytes != s .BlockBytesInCache || s .BlockReadDuration != 0 {
479
+ if total .BlockBytes != total .BlockBytesInCache || total .BlockReadDuration != 0 {
449
480
p .Printf (", %s not cached (read time: %s)" ,
450
- humanize .Bytes .Uint64 (s .BlockBytes - s .BlockBytesInCache ),
451
- humanize .FormattedString (s .BlockReadDuration .String ()),
481
+ humanize .Bytes .Uint64 (total .BlockBytes - total .BlockBytesInCache ),
482
+ humanize .FormattedString (total .BlockReadDuration .String ()),
452
483
)
453
484
}
454
485
p .Printf ("; points: %s" , humanize .Count .Uint64 (s .PointCount ))
0 commit comments