fgprof icon indicating copy to clipboard operation
fgprof copied to clipboard

The flame graph is incorrect when using go 1.23.

Open manchurio opened this issue 1 year ago • 1 comments

package main

import (
	"fmt"
	"github.com/felixge/fgprof"
	"net/http"
	"os"
	"time"
)

func main() {
	cpuf, err := os.Create("fgprof.out")
	if err != nil {
		return
	}
	stop := fgprof.Start(cpuf, fgprof.FormatPprof)
	defer stop()
	for range 30 {
		networkTask()
		cpuTask()
	}
}

func networkTask() {
	resp, err := http.Get("http://google.com")
	if err != nil {
		fmt.Println(err)
		return
	}
	defer resp.Body.Close()
}

func cpuTask() {
	start := time.Now()
	for time.Since(start) < 100*time.Millisecond {
		for i := 0; i < 10000; i++ {
			_ = i
		}
	}
}

As shown in the image, cputask and networkTask should be at the same level, but now cpuTask is below networkTask.

image

As a comparison, this is for Go 1.22.

image

manchurio avatar Aug 20 '24 08:08 manchurio

Thanks for reporting this. This might be an upstream regression, potentially in some patches submitted by my colleague and me for the go1.23 release. I'll investigate.

felixge avatar Aug 23 '24 08:08 felixge

I can confirm that this is a regression I introduced upstream, sorry about that.

I've submitted a fix and will ask for getting it back-ported to a go1.23.x release.

Meanwhile I've created a workaround and tagged a new v0.9.5 release that contains it. Upgrading should fix the issue on your end.

felixge avatar Aug 30 '24 06:08 felixge