fork of https://github.com/sourcegraph/zoekt
0

Configure Feed

Select the types of activity you want to include in your feed.

introduce BLOCK_PROFILE_RATE environment variable to control the sampling rate of Go's block profiler (#264)

+20 -1
+20 -1
cmd/zoekt-sourcegraph-indexserver/main.go
··· 708 708 } 709 709 i, err := strconv.ParseInt(v, 10, 64) 710 710 if err != nil { 711 - log.Fatalf("error parsing ENV %s: %s", k, err) 711 + log.Fatalf("error parsing ENV %s to int64: %s", k, err) 712 + } 713 + return i 714 + } 715 + 716 + func getEnvWithDefaultInt(k string, defaultVal int) int { 717 + v := os.Getenv(k) 718 + if v == "" { 719 + return defaultVal 720 + } 721 + i, err := strconv.Atoi(k) 722 + if err != nil { 723 + log.Fatalf("error parsing ENV %s to int: %s", k, err) 712 724 } 713 725 return i 714 726 } ··· 739 751 hostname := flag.String("hostname", hostnameBestEffort(), "the name we advertise to Sourcegraph when asking for the list of repositories to index. Can also be set via the NODE_NAME environment variable.") 740 752 cpuFraction := flag.Float64("cpu_fraction", 1.0, "use this fraction of the cores for indexing.") 741 753 dbg := flag.Bool("debug", srcLogLevelIsDebug(), "turn on more verbose logging.") 754 + blockProfileRate := flag.Int("block_profile_rate", getEnvWithDefaultInt("BLOCK_PROFILE_RATE", -1), "Sampling rate of Go's block profiler in nanoseconds. Values <=0 disable the blocking profiler (default). A value of 1 includes every blocking event. See https://pkg.go.dev/runtime#SetBlockProfileRate") 742 755 743 756 // non daemon mode for debugging/testing 744 757 debugFind := flag.String("debug-find", "", "find a shard by repo name.") ··· 771 784 772 785 // Tune GOMAXPROCS to match Linux container CPU quota. 773 786 _, _ = maxprocs.Set() 787 + 788 + // Set the sampling rate of Go's block profiler: https://github.com/DataDog/go-profiler-notes/blob/main/guide/README.md#block-profiler. 789 + // The block profiler is disabled by default. 790 + if blockProfileRate != nil { 791 + runtime.SetBlockProfileRate(*blockProfileRate) 792 + } 774 793 775 794 // Automatically prepend our own path at the front, to minimize 776 795 // required configuration.