Skip to content

Instantly share code, notes, and snippets.

@dtest11
Created March 23, 2021 15:05
Show Gist options
  • Save dtest11/2136de08addece4c35d884e180813f91 to your computer and use it in GitHub Desktop.
Save dtest11/2136de08addece4c35d884e180813f91 to your computer and use it in GitHub Desktop.
package main
import (
"bytes"
"fmt"
"log"
"os/exec"
"time"
)
func main() {
for i := 0; i < 10; i++ {
args := []string{
"tool",
"pprof",
"http://localhost:6060/debug/pprof/heap",
}
cmd := exec.Command("go", args...)
var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr
err := cmd.Run()
if err != nil {
log.Fatalf("cmd.Run() failed with %s\n", err)
}
outStr, errStr := string(stdout.Bytes()), string(stderr.Bytes())
fmt.Printf("out:\n%s\nerr:\n%s\n", outStr, errStr)
<-time.After(1*time.Second)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment