-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a JSON frame profile stats file pretty-printer script.
- Loading branch information
1 parent
a68bb4e
commit ab30838
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) |