性能分析

    @profile <expression> runs your expression while taking periodic backtraces. These are appended to an internal buffer of backtraces.

    Profile 里的方法均未导出,需要通过 Profile.print() 的方式调用。

    — Function

    1. clear()

    Clear any existing backtraces from the internal buffer.

    Profile.print — Function

    1. print([io::IO = stdout,] [data::Vector]; kwargs...)

    Prints profiling results to io (by default, stdout). If you do not supply a data vector, the internal buffer of accumulated backtraces will be used.

    The keyword arguments can be any combination of:

    • format – Determines whether backtraces are printed with (default, :tree) or without (:flat) indentation indicating tree structure.

    • combine – If true (default), instruction pointers are merged that correspond to the same line of code.

    • maxdepth – Limits the depth higher than maxdepth in the format.

    • sortedby – Controls the order in :flat format. :filefuncline (default) sorts by the source line, whereas :count sorts in order of number of collected samples.

    • mincount – Limits the printout to only those lines with at least mincount occurrences.

    Prints profiling results to io. This variant is used to examine results exported by a previous call to . Supply the vector data of backtraces and a dictionary lidict of line information.

    See Profile.print([io], data) for an explanation of the valid keyword arguments.

    Profile.init — Function

    1. init(; n::Integer, delay::Real))

    — Function

    1. fetch() -> data

    Returns a reference to the internal buffer of backtraces. Note that subsequent operations, like clear, can affect data unless you first make a copy. Note that the values in data have meaning only on this machine in the current session, because it depends on the exact memory addresses used in JIT-compiling. This function is primarily for internal use; may be a better choice for most users.

    Profile.retrieve — Function

    “Exports” profiling results in a portable format, returning the set of all backtraces (data) and a dictionary that maps the (session-specific) instruction pointers in data to LineInfo values that store the file name, function name, and line number. This function allows you to save profiling results for future analysis.

    — Function

      Given a previous profiling run, determine who called a particular function. Supplying the filename (and optionally, range of line numbers over which the function is defined) allows you to disambiguate an overloaded method. The returned value is a vector containing a count of the number of calls and line information about the caller. One can optionally supply backtrace data obtained from retrieve; otherwise, the current internal profile buffer is used.

      — Function

      1. clear_malloc_data()

      Clears any stored memory allocation data when running julia with --track-allocation. Execute the command(s) you want to test (to force JIT-compilation), then call clear_malloc_data. Then execute your command(s) again, quit Julia, and examine the resulting files.