From 3161fb08ff3c6b18438bb45cf70aff92d0141a7c Mon Sep 17 00:00:00 2001 From: Mark Shroyer Date: Wed, 16 Nov 2022 13:47:13 -0800 Subject: [PATCH] Include `top` in `eden rage` Summary: There have been support requests where we needed to rule out high system load on the user's computer (rather than EdenFS) slowing down their experience. This adds a snapshot of `top` to the output of `eden rage` on Linux and macOS so we don't have to ask the user for this. We only include the top ten-ish processes in the output to avoid blowing up the `rage`. Reviewed By: chadaustin Differential Revision: D41351716 fbshipit-source-id: 5db170b1b83ff58ffce21769b379e9ad2b38738a --- eden/fs/cli/rage.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/eden/fs/cli/rage.py b/eden/fs/cli/rage.py index cbc3ed8a76..32aeec79a3 100644 --- a/eden/fs/cli/rage.py +++ b/eden/fs/cli/rage.py @@ -218,6 +218,8 @@ def print_diagnostic_info( print_system_mount_table(out) + print_system_load(out) + def report_edenfs_bug(instance: EdenInstance, reporter: str) -> None: rage_lambda: Callable[ @@ -468,6 +470,32 @@ def print_system_mount_table(out: IO[bytes]) -> None: out.write(f"Error printing system mount table: {e}\n".encode()) +def print_system_load(out: IO[bytes]) -> None: + if sys.platform not in ("darwin", "linux"): + return + + try: + section_title("System load:", out) + if sys.platform == "linux": + output = subprocess.check_output(["top", "-b", "-n1"]) + + # Limit to the first 16 lines of output because top on CentOS + # doesn't seem to have a command-line flag for this. + output_lines = output.decode("utf-8").split(os.linesep)[:17] + elif sys.platform == "darwin": + output = subprocess.check_output(["top", "-l2", "-n10"]) + + # On macOS the first iteration of `top` will have incorrect CPU + # usage values for processes. So here we wait for the second + # iteration and strip the first from the output. + output_lines = output.decode("utf-8").split(os.linesep) + output_lines = output_lines[len(output_lines) // 2 :] + + out.write(os.linesep.join(output_lines).encode("utf-8")) + except Exception as e: + out.write(f"Error printing system load: {e}\n".encode()) + + def print_eden_config(instance: EdenInstance, out: IO[bytes]) -> None: try: section_title("EdenFS config:", out)