Yly
Yly

Reputation: 2310

Is there a Julia profiler equivalent to Python's cProfile?

I would like to see a breakdown of which parts of my Julia code take the most time to execute. In Python, the cProfile breaks down how much time is spent in each function called by your code; is there something similar in Julia?

Upvotes: 3

Views: 598

Answers (3)

tholy
tholy

Reputation: 12179

There are differences in how easy/useful it is to profile an interpreted language (Python, Matlab) vs a compiled language (Julia). In particular, the kind of profiling you're describing requires "instrumenting" the code, which means extra statements (reading the clock) are inserted before/after each line of your code. These extra statements add overhead, but in a slow interpreted language this overhead is usually manageable. In a fast language like Julia, you'd prefer to do everything you can to avoid "corrupting" the compiled code: often, the compiler makes optimizations that would be destroyed by the added instrumentation, so the instrumented code would not give you an accurate picture of the true performance costs.

If you really want to use an instrumenting profiler, there's the older IProfile, which does line-by-line analysis of running time. However, I'd urge you to consider using the built-in sampling profiler instead; it has many advantages, and I've never yet encountered a situation in which IProfile is genuinely more useful.

The sampling profiler doesn't modify any of your code: you're running the exact same code that runs when you don't profile. Instead, it periodically takes a "snapshot" of the current execution point. When the same point comes up over and over again, it's likely to be one of the bottlenecks. This is usually all the information you need to optimize code.

Upvotes: 6

acid-art
acid-art

Reputation: 126

You can also try using VTune Amplifier profiler to see what is going in on Julia program. It requires building the Julia package. See instructions https://software.intel.com/en-us/blogs/2013/10/10/profiling-julia-code-with-intel-vtune-amplifier

Upvotes: 1

Alexander Morley
Alexander Morley

Reputation: 4181

The @profile <expression> will probably do what you want. But there are many different ways to do this*.

Most of the profiling functions available are here.

And a more general guide is here; which will run you through what the backtraces mean and how to control the outpul. Also useful might be the ProfileView.jl package.

*NB:Profile implements a "sampling" profiler (it checks where you are in the code at some interval e.g. 1ms) - the reasons, and disadvantages, for which are explained in the guide - but this will most likely be all one need for nearly all use-cases

Upvotes: 3

Related Questions