"os"
"runtime/pprof"
"sort"
- "strconv"
)
// =============================================================================
func main() {
// Flags to enable various performance profiling options.
cpuProfile := flag.String("cpuprofile", "", "Filename for saving CPU profile output.")
- memProfilePrefix := flag.String("memprofileprefix", "", "Filename PREFIX for saving memory profile output.")
+ memProfile := flag.String("memprofile", "", "Filename for saving memory profile output.")
suppressOutput := flag.Bool("silent", false, "Suppress printing of numberline at end of simulation. Useful when profiling.")
// Obtain termination conditions from user.
// Attempt to add the new numbers to the universe. Any duplicates will
// be weeded out in the attempt.
addNumbersToUniverse(potentiallyNewNumbers, &universe)
-
- // Setup any memory profiling requested by the user. This will snapshot
- // the heap at the end of every generation.
- if *memProfilePrefix != "" {
- memProFile, err := os.Create(*memProfilePrefix + "-gen" + strconv.Itoa(generation) + ".mprof")
- if err != nil {
- log.Fatal("ERROR: Unable to write heap profile to disk:", err)
- }
- pprof.WriteHeapProfile(memProFile)
- memProFile.Close()
- }
}
fmt.Printf(".\n")
+ // Setup any memory profiling requested by the user. This will snapshot
+ // the heap only at this point, after all numbers were generated.
+ if *memProfile != "" {
+ memProFile, err := os.Create(*memProfile)
+ if err != nil {
+ log.Fatal("ERROR: Unable to open heap profile output file:", err)
+ }
+ pprof.WriteHeapProfile(memProFile)
+ memProFile.Close()
+ }
// Print the number line with generation on the horizontal axis and
// magnitude on the vertical axis.