From: Aaron Taylor Date: Sun, 16 May 2021 01:07:13 +0000 (-0700) Subject: Modified heap profiling to only dump at end of program, not after every generation. X-Git-Url: http://git.subgeniuskitty.com/surreal-numbers/.git/commitdiff_plain/7757890d8346c126a73043f0ca3660996d35c02d Modified heap profiling to only dump at end of program, not after every generation. --- diff --git a/chapter-1-experiments/ch1-breeding-numbers.go b/chapter-1-experiments/ch1-breeding-numbers.go index 35f0e20..c5baa14 100644 --- a/chapter-1-experiments/ch1-breeding-numbers.go +++ b/chapter-1-experiments/ch1-breeding-numbers.go @@ -10,7 +10,6 @@ import ( "os" "runtime/pprof" "sort" - "strconv" ) // ============================================================================= @@ -222,7 +221,7 @@ func (s *surrealSet) remove(num surrealNumber, u surrealUniverse) { 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. @@ -266,20 +265,19 @@ func main() { // 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.