DebuggingUtilities.DebuggingUtilitiesModule

DebuggingUtilities contains a few tools that may help debug julia code. The exported tools are:

  • @showln: like @show, but displays file and line number information as well
  • @showlnt: like @showlnt, but also uses indentation to display recursion depth
  • test_showline: a function that displays progress as it executes a file
  • time_showline: a function that displays execution time for each expression in a file
DebuggingUtilities.test_showlineMethod

test_showline(filename) is equivalent to include(filename), except that it also displays the expression and file-offset (in characters) for each expression it executes. This can be useful for debugging errors, especially those that cause a segfault.

DebuggingUtilities.time_showlineMethod

time_showline(filename) is equivalent to include(filename), except that it also analyzes the time expended on each expression within the file. Once finished, it displays the file-offset (in characters), elapsed time, and expression in order of increasing duration. This can help you identify bottlenecks in execution.

This is less useful now that julia has package precompilation, but can still be handy on occasion.

DebuggingUtilities.@showlnMacro

@showln x prints "x = val", where val is the value of x, along with information about the function, file, and line number at which this statement was executed. For example:

function foo()
    x = 5
    @showln x
    x = 7
    @showln x
    nothing
end

might produce output like

x = 5
(in foo at ./error.jl:26 at /tmp/showln_test.jl:52)
x = 7
(in foo at ./error.jl:26 at /tmp/showln_test.jl:54)

If you need call depth information, see @showlnt.

DebuggingUtilities.@showlntMacro

@showlnt x prints "x = val", where val is the value of x, along with information about the function, file, and line number at which this statement was executed, using indentation to indicate recursion depth. For example:

function recurses(n)
    @showlnt n
    n += 1
    @showlnt n
    if n < 10
        n = recurses(n)
    end
    return n
end

might produce output like

        x = 5
        (in foo at ./error.jl:26 at /tmp/showln_test.jl:52)
        x = 7
        (in foo at ./error.jl:26 at /tmp/showln_test.jl:54)

This macro causes a backtrace to be taken, and looking up the corresponding code information is relatively expensive, so using @showlnt can have a substantial performance cost.

The indentation of the line is proportional to the length of the backtrace, and consequently is an indication of recursion depth.