vprof
vprof copied to clipboard
`import` does not work with memory profiler
Description
import mod do not work with memory profile.
How to reproduce
mod.py:
print("I'm mod")
main.py:
import mod
Actual results
$ vprof -c cm "main.py"
Running MemoryProfiler...
I'm mod
Running FlameGraphProfiler...
Starting HTTP server...
Expected results
mod.py should be executed 2 times.
$ vprof -c cm "main.py"
Running MemoryProfiler...
I'm mod
Running FlameGraphProfiler...
I'm mod
Starting HTTP server...
Version and platform
vprof 0.37.4 python 3.6.2 Mac OSX
It happens since profiling agents are run one after another: memory profiler always runs first and in the same process and others do run in their own processes for isolation. These processes are forked after memory profiler imports the code and child processes inherit that and that's why code is not reimported.