From 6ce1332d3cac5b74d2f049861f04cc2fa282d747 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Thu, 29 Dec 2022 23:53:55 -0700 Subject: cmd/btrfs-rec inspect rebuild-nodes: Optimize memory use --- lib/textui/log_memstats.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/textui/log_memstats.go') diff --git a/lib/textui/log_memstats.go b/lib/textui/log_memstats.go index 6e3c3a1..7ef35da 100644 --- a/lib/textui/log_memstats.go +++ b/lib/textui/log_memstats.go @@ -19,14 +19,14 @@ type LiveMemUse struct { var _ fmt.Stringer = (*LiveMemUse)(nil) -var liveMemUseUpdateInterval = Tunable(1 * time.Second) +var LiveMemUseUpdateInterval = Tunable(1 * time.Second) func (o *LiveMemUse) String() string { o.mu.Lock() // runtime.ReadMemStats() calls stopTheWorld(), so we want to // rate-limit how often we call it. - if now := time.Now(); now.Sub(o.last) > liveMemUseUpdateInterval { + if now := time.Now(); now.Sub(o.last) > LiveMemUseUpdateInterval { runtime.ReadMemStats(&o.stats) o.last = now } -- cgit v1.2.3-2-g168b From b1a69c59fdfbdb43de7f8ab949cfed19fcef6387 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sat, 31 Dec 2022 12:03:51 -0700 Subject: textui: Add doc comments for LiveMemUse --- lib/textui/log_memstats.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'lib/textui/log_memstats.go') diff --git a/lib/textui/log_memstats.go b/lib/textui/log_memstats.go index 7ef35da..31d526f 100644 --- a/lib/textui/log_memstats.go +++ b/lib/textui/log_memstats.go @@ -11,6 +11,13 @@ import ( "time" ) +// LiveMemUse is an object that stringifies as the live memory use of +// the program. +// +// It is intended to be used with dlog by attaching it as a field, so +// that all log lines include the current memory use: +// +// ctx = dlog.WithField(ctx, "mem", new(textui.LiveMemUse)) type LiveMemUse struct { mu sync.Mutex stats runtime.MemStats @@ -19,8 +26,13 @@ type LiveMemUse struct { var _ fmt.Stringer = (*LiveMemUse)(nil) +// LiveMemUseUpdateInterval is the shortest interval on which +// LiveMemUse is willing to update; we have this minimum interval +// because it stops the world to collect memory statistics, so we +// don't want to be updating the statistics too often. var LiveMemUseUpdateInterval = Tunable(1 * time.Second) +// String implements fmt.Stringer. func (o *LiveMemUse) String() string { o.mu.Lock() -- cgit v1.2.3-2-g168b