Skip to content

Commit

Permalink
Add a new flag --no-processes to hide process information (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
doncamilom authored Oct 15, 2022
1 parent 49431fa commit af7d760
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Options (Please see `gpustat --help` for more details):
* `-e`, `--show-codec` : Display encoder and/or decoder utilization
* `-P`, `--show-power` : Display GPU power usage and/or limit (`draw` or `draw,limit`)
* `-a`, `--show-all` : Display all gpu properties above
* `--no-processes` : Do not display process information (user, memory)
* `--watch`, `-i`, `--interval` : Run in watch mode (equivalent to `watch gpustat`) if given. Denotes interval between updates. ([#41][gh-issue-41])
* `--json` : JSON Output (Experimental, [#10][gh-issue-10])

Expand Down
6 changes: 5 additions & 1 deletion gpustat/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def nonnegative_int(value):
parser.add_argument('-c', '--show-cmd', action='store_true',
help='Display cmd name of running process')
parser.add_argument(
'-f', '--show-full-cmd', action='store_true',
'-f', '--show-full-cmd', action='store_true', default=False,
help='Display full command and cpu stats of running process'
)
parser.add_argument('-u', '--show-user', action='store_true',
Expand Down Expand Up @@ -122,6 +122,10 @@ def nonnegative_int(value):
'--debug', action='store_true', default=False,
help='Allow to print additional informations for debugging.'
)
parser.add_argument(
'--no-processes', dest='no_processes', action='store_true',
help='Hide memory ussage from individual processes.'
)
parser.add_argument('-v', '--version', action='version',
version=('gpustat %s' % __version__))
args = parser.parse_args(argv[1:])
Expand Down
12 changes: 9 additions & 3 deletions gpustat/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ def print_to(self, fp, *,
with_colors=True, # deprecated arg
show_cmd=False,
show_full_cmd=False,
no_processes=False,
show_user=False,
show_pid=False,
show_fan_speed=None,
Expand Down Expand Up @@ -292,7 +293,10 @@ def __getitem__(self, key):
self.entry["name"], width=gpuname_width, placeholder='…'),
gpuname_width=gpuname_width or DEFAULT_GPUNAME_WIDTH
)
reps += " |"

# Add " |" only if processes information is to be added.
if not no_processes:
reps += " |"

def process_repr(p):
r = ''
Expand Down Expand Up @@ -332,10 +336,10 @@ def full_process_info(p):

processes = self.entry['processes']
full_processes = []
if processes is None:
if processes is None and not no_processes:
# None (not available)
reps += ' ({})'.format(NOT_SUPPORTED)
else:
elif not no_processes:
for p in processes:
reps += ' ' + process_repr(p)
if show_full_cmd:
Expand Down Expand Up @@ -620,6 +624,7 @@ def print_formatted(self, fp=sys.stdout, *,
show_pid=False, show_fan_speed=None,
show_codec="", show_power=None,
gpuname_width=None, show_header=True,
no_processes=False,
eol_char=os.linesep,
):
# ANSI color configuration
Expand Down Expand Up @@ -671,6 +676,7 @@ def print_formatted(self, fp=sys.stdout, *,
g.print_to(fp,
show_cmd=show_cmd,
show_full_cmd=show_full_cmd,
no_processes=no_processes,
show_user=show_user,
show_pid=show_pid,
show_fan_speed=show_fan_speed,
Expand Down
8 changes: 8 additions & 0 deletions gpustat/test_gpustat.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,11 @@ def _MockedProcess(pid):
[2] GeForce RTX 2 | 71°C, 100 %, ?? % (E: ?? % D: ?? %), 250 / ?? W | 0 / 12189 MB | (Not Supported)
""".splitlines()) # noqa: E501

MOCK_EXPECTED_OUTPUT_NO_PROCESSES = os.linesep.join("""\
[0] GeForce GTX TITAN 0 | 80°C, 76 % | 8000 / 12287 MB
[1] GeForce GTX TITAN 1 | 36°C, 0 % | 9000 / 12189 MB
[2] GeForce RTX 2 | 71°C, ?? % | 0 / 12189 MB
""".splitlines()) # noqa: E501

# -----------------------------------------------------------------------------

Expand Down Expand Up @@ -388,6 +393,9 @@ def _remove_ansi_codes_and_header_line(s):
assert s == unescaped # should have no ansi code
assert _remove_ansi_codes_and_header_line(s) == MOCK_EXPECTED_OUTPUT_DEFAULT

s = capture_output('gpustat', '--no-processes')
assert _remove_ansi_codes_and_header_line(s) == MOCK_EXPECTED_OUTPUT_NO_PROCESSES

def test_args_commandline_width(self, scenario_basic):
capture_output = self.capture_output

Expand Down

0 comments on commit af7d760

Please sign in to comment.