Skip to content

Commit

Permalink
gopls/internal/regtest: add a flag to profile didChange handling
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
findleyr committed Jul 13, 2021
1 parent de44776 commit 3844600
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
18 changes: 16 additions & 2 deletions gopls/internal/regtest/bench/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ package bench
import (
"flag"
"fmt"
"os"
"runtime/pprof"
"testing"
"time"

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion internal/lsp/fake/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 3844600

Please sign in to comment.