-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Fix profiling on OS X #4159
Fix profiling on OS X #4159
Conversation
Seems to work on my system. Do we have any code that we know this didn't work for before? |
I'll try it on some previously failing cases. |
@blakejohnson Make sure you're running a version of Clang > 3.2. Otherwise, you might still see segfaults. |
Indeed, with latest Apple build of Clang (Apple LLVM version 4.2 (clang-425.0.24)), I still see segfaults. Is the homebrew recipe up to date for Clang? |
@blakejohnson You can just set |
Once I have an up to date Clang, what needs to be recompiled? libosxunwind, libjulia, ...? |
Everything you want to profile. |
All the failures I have seen are in openblas. |
I haven't had time this evening to rebuild everything, but my previously failing test spends most of its time in OpenBLAS, so I started with that. Unfortunately, it still segfaults at least 50% of the time. I'll try running it through GDB tomorrow to see if it is still crashing inside an OpenBLAS stack trace. |
Can you give me a testcase? |
@loladiro try https://gist.github.com/blakejohnson/6353018 |
The backtraces are not very enlightening. Here's an example
|
I know what the problem is. I'll have a patch momentarily. |
See the comment in src/profile.c for an explanation for what this is doing
PR Updated |
That does seem to do the trick. I now see "unrooted" backtraces like what we have on linux #3469, but this is worlds better than segfaulting. Awesome work, Keno. |
I'll have a look at the truncated backtraces issue. |
Alright, re: truncated backtraces, I know what the issue is, but there is now way to fix it in general without implementing a full x86_64 emulator (which is what e.g. lldb does - and to some extent so do I in libosxunwind). I can however fix at least OpenBlas to generate the necessary debug information (on Mac at least, on linux you'd have to create DWARF debug info). |
Why the #@$! is generating backtraces so damned hard?!? There's a standard for this and it's just a linked list. Why can't compilers just respect that when you ask them to? Ugh. |
Really nice work, @loladiro! |
@StefanKarpinski there's two problems with that:
Both issues are solvable if you know the function boundaries and what registers are being saved since you can use some highly successful heuristics (I'm doing this in libosxunwind). However, as mentioned, that requires some debug information about the function. Libunwind (the non-OSX version), has some heuristics for doing unwinding without debug info if the function does happen to use a frame chain, but that is really just in there because of signal handlers and PLT as in general if your function doesn't have debug info it's also not very likely to adhere to the frame chain. |
I previously noticed that OpenBLAS uses bizarre prologue/epilogue conventions in its Mac asm kernels. Is that what you are looking to fix? Regarding truncated backtraces in general: where there is a straightforward fix, I would grab it. But, they are generally rare enough in practice to not make a significant difference in profiling or other uses. So, I don't think it would be worth the effort to fix all instances. On Tuesday, August 27, 2013 at 6:16 PM, Keno Fischer wrote:
|
@blakejohnson It's a question of adding an extra Mach-0 section (32bits/ function so I think it's ok). |
@loladiro I'm rather naive about these things, but OpenBLAS defines PROLOGUE and EPILOGUE like so
and I guess I was expecting to see |
That's one thing that's necessary, but it might not be sufficient, since I don't know if the system assembler will generate compact unwind info and unfortunately due to (what I assume to be) a liker bug, the unwinder expects the function to have compact unwind info. |
if (forceDwarf == 0) { | ||
// Save the backtrace | ||
bt_size_cur += rec_backtrace_ctx((ptrint_t*)bt_data_prof+bt_size_cur, bt_size_max-bt_size_cur-1, &uc); | ||
} else if(forceDwarf == 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't think you want else
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do. It jumps back to unw_getcontext on segv.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, i see you are using unw_getcontext/unw_setcontext
profiler_uc
as a setjmp/longjmp
jmp_buf
. so this is correct. perhaps a comment here may be useful?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought that was covered by the if that results in a segfault, we retry with DWARF info.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but I guess I can add a comment explicitly mentioning it being a jump buffer.
I guess we'll have to to try it and find out what the assembler does. Do you have any interest in submitting a bug report to Apple w.r.t. their libunwind implementation? I had started writing something a while back, but had only gotten as far as recognizing that there was a problem, whereas you have actually fixed it :). |
I had to revert commit 924fb0f on Mac OSX 10.6.8 in order to compile julia. Otherwise I get the error:
|
Try updating gcc. |
@loladiro would clang maybe work as well? |
Yes, clang does work, but I thought clang was the default on OS X (meaning that @BobPortmann would have had to explicitly change it, hence I didn't suggest it). |
I am on OSX 10.6 where gcc is the default. I was under the impression that clang did not work on 10.6. |
@BobPortmann it depends on what version of |
When I try using gcc 4.7.3 from Macports I get the error
I have not tried using clang yet but the version on 10.6 is very old. I could try the Macports version. I thought there was a reason for the default being gcc on 10.6? |
I'm pretty sure that's the reason – because 10.6's clang is so old. |
10.6 does not even have clang, IIRC. |
Crow julia> uname -v
|
sorry that got munged:
|
Fixes #3971 .
Apple's version of libunwind does not handle the case when we're in a prologue or epilogue. This introduces a modified version that adds support for that where possible. Note that you will still experience segfaults if you are using Clang < 3.3 as there was a bug in the way LLVM generates the Compact Unwind Info in prior versions.
Apart from that, this also replaces the SIGALRM based version of the profiler with a Mach-based one to reduce interference with libraries that may make use of SIGALRM as well as preventing the profiler from being blocked by blocking that signal.