summaryrefslogtreecommitdiff
path: root/lib/textui
diff options
context:
space:
mode:
Diffstat (limited to 'lib/textui')
-rw-r--r--lib/textui/log.go19
-rw-r--r--lib/textui/log_memstats.go16
-rw-r--r--lib/textui/log_test.go2
3 files changed, 27 insertions, 10 deletions
diff --git a/lib/textui/log.go b/lib/textui/log.go
index 801e9eb..110e1aa 100644
--- a/lib/textui/log.go
+++ b/lib/textui/log.go
@@ -180,7 +180,7 @@ func (l *logger) log(lvl dlog.LogLevel, writeMsg func(io.Writer)) {
// time ////////////////////////////////////////////////////////////////
now := time.Now()
- const timeFmt = "2006-01-02 15:04:05.0000"
+ const timeFmt = "15:04:05.0000"
logBuf.WriteString(timeFmt)
now.AppendFormat(logBuf.Bytes()[:0], timeFmt)
@@ -317,18 +317,22 @@ func fieldOrd(key string) int {
return -25
// step=rebuild (any substep)
case "btrfsinspect.rebuild-nodes.rebuild.want.key":
- return -7
+ return -9
case "btrfsinspect.rebuild-nodes.rebuild.want.reason":
- return -6
+ return -8
case "btrfsinspect.rebuild-nodes.rebuild.add-tree":
+ return -7
+ case "btrfsinspect.rebuild-nodes.rebuild.add-tree.want.key":
+ return -6
+ case "btrfsinspect.rebuild-nodes.rebuild.add-tree.want.reason":
return -5
- case "btrfsinspect.rebuild-nodes.rebuild.add-tree.substep":
+ case "btrfsinspect.rebuild-nodes.rebuild.add-root":
return -4
- case "btrfsinspect.rebuild-nodes.rebuild.add-tree.want.key":
+ case "btrfsinspect.rebuild-nodes.rebuild.index-inc-items":
return -3
- case "btrfsinspect.rebuild-nodes.rebuild.add-tree.want.reason":
+ case "btrfsinspect.rebuild-nodes.rebuild.index-all-items":
return -2
- case "btrfsinspect.rebuild-nodes.rebuild.add-root":
+ case "btrfsinspect.rebuild-nodes.rebuild.index-nodes":
return -1
// other ///////////////////////////////////////////////////////////////
@@ -368,6 +372,7 @@ func writeField(w io.Writer, key string, val any) {
if strings.HasPrefix(valStr, "/main/") {
valStr = strings.TrimPrefix(valStr, "/main")
}
+ valStr = strings.TrimPrefix(valStr, "/")
}
case strings.HasSuffix(name, ".pass"):
fmt.Fprintf(w, "/pass-%s", valStr)
diff --git a/lib/textui/log_memstats.go b/lib/textui/log_memstats.go
index 6e3c3a1..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,14 +26,19 @@ type LiveMemUse struct {
var _ fmt.Stringer = (*LiveMemUse)(nil)
-var liveMemUseUpdateInterval = Tunable(1 * time.Second)
+// 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()
// 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
}
diff --git a/lib/textui/log_test.go b/lib/textui/log_test.go
index 514d96e..bcd9c39 100644
--- a/lib/textui/log_test.go
+++ b/lib/textui/log_test.go
@@ -16,7 +16,7 @@ import (
)
func logLineRegexp(inner string) string {
- return `[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{4} ` + inner + ` \(from lib/textui/log_test\.go:[0-9]+\)\n`
+ return `[0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{4} ` + inner + ` \(from lib/textui/log_test\.go:[0-9]+\)\n`
}
func TestLogFormat(t *testing.T) {