Skip to content

Commit 7497f46

Browse files
committed
debug about tracked memory
1 parent 11d4c90 commit 7497f46

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

internal/memorytracker/memorytracker.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"sync"
88

99
"github.com/10gen/migration-verifier/internal/logger"
10+
"github.com/10gen/migration-verifier/internal/reportutils"
1011
)
1112

1213
type Unit = int64
@@ -91,6 +92,12 @@ func (mt *Tracker) track(ctx context.Context) {
9192
got := (gotVal.Interface()).(Unit)
9293
mt.cur += got
9394

95+
if got < 0 {
96+
mt.logger.Debug().
97+
Str("reclaimed", reportutils.FmtBytes(-got)).
98+
Msg("Reclaimed tracked memory.")
99+
}
100+
94101
if alive {
95102
if got == 0 {
96103
mt.logger.Panic().Msg("Got zero track value but channel is not closed.")
@@ -116,8 +123,8 @@ func (mt *Tracker) track(ctx context.Context) {
116123

117124
if !didSingleThread {
118125
mt.logger.Warn().
119-
Int64("usage", mt.cur).
120-
Int64("softLimit", mt.max).
126+
Str("usage", reportutils.FmtBytes(mt.cur)).
127+
Str("softLimit", reportutils.FmtBytes(mt.max)).
121128
Msg("Tracked memory usage now exceeds soft limit. Suspending concurrent reads until tracked usage falls.")
122129

123130
didSingleThread = true
@@ -133,8 +140,8 @@ func (mt *Tracker) track(ctx context.Context) {
133140

134141
if didSingleThread {
135142
mt.logger.Info().
136-
Int64("usage", mt.cur).
137-
Int64("softLimit", mt.max).
143+
Str("usage", reportutils.FmtBytes(mt.cur)).
144+
Str("softLimit", reportutils.FmtBytes(mt.max)).
138145
Msg("Tracked memory usage is now below soft limit. Resuming concurrent reads.")
139146
}
140147
}

internal/reportutils/reportutils.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ func DurationToHMS(duration time.Duration) string {
6767
return str
6868
}
6969

70+
// FmtBytes is a convenience that combines BytesToUnit with FindBestUnit.
71+
// Use it to format a single count of bytes.
72+
func FmtBytes[T num16Plus](count T) string {
73+
return BytesToUnit(count, FindBestUnit(count))
74+
}
75+
7076
// BytesToUnit returns a stringified number that represents `count`
7177
// in the given `unit`. For example, count=1024 and unit=KiB would
7278
// return "1".

0 commit comments

Comments
 (0)