func LoadProfile(r *report.Reporter, f io.ReadCloser) { defer f.Close() buf := bufio.NewReader(f) magic, _ := buf.Peek(4) switch string(magic) { case "heap": // Heap profile. p, err := parser.NewHeapProfParser(buf) if err != nil { log.Fatal(err) } for { rec, err := p.ReadRecord() if err == io.EOF { break } p.AdjustRecord(&rec, func(uint64) string { return "" }) r.Add(rec.Trace, rec.LiveObj, rec.LiveBytes, rec.AllocObj, rec.AllocBytes) } default: // CPU Profile. p, err := parser.NewCpuProfParser(buf) if err != nil { log.Fatal(err) } for { trace, count, err := p.ReadTrace() if trace == nil && err == io.EOF { break } r.Add(trace, int64(count)) } } }