From 52a2a1f673dfc11af89f67fea6185924be6903f9 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 22 Sep 2022 14:36:22 +0200 Subject: [PATCH] Improve profiling API endpoint docs --- api/endpoints_debug.go | 44 ++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/api/endpoints_debug.go b/api/endpoints_debug.go index 163e948..3baf1a2 100644 --- a/api/endpoints_debug.go +++ b/api/endpoints_debug.go @@ -7,6 +7,7 @@ import ( "net/http" "os" "runtime/pprof" + "strings" "time" "github.com/safing/portbase/utils/debug" @@ -44,11 +45,16 @@ func registerDebugEndpoints() error { } if err := RegisterEndpoint(Endpoint{ - Path: "debug/cpu", - Read: PermitAnyone, - DataFunc: handleCPUProfile, - Name: "Get CPU Profile", - Description: "", + Path: "debug/cpu", + Read: PermitAnyone, + DataFunc: handleCPUProfile, + Name: "Get CPU Profile", + Description: strings.ReplaceAll(`Gather and return the CPU profile. +This data needs to gathered over a period of time, which is specified using the duration parameter. + +You can easily view this data in your browser with this command (with Go installed): +"go tool pprof -http :8888 http://127.0.0.1:817/api/v1/debug/cpu" +`, `"`, "`"), Parameters: []Parameter{{ Method: http.MethodGet, Field: "duration", @@ -60,21 +66,29 @@ func registerDebugEndpoints() error { } if err := RegisterEndpoint(Endpoint{ - Path: "debug/heap", - Read: PermitAnyone, - DataFunc: handleHeapProfile, - Name: "Get Heap Profile", - Description: "", + Path: "debug/heap", + Read: PermitAnyone, + DataFunc: handleHeapProfile, + Name: "Get Heap Profile", + Description: strings.ReplaceAll(`Gather and return the heap memory profile. + + You can easily view this data in your browser with this command (with Go installed): + "go tool pprof -http :8888 http://127.0.0.1:817/api/v1/debug/heap" + `, `"`, "`"), }); err != nil { return err } if err := RegisterEndpoint(Endpoint{ - Path: "debug/allocs", - Read: PermitAnyone, - DataFunc: handleAllocsProfile, - Name: "Get Allocs Profile", - Description: "", + Path: "debug/allocs", + Read: PermitAnyone, + DataFunc: handleAllocsProfile, + Name: "Get Allocs Profile", + Description: strings.ReplaceAll(`Gather and return the memory allocation profile. + + You can easily view this data in your browser with this command (with Go installed): + "go tool pprof -http :8888 http://127.0.0.1:817/api/v1/debug/allocs" + `, `"`, "`"), }); err != nil { return err }