from pathlib import Path


def get_benchmark_directory(base_directory, executable, runtime_sec, rmw, create=False):
    """
    Return the directory to place measurements and reports for the given experiment.

    If `create` is True, the directory is created if it does not exist yet.
    """
    # Note: memory_usage.py and std_latency.py make assumptions about the directory format.
    # Do not change this without also changing these other files.
    directory = Path(base_directory)/f'{runtime_sec}s/{rmw}/{executable}/'
    if create:
        directory.mkdir(parents=True, exist_ok=True)
    return directory