Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An API for interegating recorded data #637

Open
1 task done
dnk8n opened this issue Jun 26, 2024 · 1 comment
Open
1 task done

An API for interegating recorded data #637

dnk8n opened this issue Jun 26, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@dnk8n
Copy link

dnk8n commented Jun 26, 2024

Is there an existing proposal for this?

  • I have searched the existing proposals

Is your feature request related to a problem?

I enjoy the flamegraph implementations, etc meant for human eyes. What I would love to see is an API to programmatically pull out the desired metrics of potentially massive amounts of runs (different inputs, etc)

Describe the solution you'd like

I would love if Memray had functions to pull out specific useful data, like peak memory for various dimentions

Alternatives you considered

My current workaround (very hacky, but all I could figure out due to lack of options):

import subprocess
import json
import re
from bs4 import BeautifulSoup
from pathlib import Path
import numpy as np

def pad_arg(arg: int, leading_zeros: int = 6):
    return str(arg).zfill(leading_zeros)

peak_memory_matrix_raw = []
peak_memory_series_x = []
peak_memory_series_y = []
y_axis = range(1000, 11000, 1000)
x_axis = range(100, 1100, 100)
for row in y_axis:
    peak_memory_row_raw = []
    for col in x_axis:
        subprocess.run([f"memray flamegraph analysis/mem-pivot-{pad_arg(row)}-{pad_arg(col)}.bin"], shell=True)
        with Path(f"analysis/memray-flamegraph-mem-pivot-{pad_arg(row)}-{pad_arg(col)}.html").open('r') as html:
            soup = BeautifulSoup(html)
            script = soup.find('script',  {'type': 'text/javascript'})
            memory_records = json.loads(script.contents[0].strip().split('const memory_records = ')[1].split(';')[0])
            peak_memory = max([memory_record[1] for memory_record in memory_records])
            peak_memory_row_raw.append(peak_memory)
            peak_memory_series_x.append(row * col)
            peak_memory_series_y.append(peak_memory)
    peak_memory_matrix_raw.append(peak_memory_row_raw)
peak_memory_matrix = np.matrix(peak_memory_matrix_raw)
@dnk8n dnk8n added the enhancement New feature or request label Jun 26, 2024
@dnk8n
Copy link
Author

dnk8n commented Jun 26, 2024

Also on a side note, I have noticed that the peak memory reading in the statistics section of the flamegraph webpage does not correspond to the peak value plotted on the graph. It is often the second highest value of the heap (orange) graph.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant