MCPcopy Index your code
hub / github.com/pythonprofilers/memory_profiler / MemTimer

Class MemTimer

memory_profiler.py:224–266  ·  view source on GitHub ↗

Fetch memory consumption from over a time interval

Source from the content-addressed store, hash-verified

222
223
224class MemTimer(Process):
225 """
226 Fetch memory consumption from over a time interval
227 """
228
229 def __init__(self, monitor_pid, interval, pipe, backend, max_usage=False,
230 *args, **kw):
231 self.monitor_pid = monitor_pid
232 self.interval = interval
233 self.pipe = pipe
234 self.cont = True
235 self.backend = backend
236 self.max_usage = max_usage
237 self.n_measurements = 1
238
239 self.timestamps = kw.pop("timestamps", False)
240 self.include_children = kw.pop("include_children", False)
241
242 # get baseline memory usage
243 self.mem_usage = [
244 _get_memory(self.monitor_pid, self.backend, timestamps=self.timestamps,
245 include_children=self.include_children)]
246 super(MemTimer, self).__init__(*args, **kw)
247
248 def run(self):
249 self.pipe.send(0) # we're ready
250 stop = False
251 while True:
252 cur_mem = _get_memory(
253 self.monitor_pid, self.backend, timestamps=self.timestamps,
254 include_children=self.include_children,)
255 if not self.max_usage:
256 self.mem_usage.append(cur_mem)
257 else:
258 self.mem_usage[0] = max(cur_mem, self.mem_usage[0])
259 self.n_measurements += 1
260 if stop:
261 break
262 stop = self.pipe.poll(self.interval)
263 # do one more iteration
264
265 self.pipe.send(self.mem_usage)
266 self.pipe.send(self.n_measurements)
267
268
269def memory_usage(proc=-1, interval=.1, timeout=None, timestamps=False,

Callers 1

memory_usageFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected