Skip to content

Commit

Permalink
cmd/zoekt: add -profile_time flag
Browse files Browse the repository at this point in the history
Change-Id: I1a150d337b90822097a7668c12d4cd860e29b603
  • Loading branch information
hanwen committed Feb 7, 2018
1 parent a69be25 commit 6e66a31
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion cmd/zoekt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"os"
"path/filepath"
"runtime/pprof"
"time"

"github.com/google/zoekt"
"github.com/google/zoekt/query"
Expand Down Expand Up @@ -62,6 +63,7 @@ func main() {
index := flag.String("index_dir",
filepath.Join(os.Getenv("HOME"), ".zoekt"), "search for index files in `directory`")
cpuProfile := flag.String("cpu_profile", "", "write cpu profile to `file`")
profileTime := flag.Duration("profile_time", time.Second, "run this long to gather stats.")
verbose := flag.Bool("v", false, "print some background data")

flag.Usage = func() {
Expand Down Expand Up @@ -113,9 +115,14 @@ func main() {
if *verbose {
log.Println("Displaying matches...")
}

t := time.Now()
pprof.StartCPUProfile(f)
for i := 0; i < 10; i++ {
for {
sres, err = searcher.Search(context.Background(), query, &sOpts)
if time.Now().Sub(t) > *profileTime {
break
}
}
pprof.StopCPUProfile()
}
Expand Down

0 comments on commit 6e66a31

Please sign in to comment.