| 972 | } |
| 973 | |
| 974 | func after(opts *benchOpts, data []stats.BenchResults) { |
| 975 | if opts.cpuProfile != "" { |
| 976 | pprof.StopCPUProfile() // flushes profile to disk |
| 977 | } |
| 978 | if opts.memProfile != "" { |
| 979 | f, err := os.Create(opts.memProfile) |
| 980 | if err != nil { |
| 981 | fmt.Fprintf(os.Stderr, "testing: %s\n", err) |
| 982 | os.Exit(2) |
| 983 | } |
| 984 | runtime.GC() // materialize all statistics |
| 985 | if err = pprof.WriteHeapProfile(f); err != nil { |
| 986 | fmt.Fprintf(os.Stderr, "testing: can't write heap profile %s: %s\n", opts.memProfile, err) |
| 987 | os.Exit(2) |
| 988 | } |
| 989 | f.Close() |
| 990 | } |
| 991 | if opts.benchmarkResultFile != "" { |
| 992 | f, err := os.Create(opts.benchmarkResultFile) |
| 993 | if err != nil { |
| 994 | log.Fatalf("testing: can't write benchmark result %s: %s\n", opts.benchmarkResultFile, err) |
| 995 | } |
| 996 | dataEncoder := gob.NewEncoder(f) |
| 997 | dataEncoder.Encode(data) |
| 998 | f.Close() |
| 999 | } |
| 1000 | } |
| 1001 | |
| 1002 | // nopCompressor is a compressor that just copies data. |
| 1003 | type nopCompressor struct{} |