Last active
August 22, 2025 16:46
-
-
Save qris/3fef718b1814913b0b1aa7288b01d790 to your computer and use it in GitHub Desktop.
Script to measure how long the system actually sleeps for, like "ping" for the OS scheduler.
This file contains hidden or 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
| """Measures how long simple I/O requests take, like "ping" for the OS disk I/O scheduler.""" | |
| import datetime | |
| import os | |
| import time | |
| from argparse import ArgumentParser | |
| from tempfile import NamedTemporaryFile | |
| interval = 0.5 | |
| def main(): | |
| """Measures how long simple I/O requests take, like "ping" for the OS disk I/O scheduler.""" | |
| parser = ArgumentParser(description=__doc__) | |
| parser.add_argument('dir', help="Directory to create file in") | |
| args = parser.parse_args() | |
| with NamedTemporaryFile(dir=args.dir, prefix=os.path.basename(__file__) + '.', suffix='.tmp') as handle: | |
| while True: | |
| time.sleep(interval) | |
| t0 = time.time() | |
| handle.write(b'a') | |
| handle.flush() | |
| os.fsync(handle.fileno()) | |
| t1 = time.time() | |
| actual = (t1 - t0) | |
| time_now = datetime.datetime.fromtimestamp(t1) | |
| # print(f"{time_now.time()}: expected {interval} actual {actual:.4f} overrun {actual - interval:.4f}") | |
| print(f"{time_now.time()}: {args.dir}: latency {actual:.4f} s") | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment