summaryrefslogtreecommitdiff
path: root/scripts/perf/profile_pretty.py
blob: 405b14b3733afd04922b9a4b0b748f3f20498e6e (plain)
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
37
38
39
40
#!/usr/bin/env python3
"""\
@file   profile_pretty.py
@author Nat Goodspeed
@date   2024-09-12
@brief  Pretty-print a JSON file from Develop -> Render Tests -> Frame Profile

$LicenseInfo:firstyear=2024&license=viewerlgpl$
Copyright (c) 2024, Linden Research, Inc.
$/LicenseInfo$
"""

import json
from logsdir import Error, latest_file, logsdir
import sys

def pretty(path):
    with open(path) as inf:
        data = json.load(inf)
    # print path to sys.stderr in case user is redirecting stdout
    print(path, file=sys.stderr)
    json.dump(data, sys.stdout, indent=4)

def main(*raw_args):
    from argparse import ArgumentParser
    parser = ArgumentParser(description="""
%(prog)s pretty-prints a JSON file from Develop -> Render Tests -> Frame Profile.
The file produced by the viewer is a single dense line of JSON.
""")
    parser.add_argument('path', nargs='?',
                        help="""profile filename to pretty-print (default is most recent)""")

    args = parser.parse_args(raw_args)
    pretty(args.path or latest_file(logsdir(), 'profile.*.json'))

if __name__ == "__main__":
    try:
        sys.exit(main(*sys.argv[1:]))
    except (Error, OSError, json.JSONDecodeError) as err:
        sys.exit(str(err))