Skip to content

Commit 3df69b8

Browse files
committed
gopls/internal/lsp/debug: remove memory monitoring
I noticed in passing that the withNames parameter no longer had any effect since the relevant logic was deleted in CL 466975. (https://go-review.googlesource.com/c/tools/+/466975/48/gopls/internal/lsp/debug/serve.go#b548). The whole memory monitoring feature is redundant wrt the pprof endpoints, and was never used. This change deletes it. Change-Id: Id8a084b70b6f49d6c95e563b167f99afc68cff9b Reviewed-on: https://go-review.googlesource.com/c/tools/+/496191 Run-TryBot: Alan Donovan <adonovan@google.com> gopls-CI: kokoro <noreply+kokoro@google.com> Auto-Submit: Alan Donovan <adonovan@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
1 parent a069704 commit 3df69b8

File tree

2 files changed

+0
-62
lines changed

2 files changed

+0
-62
lines changed

gopls/internal/lsp/cmd/serve.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ func (s *Serve) Run(ctx context.Context, args ...string) error {
9090
}
9191
defer closeLog()
9292
di.ServerAddress = s.Address
93-
di.MonitorMemory(ctx)
9493
di.Serve(ctx, s.Debug)
9594
}
9695
var ss jsonrpc2.StreamServer

gopls/internal/lsp/debug/serve.go

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
package debug
66

77
import (
8-
"archive/zip"
98
"bytes"
109
"context"
1110
"errors"
@@ -20,7 +19,6 @@ import (
2019
"path"
2120
"path/filepath"
2221
"runtime"
23-
rpprof "runtime/pprof"
2422
"strconv"
2523
"strings"
2624
"sync"
@@ -494,65 +492,6 @@ func (i *Instance) ListenedDebugAddress() string {
494492
return i.listenedDebugAddress
495493
}
496494

497-
// MonitorMemory starts recording memory statistics each second.
498-
func (i *Instance) MonitorMemory(ctx context.Context) {
499-
tick := time.NewTicker(time.Second)
500-
nextThresholdGiB := uint64(1)
501-
go func() {
502-
for {
503-
<-tick.C
504-
var mem runtime.MemStats
505-
runtime.ReadMemStats(&mem)
506-
if mem.HeapAlloc < nextThresholdGiB*1<<30 {
507-
continue
508-
}
509-
if err := i.writeMemoryDebug(nextThresholdGiB, true); err != nil {
510-
event.Error(ctx, "writing memory debug info", err)
511-
}
512-
if err := i.writeMemoryDebug(nextThresholdGiB, false); err != nil {
513-
event.Error(ctx, "writing memory debug info", err)
514-
}
515-
event.Log(ctx, fmt.Sprintf("Wrote memory usage debug info to %v", os.TempDir()))
516-
nextThresholdGiB++
517-
}
518-
}()
519-
}
520-
521-
func (i *Instance) writeMemoryDebug(threshold uint64, withNames bool) error {
522-
suffix := "withnames"
523-
if !withNames {
524-
suffix = "nonames"
525-
}
526-
527-
filename := fmt.Sprintf("gopls.%d-%dGiB-%s.zip", os.Getpid(), threshold, suffix)
528-
zipf, err := os.OpenFile(filepath.Join(os.TempDir(), filename), os.O_CREATE|os.O_RDWR, 0644)
529-
if err != nil {
530-
return err
531-
}
532-
zipw := zip.NewWriter(zipf)
533-
534-
f, err := zipw.Create("heap.pb.gz")
535-
if err != nil {
536-
return err
537-
}
538-
if err := rpprof.Lookup("heap").WriteTo(f, 0); err != nil {
539-
return err
540-
}
541-
542-
f, err = zipw.Create("goroutines.txt")
543-
if err != nil {
544-
return err
545-
}
546-
if err := rpprof.Lookup("goroutine").WriteTo(f, 1); err != nil {
547-
return err
548-
}
549-
550-
if err := zipw.Close(); err != nil {
551-
return err
552-
}
553-
return zipf.Close()
554-
}
555-
556495
func makeGlobalExporter(stderr io.Writer) event.Exporter {
557496
p := export.Printer{}
558497
var pMu sync.Mutex

0 commit comments

Comments
 (0)