Coder Social home page Coder Social logo

devtools.jl's Introduction

DevTools

DevTools.jl provides a couple of useful graphical tools for working with Julia, built on top of Blink.jl.

Pkg.add("Blink")
Pkg.clone("https://github.com/JunoLab/DevTools.jl")
using DevTools

Graphical Display

DevTools hooks into Media.jl to provide a graphical display for Julia types. Once DevTools, is loaded, plotting with Gadfly will open windows like this:

julia> using DevTools, Gadfly

julia> plot(x=1:100, y=cumsum(randn(100)))

Gadfly Output

There are a few utility functions that you can use to control this output, e.g. pin() will prevent new windows from being created (new plots will reuse an old window instead), and top() will set the last window to be always on top.

The Profiler

Let's borrow an example from the excellent ProfilerView.jl.

# profile.jl
function profile_test(n)
    for i = 1:n
        A = randn(100,100,20)
        m = maximum(A)
        Afft = fft(A)
        Am = mapslices(sum, A, 2)
        B = A[:,:,5]
        Bsort = mapslices(sort, B, 1)
        b = rand(100)
        C = B.*b
    end
end

profile_test(10)  # run once to trigger compilation
Profile.clear()  # in case we have any previous profiling data
@profile profile_test(100)

With this saved in a file, execute:

julia> include("profile.jl")

julia> using DevTools

julia> profiler()

This will result in an open window which looks something like the following:

Profile View

This plot represents your program, with each green cell being a line within a given function โ€“ hover over to see which. If a line in the program calls some function f, then lines from f will be displayed directly below the original line, scaled by the amount of time that they took. For example, the top line in this plot is part of the profiler itself, and the largest line below it comes from profile.jl:6, followed by abstractarray.jl:1238 as shown above โ€“ this gives a pretty clear idea of where you should aim optimisations.

If you're interested in looking more deeply into Julia's libraries, you can zoom into the plot by scrolling and pan by dragging.

This is certainly nicer than working with a text dump, but there's actually an even better way. Clicking on the profile.jl:6 cell opens up a view on that line:

Profile Line View

This view immediately makes it clear where time is being spent in the program, without having to mentally map between profile output and code. This more flat view can also be convenient for the way it aggregates time taken over the entire run of the program.

devtools.jl's People

Contributors

mikeinnes avatar vtjnash avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.