-
-
Notifications
You must be signed in to change notification settings - Fork 48
Introduce per process GPU usage #490
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
base: main
Are you sure you want to change the base?
Conversation
|
May I ask you to propose a PR that works for you? I'm wondering what would be the best solution to choose the right engine to read. We need to read driver name from GPU class and based on that do the right choice. |
|
@stsdc I've been looking around, but the kernel docs are not the clearest on this. Instead, its easier to simply read the output from various files in fdinfo on various setups. Doing this, there only shows up two engines and that the driver is Here is info from a heavy gpu process: The https://github.com/torvalds/linux/blob/master/drivers/gpu/drm/amd/include/amd_shared.h I'm assuming that engine is called the There also appears to be a pro version of the driver, but I don't have that right now. I think I can get it by installing ROCm, but I'm not sure I'd need it for a while, and it is a bit of a hassle. Might be easier to rent a server briefly to get this gpu information. |
|
@Tbusk also check what Resources does: https://github.com/nokyan/resources/blob/main/lib/process_data/src/gpu_usage.rs |
|
Just checked what my nvidia 3000 series laptop is running during a stress test (which works on the PR) towards both my onboard graphics and my nvidia card: I have
Also the only addition needed to make it work on my amd machine is to add a fall-though case above your case in the switch in So case "drm-engine-gfx":
case "drm-engine-render":I can do a pr if you want. |
|
I'll appreciate if you'll make a PR. |
After looking at it a little, the value of Example of a handful of minutes difference in a stress test: |
|
@Tbusk please check if it works for you now |
ryonakano
left a comment
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.
@stsdc Sorry for late review. Just glimpsed and leaving some comments about coding styles and scopes; I haven't tested yet.
| public string username = Utils.NO_DATA; | ||
|
|
||
| // Update interval in seconds is used to calculate GPU usage | ||
| public int update_interval; |
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.
Is this need to be public? I think we should lessen scope as possible for new codes.
| public ProcessIO io; | ||
|
|
||
| // Contains info about GPU usage | ||
| public ProcessDRM drm; |
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.
Same comment goes here.
| private uint64 last_total; | ||
| public double gpu_percentage { get; private set; } | ||
|
|
||
| private uint64 last_total; // Obsolete? |
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.
What does this comment mean? Is it TODO?
| /** | ||
| * Reads the /proc/%pid%/cmdline file and updates from the information contained therein. | ||
| */ | ||
| /** | ||
| * Reads the /proc/%pid%/cmdline file and updates from the information contained therein. | ||
| */ |
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.
Documentation comments for a method should have the same indentation with the method as the previous code does.
| if (err is FileError.ACCES) { | ||
|
|
||
| } else { | ||
| warning (err.message); | ||
| } |
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.
Is there any reason you crush FileError.ACCES error? Same reason with the following commnet?
// if the error is not no access to file, because regular user
If so please explicit by adding a comment here too.
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.
Also, isn't it possible to write something like this? I commented without testing if this is grammatically correct though.
if (!(err is FileError.ACCES)) {
warning (err.message);
}| update_engine (splitted_line[1], ref last_engine_render); | ||
| break; | ||
| default: | ||
| // warning ("Unknown value in %s", path); |
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.
Why this is commented out?
| } | ||
| } | ||
| } catch (Error e) { | ||
| if (e.code != 14) { |
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.
What 14 mean here?
| if (gpu_usage < 0.0) | ||
| ((Gtk.CellRendererText)cell).text = Utils.NO_DATA; | ||
| else | ||
| ((Gtk.CellRendererText)cell).text = "%.0f%%".printf (gpu_usage); |
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.
| if (gpu_usage < 0.0) | |
| ((Gtk.CellRendererText)cell).text = Utils.NO_DATA; | |
| else | |
| ((Gtk.CellRendererText)cell).text = "%.0f%%".printf (gpu_usage); | |
| if (gpu_usage < 0.0) { | |
| ((Gtk.CellRendererText)cell).text = Utils.NO_DATA; | |
| } else { | |
| ((Gtk.CellRendererText)cell).text = "%.0f%%".printf (gpu_usage); | |
| } |
Please always explicit brackets to prevent bugs in case we added additional lines here in the future.
See also https://docs.elementary.io/develop/writing-apps/code-style#vala:
On conditionals and loops, always use braces even if there's only one line of code:
if (my_var > 2) { print ("hello\n"); }



Needs testing on hardware.