diff options
| author | Nat Goodspeed <nat@lindenlab.com> | 2024-09-12 12:28:05 -0400 | 
|---|---|---|
| committer | Nat Goodspeed <nat@lindenlab.com> | 2024-09-18 14:05:28 -0400 | 
| commit | 277ee6830f68030ece6f469a86a49009a9c1450a (patch) | |
| tree | 2a8bf2940b1e52cb5fb73ef0060c36ff81280101 | |
| parent | a3d6544be07e3cd0bb7e4cb78564a0d6077fd910 (diff) | |
Add a JSON frame profile stats file pretty-printer script.
(cherry picked from commit ab3083819793a30911354670a7929b0d3f7c104c)
| -rw-r--r-- | scripts/perf/profile_pretty.py | 54 | 
1 files changed, 54 insertions, 0 deletions
| diff --git a/scripts/perf/profile_pretty.py b/scripts/perf/profile_pretty.py new file mode 100644 index 0000000000..ca52fe366a --- /dev/null +++ b/scripts/perf/profile_pretty.py @@ -0,0 +1,54 @@ +#!/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 logsdir +import json +from pathlib import Path +import sys + +class Error(Exception): +    pass + +def pretty(path=None): +    if not path: +        logs = logsdir.logsdir() +        profiles = Path(logs).glob('profile.*.json') +        sort = [(p.stat().st_mtime, p) for p in profiles] +        sort.sort(reverse=True) +        try: +            path = sort[0][1] +        except IndexError: +            raise Error(f'No profile.*.json files in {logs}') +        # print path to sys.stderr in case user is redirecting stdout +        print(path, file=sys.stderr) + +    with open(path) as inf: +        data = json.load(inf) +    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) + +if __name__ == "__main__": +    try: +        sys.exit(main(*sys.argv[1:])) +    except (Error, OSError, json.JSONDecodeError) as err: +        sys.exit(str(err)) | 
