summaryrefslogtreecommitdiff
path: root/scripts/perf/logsdir.py
diff options
context:
space:
mode:
authorNat Goodspeed <nat@lindenlab.com>2024-09-13 16:32:04 -0400
committerNat Goodspeed <nat@lindenlab.com>2024-09-18 17:04:46 -0400
commit705ec153c5ee3f6d1781647c1bbbfcd7c398c987 (patch)
tree1dcc75d7e1633df71e4f7d15942cf00a6ee205d6 /scripts/perf/logsdir.py
parent725e1b7d6f8ca31705372f9b391a34969f44577b (diff)
Add script to compare a Frame Profile JSON stats file vs. baseline.
Extract `latest_file()` logic replicated in profile_pretty.py and profile_csv.py out to logsdir.py, and use for new profile_cmp.py. (cherry picked from commit 439cfc97a81f221daaf8ba13aa5daa87e8511047)
Diffstat (limited to 'scripts/perf/logsdir.py')
-rw-r--r--scripts/perf/logsdir.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/scripts/perf/logsdir.py b/scripts/perf/logsdir.py
new file mode 100644
index 0000000000..c8b498cf78
--- /dev/null
+++ b/scripts/perf/logsdir.py
@@ -0,0 +1,46 @@
+#!/usr/bin/env python3
+"""\
+@file logsdir.py
+@author Nat Goodspeed
+@date 2024-09-12
+@brief Locate the Second Life logs directory for the current user on the
+ current platform.
+
+$LicenseInfo:firstyear=2024&license=viewerlgpl$
+Copyright (c) 2024, Linden Research, Inc.
+$/LicenseInfo$
+"""
+
+import os
+from pathlib import Path
+import platform
+
+class Error(Exception):
+ pass
+
+# logic used by SLVersionChecker
+def logsdir():
+ app = 'SecondLife'
+ system = platform.system()
+ if (system == 'Darwin'):
+ base_dir = os.path.join(os.path.expanduser('~'),
+ 'Library','Application Support',app)
+ elif (system == 'Linux'):
+ base_dir = os.path.join(os.path.expanduser('~'),
+ '.' + app.lower())
+ elif (system == 'Windows'):
+ appdata = os.getenv('APPDATA')
+ base_dir = os.path.join(appdata, app)
+ else:
+ raise ValueError("Unsupported platform '%s'" % system)
+
+ return os.path.join(base_dir, 'logs')
+
+def latest_file(dirpath, pattern):
+ files = Path(dirpath).glob(pattern)
+ sort = [(p.stat().st_mtime, p) for p in files if p.is_file()]
+ sort.sort(reverse=True)
+ try:
+ return sort[0][1]
+ except IndexError:
+ raise Error(f'No {pattern} files in {dirpath}')