Created
December 3, 2025 09:10
-
-
Save mmierzwa/02a1471c9d0ca54437c96e1e345ca0f3 to your computer and use it in GitHub Desktop.
For debugging
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func dumpGoroutines() { | |
| buf := make([]byte, 1<<20) // 1 MB buffer | |
| n := runtime.Stack(buf, true) | |
| log.Printf("=== goroutine dump ===\n%s\n", buf[:n]) | |
| } | |
| func monitorGoroutines() { | |
| go func() { | |
| ticker := time.NewTicker(1 * time.Second) | |
| defer ticker.Stop() | |
| for range ticker.C { | |
| n := runtime.NumGoroutine() | |
| log.Printf("goroutines: %d\n", n) | |
| } | |
| }() | |
| } | |
| func dumpHeap() { | |
| var buf bytes.Buffer | |
| if err := pprof.Lookup("heap").WriteTo(&buf, 2); err != nil { | |
| log.Println("cannot dump heap:", err) | |
| return | |
| } | |
| log.Println("=== HEAP PROFILE ===") | |
| log.Print(buf.String()) | |
| } | |
| func dumpBlockProfile() { | |
| var buf bytes.Buffer | |
| if err := pprof.Lookup("block").WriteTo(&buf, 2); err != nil { | |
| log.Printf("cannot write block profile: %v", err) | |
| return | |
| } | |
| log.Printf("=== block profile ===\n%s\n", buf.String()) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment