Skip to content

Commit 3844600

Browse files
committed
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 <[email protected]> Run-TryBot: Robert Findley <[email protected]> gopls-CI: kokoro <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Rebecca Stambler <[email protected]>
1 parent de44776 commit 3844600

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

gopls/internal/regtest/bench/bench_test.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ package bench
77
import (
88
"flag"
99
"fmt"
10+
"os"
11+
"runtime/pprof"
1012
"testing"
1113
"time"
1214

@@ -131,8 +133,9 @@ func TestBenchmarkSymbols(t *testing.T) {
131133
}
132134

133135
var (
134-
benchDir = flag.String("didchange_dir", "", "If set, run benchmarks in this dir. Must also set regtest_bench_file.")
135-
benchFile = flag.String("didchange_file", "", "The file to modify")
136+
benchDir = flag.String("didchange_dir", "", "If set, run benchmarks in this dir. Must also set regtest_bench_file.")
137+
benchFile = flag.String("didchange_file", "", "The file to modify")
138+
benchProfile = flag.String("didchange_cpuprof", "", "file to write cpu profiling data to")
136139
)
137140

138141
// TestBenchmarkDidChange benchmarks modifications of a single file by making
@@ -162,6 +165,17 @@ func TestBenchmarkDidChange(t *testing.T) {
162165
// Insert the text we'll be modifying at the top of the file.
163166
env.EditBuffer(*benchFile, fake.Edit{Text: "// __REGTEST_PLACEHOLDER_0__\n"})
164167
result := testing.Benchmark(func(b *testing.B) {
168+
if *benchProfile != "" {
169+
profile, err := os.Create(*benchProfile)
170+
if err != nil {
171+
t.Fatal(err)
172+
}
173+
defer profile.Close()
174+
if err := pprof.StartCPUProfile(profile); err != nil {
175+
t.Fatal(err)
176+
}
177+
defer pprof.StopCPUProfile()
178+
}
165179
b.ResetTimer()
166180
for i := 0; i < b.N; i++ {
167181
env.EditBuffer(*benchFile, fake.Edit{

internal/lsp/fake/sandbox.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ func UnpackTxt(txt string) map[string][]byte {
163163
}
164164

165165
func validateConfig(config SandboxConfig) error {
166-
if filepath.IsAbs(config.Workdir) && (config.Files != nil || config.InGoPath) {
166+
if filepath.IsAbs(config.Workdir) && (len(config.Files) > 0 || config.InGoPath) {
167167
return errors.New("absolute Workdir cannot be set in conjunction with Files or InGoPath")
168168
}
169169
if config.Workdir != "" && config.InGoPath {

0 commit comments

Comments
 (0)