generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add /debug/pprof handlers (#1976)
This adds debugging pprof HTTP handlers. The controller serves this directly, while the runner forwards to the user verb server's handlers, allowing verb servers to be debugged directly. Here's an example of CPU profiling the echo module: ``` 🐚 ~/dev/ftl $ go tool pprof http://localhost:8894/debug/pprof/profile Fetching profile over HTTP from http://localhost:8894/debug/pprof/profile Saved profile in /Users/alec/pprof/pprof.main.samples.cpu.001.pb.gz File: main Type: cpu Time: Jul 5, 2024 at 5:33am (AEST) Duration: 30.18s, Total samples = 600ms ( 1.99%) Entering interactive mode (type "help" for commands, "o" for options) (pprof) top10 Showing nodes accounting for 600ms, 100% of 600ms total Showing top 10 nodes out of 73 flat flat% sum% cum cum% 210ms 35.00% 35.00% 210ms 35.00% runtime.pthread_cond_signal 190ms 31.67% 66.67% 190ms 31.67% runtime.kevent 110ms 18.33% 85.00% 110ms 18.33% runtime.pthread_cond_wait 50ms 8.33% 93.33% 50ms 8.33% syscall.syscall 10ms 1.67% 95.00% 10ms 1.67% connectrpc.com/connect.grpcErrorToTrailer 10ms 1.67% 96.67% 10ms 1.67% runtime.scanobject 10ms 1.67% 98.33% 10ms 1.67% runtime.usleep 10ms 1.67% 100% 10ms 1.67% runtime.write1 0 0% 100% 30ms 5.00% bufio.(*Writer).Flush 0 0% 100% 10ms 1.67% connectrpc.com/connect.(*Handler).ServeHTTP ``` pprof index looks like this: <img width="967" alt="image" src="https://github.com/TBD54566975/ftl/assets/41767/90675d6e-edd7-495e-8b6c-2ee1e299f743">
- Loading branch information
1 parent
27a844d
commit 43a3b1e
Showing
5 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package http | ||
|
||
import ( | ||
"net/http" | ||
"net/http/pprof" | ||
) | ||
|
||
// RegisterPprof registers all pprof handlers and the index on the provided ServeMux. | ||
func RegisterPprof(mux *http.ServeMux) { | ||
mux.HandleFunc("/debug/pprof", func(w http.ResponseWriter, r *http.Request) { | ||
http.Redirect(w, r, "/debug/pprof/", http.StatusFound) | ||
}) | ||
mux.HandleFunc("/debug/pprof/", pprof.Index) | ||
mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline) | ||
mux.HandleFunc("/debug/pprof/profile", pprof.Profile) | ||
mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol) | ||
mux.HandleFunc("/debug/pprof/trace", pprof.Trace) | ||
mux.Handle("/debug/pprof/goroutine", pprof.Handler("goroutine")) | ||
mux.Handle("/debug/pprof/heap", pprof.Handler("heap")) | ||
mux.Handle("/debug/pprof/allocs", pprof.Handler("allocs")) | ||
mux.Handle("/debug/pprof/threadcreate", pprof.Handler("threadcreate")) | ||
mux.Handle("/debug/pprof/block", pprof.Handler("block")) | ||
mux.Handle("/debug/pprof/mutex", pprof.Handler("mutex")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters