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

Function read_mprofile_file

mprof.py:340–398  ·  view source on GitHub ↗

Read an mprofile file and return its content. Returns ======= content: dict Keys: - "mem_usage": (list) memory usage values, in MiB - "timestamp": (list) time instant for each memory usage value, in second - "func_timestamp": (dict) for each

(filename)

Source from the content-addressed store, hash-verified

338
339
340def read_mprofile_file(filename):
341 """Read an mprofile file and return its content.
342
343 Returns
344 =======
345 content: dict
346 Keys:
347
348 - "mem_usage": (list) memory usage values, in MiB
349 - "timestamp": (list) time instant for each memory usage value, in
350 second
351 - "func_timestamp": (dict) for each function, timestamps and memory
352 usage upon entering and exiting.
353 - 'cmd_line': (str) command-line ran for this profile.
354 """
355 func_ts = {}
356 mem_usage = []
357 timestamp = []
358 children = defaultdict(list)
359 cmd_line = None
360 f = open(filename, "r")
361 for l in f:
362 if l == '\n':
363 raise ValueError('Sampling time was too short')
364 field, value = l.split(' ', 1)
365 if field == "MEM":
366 # mem, timestamp
367 values = value.split(' ')
368 mem_usage.append(float(values[0]))
369 timestamp.append(float(values[1]))
370
371 elif field == "FUNC":
372 values = value.split(' ')
373 f_name, mem_start, start, mem_end, end = values[:5]
374 ts = func_ts.get(f_name, [])
375 to_append = [float(start), float(end), float(mem_start), float(mem_end)]
376 if len(values) >= 6:
377 # There is a stack level field
378 stack_level = values[5]
379 to_append.append(int(stack_level))
380 ts.append(to_append)
381 func_ts[f_name] = ts
382
383 elif field == "CHLD":
384 values = value.split(' ')
385 chldnum = values[0]
386 children[chldnum].append(
387 (float(values[1]), float(values[2]))
388 )
389
390 elif field == "CMDLINE":
391 cmd_line = value
392 else:
393 pass
394 f.close()
395
396 return {"mem_usage": mem_usage, "timestamp": timestamp,
397 "func_timestamp": func_ts, 'filename': filename,

Callers 3

plot_fileFunction · 0.85
flame_plotterFunction · 0.85
peak_actionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected