aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2021-10-04 02:45:08 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2021-10-04 02:45:08 +0300
commit7ce495543a606ee50ee0cd1b071bde2099fdf8fe (patch)
treef872d6c13bfa73a15a1c2faa643170b499558caa
parentfix whitespace (diff)
downloadlinux-status-7ce495543a606ee50ee0cd1b071bde2099fdf8fe.tar.gz
linux-status-7ce495543a606ee50ee0cd1b071bde2099fdf8fe.zip
top: run with -E/-e if supportedv1.1.0
-rwxr-xr-xapp.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/app.py b/app.py
index b4d2967..1ae9760 100755
--- a/app.py
+++ b/app.py
@@ -207,8 +207,10 @@ class Task(abc.ABC):
class TopTask(Task):
+ COMMAND = None
+
def __init__(self):
- self.cmd = Command('top', '-b', '-n', '1', '-w', '512')
+ self.cmd = TopTask.get_command()
def run(self):
self.task = self.cmd.run()
@@ -216,6 +218,21 @@ class TopTask(Task):
def result(self):
return self.task.result()
+ @staticmethod
+ def get_command():
+ # On more modern versions of top, we want to enable memory scaling
+ # from the command line (another option is the rc file, but that's too
+ # complicated). For that, we simply run `top -h` once, and check if
+ # the output contains the flags we want to use.
+ if TopTask.COMMAND is not None:
+ return TopTask.COMMAND
+ help_output = run_do('top', '-h')
+ args = ['top', '-b', '-n', '1', '-w', '512']
+ if 'Ee' in help_output:
+ args += ['-E', 'm', '-e', 'm']
+ TopTask.COMMAND = Command(*args)
+ return TopTask.COMMAND
+
class RebootTask(Task):
def __init__(self):