Skip to content

Commit

Permalink
Add --time-limit option to status reporter
Browse files Browse the repository at this point in the history
  • Loading branch information
tysmith committed Sep 7, 2023
1 parent d0a0b9f commit 6ecb301
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 32 deletions.
42 changes: 15 additions & 27 deletions grizzly/common/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def load_all(cls, db_file, time_limit=300):
Args:
db_file (Path): Database containing status data.
time_limit (int): Filter entries by age.
time_limit (int): Filter entries by age. Use zero for no limit.
Yields:
ReadOnlyStatus: Successfully loaded objects.
Expand All @@ -194,30 +194,18 @@ def load_all(cls, db_file, time_limit=300):
cur = con.cursor()
# collect entries
try:
if time_limit:
cur.execute(
"""SELECT pid,
_profiles,
ignored,
iteration,
log_size,
start_time,
timestamp
FROM status
WHERE timestamp > ?;""",
(time() - time_limit,),
)
else:
cur.execute(
"""SELECT pid,
_profiles,
ignored,
iteration,
log_size,
start_time,
timestamp
FROM status;"""
)
cur.execute(
"""SELECT pid,
_profiles,
ignored,
iteration,
log_size,
start_time,
timestamp
FROM status
WHERE timestamp > ?;""",
(time() - time_limit if time_limit else 0,),
)
entries = cur.fetchall()
except OperationalError as exc:
if not str(exc).startswith("no such table:"):
Expand Down Expand Up @@ -993,7 +981,7 @@ def load_all(cls, db_file, time_limit=300):
Args:
db_file (Path): Database containing status data.
time_limit (int): Only include entries with a timestamp that is within the
given number of seconds.
given number of seconds. Use zero for no limit.
Yields:
Status: Successfully loaded read-only status objects.
Expand Down Expand Up @@ -1023,7 +1011,7 @@ def load_all(cls, db_file, time_limit=300):
FROM reduce_status
WHERE timestamp > ?
ORDER BY timestamp DESC;""",
(time() - time_limit,),
(time() - time_limit if time_limit else 0,),
)
entries = cur.fetchall()
except OperationalError as exc:
Expand Down
16 changes: 11 additions & 5 deletions grizzly/common/status_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def load(cls, db_file, tb_path=None, time_limit=TIME_LIMIT):
db_file (str): Status data file to load.
tb_path (Path): Directory to scan for files containing Python tracebacks.
time_limit (int): Only include entries with a timestamp that is within the
given number of seconds.
given number of seconds. Use zero for no limit.
Returns:
StatusReporter: Contains available status reports and traceback reports.
Expand Down Expand Up @@ -631,7 +631,7 @@ def load(cls, db_file, tb_path=None, time_limit=TIME_LIMIT):
path (str): Path to scan for status data files.
tb_path (str): Directory to scan for files containing Python tracebacks.
time_limit (int): Only include entries with a timestamp that is within the
given number of seconds.
given number of seconds. Use zero for no limit.
Returns:
ReductionStatusReporter: Contains available status reports and traceback
Expand Down Expand Up @@ -876,8 +876,7 @@ def main(args=None):
choices=report_types.keys(),
default="active",
help="Report type. active: Current snapshot of activity, complete: "
"Aggregate summary of all jobs over a longer duration (8h). "
"(default: %(default)s)",
"Aggregate summary of all jobs over a longer duration. (default: %(default)s)",
)
parser.add_argument(
"--scan-mode",
Expand All @@ -890,6 +889,12 @@ def main(args=None):
action="store_true",
help="Output summary and system information",
)
parser.add_argument(
"--time-limit",
type=int,
help="Maximum age of reports in seconds. Use zero for no limit."
f" (default: {', '.join(f'{k}: {v}s' for k, v in report_types.items())})",
)
parser.add_argument(
"--tracebacks",
type=Path,
Expand All @@ -899,11 +904,12 @@ def main(args=None):
if args.tracebacks and not args.tracebacks.is_dir():
parser.error("--tracebacks must be a directory")

time_limit = report_types[args.type] if args.time_limit is None else args.time_limit
reporter_cls, status_db = modes.get(args.scan_mode)
reporter = reporter_cls.load(
status_db,
tb_path=args.tracebacks,
time_limit=report_types[args.type],
time_limit=time_limit,
)

if args.dump:
Expand Down

0 comments on commit 6ecb301

Please sign in to comment.