def profiling_csv(stage, phases, durations):
    """
    Dumps the profiling information into a CSV format.
    For example, with
        stage:     `x`
        phases:    ['a', 'b', 'c']
        durations: [1.42, 2.0, 3.4445]
    The output will be:
    ```
    x,a,1.42
    x,b,2.0
    x,c,3.444
    ```
    """
    assert all(hasattr(p, "name") for p in phases), "expected to have name attribute."
    return "\n".join(
        [f"{stage},{p.name},{round(t, 3)}" for (p, t) in zip(phases, durations)]
    )