Changes
6 changed files (+65/-0)
-
-
@@ -7,3 +7,6 @@ demo/*# QEMU disk image. *.qcow2 # Downloaded profile generated by net/http/pprof. profile
-
-
-
@@ -21,6 +21,20 @@ Run `nix run .#testing` (you need Nix Flakes) or follow steps described in `testOnce the test server is ready, pass your desired test file to `k6 run` command. Nix user can use `nix run .#k6 -- run` without installing k6 manually. ## Profiling Add `debug` build tag then access `/debug/pprof/` for profiling. The profiling feature uses [runtime/pprof](https://pkg.go.dev/runtime/pprof) in Go Standard library. ### Example Usage 1. Launch the server using `go run . -tags debug . --config ./demo/config.yaml` 2. Start profiling for 10s using `curl -sL http://localhost:5555/debug/pprof/profile?seconds=10 > profile` 3. Access a page / pages you want to profile 4. Wait for the download command (`curl`) to finish 5. Launch profiling viewer using `go tool pprof -http localhost:8082 profile` 6. Access http://localhost:8082 ## Code Formatting This project use [dprint](https://dprint.dev/).
-
-
-
@@ -85,6 +85,8 @@packages = with pkgs; [ go delve # pprof requires Graphviz for generating visualizations. graphviz ]; };
-
-
routes/debug/debug.go (new)
-
@@ -0,0 +1,25 @@//go:build debug // Copyright 2026 Shota FUJI <pockawoooh@gmail.com> // SPDX-License-Identifier: MIT // // Debug routes. To access this routes, add a "debug" build tag. package debug import ( "net/http" "net/http/pprof" ) func Register(mux *http.ServeMux) { // We have to use "/debug/pprof" path as the "net/http/pprof" package // recklessly hardcodes the path. That problematic package also registers // these paths using problematic "init()" calls, but our handlers takes // higher precedences, so we have to register manually. mux.HandleFunc("GET /debug/pprof/", pprof.Index) mux.HandleFunc("GET /debug/pprof/cmdline", pprof.Cmdline) mux.HandleFunc("GET /debug/pprof/profile", pprof.Profile) mux.HandleFunc("GET /debug/pprof/symbol", pprof.Symbol) mux.HandleFunc("GET /debug/pprof/trace", pprof.Trace) }
-
-
routes/debug/stub.go (new)
-
@@ -0,0 +1,18 @@//go:build !debug // Copyright 2026 Shota FUJI <pockawoooh@gmail.com> // SPDX-License-Identifier: MIT // // This file will be used for non-debug build, to provide no-op handler. // The purpose of this conditional compilation is to prevent pprof code from // being included in the non-debug builds. The "net/http/pprof" package uses // "init" to register default routes carelessly and not importing the file // is simple and reliable solution. package debug import ( "net/http" ) func Register(*http.ServeMux) {}
-
-
-
@@ -8,6 +8,7 @@ import ("github.com/microcosm-cc/bluemonday" "github.com/pocka/legit/config" "github.com/pocka/legit/renderer/html" "github.com/pocka/legit/routes/debug" ) // Checks for gitprotocol-http(5) specific smells; if found, passes
-
@@ -54,6 +55,8 @@ func Handlers(c *config.Config, staticDir fs.FS, templatesDir fs.FS) *http.Served.t = template.Must(template.ParseFS(d.templatesDir, "*")) } debug.Register(mux) mux.HandleFunc("GET /", d.Index) mux.HandleFunc("GET /static/{file}", d.ServeStatic) mux.HandleFunc("GET /{name}", d.Multiplex)
-