cpu profiling in CGO

745 views
Skip to first unread message

Yucong Sun

unread,
Jan 10, 2017, 3:52:03 PM1/10/17
to golang-nuts
Hi,

I've successfully compile and staticlly linked my C++ project and CGO , I was trying to get on demand CPU profling to work, but it keeps generating empty outputs.

The CPU profiling page mentioned that if code built in C mode, i need to do something with SIGPROF , but no examples were given, could anyone enlighten me?

Thanks

Ian Lance Taylor

unread,
Jan 10, 2017, 4:22:03 PM1/10/17
to Yucong Sun, golang-nuts
What operating system?

What version of Go?

What is the "CPU profiling page"? Do you mean
https://golang.org/pkg/runtime/pprof? The references there to SIGPROF
are specific to using -buildmode=c-archive or -buildmode=c-shared.
Are you using one of those build modes?

Ian

Yucong Sun

unread,
Jan 15, 2017, 4:05:26 AM1/15/17
to Ian Lance Taylor, golang-nuts
Hi Ian,

Sorry for replying late.

1: operating system is linux
2. golang 1.7
3. I'm statically linking  Go with C++ code, so I guess that is -buildmode=c-archive. 

Thanks

Ian Lance Taylor

unread,
Jan 15, 2017, 8:47:31 PM1/15/17
to Yucong Sun, golang-nuts
On Sun, Jan 15, 2017 at 1:04 AM, Yucong Sun <suny...@gmail.com> wrote:
>
> Sorry for replying late.
>
> 1: operating system is linux
> 2. golang 1.7
> 3. I'm statically linking Go with C++ code, so I guess that is
> -buildmode=c-archive.

With 1.7, if your program spends most of its time in C code that runs
in threads created by C code, then most of the profiling information
will be discarded. This is fixed in 1.8
(https://golang.org/cl/30252). So my first suggestion is that you try
the 1.8 release candidate to see if it fixes the problem.

Ian

Yucong Sun

unread,
Jan 15, 2017, 9:44:41 PM1/15/17
to Ian Lance Taylor, golang-nuts
Thanks! Indeed, my program spends majority of time in C code. So for 1.8,  would the profiling actually include C/C++ funciton informations? That's actually a major incentive for me to use Go, because it saves so much time reinventing the wheel on tasks like this

Ian Lance Taylor

unread,
Jan 16, 2017, 12:04:04 AM1/16/17
to Yucong Sun, golang-nuts
On Sun, Jan 15, 2017 at 6:44 PM, Yucong Sun <suny...@gmail.com> wrote:
> Thanks! Indeed, my program spends majority of time in C code. So for 1.8,
> would the profiling actually include C/C++ funciton informations?

It should, yes.

Ian
Reply all
Reply to author
Forward
0 new messages