mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2025-04-28 07:22:00 +00:00
document profiling
This commit is contained in:
parent
52bc59aee9
commit
368b7c9f41
3 changed files with 22 additions and 4 deletions
4
Justfile
4
Justfile
|
@ -1,13 +1,13 @@
|
||||||
CGO_FLAGS := '-extldflags "-static" -linkmode external'
|
CGO_FLAGS := '-extldflags "-static" -linkmode external'
|
||||||
TAGS := 'sqlite sqlite_unlock_notify netgo'
|
TAGS := 'sqlite sqlite_unlock_notify netgo'
|
||||||
|
|
||||||
dev:
|
dev *FLAGS:
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -euxo pipefail
|
set -euxo pipefail
|
||||||
set -a # automatically export all variables
|
set -a # automatically export all variables
|
||||||
source .env-dev
|
source .env-dev
|
||||||
set +a
|
set +a
|
||||||
go run -tags '{{TAGS}}' .
|
go run -tags '{{TAGS}}' . {{FLAGS}}
|
||||||
|
|
||||||
build:
|
build:
|
||||||
CGO_ENABLED=1 go build -tags '{{TAGS}}' -ldflags '-s -w {{CGO_FLAGS}}' -v -o build/codeberg-pages-server ./
|
CGO_ENABLED=1 go build -tags '{{TAGS}}' -ldflags '-s -w {{CGO_FLAGS}}' -v -o build/codeberg-pages-server ./
|
||||||
|
|
15
README.md
15
README.md
|
@ -124,3 +124,18 @@ now these pages should work:
|
||||||
- <https://momar.localhost.mock.directory:4430/ci-testing/>
|
- <https://momar.localhost.mock.directory:4430/ci-testing/>
|
||||||
- <https://momar.localhost.mock.directory:4430/pag/@master/>
|
- <https://momar.localhost.mock.directory:4430/pag/@master/>
|
||||||
- <https://mock-pages.codeberg-test.org:4430/README.md>
|
- <https://mock-pages.codeberg-test.org:4430/README.md>
|
||||||
|
|
||||||
|
### Profiling
|
||||||
|
|
||||||
|
> This section is just a collection of commands for quick reference. If you want to learn more about profiling read [this](https://go.dev/doc/diagnostics) article or google `golang profiling`.
|
||||||
|
|
||||||
|
First enable profiling by supplying the cli arg `--enable-profiling` or using the environment variable `EENABLE_PROFILING`.
|
||||||
|
|
||||||
|
Get cpu and mem stats:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
go tool pprof -raw -output=cpu.txt 'http://localhost:9999/debug/pprof/profile?seconds=60' &
|
||||||
|
curl -so mem.txt 'http://localhost:9999/debug/pprof/heap?seconds=60'
|
||||||
|
```
|
||||||
|
|
||||||
|
More endpoints are documented here: <https://pkg.go.dev/net/http/pprof>
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
_ "net/http/pprof"
|
_ "net/http/pprof"
|
||||||
|
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func StartProfilingServer(listeningAddress string) {
|
func StartProfilingServer(listeningAddress string) {
|
||||||
|
@ -12,7 +13,9 @@ func StartProfilingServer(listeningAddress string) {
|
||||||
Handler: http.DefaultServeMux,
|
Handler: http.DefaultServeMux,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Info().Msgf("Starting debug server on %s", listeningAddress)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
log.Fatal(server.ListenAndServe())
|
log.Fatal().Err(server.ListenAndServe()).Msg("Failed to start debug server")
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue