Ejemplo n.º 1
0
Archivo: pprof.go Proyecto: oshimaya/go
func profileWriter(w io.Writer) {
	startTime := time.Now()
	// This will buffer the entire profile into buf and then
	// translate it into a profile.Profile structure. This will
	// create two copies of all the data in the profile in memory.
	// TODO(matloob): Convert each chunk of the proto output and
	// stream it out instead of converting the entire profile.
	var buf bytes.Buffer
	for {
		data := runtime.CPUProfile()
		if data == nil {
			break
		}
		buf.Write(data)
	}

	profile, err := protopprof.TranslateCPUProfile(buf.Bytes(), startTime)
	if err != nil {
		// The runtime should never produce an invalid or truncated profile.
		// It drops records that can't fit into its log buffers.
		panic(fmt.Errorf("could not translate binary profile to proto format: %v", err))
	}

	profile.Write(w)
	cpu.done <- true
}
Ejemplo n.º 2
0
Archivo: pprof.go Proyecto: achanda/go
func profileWriter(w io.Writer) {
	var buf bytes.Buffer
	for {
		data := runtime.CPUProfile()
		buf.Write(data)
		if data == nil {
			break
		}
	}
	p, err := protopprof.TranslateCPUProfile(buf.Bytes(), cpu.startTime)
	if err != nil {
		panic(err)
	}
	p.RemapAll()
	protopprof.CleanupDuplicateLocations(p)
	protopprof.Symbolize(p)
	p.Write(w)
	cpu.done <- true
}