Markata plugin to create a pyinstrument profile if pyinstrument is installed.

The profile will be saved to <output_dir>/_profile/index.html

MarkataInstrument class

MarkataInstrument source
class MarkataInstrument(Markata):
    should_profile = False
    profiler = None

configure function

set the should_profile variable

configure source
def configure(markata: MarkataInstrument) -> None:
    "set the should_profile variable"
    markata.profiler = None

    if "should_profile" not in markata.__dict__.keys():
        markata.should_profile = markata.config.get("pyinstrument", {}).get(
            "should_profile", True

    if markata.should_profile and "profiler" not in markata.__dict__.keys():
            markata.profiler = Profiler(async_mode="disabled")
        except NameError:
            "ignore if Profiler does not exist"

save function

stop the profiler and save as late as possible

save source
def save(markata: MarkataInstrument) -> None:
    "stop the profiler and save as late as possible"
    if markata.should_profile:
            if "profiler" in markata.__dict__.keys():
                output_file = (
                    Path(markata.config["output_dir"]) / "_profile" / "index.html"
                output_file.parent.mkdir(parents=True, exist_ok=True)
                html = markata.profiler.output_html()

        except AttributeError:
            "ignore if markata does not have a profiler attribute"

teardown function

stop the profiler on exit

teardown source
def teardown(markata: MarkataInstrument) -> None:
    "stop the profiler on exit"

    if markata.should_profile:
        if hasattr(markata, "profiler"):
            if markata.profiler is not None:
                if markata.profiler.is_running: