summaryrefslogtreecommitdiff
path: root/scripts/perf/profile_pretty.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/perf/profile_pretty.py')
-rw-r--r--scripts/perf/profile_pretty.py22
1 files changed, 4 insertions, 18 deletions
diff --git a/scripts/perf/profile_pretty.py b/scripts/perf/profile_pretty.py
index 15b6efd94d..405b14b373 100644
--- a/scripts/perf/profile_pretty.py
+++ b/scripts/perf/profile_pretty.py
@@ -10,17 +10,15 @@ Copyright (c) 2024, Linden Research, Inc.
$/LicenseInfo$
"""
-import logsdir
import json
-from pathlib import Path
+from logsdir import Error, latest_file, logsdir
import sys
-class Error(Exception):
- pass
-
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):
@@ -33,19 +31,7 @@ The file produced by the viewer is a single dense line of JSON.
help="""profile filename to pretty-print (default is most recent)""")
args = parser.parse_args(raw_args)
- if not args.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:
- args.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(args.path, file=sys.stderr)
-
- pretty(args.path)
+ pretty(args.path or latest_file(logsdir(), 'profile.*.json'))
if __name__ == "__main__":
try: