mirror of
https://github.com/morgan9e/gnome-shell-extension-freon
synced 2026-04-14 00:14:14 +09:00
nvidiaUtil: code cleanup, fix recognizing the card (#242)
Since the card list is populated only in constructor, to update it we had to toggle "Nvidia" switch `on`->`off`->`on`. The fix is to get the temperature along with the card name in one `nvidia-smi` call. Also some code cleanup was made, removed old unused code. Fixes #241 Signed-off-by: Pavel Artsishevsky <polter.rnd@gmail.com>
This commit is contained in:
@@ -10,59 +10,25 @@ var NvidiaUtil = class extends CommandLineUtil.CommandLineUtil {
|
|||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
let path = GLib.find_program_in_path('nvidia-smi');
|
let path = GLib.find_program_in_path('nvidia-smi');
|
||||||
this._argv = path ? [path, '--query-gpu=temperature.gpu', '--format=csv,noheader'] : null;
|
this._argv = path ? [path, '--query-gpu=name,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, '--query-gpu=name', '--format=csv,noheader'], /* args */
|
|
||||||
null, /* env */
|
|
||||||
GLib.SpawnFlags.DO_NOT_REAP_CHILD,
|
|
||||||
null /* child_setup */);
|
|
||||||
|
|
||||||
let stdout = new Gio.UnixInputStream({fd: stdoutFd, close_fd: true});
|
|
||||||
let outReader = new Gio.DataInputStream({base_stream: stdout});
|
|
||||||
|
|
||||||
GLib.close(stdinFd);
|
|
||||||
GLib.close(stderrFd);
|
|
||||||
let childWatch = GLib.child_watch_add(GLib.PRIORITY_DEFAULT, pid, (pid, status, requestObj) => {
|
|
||||||
let output = [];
|
|
||||||
let [line, size] = [null, 0];
|
|
||||||
|
|
||||||
while (([line, size] = outReader.read_line(null)) != null && line != null) {
|
|
||||||
this._labels.push(ByteArray.toString(line));
|
|
||||||
}
|
|
||||||
|
|
||||||
stdout.close(null);
|
|
||||||
GLib.source_remove(childWatch);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get temp() {
|
get temp() {
|
||||||
let output = [];
|
|
||||||
if(this._output)
|
|
||||||
output.push(...this._output)
|
|
||||||
if(this._error_output)
|
|
||||||
output.push(...this._error_output)
|
|
||||||
|
|
||||||
if(output.length === 0)
|
|
||||||
return [];
|
|
||||||
let temps = [];
|
|
||||||
for (let line of this._output) {
|
|
||||||
let convertedLine = parseFloat(line);
|
|
||||||
|
|
||||||
if(!line || !convertedLine)
|
|
||||||
continue;
|
|
||||||
temps.push(convertedLine);
|
|
||||||
}
|
|
||||||
|
|
||||||
let gpus = [];
|
let gpus = [];
|
||||||
|
|
||||||
if(this._labels.length == temps.length){
|
if (this._output) {
|
||||||
for(let i = 0; i < this._labels.length; i++){
|
for (let line of this._output) {
|
||||||
gpus.push({ label: this._labels[i], temp: temps[i] })
|
let values = line.split(',');
|
||||||
|
if (values.length < 2)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
let label = values[0].trim();
|
||||||
|
let temp = parseFloat(values[1]);
|
||||||
|
|
||||||
|
if(!label || !temp)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
gpus.push({ label: label, temp: temp });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user