Documentation
¶
Overview ¶
Package debug exposes runtime memory diagnostics for a running instance: a memstats snapshot and a pprof heap profile. They exist so memory can be observed per process over the same HTTP surface real deployments run — the duo harness samples both of its tingly-box instances through these endpoints, and the same endpoints serve live incident diagnosis.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterRoutes ¶
func RegisterRoutes(router *swagger.RouteGroup, authMiddleware gin.HandlerFunc, handler *Handler)
RegisterRoutes registers the runtime memory diagnostics routes under the given /api/v1 group. Auth middleware is attached per-route via WithMiddleware so this registration does not mutate the parent group's middleware chain.
Types ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler serves the runtime memory diagnostics endpoints.
func (*Handler) GetHeapProfile ¶
GetHeapProfile streams a pprof heap profile (gzipped protobuf, the format `go tool pprof` reads). With ?gc=true it forces a full GC first (subject to the throttle; the X-Debug-GC-Forced header reports whether it ran) so the profile reflects retained memory rather than garbage awaiting collection.
func (*Handler) GetMemStats ¶
GetMemStats returns a runtime.MemStats snapshot. With ?gc=true it forces a full GC first (subject to the throttle), so heap_alloc_bytes is the post-GC retained set; gc_forced reports whether the GC actually ran.
type MemStatsResponse ¶
type MemStatsResponse struct {
// HeapAllocBytes is the live heap (bytes of allocated, not yet freed
// objects). Sampled after a forced GC (gc=true) it is the post-GC
// retained set — the number retention-slope measurements diff.
HeapAllocBytes uint64 `json:"heap_alloc_bytes" example:"10485760"`
HeapInuseBytes uint64 `json:"heap_inuse_bytes" example:"12582912"`
HeapSysBytes uint64 `json:"heap_sys_bytes" example:"16777216"`
HeapObjects uint64 `json:"heap_objects" example:"52000"`
// TotalAllocBytes is cumulative bytes allocated since process start
// (monotonic); diffs of it measure allocation churn.
TotalAllocBytes uint64 `json:"total_alloc_bytes" example:"104857600"`
NumGC uint32 `json:"num_gc" example:"12"`
NumGoroutine int `json:"num_goroutine" example:"42"`
// GCForced reports whether this sample ran a forced GC first (gc=true).
GCForced bool `json:"gc_forced" example:"true"`
}
MemStatsResponse is the response body of GET /debug/memstats. Byte fields come straight from runtime.MemStats so external observers (the duo memory harness, incident diagnosis against a live instance) read the same numbers an in-process runtime.ReadMemStats would.