-
Notifications
You must be signed in to change notification settings - Fork 11
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 GPU support for mac, multi gpu for linux #7
Conversation
# Conflicts: # src/scanner.rs
Heya! I wasn't aware that Regarding macOS, for m1 machines I have seen just I left some comments in the PR review, mostly out of curiosity. I'll be testing the changes out on my machines and seeing how it goes. And as always, thanks for chipping in! ✌️ Hoping to merge these soon. |
|
||
lazy_static! { | ||
static ref GPU_RE: Regex = | ||
Regex::new(r#"^\S+? "(VGA|3D|Display).*?" ".*?" "(?P<gpu>.*?)""#).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking unwrap()
here might not be the best option - even though it does seem unlikely to fail since the regex has been tested already. If it does, however, omitting routines dependent on GPU_RE
could be an option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally, I too am averse to unwrap()
- the docs discourage its use, although most people in the rust community don't seem to heed this.
However, in this case, the error will only occur if the regex: r#"^\S+? "(VGA|3D|Display).*?" ".*?" "(?P<gpu>.*?)""#
is not well-defined, not if there is an error when matching any particular string. Because the regex is a constant string, the value of Regex::new(...)
will either always be an Err
, or always be an Ok
. There is no variation in runtime behaviour. So pushing the error handling down to the consumers of GPU_RE
at runtime is a waste. (Incidentally, the fact that the regex is constant is also why I'm using the lazy_static
macro to ensure it's only compiled once.)
Ideally, this is something that could be detected at compile time, but it might be outside the design of the compiler to check this. I think this is the next best thing: any attempt to use this module will break, even if no methods from the module are invoked. One way to make this more robust is to have a test that asserts that the regex does not panic. I suspect any test that has use crate::scanner
in it will achieve this. I think I might verify this and add one.
LMK what you think.
Looks like the action-rs family of github actions is not maintained. So replace them with some hand rolled ones.
9c729a1
to
3c537e1
Compare
@nidnogg I've verified that the tests fail if regex is not well defined:
The GitHub actions won't run on this repo, but they seem to work on my fork: https://github.com/triarius/zeitfetch/actions/runs/4645677080. They will probably start to run once you've merged this in. |
@triarius this looks pretty much good to. There's just one comment I'd like some clarification on - it's the |
86b3a87
to
930ea00
Compare
@nidnogg The |
Used system_profiler to obtain the GPU name in macOS. I've only tested it on a M1 MacBook Air, it givs the output "Apple M1".
For linux, I dug a little into the data that lspci gives back instead of just presenting the entire line. On my machine, it previously gave:
But now it is just
which I think is more in line with what users expect.
Also, in both macOS and linux, multiple gpus will be returned if the respective commands detect them.
You can see this in the screenshot from my system where the new behaviour is on top, and the old is below.
Some implementations notes
I used serde_json to parse the output of
system_profiler
, but a regex forlspci -mm
. This could be improved by finding an approproite parser for the ouput oflspci -mm
, but it's a mixture of quoted and unquoted space seperated fields. Perhaps some csv style parser will work, but I didn't try too hard to find one. According to the man, the fields are quoted "if necessary". So, the regex implementation will break if some of the quoted fields are not quoted. However, I think we can ship this and fix it if we find reports of failure.To allow mutiple GPUs, I collected the gpu names into a vector and then joined them with a newline separator. There is no need to allocate that vecotor, but I think it's a microoptimisation to improve it. It's highly likely that the number of GPUs is one or two, so improveing this is not going to yeild a massive performance improvement.