Skip to content

Commit

Permalink
Add profiler support
Browse files Browse the repository at this point in the history
  • Loading branch information
maxsupermanhd committed Nov 27, 2023
1 parent 344f9c7 commit 1e0e94f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ config.json
__debug_bin
storage
out.nbt
*.prof
15 changes: 14 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"os"
"os/signal"
"runtime/debug"
"runtime/pprof"
"sync"
"syscall"
"time"
Expand Down Expand Up @@ -82,10 +83,19 @@ func main() {
}
log.SetOutput(io.MultiWriter(&lg, os.Stdout))
log.Println()
log.Println("WebChunk web server is starting up...")
log.Println("WebChunk server is starting up...")
log.Printf("Built %s, Ver %s (%s) (%s)\n", BuildTime, GitTag, CommitHash, GoVersion)
log.Println()

profileCPU := cfg.GetDBool(false, "cpuprofile")
if profileCPU {
f, err := os.Create("webchunk.prof")
if err != nil {
log.Fatal(err)
}
pprof.StartCPUProfile(f)
}

var wg sync.WaitGroup
ctx, ctxCancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)

Expand Down Expand Up @@ -248,6 +258,9 @@ func main() {
log.Println("Shutting down storages...")
chunkStorage.CloseStorages(storages)
log.Println("Storages closed.")
if profileCPU {
pprof.StopCPUProfile()
}
lg.Close()
log.Println("Shutdown complete, bye!")
}

0 comments on commit 1e0e94f

Please sign in to comment.