i have a python script (runner.py
) which regularly measures memory consumption of a process. to monitor memory consumption I use a helper class called ProcessTimer.py
. processtimer is implemented based on the solution given here.
the solution is based on polling. so there is a while
-loop. in this while
-loop memory consumption is measured and then the thread sleeps for a certain amount of time to ensure regular measurements. in my case sleep is done for 500ms. however, my problem is that the measurements are not done each 500ms. the time inbetween measurements seems arbitrary and I don't know why it's not done each 500ms (according to the time.sleep(.500)
).
here you can see the CSV output of my measurements. first column is the time (in sec) and second column is the memory consumption:
time,rss_mem
0.0,12.38
1.1,101.89
2.3,110.74
3.4,110.79
4.5,113.61
5.7,101.6
6.8,102.44
8.0,104.28
9.1,104.48
10.3,108.13
11.4,102.64
12.6,102.83
13.7,102.86
14.9,102.86
as you can see there is always ~1.1sec inbetween each measurement, even though the while
-loop (which is used for measuring memory consumption of another process) should be executed each 500ms. why is that?
the relevant code of runner.py can be seen here. The helper class ProcessTimer.py can be seen here.