-
-
Save jacobsa/59f9bbfa096fd3c595dc to your computer and use it in GitHub Desktop.
This file contains 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
package main | |
import ( | |
"flag" | |
"io" | |
"io/ioutil" | |
"log" | |
"os" | |
"runtime" | |
"runtime/pprof" | |
) | |
var fSize = flag.Int64("size", 0, "Number of zeroes to read.") | |
func run() (err error) { | |
// Collect a detailed heap profile, writing it out when we're finished. | |
runtime.MemProfileRate = 1 | |
profile, err := os.Create("/tmp/mem.pprof") | |
if err != nil { | |
return | |
} | |
defer profile.Close() | |
defer func() { | |
pprof.Lookup("heap").WriteTo(profile, 1) | |
}() | |
// Read some zeroes. | |
zero, err := os.Open("/dev/zero") | |
if err != nil { | |
return | |
} | |
defer zero.Close() | |
_, err = ioutil.ReadAll(io.LimitReader(zero, *fSize)) | |
if err != nil { | |
return | |
} | |
// Make some other allocations. | |
for i := 0; i < 1<<10; i++ { | |
io.MultiWriter(ioutil.Discard, ioutil.Discard) | |
} | |
return | |
} | |
func main() { | |
flag.Parse() | |
// Run. | |
err := run() | |
if err != nil { | |
log.Fatal(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment