From 9bc41099f05d69cfb5a43e03dd0195349070428a Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Sun, 16 Nov 2025 13:51:13 -0600 Subject: [PATCH] scripts: Changed -~/--sleep -> -w/--wait to sleep after -k/--keep-open This changes -w/--wait to sleep _after_ -k/--keep-open, instead of including the time spent waiting on inotifywait in the sleep time. 1. It's easier, no need to keep track of when we started waiting. 2. It's simpler to reason about. 3. It trivially avoids the multiple wakeup noise that plagued watch.py + vim (vim likes to do a bunch of renaming and stuff when saving files, including the file 4913 randomly?) Avoiding this was previously impossible because -~/--sleep was effectively a noop when combined with -k/--keep-open. --- Also renamed from -~/--sleep -> -w/--wait, which is a bit more intuitive and avoids possible shell issues with -~. To make this work, dropped the -w/--block-cycles shortform flag in dbgtrace.py. It's not like this flag is ever used anyways. Though at the moment this is ignoring the possible conflict with -w/--word-bits... --- scripts/codemap.py | 13 ++++++------- scripts/dbgbmap.py | 13 ++++++------- scripts/dbgtrace.py | 14 ++++++-------- scripts/plot.py | 13 ++++++------- scripts/tailpipe.py | 8 ++++---- scripts/treemap.py | 13 ++++++------- scripts/watch.py | 14 ++++++-------- 7 files changed, 40 insertions(+), 48 deletions(-) diff --git a/scripts/codemap.py b/scripts/codemap.py index 0508a8f9..19cd026c 100755 --- a/scripts/codemap.py +++ b/scripts/codemap.py @@ -1461,7 +1461,7 @@ def main(paths, *, lines=None, head=False, cat=False, - sleep=False, + wait=False, **args): # keep-open? if keep_open: @@ -1510,13 +1510,12 @@ def main(paths, *, # try to inotifywait if Inotify: - ptime = time.time() inotify.read() inotify.close() - # sleep a minimum amount of time to avoid flickering - time.sleep(max(0, (sleep or 0.01) - (time.time()-ptime))) - else: - time.sleep(sleep or 2) + # sleep a minimum amount of time to avoid flickering + time.sleep(wait if wait is not None + else 2 if not Inotify + else 0.01) except KeyboardInterrupt: pass @@ -1788,7 +1787,7 @@ if __name__ == "__main__": action='store_true', help="Pipe directly to stdout.") parser.add_argument( - '-~', '--sleep', + '-w', '--wait', type=float, help="Time in seconds to sleep between redraws when running " "with -k. Defaults to 2 seconds.") diff --git a/scripts/dbgbmap.py b/scripts/dbgbmap.py index 62d6607a..819d5bed 100755 --- a/scripts/dbgbmap.py +++ b/scripts/dbgbmap.py @@ -5126,7 +5126,7 @@ def main(disk, mroots=None, *, lines=None, head=False, cat=False, - sleep=False, + wait=False, **args): # keep-open? if keep_open: @@ -5175,13 +5175,12 @@ def main(disk, mroots=None, *, # try to inotifywait if Inotify: - ptime = time.time() inotify.read() inotify.close() - # sleep a minimum amount of time to avoid flickering - time.sleep(max(0, (sleep or 0.01) - (time.time()-ptime))) - else: - time.sleep(sleep or 2) + # sleep a minimum amount of time to avoid flickering + time.sleep(wait if wait is not None + else 2 if not Inotify + else 0.01) except KeyboardInterrupt: pass @@ -5395,7 +5394,7 @@ if __name__ == "__main__": action='store_true', help="Pipe directly to stdout.") parser.add_argument( - '-~', '--sleep', + '-w', '--wait', type=float, help="Time in seconds to sleep between redraws when running " "with -k. Defaults to 2 seconds.") diff --git a/scripts/dbgtrace.py b/scripts/dbgtrace.py index b7e3580f..b9ca15e3 100755 --- a/scripts/dbgtrace.py +++ b/scripts/dbgtrace.py @@ -1039,7 +1039,7 @@ def main(path='-', *, head=False, cat=False, coalesce=None, - sleep=None, + wait=None, keep_open=False, **args): # figure out what color should be @@ -1633,14 +1633,14 @@ def main(path='-', *, # always redraw if we're sleeping, otherwise # wait for coalesce number of operations - if sleep is not None or count >= (coalesce or 1): + if wait is not None or count >= (coalesce or 1): event.set() count = 0 if not keep_open: break # don't just flood open calls - time.sleep(sleep or 2) + time.sleep(wait or 2) except FileNotFoundError as e: print("error: file not found %r" % path, @@ -1692,7 +1692,7 @@ def main(path='-', *, with lock: draw_() # sleep a minimum amount of time to avoid flickering - time.sleep(sleep or 0.01) + time.sleep(wait or 0.01) th.Thread(target=background, daemon=True).start() main_() @@ -1754,10 +1754,8 @@ if __name__ == "__main__": action='store_true', help="Only render wear, don't render bd ops. Implies --wear.") parser.add_argument( - '-w', '--block-cycles', - nargs='?', + '--block-cycles', type=lambda x: int(x, 0), - const=0, help="Assumed maximum number of erase cycles when measuring " "wear. Defaults to the maximum wear on any single block. " "Implies --wear.") @@ -1919,7 +1917,7 @@ if __name__ == "__main__": type=lambda x: int(x, 0), help="Number of operations to coalesce together.") parser.add_argument( - '-~', '--sleep', + '-w', '--wait', type=float, help="Seconds to sleep between draws, coalescing operations " "in between.") diff --git a/scripts/plot.py b/scripts/plot.py index 7781b13a..c871a777 100755 --- a/scripts/plot.py +++ b/scripts/plot.py @@ -1916,7 +1916,7 @@ def main(csv_paths, *, keep_open=False, head=False, cat=False, - sleep=False, + wait=False, **args): # keep-open? if keep_open: @@ -1945,13 +1945,12 @@ def main(csv_paths, *, # try to inotifywait if Inotify: - ptime = time.time() inotify.read() inotify.close() - # sleep a minimum amount of time to avoid flickering - time.sleep(max(0, (sleep or 0.01) - (time.time()-ptime))) - else: - time.sleep(sleep or 2) + # sleep a minimum amount of time to avoid flickering + time.sleep(wait if wait is not None + else 2 if not Inotify + else 0.01) except KeyboardInterrupt: pass @@ -2251,7 +2250,7 @@ if __name__ == "__main__": action='store_true', help="Pipe directly to stdout.") parser.add_argument( - '-~', '--sleep', + '-w', '--wait', type=float, help="Time in seconds to sleep between redraws when running " "with -k. Defaults to 2 seconds.") diff --git a/scripts/tailpipe.py b/scripts/tailpipe.py index 525bd6b2..f6c8acf1 100755 --- a/scripts/tailpipe.py +++ b/scripts/tailpipe.py @@ -152,7 +152,7 @@ def main(path='-', *, lines=5, cat=False, coalesce=None, - sleep=None, + wait=None, keep_open=False): lock = th.Lock() event = th.Event() @@ -175,7 +175,7 @@ def main(path='-', *, if not keep_open: break # don't just flood open calls - time.sleep(sleep or 2) + time.sleep(wait or 2) except FileNotFoundError as e: print("error: file not found %r" % path, @@ -200,7 +200,7 @@ def main(path='-', *, with lock: ring.draw() # sleep a minimum amount of time to avoid flickering - time.sleep(sleep or 0.01) + time.sleep(wait or 0.01) th.Thread(target=background, daemon=True).start() main_(ring) @@ -240,7 +240,7 @@ if __name__ == "__main__": type=lambda x: int(x, 0), help="Number of lines to coalesce together.") parser.add_argument( - '-~', '--sleep', + '-w', '--wait', type=float, help="Seconds to sleep between draws, coalescing lines in " "between.") diff --git a/scripts/treemap.py b/scripts/treemap.py index 6e0b7ead..527edc33 100755 --- a/scripts/treemap.py +++ b/scripts/treemap.py @@ -1320,7 +1320,7 @@ def main(csv_paths, *, lines=None, head=False, cat=False, - sleep=False, + wait=False, **args): # keep-open? if keep_open: @@ -1369,13 +1369,12 @@ def main(csv_paths, *, # try to inotifywait if Inotify: - ptime = time.time() inotify.read() inotify.close() - # sleep a minimum amount of time to avoid flickering - time.sleep(max(0, (sleep or 0.01) - (time.time()-ptime))) - else: - time.sleep(sleep or 2) + # sleep a minimum amount of time to avoid flickering + time.sleep(wait if wait is not None + else 2 if not Inotify + else 0.01) except KeyboardInterrupt: pass @@ -1592,7 +1591,7 @@ if __name__ == "__main__": action='store_true', help="Pipe directly to stdout.") parser.add_argument( - '-~', '--sleep', + '-w', '--wait', type=float, help="Time in seconds to sleep between redraws when running " "with -k. Defaults to 2 seconds.") diff --git a/scripts/watch.py b/scripts/watch.py index 6e0de3f9..71061f3b 100755 --- a/scripts/watch.py +++ b/scripts/watch.py @@ -190,7 +190,7 @@ def main(command, *, lines=0, head=False, cat=False, - sleep=None, + wait=None, keep_open=False, keep_open_paths=None, buffer=False, @@ -285,14 +285,12 @@ def main(command, *, # try to inotifywait if keep_open and Inotify: - ptime = time.time() inotify.read() inotify.close() - # sleep a minimum amount of time to avoid flickering - time.sleep(max(0, (sleep or 0.01) - (time.time()-ptime))) - # or sleep - else: - time.sleep(sleep or 2) + # sleep a minimum amount of time to avoid flickering + time.sleep(wait if wait is not None + else 2 if not (keep_open and Inotify) + else 0.01) except KeyboardInterrupt: pass @@ -329,7 +327,7 @@ if __name__ == "__main__": action='store_true', help="Pipe directly to stdout.") parser.add_argument( - '-~', '--sleep', + '-w', '--wait', type=float, help="Seconds to sleep between runs. Defaults to 2 seconds.") parser.add_argument(