about summary refs log tree commit diff stats
path: root/cmd/searchix-web
diff options
context:
space:
mode:
authorAlan Pearce2025-01-24 13:03:25 +0100
committerAlan Pearce2025-01-24 13:04:41 +0100
commitfdccb55f55870813724b5eccd60abd388789b751 (patch)
treeb5bbddea9fa918f9cda67e6271a267b477e7a0b7 /cmd/searchix-web
parent4278551c28c5bcc87ed0754b67413b57d5c17e72 (diff)
downloadsearchix-fdccb55f55870813724b5eccd60abd388789b751.tar.lz
searchix-fdccb55f55870813724b5eccd60abd388789b751.tar.zst
searchix-fdccb55f55870813724b5eccd60abd388789b751.zip
perf: enable support for cpu profiling
Diffstat (limited to 'cmd/searchix-web')
-rw-r--r--cmd/searchix-web/main.go21
1 files changed, 17 insertions, 4 deletions
diff --git a/cmd/searchix-web/main.go b/cmd/searchix-web/main.go
index 2cffb6b..6d6dffa 100644
--- a/cmd/searchix-web/main.go
+++ b/cmd/searchix-web/main.go
@@ -6,6 +6,7 @@ import (
 	"fmt"
 	"os"
 	"os/signal"
+	"runtime/pprof"
 
 	"badc0de.net/pkg/flagutil"
 
@@ -21,10 +22,11 @@ var (
 		false,
 		"print default configuration and exit",
 	)
-	dev     = flag.Bool("dev", false, "enable live reloading and nicer logging")
-	replace = flag.Bool("replace", false, "replace existing index and exit")
-	update  = flag.Bool("update", false, "update index and exit")
-	version = flag.Bool("version", false, "print version information")
+	dev        = flag.Bool("dev", false, "enable live reloading and nicer logging")
+	replace    = flag.Bool("replace", false, "replace existing index and exit")
+	update     = flag.Bool("update", false, "update index and exit")
+	version    = flag.Bool("version", false, "print version information")
+	cpuprofile = flag.String("cpuprofile", "", "enable CPU profiling and save to `file`")
 )
 
 func main() {
@@ -43,6 +45,17 @@ func main() {
 		}
 		os.Exit(0)
 	}
+	if *cpuprofile != "" {
+		f, err := os.Create(*cpuprofile)
+		if err != nil {
+			panic("can't create CPU profile: " + err.Error())
+		}
+		err = pprof.StartCPUProfile(f)
+		if err != nil {
+			panic("can't start CPU profile: " + err.Error())
+		}
+		defer pprof.StopCPUProfile()
+	}
 
 	logger := log.Configure(!*dev)