import logging


def _get_profiling_data(filename):
    """Read a given file and parse its content for profiling data."""
    data, timestamps = [], []

    try:
        with open(filename, "r") as f:
            file_data = f.readlines()
    except Exception:
        logging.error("Could not read profiling data.", exc_info=True)
        raise SystemExit(1)

    for line in file_data:
        if line == "\n":
            continue

        line = line.strip()
        line_data = line.split(" ")
        if len(line_data) != 3:
            continue
        _, mem_usage, timestamp = line.split(" ")
        data.append(float(mem_usage))
        timestamps.append(float(timestamp))

    if not data:
        logging.error("No samples to parse in {}.".format(filename))
        raise SystemExit(1)

    return {"data": data, "timestamp": timestamps}