[GoLand] Profiler just says "no sampling data"

已完成

I'd like to run the CPU profiler on my project in GoLand, but when I invoke it, I just get a message saying "no sampling data".

Here's how to reproduce:

Create a new project and then create profilin.go and profilin_test.go like so:

// profilin.go
package main

import "fmt"

func DoNothing() {
fmt.Println("Hello")
}

func main() {
DoNothing()
}
// profilin_test.go
package main

import "testing"

func TestNothing(t *testing.T) {
DoNothing()
}

Then right click the play button on TestNothing, and select "Profile 'TestNothing in profi...' with 'CPU Profiler'"

I see the Profiler panel pop up at the bottom saying "No sampling data".

Is there a step that I'm missing?

评论操作 固定链接
正式评论

Hello Andrew,

In your example, the code executes so fast that it doesn't generate useful profiling information.

Do you get the same result on a real-world example? For example, the following benchmark should generate profiling information:

func BenchmarkDoNothing(b *testing.B) {
for i := 0; i < b.N; i++ {
DoNothing()
}
}
评论操作 固定链接

Thanks! That makes sense and that fixes it!

0

请先登录再写评论。