Skip to content

runtime/pprof: Golang pprof cpu performance analysis, after the sampling frequency increases on the windows platform, the number of samples decreases #61665

@ypcd

Description

@ypcd

What version of Go are you using (go version)?

go version go1.20.6 windows/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

windows/amd64
windows11 (22H2, 22621.1992)
cpu x86 amd pyzen 5500

What did you do?

I want to increase the sampling frequency of cpu profiling and get more cpu sampling samples.
On the windows platform, I use the runtime.SetCPUProfileRate() interface to set the cpu performance analysis sampling frequency.
It was found that after increasing the sampling frequency, the number of cpu samples (Total samples) decreased abnormally.
When the computer is running the test program, the total CPU usage does not exceed 50%.

I tested again on the same computer using linux (centos stream 9, 5.14.0-340.el9.x86_64) through a virtual machine, and found that the sampling results were basically the same, and the results were normal.

Test code:

package main

import (
	"fmt"
	"os"
	"runtime"
	"runtime/pprof"
	"time"
)

func inrun1() {
	t1 := time.Now()
	for {
		if time.Since(t1) > time.Second*3 {
			return
		}
	}
}

func main() {
	samplesNum := 100
	fn := fmt.Sprintf("cpuprof-%d--%s--main.prof", samplesNum, runtime.GOOS)
	f, err := os.Create(fn)
	if err != nil {
		panic(err)
	}
	defer f.Close()
	runtime.SetCPUProfileRate(samplesNum)
	pprof.StartCPUProfile(f)

	inrun1()

	pprof.StopCPUProfile()
}

What did you expect to see?

I want to increase the sampling frequency of cpu profiling and get more cpu sampling samples.

What did you see instead?

It was found that after increasing the sampling frequency, the number of cpu samples (Total samples) decreased abnormally.
When the computer is running the test program, the total CPU usage does not exceed 50%.

I tested again on the same computer using linux (centos stream 9, 5.14.0-340.el9.x86_64) through a virtual machine, and found that the sampling results were basically the same, and the results were normal.

Specific sampling results:
windows11 (22H2, 22621.1992):
Sampling frequency Sampling result
25 Duration: 3.08s, Total samples = 2.92s (94.68%)
50 Duration: 3.19s, Total samples = 3s (93.94%)
100 Duration: 3.16s, Total samples = 1.91s (60.48%)
200 Duration: 3.18s, Total samples = 960ms (30.20%)

linux --centos-stream 9, 5.14.0-340.el9.x86_64:
Sampling frequency Sampling result
25 Duration: 3.13s, Total samples = 2.84s (90.68%)
50 Duration: 3.13s, Total samples = 2.84s (90.71%)
100 Duration: 3.13s, Total samples = 2.85s (91.06%)
200 Duration: 3.13s, Total samples = 2.85s (91.01%)

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.OS-Windowscompiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions