From 2698b0da6db22b021a7d6fd576d6393097688378 Mon Sep 17 00:00:00 2001 From: timholy Date: Mon, 30 Jun 2014 15:45:19 -0500 Subject: [PATCH] Make Profile.init more flexible (fix #7365) --- base/profile.jl | 13 ++++++++++++- doc/stdlib/profile.rst | 10 +++++++--- src/profile.c | 5 +++++ 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/base/profile.jl b/base/profile.jl index d7cc1f3c03230..6a2af4895bf7e 100644 --- a/base/profile.jl +++ b/base/profile.jl @@ -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 @@ -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 diff --git a/doc/stdlib/profile.rst b/doc/stdlib/profile.rst index 5421a456686db..5188427e5fb85 100644 --- a/doc/stdlib/profile.rst +++ b/doc/stdlib/profile.rst @@ -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 @@ -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 diff --git a/src/profile.c b/src/profile.c index cb7c852aacbb5..8668d6572662a 100644 --- a/src/profile.c +++ b/src/profile.c @@ -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;