mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 00:39:13 +00:00
feat(diagnostics): add pprof profiling (#1627)
* feat(tracing): enable tracing * of course the squash didn't work. * gah. always nice when there's 40 csets. * might as well. * refactor: tracing to diagnostics * feat: add note about the magic methods from pprof --------- Co-authored-by: ze0s <ze0s@riseup.net>
This commit is contained in:
parent
5ae4ed3604
commit
65d25c56c9
4 changed files with 63 additions and 0 deletions
30
internal/diagnostics/profiling.go
Normal file
30
internal/diagnostics/profiling.go
Normal file
|
@ -0,0 +1,30 @@
|
|||
// Copyright (c) 2021 - 2024, Ludvig Lundgren and the autobrr contributors.
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
package diagnostics
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
_ "net/http/pprof"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
// SetupProfiling pprof profiling
|
||||
func SetupProfiling(enabled bool, host string, port int) {
|
||||
if enabled {
|
||||
go func() {
|
||||
// pprof has an init method which adds the following endpoints
|
||||
// http.HandleFunc(prefix+"/debug/pprof/", Index)
|
||||
// http.HandleFunc(prefix+"/debug/pprof/cmdline", Cmdline)
|
||||
// http.HandleFunc(prefix+"/debug/pprof/profile", Profile)
|
||||
// http.HandleFunc(prefix+"/debug/pprof/symbol", Symbol)
|
||||
// http.HandleFunc(prefix+"/debug/pprof/trace", Trace)
|
||||
err := http.ListenAndServe(fmt.Sprintf("%s:%d", host, port), nil)
|
||||
if err != nil {
|
||||
log.Printf("Error starting profiling server: %v", err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue