import textwrap


def pyinstrument_magic(rest):
    """
    Profile the code with pyinstrument.
    """
    res = """\
from pyinstrument import Profiler as _Profiler

try:
    with _Profiler() as _profiler:
        pass
{rest}

    _profiler.open_in_browser()
finally:
    del _profiler, _Profiler
"""
    return res.format(rest=textwrap.indent(rest, ' '*8))