mirror of https://github.com/golang/go.git
gopls/internal/regtest: add a flag to profile didChange handling
Using the -cpuprofile testing flag for profiling didChange handling causes the profile to capture the IWL. Add a new -didchange_cpuprof flag that instruments just the change handling. Also fix a check for empty workspace files that was preventing This inaccurate check was preventing the didChange benchmark from working. Change-Id: Ie9f5402960ddccda5d6b9b36ae3c111aa5b51bb8 Reviewed-on: https://go-review.googlesource.com/c/tools/+/333939 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> gopls-CI: kokoro <noreply+kokoro@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
parent
de44776175
commit
384460091c
|
|
@ -7,6 +7,8 @@ package bench
|
|||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime/pprof"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
|
@ -131,8 +133,9 @@ func TestBenchmarkSymbols(t *testing.T) {
|
|||
}
|
||||
|
||||
var (
|
||||
benchDir = flag.String("didchange_dir", "", "If set, run benchmarks in this dir. Must also set regtest_bench_file.")
|
||||
benchFile = flag.String("didchange_file", "", "The file to modify")
|
||||
benchDir = flag.String("didchange_dir", "", "If set, run benchmarks in this dir. Must also set regtest_bench_file.")
|
||||
benchFile = flag.String("didchange_file", "", "The file to modify")
|
||||
benchProfile = flag.String("didchange_cpuprof", "", "file to write cpu profiling data to")
|
||||
)
|
||||
|
||||
// TestBenchmarkDidChange benchmarks modifications of a single file by making
|
||||
|
|
@ -162,6 +165,17 @@ func TestBenchmarkDidChange(t *testing.T) {
|
|||
// Insert the text we'll be modifying at the top of the file.
|
||||
env.EditBuffer(*benchFile, fake.Edit{Text: "// __REGTEST_PLACEHOLDER_0__\n"})
|
||||
result := testing.Benchmark(func(b *testing.B) {
|
||||
if *benchProfile != "" {
|
||||
profile, err := os.Create(*benchProfile)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer profile.Close()
|
||||
if err := pprof.StartCPUProfile(profile); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer pprof.StopCPUProfile()
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
env.EditBuffer(*benchFile, fake.Edit{
|
||||
|
|
|
|||
|
|
@ -163,7 +163,7 @@ func UnpackTxt(txt string) map[string][]byte {
|
|||
}
|
||||
|
||||
func validateConfig(config SandboxConfig) error {
|
||||
if filepath.IsAbs(config.Workdir) && (config.Files != nil || config.InGoPath) {
|
||||
if filepath.IsAbs(config.Workdir) && (len(config.Files) > 0 || config.InGoPath) {
|
||||
return errors.New("absolute Workdir cannot be set in conjunction with Files or InGoPath")
|
||||
}
|
||||
if config.Workdir != "" && config.InGoPath {
|
||||
|
|
|
|||
Loading…
Reference in New Issue