Skip to content

Commit

Permalink
tool/logs: sort output by (start, node, store)
Browse files Browse the repository at this point in the history
Currently the output of the compaction log tool sorts by (node, store,
start). When diagnosing issues, one typically wants to look at all
stores in a given time slice, before moving to the next window.

Re-sort the computed windows by (time, node, store) to improve the
presentation.
  • Loading branch information
nicktrav committed May 23, 2022
1 parent 0a77780 commit d1cf341
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 12 deletions.
26 changes: 26 additions & 0 deletions tool/logs/compaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,28 @@ func (s windowSummary) String() string {
return sb.String()
}

// windowSummarySlice is a slice of windowSummary that sorts in order of start
// time, node, then store.
type windowsSummarySlice []windowSummary

func (s windowsSummarySlice) Len() int {
return len(s)
}

func (s windowsSummarySlice) Less(i, j int) bool {
if !s[i].tStart.Equal(s[j].tStart) {
return s[i].tStart.Before(s[j].tStart)
}
if s[i].nodeID != s[j].nodeID {
return s[i].nodeID < s[j].nodeID
}
return s[i].storeID < s[j].storeID
}

func (s windowsSummarySlice) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}

// eventSlice is a slice of events that sorts in order of node, store,
// then event start time.
type eventSlice []event
Expand Down Expand Up @@ -810,6 +832,10 @@ func (a *aggregator) aggregate() []windowSummary {
}
}

// Windows are added in order of (node, store, time). Re-sort the windows by
// (time, node, store) for better presentation.
sort.Sort(windowsSummarySlice(windows))

return windows
}

Expand Down
25 changes: 13 additions & 12 deletions tool/logs/testdata/compactions
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ _kind______from______to___default____move___elide__delete___total___bytes______t
compact L3 L4 1 0 0 0 1 13 M 10s
total 1 0 0 0 1 13 M 10s

# Multiple nodes, multiple stores. Two separate pebble logs.
# Multiple nodes, multiple stores. Two separate pebble logs. Output is sorted by
# (time, node, store).

reset
----
Expand All @@ -215,8 +216,8 @@ log
I211215 00:01:10.000000 51831533 3@vendor/github.com/cockroachdb/pebble/compaction.go:1845 ⋮ [n1,pebble,s1] 1216510 [JOB 1] compacting(default) L2 [442555] (4.2 M) + L3 [445853] (8.4 M)
I211215 00:01:20.000000 51831533 3@vendor/github.com/cockroachdb/pebble/compaction.go:1886 ⋮ [n1,pebble,s1] 1216554 [JOB 1] compacted(default) L2 [442555] (4.2 M) + L3 [445853] (8.4 M) -> L3 [445883 445887] (13 M), in 0.3s, output rate 42 M/s

I211215 00:03:10.000000 51831533 3@vendor/github.com/cockroachdb/pebble/compaction.go:1845 ⋮ [n1,pebble,s2] 1216510 [JOB 2] compacting(default) L1 [442555] (4.2 M) + L2 [445853] (8.4 M)
I211215 00:03:20.000000 51831533 3@vendor/github.com/cockroachdb/pebble/compaction.go:1886 ⋮ [n1,pebble,s2] 1216554 [JOB 2] compacted(default) L1 [442555] (4.2 M) + L2 [445853] (8.4 M) -> L2 [445883 445887] (13 M), in 0.3s, output rate 42 M/s
I211215 00:02:10.000000 51831533 3@vendor/github.com/cockroachdb/pebble/compaction.go:1845 ⋮ [n1,pebble,s2] 1216510 [JOB 2] compacting(default) L1 [442555] (4.2 M) + L2 [445853] (8.4 M)
I211215 00:02:20.000000 51831533 3@vendor/github.com/cockroachdb/pebble/compaction.go:1886 ⋮ [n1,pebble,s2] 1216554 [JOB 2] compacted(default) L1 [442555] (4.2 M) + L2 [445853] (8.4 M) -> L2 [445883 445887] (13 M), in 0.3s, output rate 42 M/s
----
0.log

Expand All @@ -231,6 +232,13 @@ I211215 00:02:20.000000 51831533 3@vendor/github.com/cockroachdb/pebble/compacti

summarize
----
node: 2, store: 1
from: 211215 00:00
to: 211215 00:01
r-amp: NaN
_kind______from______to___default____move___elide__delete___total___bytes______time
compact L3 L4 1 0 0 0 1 13 M 10s
total 1 0 0 0 1 13 M 10s
node: 1, store: 1
from: 211215 00:01
to: 211215 00:02
Expand All @@ -239,19 +247,12 @@ _kind______from______to___default____move___elide__delete___total___bytes______t
compact L2 L3 1 0 0 0 1 13 M 10s
total 1 0 0 0 1 13 M 10s
node: 1, store: 2
from: 211215 00:03
to: 211215 00:04
from: 211215 00:02
to: 211215 00:03
r-amp: NaN
_kind______from______to___default____move___elide__delete___total___bytes______time
compact L1 L2 1 0 0 0 1 13 M 10s
total 1 0 0 0 1 13 M 10s
node: 2, store: 1
from: 211215 00:00
to: 211215 00:01
r-amp: NaN
_kind______from______to___default____move___elide__delete___total___bytes______time
compact L3 L4 1 0 0 0 1 13 M 10s
total 1 0 0 0 1 13 M 10s
node: 2, store: 2
from: 211215 00:02
to: 211215 00:03
Expand Down

0 comments on commit d1cf341

Please sign in to comment.