Skip to content

Commit

Permalink
feat: add profiling endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
wolffshots committed Apr 9, 2024
1 parent 28a783d commit ae4d477
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 2 additions & 1 deletion config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
},
"DelaySeconds": 15,
"RandDelaySeconds": 5,
"MinDelaySeconds": 5
"MinDelaySeconds": 5,
"Profiling": false
}
12 changes: 11 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import (

"encoding/json" // for config reading

"net/http" // base network package
_ "net/http/pprof" // expose profiling over the network

"github.com/gin-gonic/gin"
api "github.com/wolffshots/phocus/v2/api" // api setup
messages "github.com/wolffshots/phocus/v2/messages" // message structures
Expand All @@ -19,7 +22,7 @@ import (
serial "github.com/wolffshots/phocus/v2/serial" // comms with inverter
)

const version = "v2.9.11"
const version = "v2.10.0"

type Configuration struct {
Serial struct {
Expand All @@ -43,6 +46,7 @@ type Configuration struct {
DelaySeconds int
RandDelaySeconds int
MinDelaySeconds int
Profiling bool
}

func ParseConfig(fileName string) (Configuration, error) {
Expand Down Expand Up @@ -74,6 +78,12 @@ func main() {

configuration, err := ParseConfig("config.json")

if err == nil && configuration.Profiling {
go func() { // start profiling endpoint in goroutine
log.Println(http.ListenAndServe("0.0.0.0:6060", nil))
}()
}

if err != nil {
log.Printf("Error parsing config: %v", err)
os.Exit(1)
Expand Down

0 comments on commit ae4d477

Please sign in to comment.