{"action":"created","issue":{"url":"https://api.github.com/repos/golang/go/issues/13466","labels_url":"https://api.github.com/repos/golang/go/issues/13466/labels{/name}","comments_url":"https://api.github.com/repos/golang/go/issues/13466/comments","events_url":"https://api.github.com/repos/golang/go/issues/13466/events","html_url":"https://github.com/golang/go/issues/13466","id":120216384,"number":13466,"title":"runtime: _ExternalCode when profiling cgo ","user":{"login":"petermattis","id":6201335,"avatar_url":"https://avatars.githubusercontent.com/u/6201335?v=3","gravatar_id":"","url":"https://api.github.com/users/petermattis","html_url":"https://github.com/petermattis","followers_url":"https://api.github.com/users/petermattis/followers","following_url":"https://api.github.com/users/petermattis/following{/other_user}","gists_url":"https://api.github.com/users/petermattis/gists{/gist_id}","starred_url":"https://api.github.com/users/petermattis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/petermattis/subscriptions","organizations_url":"https://api.github.com/users/petermattis/orgs","repos_url":"https://api.github.com/users/petermattis/repos","events_url":"https://api.github.com/users/petermattis/events{/privacy}","received_events_url":"https://api.github.com/users/petermattis/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"aclements","id":2688315,"avatar_url":"https://avatars.githubusercontent.com/u/2688315?v=3","gravatar_id":"","url":"https://api.github.com/users/aclements","html_url":"https://github.com/aclements","followers_url":"https://api.github.com/users/aclements/followers","following_url":"https://api.github.com/users/aclements/following{/other_user}","gists_url":"https://api.github.com/users/aclements/gists{/gist_id}","starred_url":"https://api.github.com/users/aclements/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aclements/subscriptions","organizations_url":"https://api.github.com/users/aclements/orgs","repos_url":"https://api.github.com/users/aclements/repos","events_url":"https://api.github.com/users/aclements/events{/privacy}","received_events_url":"https://api.github.com/users/aclements/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/golang/go/milestones/24","html_url":"https://github.com/golang/go/milestones/Go1.6","labels_url":"https://api.github.com/repos/golang/go/milestones/24/labels","id":1096159,"number":24,"title":"Go1.6","description":"","creator":{"login":"josharian","id":67496,"avatar_url":"https://avatars.githubusercontent.com/u/67496?v=3","gravatar_id":"","url":"https://api.github.com/users/josharian","html_url":"https://github.com/josharian","followers_url":"https://api.github.com/users/josharian/followers","following_url":"https://api.github.com/users/josharian/following{/other_user}","gists_url":"https://api.github.com/users/josharian/gists{/gist_id}","starred_url":"https://api.github.com/users/josharian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/josharian/subscriptions","organizations_url":"https://api.github.com/users/josharian/orgs","repos_url":"https://api.github.com/users/josharian/repos","events_url":"https://api.github.com/users/josharian/events{/privacy}","received_events_url":"https://api.github.com/users/josharian/received_events","type":"User","site_admin":false},"open_issues":61,"closed_issues":548,"state":"open","created_at":"2015-05-05T02:39:06Z","updated_at":"2016-01-06T19:58:49Z","due_on":"2016-01-31T08:00:00Z","closed_at":null},"comments":5,"created_at":"2015-12-03T16:37:38Z","updated_at":"2016-01-06T20:00:22Z","closed_at":null,"body":"[I'm using go-1.5.1 on Mac OS X]\r\n\r\nIn profiling an app which uses cgo I see a lot of time locked up in the stack trace `_ExternalCode -> _System`. And stack traces which I expect to see leading up to the cgo calls are not present. Looking at the code in `runtime.sigprof` I can see that the `_ExternalCode` marker is used when the profiling signal handler cannot safely call `gentraceback` (i.e. `setsSP(pc)` returns true). But it looks like this code path is overaggressively applied when we're in a cgo call as it should be safe to call `gentraceback(mp.curg.syscallpc, mp.curg.syscallsp, ...)`. In fact, the current code is executing `gentraceback` for cgo calls, but if `traceback` has been set to false the generated trace is tossed out and replaced with `_ExternalCode`.\r\n\r\nTo make this more concrete, this diff seems to fix the issue I'm seeing:\r\n\r\n```\r\ndiff --git a/src/runtime/proc1.go b/src/runtime/proc1.go\r\nindex 09cb775..3dbda19 100644\r\n--- a/src/runtime/proc1.go\r\n+++ b/src/runtime/proc1.go\r\n@@ -2581,6 +2581,7 @@ func sigprof(pc, sp, lr uintptr, gp *g, mp *m) {\r\n                // so instead collect Go stack that leads to the cgo call.\r\n                // This is especially important on windows, since all syscalls are cgo calls.\r\n                n = gentraceback(mp.curg.syscallpc, mp.curg.syscallsp, 0, mp.curg, 0, &stk[0], len(stk), nil, nil, 0)\r\n+               traceback = true\r\n        } else if traceback {\r\n                n = gentraceback(pc, sp, lr, gp, 0, &stk[0], len(stk), nil, nil, _TraceTrap|_TraceJumpStack)\r\n        }\r\n```"},"comment":{"url":"https://api.github.com/repos/golang/go/issues/comments/169441629","html_url":"https://github.com/golang/go/issues/13466#issuecomment-169441629","issue_url":"https://api.github.com/repos/golang/go/issues/13466","id":169441629,"user":{"login":"gopherbot","id":8566911,"avatar_url":"https://avatars.githubusercontent.com/u/8566911?v=3","gravatar_id":"","url":"https://api.github.com/users/gopherbot","html_url":"https://github.com/gopherbot","followers_url":"https://api.github.com/users/gopherbot/followers","following_url":"https://api.github.com/users/gopherbot/following{/other_user}","gists_url":"https://api.github.com/users/gopherbot/gists{/gist_id}","starred_url":"https://api.github.com/users/gopherbot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gopherbot/subscriptions","organizations_url":"https://api.github.com/users/gopherbot/orgs","repos_url":"https://api.github.com/users/gopherbot/repos","events_url":"https://api.github.com/users/gopherbot/events{/privacy}","received_events_url":"https://api.github.com/users/gopherbot/received_events","type":"User","site_admin":false},"created_at":"2016-01-06T20:00:22Z","updated_at":"2016-01-06T20:00:22Z","body":"CL https://golang.org/cl/18327 mentions this issue."}}