File: create_sample_json.py

package info (click to toggle)
python-pyinstrument 5.1.1%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,624 kB
  • sloc: python: 6,713; ansic: 897; makefile: 46; sh: 26; javascript: 18
file content (36 lines) | stat: -rwxr-xr-x 893 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python3
import argparse
import subprocess
import sys
from pathlib import Path

ROOT_DIR = Path(__file__).parent.parent
OUTPUT_DIR = ROOT_DIR / "html_renderer" / "demo-data"


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("SCRIPT", help="The script to run to produce the sample", type=Path)
    args = parser.parse_args()
    script_file: Path = args.SCRIPT
    output_file = (OUTPUT_DIR / script_file.with_suffix("").name).with_suffix(".json")

    result = subprocess.run(
        [
            "pyinstrument",
            "-o",
            str(output_file),
            "-r",
            "pyinstrument.renderers.html.JSONForHTMLRenderer",
            script_file,
        ]
    )

    if result.returncode != 0:
        return result.returncode

    print(f"Sample JSON written to {output_file}")


if __name__ == "__main__":
    sys.exit(main())