Skip to content

Commit b6f3ec0

Browse files
move macro to InteractiveUtils
1 parent 5ddf6de commit b6f3ec0

File tree

5 files changed

+46
-44
lines changed

5 files changed

+46
-44
lines changed

base/exports.jl

-1
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,6 @@ export
993993
@timev,
994994
@elapsed,
995995
@allocated,
996-
@time_imports,
997996

998997
# tasks
999998
@sync,

base/timing.jl

-42
Original file line numberDiff line numberDiff line change
@@ -371,45 +371,3 @@ macro timed(ex)
371371
(value=val, time=elapsedtime/1e9, bytes=diff.allocd, gctime=diff.total_time/1e9, gcstats=diff)
372372
end
373373
end
374-
375-
"""
376-
@time_imports
377-
378-
A macro to execute an expression and produce a report of any time spent importing packages and their
379-
dependencies.
380-
381-
If a package's dependencies have already been imported either globally or by another dependency they will
382-
not appear under that package and the package will accurately report a faster load time than if it were to
383-
be loaded in isolation.
384-
385-
```julia-repl
386-
julia> @time_imports using CSV
387-
3.5 ms ┌ IteratorInterfaceExtensions
388-
27.4 ms ┌ TableTraits
389-
614.0 ms ┌ SentinelArrays
390-
138.6 ms ┌ Parsers
391-
2.7 ms ┌ DataValueInterfaces
392-
3.4 ms ┌ DataAPI
393-
59.0 ms ┌ WeakRefStrings
394-
35.4 ms ┌ Tables
395-
49.5 ms ┌ PooledArrays
396-
972.1 ms CSV
397-
```
398-
399-
!!! note
400-
During the load process a package sequentially imports where necessary all of its dependencies, not just
401-
its direct dependencies. That is also true for the dependencies themselves so nested importing will likely
402-
occur, but not always. Therefore the nesting shown in this output report is not equivalent to the dependency
403-
tree, but does indicate where import time has accumulated.
404-
405-
"""
406-
macro time_imports(ex)
407-
quote
408-
try
409-
LOAD_TIMING[Threads.threadid()] += 1
410-
$(esc(ex))
411-
finally
412-
LOAD_TIMING[Threads.threadid()] -= 1
413-
end
414-
end
415-
end

stdlib/InteractiveUtils/docs/src/index.md

+1
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@ InteractiveUtils.code_llvm
2626
InteractiveUtils.@code_llvm
2727
InteractiveUtils.code_native
2828
InteractiveUtils.@code_native
29+
InteractiveUtils.@time_imports
2930
InteractiveUtils.clipboard
3031
```

stdlib/InteractiveUtils/src/InteractiveUtils.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Base.Experimental.@optlevel 1
66

77
export apropos, edit, less, code_warntype, code_llvm, code_native, methodswith, varinfo,
88
versioninfo, subtypes, supertypes, @which, @edit, @less, @functionloc, @code_warntype,
9-
@code_typed, @code_lowered, @code_llvm, @code_native, clipboard
9+
@code_typed, @code_lowered, @code_llvm, @code_native, @time_imports, clipboard
1010

1111
import Base.Docs.apropos
1212

stdlib/InteractiveUtils/src/macros.jl

+44
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,17 @@ macro code_lowered(ex0...)
232232
end
233233
end
234234

235+
macro time_imports(ex)
236+
quote
237+
try
238+
Base.LOAD_TIMING[Threads.threadid()] += 1
239+
$(esc(ex))
240+
finally
241+
Base.LOAD_TIMING[Threads.threadid()] -= 1
242+
end
243+
end
244+
end
245+
235246
"""
236247
@functionloc
237248
@@ -332,3 +343,36 @@ Set the optional keyword argument `debuginfo` by putting it before the function
332343
`debuginfo` may be one of `:source` (default) or `:none`, to specify the verbosity of code comments.
333344
"""
334345
:@code_native
346+
347+
"""
348+
@time_imports
349+
350+
A macro to execute an expression and produce a report of any time spent importing packages and their
351+
dependencies.
352+
353+
If a package's dependencies have already been imported either globally or by another dependency they will
354+
not appear under that package and the package will accurately report a faster load time than if it were to
355+
be loaded in isolation.
356+
357+
```julia-repl
358+
julia> @time_imports using CSV
359+
3.5 ms ┌ IteratorInterfaceExtensions
360+
27.4 ms ┌ TableTraits
361+
614.0 ms ┌ SentinelArrays
362+
138.6 ms ┌ Parsers
363+
2.7 ms ┌ DataValueInterfaces
364+
3.4 ms ┌ DataAPI
365+
59.0 ms ┌ WeakRefStrings
366+
35.4 ms ┌ Tables
367+
49.5 ms ┌ PooledArrays
368+
972.1 ms CSV
369+
```
370+
371+
!!! note
372+
During the load process a package sequentially imports where necessary all of its dependencies, not just
373+
its direct dependencies. That is also true for the dependencies themselves so nested importing will likely
374+
occur, but not always. Therefore the nesting shown in this output report is not equivalent to the dependency
375+
tree, but does indicate where import time has accumulated.
376+
377+
"""
378+
:@time_imports

0 commit comments

Comments
 (0)