Created
November 4, 2017 05:15
-
-
Save tjumyk/7319643db1d6b18a93343a185b7c2e8f to your computer and use it in GitHub Desktop.
GPU Provider for Ubuntu indicator-multiload
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/****************************************************************************** | |
* Copyright (C) 2017 Yukai Miao <[email protected]> * | |
* * | |
* This program is free software; you can redistribute it and/or modify * | |
* it under the terms of the GNU General Public License as published by * | |
* the Free Software Foundation; either version 3 of the License, or * | |
* (at your option) any later version. * | |
* * | |
* This program is distributed in the hope that it will be useful, * | |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
* GNU General Public License for more details. * | |
* * | |
* You should have received a copy of the GNU General Public License along * | |
* with this program; if not, write to the Free Software Foundation, Inc., * | |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * | |
******************************************************************************/ | |
public class GpuProvider : Provider { | |
public GpuProvider() { | |
base("gpu", {"util", "memtotal", "memused", "memfree"}, 'p'); | |
} | |
public override void update() { | |
try { | |
string[] spawn_args = {"nvidia-smi", "-i", "0", "--query-gpu=utilization.gpu,memory.total,memory.used,memory.free", "--format=csv,noheader,nounits"}; | |
string spawn_stdout; | |
string spawn_stderr; | |
int spawn_status; | |
Process.spawn_sync(null, spawn_args, null, SpawnFlags.SEARCH_PATH, null, out spawn_stdout, out spawn_stderr, out spawn_status); | |
string[] columns = spawn_stdout.split(", "); | |
this.values[0] = double.parse(columns[0]) / 100.0; | |
for(int i = 1 ; i < 4; ++i) | |
this.values[i] = double.parse(columns[i]) * 1000000; | |
} catch (SpawnError e) { | |
stdout.printf ("Error: %s\n", e.message); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is nice, but especially for Gnome-Shell the spawn call should be asynchronous. I forked it for use on Debian and now added support for Nvidia (still untested, part of it came from this code) and AMD asynchronously, plus the initial Intel rudiments. If anyone is interested: https://gitlab.com/lestcape/indicator-multiload/