mirror of
https://github.com/morgan9e/gnome-shell-extension-freon
synced 2026-04-15 00:44:22 +09:00
Merge pull request #162 from jonasmalacofilho/optimize-nvidia-temps
Switch to nvidia-smi to reduce CPU load when fetching GPU temperatures
This commit is contained in:
@@ -9,14 +9,14 @@ var NvidiaUtil = class extends CommandLineUtil.CommandLineUtil {
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
let path = GLib.find_program_in_path('nvidia-settings');
|
||||
this._argv = path ? [path, '-q', 'gpucoretemp', '-t'] : null;
|
||||
let path = GLib.find_program_in_path('nvidia-smi');
|
||||
this._argv = path ? [path, '--query-gpu=temperature.gpu', '--format=csv,noheader'] : null;
|
||||
this._labels = [];
|
||||
if(this._argv){
|
||||
// [0] ushakov-pc:0[gpu:0] (GeForce GTX 770)
|
||||
let [exit, pid, stdinFd, stdoutFd, stderrFd] =
|
||||
GLib.spawn_async_with_pipes(null, /* cwd */
|
||||
[path, '-q', 'gpus'], /* args */
|
||||
[path, '--query-gpu=name', '--format=csv,noheader'], /* args */
|
||||
null, /* env */
|
||||
GLib.SpawnFlags.DO_NOT_REAP_CHILD,
|
||||
null /* child_setup */);
|
||||
@@ -31,10 +31,7 @@ var NvidiaUtil = class extends CommandLineUtil.CommandLineUtil {
|
||||
let [line, size] = [null, 0];
|
||||
|
||||
while (([line, size] = outReader.read_line(null)) != null && line != null) {
|
||||
let match = /.*\[gpu:[\d]\].*\(([\w\d\ ]+)\).*/.exec(ByteArray.toString(line));
|
||||
if(match){
|
||||
this._labels.push(match[1]);
|
||||
}
|
||||
this._labels.push(ByteArray.toString(line));
|
||||
}
|
||||
|
||||
stdout.close(null);
|
||||
@@ -63,20 +60,10 @@ var NvidiaUtil = class extends CommandLineUtil.CommandLineUtil {
|
||||
|
||||
let gpus = [];
|
||||
|
||||
if(this._labels.length > 0 && this._labels.length == temps.length - 1){
|
||||
// usually we should skip first line (most popular case)
|
||||
for(let i = 0; i < this._labels.length; i++){
|
||||
gpus.push({ label: this._labels[i], temp: temps[i + 1] })
|
||||
}
|
||||
} else if(temps.length == 1 || temps.length == 2){
|
||||
// cannot parse GPU label, usually temp duplicated
|
||||
gpus.push({ label: 'NVIDIA', temp: temps[0] })
|
||||
} else {
|
||||
// I think it is not possible
|
||||
for(let i = 0; i < temps.length; i++){
|
||||
let label = 'NVIDIA-' + (i + 1);
|
||||
gpus.push({ label: label, temp: temps[i] })
|
||||
}
|
||||
if(this._labels.length == temps.length){
|
||||
for(let i = 0; i < this._labels.length; i++){
|
||||
gpus.push({ label: this._labels[i], temp: temps[i] })
|
||||
}
|
||||
}
|
||||
|
||||
return gpus;
|
||||
|
||||
Reference in New Issue
Block a user