Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

profiler: not collecting CPU data for Go code in a c-archive #993

Closed
willie opened this issue May 7, 2018 · 5 comments
Closed

profiler: not collecting CPU data for Go code in a c-archive #993

willie opened this issue May 7, 2018 · 5 comments
Assignees
Labels
api: cloudprofiler Issues related to the Cloud Profiler API. priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release.

Comments

@willie
Copy link

willie commented May 7, 2018

Client

Profiler

Describe Your Environment

Ubuntu on GKE, Go code is built with -buildmode=c-archive. C++ program is calling the built Go archive.

Expected Behavior

I expect to be able to see, for my Go code: CPU, Heap, Contention, and Threads profiles.

Actual Behavior

I see, for my Go code: Heap, Contention, and Threads profiles. The CPU profile is missing.

I know that the docs for pprof note that:

StartCPUProfile does not work by default for Go code built with -buildmode=c-archive or -buildmode=c-shared. StartCPUProfile relies on the SIGPROF signal, but that signal will be delivered to the main program's SIGPROF signal handler (if any) not to the one used by Go. To make it work, call os/signal.Notify for syscall.SIGPROF, but note that doing so may break any profiling being done by the main program.

I'm happy with those limitations. I just need to know how to turn this on in the context of using the stackdriver profiler.

@jeanbza jeanbza added priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. api: cloudprofiler Issues related to the Cloud Profiler API. labels May 7, 2018
@aalexand
Copy link
Contributor

aalexand commented May 7, 2018

@jqll FYI

@willie
Copy link
Author

willie commented May 7, 2018

After reading more about signal.Notify (and how it chains vs. replaces), I was able to remedy my immediate problem by putting this code immediately before the call to profiler.Start:

	sig := make(chan os.Signal, 1)
	signal.Notify(sig, syscall.SIGPROF)
	go func() {
		for {
			<-sig
		}
	}()

I don't know if that's the correct way or if there's some way that you want to address this in the profiler library. I just didn't realize the behavior of signal.Notify.

@aalexand
Copy link
Contributor

aalexand commented May 7, 2018

Does the code inside of the goroutine here ever execute? I have a feeling that SIGPROF is handled by the runtime so just signal.Notify(make(chan os.Signal), syscall.SIGPROF) might be sufficient.

@willie
Copy link
Author

willie commented May 7, 2018

Honestly, I didn't know and didn't want something to block unnecessarily, so I was being super cautious. I will change it to your code. Thanks! (Maybe this should make it into the docs as to how to properly do this for this case?)

@willie
Copy link
Author

willie commented May 8, 2018

@aalexand Your proposed change works just fine. A lot simpler!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: cloudprofiler Issues related to the Cloud Profiler API. priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release.
Projects
None yet
Development

No branches or pull requests

4 participants