add tests for TCP and lneto along with TCB control logic

This commit is contained in:
soypat
2024-12-27 17:27:28 -03:00
parent 7f03c1c0a6
commit ba81dfac58
13 changed files with 2177 additions and 22 deletions
+7
View File
@@ -0,0 +1,7 @@
package internal
import "log/slog"
const (
LevelTrace slog.Level = slog.LevelDebug - 2
)
+60
View File
@@ -0,0 +1,60 @@
//go:build debugheaplog
package internal
import (
"log/slog"
"runtime"
"time"
"unsafe"
)
const (
HeapAllocDebugging = true
timefmt = "[01-02 15:04:05.000]"
)
var (
memstats runtime.MemStats
lastAllocs uint64
timebuf [len(timefmt) * 2]byte
)
func LogAttrs(_ *slog.Logger, level slog.Level, msg string, attrs ...slog.Attr) {
now := time.Now()
n := len(now.AppendFormat(timebuf[:0], timefmt))
runtime.ReadMemStats(&memstats)
if memstats.TotalAlloc != lastAllocs {
print("[ALLOC] inc=", int64(memstats.TotalAlloc)-int64(lastAllocs))
print(" tot=", memstats.TotalAlloc, " seqs")
println()
}
print("time=", unsafe.String(&timebuf[0], n), " ")
if level == LevelTrace {
print("TRACE ")
} else if level < slog.LevelDebug {
print("SEQS ")
} else {
print(level.String(), " ")
}
print(msg)
for _, a := range attrs {
switch a.Value.Kind() {
case slog.KindString:
print(" ", a.Key, "=", a.Value.String())
case slog.KindInt64:
print(" ", a.Key, "=", a.Value.Int64())
case slog.KindUint64:
print(" ", a.Key, "=", a.Value.Uint64())
case slog.KindBool:
print(" ", a.Key, "=", a.Value.Bool())
}
}
println()
runtime.ReadMemStats(&memstats)
if memstats.TotalAlloc != lastAllocs {
lastAllocs = memstats.TotalAlloc
}
}
+19
View File
@@ -0,0 +1,19 @@
//go:build !debugheaplog
package internal
import (
"context"
"log/slog"
)
const HeapAllocDebugging = false
// LogAttrs is a helper function that is used by all package loggers and that
// can be switched out with the `debugheaplog` build tag for a non-allocating
// logger that prints out when heap allocations occur.
func LogAttrs(l *slog.Logger, level slog.Level, msg string, attrs ...slog.Attr) {
if l != nil {
l.LogAttrs(context.Background(), level, msg, attrs...)
}
}