@@ -11,7 +11,6 @@ import (
1111 "io"
1212 "net/http"
1313 "os"
14- "strings"
1514 "sync"
1615 "time"
1716
@@ -122,71 +121,3 @@ func collectTo(ctx context.Context, host string, diag *driver.Diagnostics, typ d
122121 }
123122 return err
124123}
125-
126- // TODO: Delete below here
127-
128- func CollectDiagnostic (host , tmpDir , benchName string , typ diagnostics.Type ) (int64 , error ) {
129- // We attempt to use the benchmark name to create a temp file so replace all
130- // path separators with "_".
131- benchName = strings .Replace (benchName , "/" , "_" , - 1 )
132- benchName = strings .Replace (benchName , string (os .PathSeparator ), "_" , - 1 )
133- f , err := os .CreateTemp (tmpDir , benchName + "." + string (typ ))
134- if err != nil {
135- return 0 , err
136- }
137- defer f .Close ()
138- resp , err := http .Get (fmt .Sprintf ("http://%s/debug/pprof/%s" , host , endpoint (typ )))
139- if err != nil {
140- return 0 , err
141- }
142- defer resp .Body .Close ()
143- n , err := io .Copy (f , resp .Body )
144- if err != nil {
145- return 0 , err
146- }
147- return n , driver .CopyDiagnosticData (f .Name (), typ , benchName )
148- }
149-
150- func endpoint (typ diagnostics.Type ) string {
151- switch typ {
152- case diagnostics .CPUProfile :
153- return "profile?seconds=1"
154- case diagnostics .MemProfile :
155- return "heap"
156- case diagnostics .Trace :
157- return "trace?seconds=1"
158- }
159- panic ("diagnostic " + string (typ ) + " has no endpoint" )
160- }
161-
162- func PollDiagnostic (host , tmpDir , benchName string , typ diagnostics.Type ) (stop func () uint64 ) {
163- // TODO(mknyszek): This is kind of a hack. We really should find a way to just
164- // enable diagnostic collection at a lower level for the entire server run.
165- var stopc chan struct {}
166- var wg sync.WaitGroup
167- var size uint64
168- wg .Add (1 )
169- stopc = make (chan struct {})
170- go func () {
171- defer wg .Done ()
172- for {
173- select {
174- case <- stopc :
175- return
176- default :
177- }
178- n , err := CollectDiagnostic (host , tmpDir , benchName , typ )
179- if err != nil {
180- fmt .Fprintf (os .Stderr , "failed to read diagnostic %s: %v" , typ , err )
181- return
182- }
183- size += uint64 (n )
184- }
185- }()
186- return func () uint64 {
187- // Stop the loop.
188- close (stopc )
189- wg .Wait ()
190- return size
191- }
192- }
0 commit comments