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

Make Profile.init more flexible (fix #7365) #7475

Merged
merged 1 commit into from
Jun 30, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion base/profile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ end
####
#### User-level functions
####
function init(; n::Union(Nothing,Integer) = nothing, delay::Union(Nothing,Float64) = nothing)
n_cur = ccall(:jl_profile_maxlen_data, Csize_t, ())
delay_cur = ccall(:jl_profile_delay_nsec, Uint64, ())/10^9
if n == nothing && delay == nothing
return int(n_cur), delay_cur
end
nnew = (n == nothing) ? n_cur : n
delaynew = (delay == nothing) ? delay_cur : delay
init(nnew, delaynew)
end

function init(n::Integer, delay::Float64)
status = ccall(:jl_profile_init, Cint, (Csize_t, Uint64), n, iround(10^9*delay))
if status == -1
Expand Down Expand Up @@ -108,7 +119,7 @@ function fetch()
len = len_data()
maxlen = maxlen_data()
if (len == maxlen)
warn("The profile data buffer is full; profiling probably terminated\nbefore your program finished. To profile for longer runs, call Profile.init()\nwith a larger buffer and/or larger delay.")
warn("The profile data buffer is full; profiling probably terminated\nbefore your program finished. To profile for longer runs, call Profile.init\nwith a larger buffer and/or larger delay.")
end
pointer_to_array(get_data_pointer(), (len,))
end
Expand Down
10 changes: 7 additions & 3 deletions doc/stdlib/profile.rst
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,11 @@ backtraces will be filled. If that happens, the backtraces stop but
your computation continues. As a consequence, you may miss some
important profiling data (you will get a warning when that happens).

You can configure the relevant parameters this way::
You can obtain and configure the relevant parameters this way::

Profile.init() # returns the current settings
Profile.init(n, delay)
Profile.init(delay = 0.01)

``n`` is the total number of instruction pointers you can store, with
a default value of ``10^6``. If your typical backtrace is 20
Expand Down Expand Up @@ -325,13 +327,15 @@ Function reference
Supply the vector ``data`` of backtraces and a dictionary
``lidict`` of line information.

.. function:: init(n::Integer, delay::Float64)
.. function:: init(; n::Integer, delay::Float64)

Configure the ``delay`` between backtraces (measured in seconds),
and the number ``n`` of instruction pointers that may be
stored. Each instruction pointer corresponds to a single line of
code; backtraces generally consist of a long list of instruction
pointers. Default settings are ``n=10^6`` and ``delay=0.001``.
pointers. Default settings can be obtained by calling this function
with no arguments, and each can be set independently using keywords
or in the order ``(n, delay)``.

.. function:: fetch() -> data

Expand Down
5 changes: 5 additions & 0 deletions src/profile.c
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,11 @@ DLLEXPORT size_t jl_profile_maxlen_data(void)
return bt_size_max;
}

DLLEXPORT u_int64_t jl_profile_delay_nsec(void)
{
return nsecprof;
}

DLLEXPORT void jl_profile_clear_data(void)
{
bt_size_cur = 0;
Expand Down