Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for enc/dec gpu utilization (#79) #80

Merged
merged 2 commits into from Mar 24, 2020

Conversation

ChaoticMind
Copy link
Contributor

@ChaoticMind ChaoticMind commented Mar 19, 2020

This PR only adds encoder and decoder utilization to --json from the cmdline, or to the GPUStat object if gpustat is used as a library.

The information is also exposed to the standard command line output via the -e or --show-codec flag

See issue #79

@Stonesjtu
Copy link
Collaborator

But Travis gives a passed result. Can you also try to add the cli interface?

@ChaoticMind
Copy link
Contributor Author

ChaoticMind commented Mar 19, 2020

Maybe it was because I ran them through SSH which messed with the encoding (stripping ansi?):

- [0] GeForce GTX TITAN 0 | 80'C,  76 % |  8000 / 12287 MB | user1(4000M) user2(4000M)
                              ^
+ [0] GeForce GTX TITAN 0 | 80°C,  76 % |  8000 / 12287 MB | user1(4000M) user2(4000M)
                              ^

Edit: It was because the tests were importing the system version of gpustat and therefore there was a mismatch 😕 - Will now run it in a venv instead 😀

Ok, will look into the cli interface soon. Do you think it should be hidden behind a flag or always exposed?

@ChaoticMind ChaoticMind force-pushed the enc_dec_util branch 2 times, most recently from 42be639 to 0b287e5 Compare March 19, 2020 11:37
@ChaoticMind
Copy link
Contributor Author

@Stonesjtu I hid the encoder/decoder info behind a -e flag. It takes -e enc, -e dec, or -e enc,dec (default).

The functionality seems to be working well, however the test is currently failing, and I'm not exactly sure why:

>           if "enc" in show_encoder and "dec" in show_encoder:
E           TypeError: argument of type 'bool' is not iterable

Even though show_encoder is of type strand notbool, and the code is working for all parameters. Any idea what's up?

Another minor thing is that I expected the strings "enc" and "dec" in gpustat -e to be bold (because of CBold), but they don't seem to be properly bolded on my terminal.

Copy link
Collaborator

@Stonesjtu Stonesjtu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plz see comments

gpustat/cli.py Show resolved Hide resolved
@ChaoticMind ChaoticMind force-pushed the enc_dec_util branch 2 times, most recently from aa92b4c to 09963d5 Compare March 19, 2020 13:11
Copy link
Collaborator

@Stonesjtu Stonesjtu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plz fix the failed test.

gpustat/core.py Outdated Show resolved Hide resolved
gpustat/test_gpustat.py Outdated Show resolved Hide resolved
Copy link
Owner

@wookayin wookayin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. I added some comments.

gpustat/cli.py Outdated Show resolved Hide resolved
gpustat/core.py Outdated Show resolved Hide resolved
gpustat/test_gpustat.py Outdated Show resolved Hide resolved
@Stonesjtu
Copy link
Collaborator

Can you modify second paragraph of the pr message because you have added cli output feature.

gpustat/core.py Outdated
@@ -221,6 +249,14 @@ def _repr(v, none_value='??'):
reps += "%(FSpeed)s{entry[fan.speed]:>3} %%%(C0)s, "

reps += "%(CUtil)s{entry[utilization.gpu]:>3} %%%(C0)s"
if "enc" in show_codec:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's good to wrap them with parenthesis when --show-codec is specified, like the first version.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I added the parenthesis back.

Copy link
Collaborator

@Stonesjtu Stonesjtu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR looks good overall.

@ChaoticMind
Copy link
Contributor Author

I added the parenthesis back and force pushed.

Copy link
Collaborator

@Stonesjtu Stonesjtu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can append encoder_line and decoder_line in to a list and then ' '.join(a_certain_ilst)

@ChaoticMind
Copy link
Contributor Author

ChaoticMind commented Mar 21, 2020

You can append encoder_line and decoder_line in to a list and then ' '.join(a_certain_ilst)

Do you mean, instead of:

if "enc" in show_codec and "dec" in show_codec:
    reps += encoder_line + "  " + decoder_line
elif "enc" in show_codec:
    reps += encoder_line
elif "dec" in show_codec:
    reps += decoder_line

Something like:

if "enc" in show_codec and "dec" in show_codec:
    reps += "  ".join([encoder_line, decoder_line])
elif "enc" in show_codec:
    reps += encoder_line
elif "dec" in show_codec:
    reps += decoder_line

I'd still need to have three separate if/elif clauses. I think it's less readable, no?

@Stonesjtu
Copy link
Collaborator

I mean:

codec_fields = []
if "enc" in show_codec:
    codec_fields.append(encoder_field)
if "dec" in show_codec:
    codec_fields.append(decoder_field)

reps += " ".join(codec_fields)

I think this should be easier to follow.

BTW: I would rather not calling them encoder/decoder line because they are not lines.

@ChaoticMind
Copy link
Contributor Author

I'm happy with the PR now. If we want to be extra picky:

  1. Does -e as short flag for --show-codec make sense? The flag was originally called --show-encoder. -c is already taken, but maybe -C?
  2. Should I add a line to CHANGELOG.md
  3. colors['CBold'] doesn't seem to actually make the E: and D: characters bold for some reason, at least on my terminal.

@wookayin
Copy link
Owner

wookayin commented Mar 22, 2020

@ChaoticMind Overall LGTM, thanks. I will update CHANGELOG and do a bit more of cleanup myself. I am supportive of -C, but need to think more. Actually -e sounds good. I am also considering using -C for #65. Any opinions are welcome.

For bold text, you may need to configure your terminal to draw bold text in bold font. For example, iTerm2 has such an option (Preferences > Text > Text Rendering).

@wookayin wookayin added this to the 1.0 milestone Mar 22, 2020
Copy link
Collaborator

@Stonesjtu Stonesjtu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm

@Stonesjtu
Copy link
Collaborator

@wookayin Actually we don't have to give every option an abbr. It's enough to cover the most frequently used ones.

@Stonesjtu
Copy link
Collaborator

@wookayin can you approve the PR so we can merge it.

Copy link
Owner

@wookayin wookayin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for the contribution.

@wookayin wookayin merged commit b80d8e8 into wookayin:master Mar 24, 2020
@ChaoticMind ChaoticMind deleted the enc_dec_util branch April 5, 2020 05:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants