Skip to content

Instantly share code, notes, and snippets.

@nkottary

nkottary/leaky.jl

Last active Feb 24, 2016
Embed
What would you like to do?
const PID = getpid()
const command = "ps -p $PID -o vsz | sed -n 2p"
const NUM_ITER = 10000
const NUM_PRINT = div(NUM_ITER, 10)
# Get virtual memory usage from julia
jvsz() = split(readall(`ps -p $PID -o vsz`),"\n")[2]
# Get virtual memory usage from C
function cvsz()
path = zeros(Cuchar, 100)
fp = ccall(:popen, Ptr{Void}, (Ptr{Cchar}, Ptr{Cchar}, ),
pointer(command), "r")
@assert fp != C_NULL
mem = ""
while ccall(:fgets, Ptr{Void}, (Ptr{Cchar}, Csize_t, Ptr{Void}, ),
pointer(path), sizeof(path)-1, fp) != C_NULL
mem = split(bytestring(path), "\n")[1]
end
ccall(:pclose, Cint, (Ptr{Void}, ), fp)
return mem
end
# The original code in the issue that was filed but without ZMQ calls.
# This causes virtual memory to increase.
function caseA()
for i = 1:NUM_ITER
jvsz()
if i % NUM_PRINT == 0
println("Current VSZ = ", jvsz())
end
end
end
# Get VSZ from C calls, this does not cause virtual memory to increase.
function caseB()
for i = 1:NUM_ITER
cvsz()
if i % NUM_PRINT == 0
println("Current VSZ = ", cvsz())
end
end
end
# Proof that readall causes VMEM increase.
function caseC()
for i = 1:NUM_ITER
readall(`ls`)
if i % NUM_PRINT == 0
println("Current VSZ = ", cvsz())
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.