5
5
package debug
6
6
7
7
import (
8
- "archive/zip"
9
8
"bytes"
10
9
"context"
11
10
"errors"
@@ -20,7 +19,6 @@ import (
20
19
"path"
21
20
"path/filepath"
22
21
"runtime"
23
- rpprof "runtime/pprof"
24
22
"strconv"
25
23
"strings"
26
24
"sync"
@@ -494,65 +492,6 @@ func (i *Instance) ListenedDebugAddress() string {
494
492
return i .listenedDebugAddress
495
493
}
496
494
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
-
556
495
func makeGlobalExporter (stderr io.Writer ) event.Exporter {
557
496
p := export.Printer {}
558
497
var pMu sync.Mutex
0 commit comments