···708708 }
709709 i, err := strconv.ParseInt(v, 10, 64)
710710 if err != nil {
711711- log.Fatalf("error parsing ENV %s: %s", k, err)
711711+ log.Fatalf("error parsing ENV %s to int64: %s", k, err)
712712+ }
713713+ return i
714714+}
715715+716716+func getEnvWithDefaultInt(k string, defaultVal int) int {
717717+ v := os.Getenv(k)
718718+ if v == "" {
719719+ return defaultVal
720720+ }
721721+ i, err := strconv.Atoi(k)
722722+ if err != nil {
723723+ log.Fatalf("error parsing ENV %s to int: %s", k, err)
712724 }
713725 return i
714726}
···739751 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.")
740752 cpuFraction := flag.Float64("cpu_fraction", 1.0, "use this fraction of the cores for indexing.")
741753 dbg := flag.Bool("debug", srcLogLevelIsDebug(), "turn on more verbose logging.")
754754+ 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")
742755743756 // non daemon mode for debugging/testing
744757 debugFind := flag.String("debug-find", "", "find a shard by repo name.")
···771784772785 // Tune GOMAXPROCS to match Linux container CPU quota.
773786 _, _ = maxprocs.Set()
787787+788788+ // Set the sampling rate of Go's block profiler: https://github.com/DataDog/go-profiler-notes/blob/main/guide/README.md#block-profiler.
789789+ // The block profiler is disabled by default.
790790+ if blockProfileRate != nil {
791791+ runtime.SetBlockProfileRate(*blockProfileRate)
792792+ }
774793775794 // Automatically prepend our own path at the front, to minimize
776795 // required configuration.