debug.go 942 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright (c) Tailscale Inc & AUTHORS
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. package controlclient
  4. import (
  5. "bytes"
  6. "compress/gzip"
  7. "context"
  8. "log"
  9. "net/http"
  10. "time"
  11. "tailscale.com/util/goroutines"
  12. )
  13. func dumpGoroutinesToURL(c *http.Client, targetURL string) {
  14. ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
  15. defer cancel()
  16. zbuf := new(bytes.Buffer)
  17. zw := gzip.NewWriter(zbuf)
  18. zw.Write(goroutines.ScrubbedGoroutineDump())
  19. zw.Close()
  20. req, err := http.NewRequestWithContext(ctx, "PUT", targetURL, zbuf)
  21. if err != nil {
  22. log.Printf("dumpGoroutinesToURL: %v", err)
  23. return
  24. }
  25. req.Header.Set("Content-Encoding", "gzip")
  26. t0 := time.Now()
  27. _, err = c.Do(req)
  28. d := time.Since(t0).Round(time.Millisecond)
  29. if err != nil {
  30. log.Printf("dumpGoroutinesToURL error: %v to %v (after %v)", err, targetURL, d)
  31. } else {
  32. log.Printf("dumpGoroutinesToURL complete to %v (after %v)", targetURL, d)
  33. }
  34. }