Skip to content

Commit 81eb671

Browse files
committed
Merge pull request #7475 from JuliaLang/teh/profileinit
Make Profile.init more flexible (fix #7365)
2 parents 1e18dfc + 2698b0d commit 81eb671

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

base/profile.jl

+12-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ end
2121
####
2222
#### User-level functions
2323
####
24+
function init(; n::Union(Nothing,Integer) = nothing, delay::Union(Nothing,Float64) = nothing)
25+
n_cur = ccall(:jl_profile_maxlen_data, Csize_t, ())
26+
delay_cur = ccall(:jl_profile_delay_nsec, Uint64, ())/10^9
27+
if n == nothing && delay == nothing
28+
return int(n_cur), delay_cur
29+
end
30+
nnew = (n == nothing) ? n_cur : n
31+
delaynew = (delay == nothing) ? delay_cur : delay
32+
init(nnew, delaynew)
33+
end
34+
2435
function init(n::Integer, delay::Float64)
2536
status = ccall(:jl_profile_init, Cint, (Csize_t, Uint64), n, iround(10^9*delay))
2637
if status == -1
@@ -108,7 +119,7 @@ function fetch()
108119
len = len_data()
109120
maxlen = maxlen_data()
110121
if (len == maxlen)
111-
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.")
122+
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.")
112123
end
113124
pointer_to_array(get_data_pointer(), (len,))
114125
end

doc/stdlib/profile.rst

+7-3
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,11 @@ backtraces will be filled. If that happens, the backtraces stop but
272272
your computation continues. As a consequence, you may miss some
273273
important profiling data (you will get a warning when that happens).
274274

275-
You can configure the relevant parameters this way::
275+
You can obtain and configure the relevant parameters this way::
276276

277+
Profile.init() # returns the current settings
277278
Profile.init(n, delay)
279+
Profile.init(delay = 0.01)
278280

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

328-
.. function:: init(n::Integer, delay::Float64)
330+
.. function:: init(; n::Integer, delay::Float64)
329331

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

336340
.. function:: fetch() -> data
337341

src/profile.c

+5
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,11 @@ DLLEXPORT size_t jl_profile_maxlen_data(void)
429429
return bt_size_max;
430430
}
431431

432+
DLLEXPORT u_int64_t jl_profile_delay_nsec(void)
433+
{
434+
return nsecprof;
435+
}
436+
432437
DLLEXPORT void jl_profile_clear_data(void)
433438
{
434439
bt_size_cur = 0;

0 commit comments

Comments
 (0)