Skip to content

cmd/pprof: macOS 10.12 profile overcounts system calls #17406

@lucas-clemente

Description

@lucas-clemente

I've encountered a strong discrepancy between pprof and dtrace while profiling quic-go. I've managed to reduce it to a somewhat simple test case (link), where (in a loop) data is sent via UDP to localhost and some CPU intensive computation that takes a few ms runs.

Profiling this via dtrace gives the expected result, with the CPU intensive part taking the majority of the time. dtrace (imo correctly) shows doSomething taking almost all of the runtime, whereas pprof says 62% is spent in syscall.Syscall6, called by the netFD.Write method.

The dtrace profile is generated using flamegraph with

sudo dtrace -x ustackframes=1000 -n 'profile-99 /execname == "pprof-test" && arg1/ { @[ustack()] = count(); } tick-20s { exit(0); }' -o out.dtrace && ~/src/FlameGraph/stackcollapse.pl out.dtrace > folded.dtrace && ~/src/FlameGraph/flamegraph.pl folded.dtrace > dtrace.svg

screenshot 2016-10-11 11 24 04

The pprof profile is generated using

go build && ./pprof-test
# in another shell
go tool pprof pprof-test localhost:8080/debug/pprof/profile

screenshot 2016-10-11 11 24 08

### All files - [The dtrace flamegraph SVG](https://dl.dropboxusercontent.com/u/1428776/pprof-report/dtrace.svg) - [The dtrace output](https://dl.dropboxusercontent.com/u/1428776/pprof-report/out.dtrace) - [The pprof SVG](https://dl.dropboxusercontent.com/u/1428776/pprof-report/pprof.svg) - [The pprof profile](https://dl.dropboxusercontent.com/u/1428776/pprof-report/pprof.pprof-test.localhost%3A8080.samples.cpu.002.pb.gz) - [The compiled binary from which the profile was generated](https://dl.dropboxusercontent.com/u/1428776/pprof-report/pprof-test) ### What version of Go are you using (`go version`)?

go version go1.7.1 darwin/amd64

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

macOS 10.12 (16A323)

~/D/pprof-test → go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/lucas/src/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.7.1/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.7.1/libexec/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/8c/y8j1444j1fbddn6bl788p1ym0000gn/T/go-build975132377=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions