Runtime.cgocall always appearing at the top of pprof cpu profile

Hello,
I decided to check out the pprof tool for once as I’d never used it before. I’ve added the code as shown at https://golang.org/pkg/runtime/pprof/ around my program’s code. The cpu profile was made correctly, so I opened it with go tool pprof cpu.prof and got this:

Main binary filename not available.
Type: cpu
Time: Jul 25, 2018 at 10:24am (CEST)
Duration: 26.90s, Total samples = 32.03s (119.06%)
Entering interactive mode (type "help" for commands, "o" for options)

Seemed all good so far, so I proceeded with (pprof) top10

The result showed up correctly, but I was really surprised as I got this:

Showing nodes accounting for 29.21s, 91.20% of 32.03s total
Dropped 198 nodes (cum <= 0.16s)
Showing top 10 nodes out of 45
      flat  flat%   sum%        ■■■   ■■■%
    26.70s 83.36% 83.36%     26.70s 83.36%  runtime.cgocall
     0.77s  2.40% 85.76%      1.49s  4.65%  runtime.scanobject
     0.46s  1.44% 87.20%      0.46s  1.44%  runtime.stdcall1
     0.39s  1.22% 88.42%      0.39s  1.22%  runtime.memclrNoHeapPointers
     0.22s  0.69% 89.10%      0.35s  1.09%  runtime.greyobject
     0.17s  0.53% 89.63%      0.66s  2.06%  runtime.sweepone
     0.14s  0.44% 90.07%      0.39s  1.22%  runtime.lock
     0.13s  0.41% 90.48%      0.19s  0.59%  runtime.heapBitsForObject
     0.12s  0.37% 90.85%      0.17s  0.53%  runtime.scanblock
     0.11s  0.34% 91.20%      1.88s  5.87%  runtime.gcDrain

The thing is, I never once use cgo in my program.

$ go env
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Sander\AppData\Local\go-build
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\Users\Sander\go
set GORACE=
set GOROOT=C:\Go
set GOTMPDIR=
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=0
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\Sander\AppData\Local\Temp\go-build411961950=/tmp/go-build -gno-record-gcc-switches

As you can see, CGO_ENABLED is set to 0, yet still runtime.cgocall is at the top of my cpu profile.

Does anybody know why this is happening, and if it’s something to be concerned about? This is also a long running program using tickers.

This will most likely be because your running on Windows. Golang delegates tasks to the underlying OS, so on Linux syscall is used but on WIndows an exposed C API is mostly used.

1 Like

Thank you, I’ll give it a try on Linux and see if I still get the same results!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.