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

Profiling doesn't work at all on OS X #6275

Closed
newhouseb opened this issue Mar 27, 2014 · 30 comments
Closed

Profiling doesn't work at all on OS X #6275

newhouseb opened this issue Mar 27, 2014 · 30 comments
Assignees
Labels
bug Indicates an unexpected problem or unintended behavior system:mac Affects only macOS
Milestone

Comments

@newhouseb
Copy link

If I run the following from the documentation here: http://julia.readthedocs.org/en/latest/stdlib/profile/

julia> function myfunc()
           A = rand(100, 100, 200)
           max(A)
       end
myfunc (generic function with 1 method)

julia> myfunc()
WARNING: max(x) is deprecated, use maximum(x) instead.
0.9999994755239174

julia> @profile myfunc()
WARNING: max(x) is deprecated, use maximum(x) instead.
0.9999998409036248

julia> Profile.print()

julia>

This may be related to: #3469, as I never get any backtraces either.

I'm running Version 0.3.0-prerelease+2156 (2014-03-24 16:53 UTC), Commit c81664a* (2 days old master), x86_64-apple-darwin13.0.0. Installed through homebrew.

Happy to explore, debug, but I'm relatively new to Julia so would need some pointers on where to poke around.

@rened
Copy link
Member

rened commented Mar 27, 2014

I tried to reproduce this, but on the current master, as well as on c81664a and a 24 days old build this works. In all cases julia was installed manually though, on 10.9.2.

  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.3.0-prerelease+2177 (2014-03-27 01:39 UTC)
 _/ |\__'_|_|_|\__'_|  |  Commit 7d475bf* (0 days old master)
|__/                   |  x86_64-apple-darwin13.1.0

julia> function myfunc()
                  A = rand(100, 100, 200)
                  max(A)
              end
myfunc (generic function with 1 method)

julia> myfunc()
WARNING: max(x) is deprecated, use maximum(x) instead.
 in max at deprecated.jl:26
 in myfunc at none:3
0.999999615846902

julia> @profile myfunc()
0.9999998838460968

julia> Profile.print()
           17 profile.jl; anonymous; line: 14
            12 none; myfunc; line: 2
             12 librandom.jl; dsfmt_gv_fill_array_close_open!; line: 129
            5  none; myfunc; line: 3
             2 deprecated.jl; max; line: 26
                 1 util.jl; warn; line: 508
                    1 set.jl; in; line: 16
                     1 dict.jl; ht_keyindex; line: 451
             3 deprecated.jl; max; line: 28
              1 reduce.jl; maximum_rgn; line: 396
              2 reduce.jl; maximum_rgn; line: 397

perhaps @staticfloat can comment on what might be different in the homebrew builds?

@staticfloat
Copy link
Member

I can confirm that this happens in the Homebrew build. I'll try to take a look at this soon.

@staticfloat
Copy link
Member

@timholy Do you have any idea why this might be happening? It looks to me like the profile data structures are just never getting filled.

@ViralBShah ViralBShah added this to the 0.4 milestone Mar 28, 2014
@timholy
Copy link
Member

timholy commented Mar 28, 2014

@newhouseb, am I right in understanding that you don't get backtraces from any errors? #3469 is deeply annoying but relatively infrequent, and tends to happen only for functions that are inlined. If a function like

function myfunc()
    b = true
    if b
        error("1")
    else
        error("0")
    end
end

does not give you a backtrace, then (1) it's not #3469, and (2) it's not profiler-specific. Instead there's something broken in your backtraces. The profiler simply co-opts that infrastructure for its own purposes.

@timholy
Copy link
Member

timholy commented Mar 28, 2014

(Welcome back @staticfloat! We missed you while you were gone 😄)

@newhouseb
Copy link
Author

Yes, running your sample above, @timholy, I get:

julia> myfunc()
ERROR: 1

If it's not working through homebrew would it be unreasonable to assume that some compiler setting/flag is doing strange things and therefore I might be able to narrow down the problem by compiling from source? I'll go ahead and try that anyway in a bit.

@staticfloat
Copy link
Member

@newhouseb I can confirm that compiling from source works and compiling through Homebrew doesn't. Unfortunately, there's a lot of configuration done in the Homebrew formula, so narrowing down exactly what's changing this could be difficult. I'm betting it has something to do with libunwind though.

@Keno
Copy link
Member

Keno commented Apr 23, 2014

Are you using libosxunwind?

@dpo
Copy link
Contributor

dpo commented Apr 26, 2014

Having the same issue on 10.8.5 (clang 425), built with Homebrew. Julia 0.3.0-prerelease+2690 (2014-04-20 12:15 UTC).

@staticfloat staticfloat self-assigned this Apr 26, 2014
@staticfloat
Copy link
Member

I'm assigning myself so that I don't lose track of this.

@randy3k
Copy link
Contributor

randy3k commented Apr 29, 2014

I have the same problem, also built with homebrew...

@staticfloat
Copy link
Member

Alright. I spent a while digging into how this all works, and I've found the culprit.

First off, the profiler is working, but all backtraces on Homebrew-built are marked as coming from C, so unless you pass C=true to Profile.print(), nothing is going to get printed.

The reason every backtrace is marked as C is because Julia apparently is not getting any debug information about Julia-built objects. I put on my debugging hat and figured out that NotifyFunctionEmitted is not getting called at all on Homebrew-built julia versions, and that this happens any time you are running on llvm-3.4.

@loladiro @vtjnash I'm over my head in LLVM now, is this expected behavior?

For everyone else, locally applying this patch to the julia formula should get you up and running with the Profiler:

