From 53dc3af49d0c1f2227762a9cf5df58a870f43029 Mon Sep 17 00:00:00 2001 From: Mateusz Karlowski Date: Mon, 15 Sep 2025 15:03:57 +0200 Subject: [PATCH] Add flag for psutil version only --- sargraph.py | 3 ++- watch.py | 25 +++++++++++++++++-------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/sargraph.py b/sargraph.py index 632bea0..17588cb 100755 --- a/sargraph.py +++ b/sargraph.py @@ -24,6 +24,7 @@ parser.add_argument('-n', metavar='IFACE-NAME', type=str, nargs='?', defa parser.add_argument('-o', metavar='OUTPUT-NAME', type=str, nargs='?', default='data', dest='name', help='set output base names') parser.add_argument('-t', metavar='TMPFS-COLOR', type=str, nargs='?', default='#f2c71b', dest='tmpfs', help='set tmpfs plot color' ) parser.add_argument('-c', metavar='CACHE-COLOR', type=str, nargs='?', default='#ee7af0', dest='cache', help='set cache plot color' ) +parser.add_argument('-p', action='store_true', dest='psutil', help='use psutil instead of sar') args = parser.parse_args() def send(sid, msg): @@ -52,7 +53,7 @@ if args.session is None: if not args.fsdev: fail(f"no device is mounted on {args.fspath}") - watch.watch(args.name, args.fsdev, args.iface, args.tmpfs, args.cache) + watch.watch(args.name, args.fsdev, args.iface, args.tmpfs, args.cache, args.psutil) sys.exit(0) # Now handle the commands diff --git a/watch.py b/watch.py index 8ebc0a8..852e714 100644 --- a/watch.py +++ b/watch.py @@ -252,13 +252,13 @@ def get_meminfo(scheduler): DATA_FILE_HANDLE.write(" ".join(["psu"]+[str(i) for i in line])) -def watch(session, fsdev, iface, tmpfs_color, other_cache_color): - if is_darwin(): - return watch_darwin(session, fsdev, iface, tmpfs_color, other_cache_color) - return watch_linux(session, fsdev, iface, tmpfs_color, other_cache_color) +def watch(session, fsdev, iface, tmpfs_color, other_cache_color, use_psutil): + if is_darwin() or use_psutil: + return watch_psutil(session, fsdev, iface, tmpfs_color, other_cache_color) + return watch_sar(session, fsdev, iface, tmpfs_color, other_cache_color) # Run sar and gather data from it -def watch_linux(session, fsdev, iface, tmpfs_color, other_cache_color): +def watch_sar(session, fsdev, iface, tmpfs_color, other_cache_color): global SAMPLE_NUMBER global START_DATE global END_DATE @@ -450,7 +450,7 @@ def watch_linux(session, fsdev, iface, tmpfs_color, other_cache_color): summarize(session) graph.graph(session, tmpfs_color, other_cache_color) -def watch_darwin(session, fsdev, iface, tmpfs_color, other_cache_color): +def watch_psutil(session, fsdev, iface, tmpfs_color, other_cache_color): global DATA_FILE_HANDLE if DATA_FILE_HANDLE == None: @@ -569,8 +569,17 @@ def psutil_sar_simulation(scheduler): if MAX_TX < curr_tx: MAX_TX = curr_tx # apfs implements lvm, so it's a better option for visualizing the place in the container (which is shared by all partitions). - FS_NAME = "apfs container" - disk_stats = psutil.disk_usage('/') + if is_darwin(): + FS_NAME = "apfs container" + disk_stats = psutil.disk_usage('/') + else: + largest_partition = max( + psutil.disk_partitions(all=False), + key=lambda p: psutil.disk_usage(p.mountpoint).total + ) + disk_stats = psutil.disk_usage(largest_partition.mountpoint) + FS_NAME = largest_partition.device + curr_used = (disk_stats.total - disk_stats.free) / (1024 * 1024) if TOTAL_FS == 0: TOTAL_FS = disk_stats.total / (1024 * 1024)