Skip to content

Commit d4cefa4

Browse files
committed
added cpuprofile command-line flag to capture performance profiles
1 parent c545e36 commit d4cefa4

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

main.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,41 @@
11
package main
22

33
import (
4+
"flag"
5+
"os"
6+
"runtime/pprof"
7+
48
"github.com/DDP-Projekt/DDPLS/ddpls"
9+
"github.com/DDP-Projekt/DDPLS/log"
510
"github.com/tliron/kutil/logging"
611

712
// Must include a backend implementation. See kutil's logging/ for other options.
813
_ "github.com/tliron/kutil/logging/simple"
914
)
1015

1116
func main() {
17+
var cpuprofile string
18+
flag.StringVar(&cpuprofile, "cpuprofile", "", "write cpu profile to file")
19+
flag.Parse()
20+
1221
// This increases logging verbosity (optional)
1322
logging.Configure(1, nil)
1423

15-
ddpls := ddpls.NewDDPLS()
16-
ddpls.Server.RunStdio()
24+
ls := ddpls.NewDDPLS()
25+
26+
if cpuprofile != "" {
27+
f, err := os.Create(cpuprofile)
28+
if err != nil {
29+
log.Warningf("error creating cpuprofile file: %w", err)
30+
} else {
31+
defer f.Close()
32+
if err := pprof.StartCPUProfile(f); err != nil {
33+
log.Warningf("error starting cpuprofile: %w", err)
34+
} else {
35+
defer pprof.StopCPUProfile()
36+
}
37+
}
38+
}
39+
40+
ls.Server.RunStdio()
1741
}

0 commit comments

Comments
 (0)