Skip to content

Commit bb25243

Browse files
committed
metrics: replace horizontal dividers between tables with newlines
The output is easier to read and the code is simpler.
1 parent 5a78b80 commit bb25243

File tree

7 files changed

+359
-293
lines changed

7 files changed

+359
-293
lines changed

metrics.go

Lines changed: 23 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"fmt"
99
"iter"
1010
"math"
11-
"strings"
1211
"time"
1312
"unsafe"
1413

@@ -637,7 +636,6 @@ var (
637636
table.Literal[*LevelMetrics](" "),
638637
table.Float("w", 5, table.AlignRight, func(m *LevelMetrics) float64 { return m.WriteAmp() }),
639638
)
640-
levelMetricsTableBottomDivider = strings.Repeat("-", levelMetricsTable.CumulativeFieldWidth)
641639
levelCompactionMetricsTableTopHeader = `COMPACTIONS | moved | multilevel | read | written`
642640
compactionLevelMetricsTable = table.Define[*LevelMetrics](
643641
table.AutoIncrement[*LevelMetrics]("level", 5, table.AlignRight),
@@ -881,7 +879,8 @@ func (m *Metrics) String() string {
881879
}
882880
cur = levelMetricsTable.Render(cur, table.RenderOptions{}, levelIter)
883881
cur.Offset(-1, 0).WriteString("total")
884-
cur = cur.WriteString(levelMetricsTableBottomDivider).NewlineReturn()
882+
//cur = cur.WriteString(levelMetricsTableBottomDivider).NewlineReturn()
883+
cur = cur.NewlineReturn()
885884

886885
// Compaction level metrics.
887886
cur = cur.WriteString(levelCompactionMetricsTableTopHeader).NewlineReturn()
@@ -895,16 +894,6 @@ func (m *Metrics) String() string {
895894
cur = compactionLevelMetricsTable.Render(cur, table.RenderOptions{}, compactionLevelIter)
896895
cur.Offset(-1, 0).WriteString("total")
897896

898-
renderTableWithDivider := func(
899-
cur ascii.Cursor, renderFunc func(ascii.Cursor) ascii.Cursor, dividerLen int, dr int,
900-
) ascii.Cursor {
901-
startCur := cur.NewlineReturn()
902-
cur = renderFunc(startCur)
903-
startCur.Offset(dr, 0).RepeatByte(dividerLen, '-')
904-
cur = cur.NewlineReturn()
905-
return cur
906-
}
907-
908897
compactionKindsContents := compactionKindsInfo{
909898
def: humanizeCount(m.Compact.DefaultCount).String(),
910899
delete: humanizeCount(m.Compact.DeleteOnlyCount).String(),
@@ -918,9 +907,9 @@ func (m *Metrics) String() string {
918907
blob: humanizeCount(m.Compact.BlobFileRewriteCount).String(),
919908
}
920909

921-
cur = renderTableWithDivider(cur, func(cur ascii.Cursor) ascii.Cursor {
922-
return compactionKindTable.Render(cur, table.RenderOptions{}, oneItemIter(compactionKindsContents))
923-
}, compactionKindTable.CumulativeFieldWidth, -1)
910+
cur = cur.NewlineReturn()
911+
cur = compactionKindTable.Render(cur, table.RenderOptions{}, oneItemIter(compactionKindsContents))
912+
cur = cur.NewlineReturn()
924913

925914
commitPipelineInfoContents := commitPipelineInfo{
926915
// wals.
@@ -936,10 +925,9 @@ func (m *Metrics) String() string {
936925
flushable: fmt.Sprintf("%s (%s)", humanizeCount(m.Flush.AsIngestCount), humanizeBytes(m.Flush.AsIngestBytes)),
937926
}
938927
cur = cur.WriteString(commitPipelineInfoTableTopHeader).NewlineReturn()
939-
cur = cur.WriteString(commitPipelineInfoTableSubHeader)
940-
cur = renderTableWithDivider(cur, func(cur ascii.Cursor) ascii.Cursor {
941-
return commitPipelineInfoTable.Render(cur, table.RenderOptions{}, oneItemIter(commitPipelineInfoContents))
942-
}, max(commitPipelineInfoTable.CumulativeFieldWidth, cur.Column()), -3)
928+
cur = cur.WriteString(commitPipelineInfoTableSubHeader).NewlineReturn()
929+
cur = commitPipelineInfoTable.Render(cur, table.RenderOptions{}, oneItemIter(commitPipelineInfoContents))
930+
cur = cur.NewlineReturn()
943931

944932
iteratorInfoContents := iteratorInfo{
945933
bcEntries: fmt.Sprintf("%s (%s)", humanizeCount(m.BlockCache.Count), humanizeBytes(m.BlockCache.Size)),
@@ -951,10 +939,9 @@ func (m *Metrics) String() string {
951939
snapshotsOpen: humanizeCount(m.Snapshots.Count).String(),
952940
}
953941
cur = cur.WriteString(iteratorInfoTableTopHeader).NewlineReturn()
954-
cur = cur.WriteString(iteratorInfoTableSubHeader)
955-
cur = renderTableWithDivider(cur, func(cur ascii.Cursor) ascii.Cursor {
956-
return iteratorInfoTable.Render(cur, table.RenderOptions{}, oneItemIter(iteratorInfoContents))
957-
}, max(iteratorInfoTable.CumulativeFieldWidth, cur.Column()), -3)
942+
cur = cur.WriteString(iteratorInfoTableSubHeader).NewlineReturn()
943+
cur = iteratorInfoTable.Render(cur, table.RenderOptions{}, oneItemIter(iteratorInfoContents))
944+
cur = cur.NewlineReturn()
958945

959946
status := fmt.Sprintf("%s pending", humanizeCount(m.Table.PendingStatsCollectionCount))
960947
if !m.Table.InitialStatsCollectionComplete {
@@ -977,10 +964,9 @@ func (m *Metrics) String() string {
977964
tableInfo: tableInfoContents,
978965
blobInfo: blobInfoContents,
979966
}
980-
cur = cur.WriteString(fileInfoTableHeader)
981-
cur = renderTableWithDivider(cur, func(cur ascii.Cursor) ascii.Cursor {
982-
return fileInfoTable.Render(cur, table.RenderOptions{}, oneItemIter(fileInfoContents))
983-
}, max(fileInfoTable.CumulativeFieldWidth, cur.Column()), -2)
967+
cur = cur.WriteString(fileInfoTableHeader).NewlineReturn()
968+
cur = fileInfoTable.Render(cur, table.RenderOptions{}, oneItemIter(fileInfoContents))
969+
cur = cur.NewlineReturn()
984970

985971
var inUseTotal uint64
986972
for i := range m.manualMemory {
@@ -998,10 +984,9 @@ func (m *Metrics) String() string {
998984
bcEnts: humanizeBytes(inUse(manual.BlockCacheEntry)).String(),
999985
memtablesTot: humanizeBytes(inUse(manual.MemTable)).String(),
1000986
}
1001-
cur = cur.WriteString(cgoMemInfoTableHeader)
1002-
cur = renderTableWithDivider(cur, func(cur ascii.Cursor) ascii.Cursor {
1003-
return cgoMemInfoTable.Render(cur, table.RenderOptions{}, oneItemIter(cgoMemInfoContents))
1004-
}, max(cgoMemInfoTable.CumulativeFieldWidth, cur.Column()), -2)
987+
cur = cur.WriteString(cgoMemInfoTableHeader).NewlineReturn()
988+
cur = cgoMemInfoTable.Render(cur, table.RenderOptions{}, oneItemIter(cgoMemInfoContents))
989+
cur = cur.NewlineReturn()
1005990

1006991
compactionMetricsInfoContents := compactionMetricsInfo{
1007992
estimatedDebt: humanizeBytes(m.Compact.EstimatedDebt).String(),
@@ -1012,10 +997,9 @@ func (m *Metrics) String() string {
1012997
failed: m.Compact.FailedCount,
1013998
problemSpans: fmt.Sprintf("%d%s", m.Compact.NumProblemSpans, ifNonZero(m.Compact.NumProblemSpans, "!!")),
1014999
}
1015-
cur = cur.WriteString(compactionInfoTableTopHeader)
1016-
cur = renderTableWithDivider(cur, func(cur ascii.Cursor) ascii.Cursor {
1017-
return compactionInfoTable.Render(cur, table.RenderOptions{}, oneItemIter(compactionMetricsInfoContents))
1018-
}, max(compactionInfoTable.CumulativeFieldWidth, cur.Column()), -2)
1000+
cur = cur.WriteString(compactionInfoTableTopHeader).NewlineReturn()
1001+
cur = compactionInfoTable.Render(cur, table.RenderOptions{}, oneItemIter(compactionMetricsInfoContents))
1002+
cur = cur.NewlineReturn()
10191003

10201004
keysInfoContents := keysInfo{
10211005
rangeKeys: humanizeCount(m.Keys.RangeKeySetsCount).String(),
@@ -1024,11 +1008,9 @@ func (m *Metrics) String() string {
10241008
pointDels: humanizeBytes(m.Table.Garbage.PointDeletionsBytesEstimate).String(),
10251009
rangeDels: humanizeBytes(m.Table.Garbage.RangeDeletionsBytesEstimate).String(),
10261010
}
1027-
cur = cur.WriteString(keysInfoTableTopHeader)
1028-
cur = renderTableWithDivider(cur, func(cur ascii.Cursor) ascii.Cursor {
1029-
return keysInfoTable.Render(cur, table.RenderOptions{}, oneItemIter(keysInfoContents))
1030-
}, max(keysInfoTable.CumulativeFieldWidth, cur.Column()), -2)
1031-
cur.Offset(-1, 0).RepeatByte(max(keysInfoTable.CumulativeFieldWidth, cur.Column()), '-')
1011+
cur = cur.WriteString(keysInfoTableTopHeader).NewlineReturn()
1012+
cur = keysInfoTable.Render(cur, table.RenderOptions{}, oneItemIter(keysInfoContents))
1013+
cur = cur.NewlineReturn()
10321014

10331015
func(cur ascii.Cursor) {
10341016
maybePrintCompression := func(pos ascii.Cursor, name string, value int64) ascii.Cursor {

testdata/compaction/l0_to_lbase_compaction

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ L6:
3232

3333
metrics
3434
----
35+
----
3536
LSM | vtables | value sep | | ingested | amp
3637
level size | tables size | count size | refsz valblk | in | tables size | r w
3738
-----------------+--------------+--------------+---------------+--------+--------------+----------
@@ -42,7 +43,7 @@ level size | tables size | count size | refsz valblk | in | tables
4243
4 0B | 0 0B | 0 0 | 0B 0B | 0B | 0 0B | 0 0
4344
5 0B | 0 0B | 0 0 | 0B 0B | 0B | 0 0B | 0 0
4445
total 6MB | 3 6MB | 0 0 | 0B 0B | 0B | 0 0B | 1 0
45-
--------------------------------------------------------------------------------------------------
46+
4647
COMPACTIONS | moved | multilevel | read | written
4748
level | score ff cff | tables size | top in read | tables blob | tables sstsz blobsz
4849
------+-------------------+--------------+-------------------+--------------+---------------------
@@ -53,42 +54,44 @@ level | score ff cff | tables size | top in read | tables blob | ta
5354
4 | 0 0 0 | 0 0B | 0B 0B 0B | 0B 0B | 0 0B 0B
5455
5 | 0 0 0 | 0 0B | 0B 0B 0B | 0B 0B | 0 0B 0B
5556
total | 0 0.09 0.09 | 3 6MB | 0B 0B 0B | 0B 0B | 0 0B 0B
56-
--------------------------------------------------------------------------------------------------
57+
5758
kind | default delete elision copy move read tomb rewrite multi blob
5859
-------+------------------------------------------------------------------------------------------
5960
count | 0 0 0 0 3 0 0 0 0 0
60-
--------------------------------------------------------------------------------------------------
61+
6162
COMMIT PIPELINE
6263
wals | memtables | ingestions
6364
files | written | overhead | flushes | live | zombie | total | flushable
6465
----------+------------+-----------+-----------+------------+------------+-----------+------------
6566
1 (0B) | 4.5MB: 4.5 | 0.0% | 2 | 1 (512KB) | 1 (512KB) | 9.5 M | 0 (0B)
66-
--------------------------------------------------------------------------------------------------
67+
6768
ITERATORS
6869
block cache | file cache | filter | sst iters | snapshots
6970
entries | hit rate | entries | hit rate | util | open | open
7071
-------------+-------------+--------------+-------------+--------------+-------------+------------
7172
1.5K (6.4MB) | 60.0% | 3 (840B) | 90.0% | 0.0% | 0 | 0
72-
--------------------------------------------------------------------------------------------------
73+
7374
FILES tables | blob files | blob values
7475
stats prog | backing | zombie | live | zombie | total | refed
7576
--------------+------------+-----------------------+------------+------------+--------+-----------
7677
all loaded | 0 (0B) | 0 (0B local:0B) | 0 (0B) | 0 (0B) | 0B | 0% (0B)
77-
--------------------------------------------------------------------------------------------------
78+
7879
CGO MEMORY | block cache | memtables
7980
tot | tot | data | maps | ents | tot
8081
--------------+---------------+----------------+-----------------+-----------------+--------------
8182
0B | 0B | 0B | 0B | 0B | 0B
82-
--------------------------------------------------------------------------------------------------
83+
8384
COMPACTIONS
8485
estimated debt | in progress | cancelled | failed | problem spans
8586
------------------+-------------------+-------------------+-------------------+-------------------
8687
0B | 0 (0B) | 0 (0B) | 0 | 0
87-
--------------------------------------------------------------------------------------------------
88+
8889
KEYS
8990
range keys | tombstones | missized tombstones | point dels | range dels
9091
-----------------+------------------+--------------------------+-----------------+----------------
9192
0 | 0 | 0 | 0B | 0B
92-
--------------------------------------------------------------------------------------------------
93+
9394
COMPRESSION
9495
snappy: 3
96+
----
97+
----

0 commit comments

Comments
 (0)