Esempio n. 1
0
def test_compress(datapath):
    with AustinFileReader(datapath / "austin.out") as original:
        compressed = io.StringIO()
        compress(original, compressed)

        with open(datapath / "austin.out") as original:
            compressed_value = compressed.getvalue()
            assert compressed_value
            assert len(compressed_value.splitlines()) < len(
                original.readlines())
Esempio n. 2
0
def main() -> None:
    """austin2speedscope entry point."""
    from argparse import ArgumentParser
    import os

    arg_parser = ArgumentParser(
        prog="austin2speedscope",
        description=
        ("Convert Austin generated profiles to the Speedscope JSON format "
         "accepted by https://speedscope.app. The output will contain a profile "
         "for each thread and metric included in the input file."),
    )

    arg_parser.add_argument(
        "input",
        type=str,
        help="The input file containing Austin samples in normal format.",
    )
    arg_parser.add_argument(
        "output",
        type=str,
        help="The name of the output Speedscope JSON file.")
    arg_parser.add_argument(
        "--indent",
        type=int,
        help="Give a non-null value to prettify the JSON output.")

    arg_parser.add_argument("-V",
                            "--version",
                            action="version",
                            version=__version__)

    args = arg_parser.parse_args()

    try:
        with AustinFileReader(args.input) as fin:
            mode = fin.metadata["mode"]
            speedscope = Speedscope(os.path.basename(args.input), mode,
                                    args.indent)
            for line in fin:
                try:
                    speedscope.add_samples(
                        Sample.parse(line, MetricType.from_mode(mode)))
                except InvalidSample:
                    continue

    except FileNotFoundError:
        print(f"No such input file: {args.input}")
        exit(1)

    with open(args.output, "w") as fout:
        speedscope.dump(fout)
Esempio n. 3
0
def test_compress_counts(datapath):
    with AustinFileReader(datapath / "austin.out") as original:
        compressed = io.StringIO()
        compress(original, compressed, counts=True)

        for sample in compressed.getvalue().splitlines():
            head, _, metric = sample.rpartition(" ")
            if (head == "P4317;T7ffb7f8f0700;"
                    "_bootstrap (/usr/lib/python3.6/threading.py);L884;"
                    "_bootstrap_inner (/usr/lib/python3.6/threading.py);L916;"
                    "run (/usr/lib/python3.6/threading.py);L864;"
                    "keep_cpu_busy (../austin/test/target34.py);L31"):
                assert int(metric) == 20
                break
Esempio n. 4
0
def test_austin_file_reader(datapath):
    with AustinFileReader(datapath / "austin.out") as fr:
        assert fr.metadata == {
            "austin": "3.0.0",
            "interval": "10000",
            "mode": "wall",
        }

        assert sum(bool(Sample.parse(line, MetricType.TIME))
                   for line in fr) == 73

        assert fr.metadata == {
            "austin": "3.0.0",
            "interval": "10000",
            "mode": "wall",
            "duration": "383010",
        }
Esempio n. 5
0
def test_pprof(datapath):
    with AustinFileReader(datapath / "austin.out") as austin:
        mode = austin.metadata["mode"]
        prof = PProf(mode)

        for line in austin:
            try:
                prof.add_samples(Sample.parse(line,
                                              MetricType.from_mode(mode)))
            except InvalidSample:
                continue

        bstream = io.BytesIO()
        prof.dump(bstream)

        with open(datapath / "austin.pprof", "rb") as pprof:
            assert pprof.read() == bstream.getvalue()
Esempio n. 6
0
def main() -> None:
    """austin2pprof entry point."""
    arg_parser = ArgumentParser(
        prog="austin2pprof",
        description=(
            "Convert Austin generated profiles to the pprof protobuf format. "
            "See https://github.com/google/pprof for more details."),
    )

    arg_parser.add_argument(
        "input",
        type=str,
        help="The input file containing Austin samples.",
    )
    arg_parser.add_argument("output",
                            type=str,
                            help="The name of the output pprof file.")

    arg_parser.add_argument("-V",
                            "--version",
                            action="version",
                            version="0.1.0")

    args = arg_parser.parse_args()

    try:
        with AustinFileReader(args.input) as fin:
            mode = fin.metadata["mode"]
            pprof = PProf(mode=mode)

            # Read samples
            for line in fin:
                try:
                    pprof.add_samples(
                        Sample.parse(line, MetricType.from_mode(mode)))
                except InvalidSample:
                    continue

    except FileNotFoundError:
        print(f"No such input file: {args.input}")
        exit(1)

    with open(args.output, "wb") as fout:
        pprof.dump(fout)
Esempio n. 7
0
def test_speedscope_wall_metrics_only(datapath):
    with AustinFileReader(datapath / "austin.out") as austin:
        mode = austin.metadata["mode"]
        assert Mode.from_metadata(mode) == Mode.WALL

        speedscope = Speedscope("austin.out", mode, indent=2)

        for line in austin:
            try:
                speedscope.add_samples(
                    Sample.parse(line, MetricType.from_mode(mode)))
            except InvalidSample:
                continue

        text_stream = io.StringIO()
        speedscope.dump(text_stream)

        with open(datapath / "austin.json", "r") as sprof:
            assert text_stream.getvalue() == sprof.read()