diff --git a/julia.rb b/julia.rb
index 160237c..7f4d6c8 100644
--- a/julia.rb
+++ b/julia.rb
@@ -32,7 +32,7 @@ class Julia < Formula

   head do
     url 'https://github.com/JuliaLang/julia.git', :using => GitNoDepthDownloadStrategy
-    depends_on "llvm"
+    depends_on "homebrew/versions/llvm33"
   end

   depends_on "readline"
@@ -157,7 +157,7 @@ class Julia < Formula
     end

     # Tell julia about our llc, if it's been named nonstandardly
-    if build.head?
+    if false
       if which( 'llc' ) == nil
         build_opts << "LLVM_LLC=llc-#{Formula["llvm"].version}"
       end

@ihnorton
Copy link
Member

ihnorton commented May 1, 2014

Yes - the issue is that we turn on MCJIT with LLVM3.4, and NotifyFunctionEmitted is no longer called. MCJIT emits everything in a module at once and then calls NotifyObjectEmitted instead. I'm partway through an implementation adding support for this as a side effect of #6635. Should have a PR tonight or tomorrow night.

IMHO binaries really should be using a consistent version of LLVM so that we don't run into weird mystery cases. [edit: which we are!]

@staticfloat
Copy link
Member

These aren't the OSX binaries; these are user's personal Homebrew builds.

@staticfloat
Copy link
Member

And thanks for the explanation. :) I knew that MCJIT did a lot more things on a module-by-module basis, interesting to see the small things that pop up everywhere because of that.

@ihnorton
Copy link
Member

ihnorton commented May 1, 2014

Ah, didn't read the rest of the thread. Anyway, that's why, and it should hopefully be fixed on master pretty soon. Nice sleuthing!

@JeffBezanson
Copy link
Member

We really need to ensure the expected version of LLVM is used.

@staticfloat
Copy link
Member

I don't think there's anything unusual going on here; we support compiling against LLVM 3.4, right? Julia is being compiled locally, on the user's machines with full knowledge that she's getting built against 3.4. The only bug here is that even when building against 3.4 we expect to be able to use NotifyFunctionEmitted, which we apparently cannot.

@JeffBezanson
Copy link
Member

In my opinion LLVM 3.4 is not supported. Just for fun a few hooks were put in for it, probably for @loladiro 's own testing of MCJIT. But we knew not everything would work, which is why it is not supported.

@staticfloat
Copy link
Member

Ah, I didn't know that. I'll go ahead and change the Homebrew formula to requiring llvm-3.3 then.

@Keno
Copy link
Member

Keno commented May 1, 2014

MCJIT basically works, but still has problems with backtraces, which I didn't get to address yet.

@pwl
Copy link
Contributor

pwl commented May 5, 2014

I am running Linux and have encountered exactly the same problem. For my system (archlinux) only llvm-3.4 is avaiable and there is no easy way to downgrade it to llvm-3.3. Is there any way I can get the profiler running without downgrading llvm?

@ihnorton
Copy link
Member

ihnorton commented May 5, 2014

You should always be able to build LLVM yourself, regardless of the system-provided version; follow the build instructions in the main README.

@timholy
Copy link
Member

timholy commented May 5, 2014

Right, just git cloneing julia and typing make should build llvm-3.3 for you. It will remain specific to julia, so it won't affect anything else on your system.

@jakebolewski
Copy link
Member

@pwl I use Arch linux as well, you just need to edit the PKGBUILD to no use the system llvm.

@pwl
Copy link
Contributor

pwl commented May 5, 2014

@jakebolewski Thanks, I set the flag USE_SYSTEM_LLVM to 0 in PKGBUILD and now profiling works just fine now (although build time increased significantly). Sorry for bringing my problem up in the issue thread.

@kmsquire
Copy link
Member

kmsquire commented May 5, 2014

As long as LLVM is not updated, the build time should go back to normal for
future builds.

Cheers, Kevin

On Monday, May 5, 2014, Paweł Biernat notifications@github.com wrote:

@jakebolewski https://github.com/jakebolewski Thanks, I set the flag
USE_SYSTEM_LLVM to 0 in PKGBUILD and now profiling works just fine now
(although build time increased significantly). Sorry for bringing my
problem in the issue thread.


Reply to this email directly or view it on GitHubhttps://github.com//issues/6275#issuecomment-42194130
.

@timholy
Copy link
Member

timholy commented May 5, 2014

By happenstance I had a user of HDF5.jl file an issue that made it clear he was suffering from this problem (on Arch Linux) too. It occurred to me that not having good backtraces might lead to a "suffer in silence" kind of problem, and it might take a while for people to realize what they are missing. In a1a4701 I added an explicit test for backtraces (I can't be sure it's comprehensive enough to catch this issue), and modified the README to encourage users to run make testall before seriously using Julia. (The latter is presumably good advice anyway, as it should catch all sorts of platform-specific bugs.)

@cdsousa
Copy link
Contributor

cdsousa commented May 5, 2014

HDF5.jl user here. Indeed I was "suffering in silence" 😆 (and debugging with printlns and @whichs), although I felt I miss something since I'd got backtraces in the past. I'll forward this issue to the Julia package maintainers of Arch Linux.

@xyproto
Copy link

xyproto commented May 7, 2014

Packager of the Julia package on Arch Linux here. I'm looking into fixing this issue on Arch Linux. See also: https://bugs.archlinux.org/task/40231.

Keno added a commit that referenced this issue Jun 6, 2014
The approach is as follows. On MCJIT with LLVM trunk we get proper line numbers.
On 3.3 we get proper line numbers on Linux (and probably Windows), but on Mac,
you have to use a patched version of LLVM. If you don't use the patched version
of LLVM you'll still get the function names but no line numbers.
Keno added a commit that referenced this issue Jun 11, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior system:mac Affects only macOS
Projects
None yet
Development

No branches or pull requests