(filename, index=0, timestamps=True, children=True, options=None)
| 399 | |
| 400 | |
| 401 | def plot_file(filename, index=0, timestamps=True, children=True, options=None): |
| 402 | try: |
| 403 | import pylab as pl |
| 404 | except ImportError as e: |
| 405 | print("matplotlib is needed for plotting.") |
| 406 | print(e) |
| 407 | sys.exit(1) |
| 408 | import numpy as np # pylab requires numpy anyway |
| 409 | mprofile = read_mprofile_file(filename) |
| 410 | |
| 411 | if len(mprofile['timestamp']) == 0: |
| 412 | print('** No memory usage values have been found in the profile ' |
| 413 | 'file.**\nFile path: {0}\n' |
| 414 | 'File may be empty or invalid.\n' |
| 415 | 'It can be deleted with "mprof rm {0}"'.format( |
| 416 | mprofile['filename'])) |
| 417 | sys.exit(0) |
| 418 | |
| 419 | # Merge function timestamps and memory usage together |
| 420 | ts = mprofile['func_timestamp'] |
| 421 | t = mprofile['timestamp'] |
| 422 | mem = mprofile['mem_usage'] |
| 423 | chld = mprofile['children'] |
| 424 | |
| 425 | if len(ts) > 0: |
| 426 | for values in ts.values(): |
| 427 | for v in values: |
| 428 | t.extend(v[:2]) |
| 429 | mem.extend(v[2:4]) |
| 430 | |
| 431 | mem = np.asarray(mem) |
| 432 | t = np.asarray(t) |
| 433 | ind = t.argsort() |
| 434 | mem = mem[ind] |
| 435 | t = t[ind] |
| 436 | |
| 437 | # Plot curves |
| 438 | global_start = float(t[0]) |
| 439 | t = t - global_start |
| 440 | |
| 441 | max_mem = mem.max() |
| 442 | max_mem_ind = mem.argmax() |
| 443 | |
| 444 | all_colors = ("c", "y", "g", "r", "b") |
| 445 | mem_line_colors = ("k", "b", "r", "g", "c", "y", "m") |
| 446 | |
| 447 | show_trend_slope = options is not None and hasattr(options, 'slope') and options.slope is True |
| 448 | |
| 449 | mem_line_label = time.strftime("%d / %m / %Y - start at %H:%M:%S", |
| 450 | time.localtime(global_start)) \ |
| 451 | + ".{0:03d}".format(int(round(math.modf(global_start)[0] * 1000))) |
| 452 | |
| 453 | mem_trend = None |
| 454 | if show_trend_slope: |
| 455 | # Compute trend line |
| 456 | mem_trend = np.polyfit(t, mem, 1) |
| 457 | |
| 458 | # Append slope to label |
nothing calls this directly
no test coverage detected