(ctx context.Context, conn workspacesdk.AgentConn, log slog.Logger)
| 885 | } |
| 886 | |
| 887 | func PprofInfoFromAgent(ctx context.Context, conn workspacesdk.AgentConn, log slog.Logger) *PprofCollection { |
| 888 | if conn == nil { |
| 889 | return nil |
| 890 | } |
| 891 | |
| 892 | var ( |
| 893 | p PprofCollection |
| 894 | eg errgroup.Group |
| 895 | ) |
| 896 | |
| 897 | p.EndpointURL = "agent" |
| 898 | p.CollectedAt = time.Now() |
| 899 | |
| 900 | // Define agent pprof endpoints - these go through the agent connection |
| 901 | endpoints := map[string]func([]byte){ |
| 902 | "/debug/pprof/allocs": func(data []byte) { |
| 903 | p.Allocs = compressData(data) |
| 904 | }, |
| 905 | "/debug/pprof/heap": func(data []byte) { |
| 906 | p.Heap = compressData(data) |
| 907 | }, |
| 908 | "/debug/pprof/profile?seconds=30": func(data []byte) { |
| 909 | p.Profile = compressData(data) |
| 910 | }, |
| 911 | "/debug/pprof/block": func(data []byte) { |
| 912 | p.Block = compressData(data) |
| 913 | }, |
| 914 | "/debug/pprof/mutex": func(data []byte) { |
| 915 | p.Mutex = compressData(data) |
| 916 | }, |
| 917 | "/debug/pprof/goroutine": func(data []byte) { |
| 918 | p.Goroutine = compressData(data) |
| 919 | }, |
| 920 | "/debug/pprof/threadcreate": func(data []byte) { |
| 921 | p.Threadcreate = compressData(data) |
| 922 | }, |
| 923 | "/debug/pprof/trace?seconds=30": func(data []byte) { |
| 924 | p.Trace = compressData(data) |
| 925 | }, |
| 926 | "/debug/pprof/cmdline": func(data []byte) { |
| 927 | p.Cmdline = string(data) |
| 928 | }, |
| 929 | "/debug/pprof/symbol": func(data []byte) { |
| 930 | p.Symbol = string(data) |
| 931 | }, |
| 932 | } |
| 933 | |
| 934 | // Collect each endpoint in parallel |
| 935 | for endpoint, setter := range endpoints { |
| 936 | eg.Go(func() error { |
| 937 | // Set longer timeout for profile and trace endpoints (they take 30 seconds) |
| 938 | timeout := 10 * time.Second |
| 939 | if strings.Contains(endpoint, "seconds=30") { |
| 940 | timeout = 45 * time.Second |
| 941 | } |
| 942 | |
| 943 | ctx, cancel := context.WithTimeout(ctx, timeout) |
| 944 | defer cancel() |
no test coverage detected