nvdv / vprof

Visual profiler for Python
BSD 2-Clause "Simplified" License
3.95k stars 154 forks source link

`import` does not work with memory profiler #77

Open ahuigo opened 6 years ago

ahuigo commented 6 years ago
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

nvdv commented 6 years ago

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.