diff --git a/ipn/ipnlocal/c2n.go b/ipn/ipnlocal/c2n.go index 9e6af14de..65905d135 100644 --- a/ipn/ipnlocal/c2n.go +++ b/ipn/ipnlocal/c2n.go @@ -48,6 +48,7 @@ req("/debug/metrics"): handleC2NDebugMetrics, req("/debug/component-logging"): handleC2NDebugComponentLogging, req("/debug/logheap"): handleC2NDebugLogHeap, + req("/debug/logallocs"): handleC2NDebugLogAllocs, req("POST /logtail/flush"): handleC2NLogtailFlush, req("POST /sockstats"): handleC2NSockStats, @@ -175,9 +176,22 @@ func handleC2NDebugLogHeap(b *LocalBackend, w http.ResponseWriter, r *http.Reque http.Error(w, "not implemented", http.StatusNotImplemented) return } + runtime.GC() c2nLogHeap(w, r) } +var c2nLogAllocs func(http.ResponseWriter, *http.Request) // non-nil on most platforms (c2n_pprof.go) + +func handleC2NDebugLogAllocs(b *LocalBackend, w http.ResponseWriter, r *http.Request) { + if c2nLogAllocs == nil { + // Not implemented on platforms trying to optimize for binary size or + // reduced memory usage. + http.Error(w, "not implemented", http.StatusNotImplemented) + return + } + c2nLogAllocs(w, r) +} + func handleC2NSSHUsernames(b *LocalBackend, w http.ResponseWriter, r *http.Request) { var req tailcfg.C2NSSHUsernamesRequest if r.Method == "POST" { diff --git a/ipn/ipnlocal/c2n_pprof.go b/ipn/ipnlocal/c2n_pprof.go index 9341548ee..b5314186c 100644 --- a/ipn/ipnlocal/c2n_pprof.go +++ b/ipn/ipnlocal/c2n_pprof.go @@ -14,4 +14,8 @@ func init() { c2nLogHeap = func(w http.ResponseWriter, r *http.Request) { pprof.WriteHeapProfile(w) } + + c2nLogAllocs = func(w http.ResponseWriter, r *http.Request) { + pprof.Lookup("allocs").WriteTo(w, 0) + } }