Skip to content

Commit

Permalink
Add scripts for snooping
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf committed Apr 11, 2019
1 parent 112d84f commit 9941dac
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
*.pyc
.cache
.pytest_cache
/tmp
Manifest.toml
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
precompile: tmp/precompile

tmp/precompile: tmp/compiles.csv
rm -rf $@
scripts/dump_precompile.jl $< $@

tmp/compiles.csv:
rm -f $@
scripts/snoop_repl.jl $@
15 changes: 15 additions & 0 deletions scripts/dump_precompile.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
# -*- mode: julia -*-
#=
exec ${JULIA:-julia} --color=yes --startup-file=no \
-e "include(popfirst!(ARGS))" "${BASH_SOURCE[0]}" \
"$@"
=#

csv_path, output = ARGS

using SnoopCompile

data = SnoopCompile.read(csv_path)
pc = SnoopCompile.parcel(reverse!(data[2]))
SnoopCompile.write(output, pc)
46 changes: 46 additions & 0 deletions scripts/snoop_repl.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash
# -*- mode: julia -*-
#=
exec ${JULIA:-julia} --startup-file=no -i \
-e "include(popfirst!(ARGS))" "${BASH_SOURCE[0]}" \
"$@"
=#

function start_repl(;
interactive::Bool = true,
quiet::Bool = true,
banner::Bool = false,
history_file::Bool = true,
color_set::Bool = false,
)
if !(stdout isa Base.TTY)
error("stdout is not a TTY")
elseif !(stdin isa Base.TTY)
error("stdin is not a TTY")
end
was_interactive = Base.is_interactive
try
# Required for Pkg.__init__ to setup the REPL mode:
Base.eval(:(is_interactive = $interactive))

@info "Starting REPL..."
Base.run_main_repl(interactive, quiet, banner, history_file, color_set)
finally
Base.eval(:(is_interactive = $was_interactive))
end
end

csv_path, = ARGS

let io = open(csv_path, "w")
ccall(:jl_dump_compiles, Nothing, (Ptr{Nothing},), io.handle)
try
@info "Loading IPython..."
using IPython
start_repl()
finally
ccall(:jl_dump_compiles, Nothing, (Ptr{Nothing},), C_NULL)
close(io)
end
end
exit()
17 changes: 17 additions & 0 deletions scripts/snoop_tests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
# -*- mode: julia -*-
#=
exec ${JULIA:-julia} --color=yes --startup-file=no \
-e "include(popfirst!(ARGS))" "${BASH_SOURCE[0]}" \
"$@"
=#

csv_path, = ARGS

using SnoopCompile

SnoopCompile.@snoopc ["-i"] csv_path begin
using IPython
IPython.test_ipython_jl(inprocess=true)
IPython.start_ipython()
end

0 comments on commit 9941dac

Please sign in to comment.