From 06c85b4dc49be4f917baacd429e7f8490313f351 Mon Sep 17 00:00:00 2001 From: Riley Redpath Date: Sat, 10 Jun 2017 15:33:53 -0500 Subject: [PATCH 1/2] Added nvidiagpu module, which parses nvidia-smi to get the gpu name, temperature and vram usage. --- bumblebee/modules/nvidiagpu.py | 42 ++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 bumblebee/modules/nvidiagpu.py diff --git a/bumblebee/modules/nvidiagpu.py b/bumblebee/modules/nvidiagpu.py new file mode 100644 index 0000000..b60f04e --- /dev/null +++ b/bumblebee/modules/nvidiagpu.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import subprocess +import bumblebee.input +import bumblebee.output +import bumblebee.engine + +class Module(bumblebee.engine.Module): + def __init__(self,engine,config): + super(Module,self).__init__(engine,config,bumblebee.output.Widget(full_text=self.utilization)) + self._utilization = "Not found: 0 0/0" + + def utilization(self,widget): + return self._utilization + + def update(self,widgets): + sp = subprocess.Popen(['nvidia-smi', '-q'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + out_str = sp.communicate() + out_list = out_str[0].decode("utf-8").split('\n') + + title = "" + usedMem = "" + totalMem = "" + temp = "" + name = "not found" + for item in out_list: + try: + key, val = item.split(':') + key, val = key.strip(), val.strip() + if title == "FB Memory Usage": + if key == "Total": + totalMem = val + elif key == "Used": + usedMem = val.split(" ")[0] + elif key == "GPU Current Temp": + temp = val.split(" ")[0] + elif key == "Product Name": + name = val + except: + title = item.strip() + self._utilization = u"%s: %s°C %s/%s"%(name,temp,usedMem,totalMem) From 37f3a11f68cfeff349f2533fd102c186cf3c365c Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Sun, 11 Jun 2017 14:43:59 +0200 Subject: [PATCH 2/2] [modules/nvidiagpu] Added docstring --- bumblebee/modules/nvidiagpu.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bumblebee/modules/nvidiagpu.py b/bumblebee/modules/nvidiagpu.py index b60f04e..87c34f5 100644 --- a/bumblebee/modules/nvidiagpu.py +++ b/bumblebee/modules/nvidiagpu.py @@ -1,6 +1,11 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +"""Displays GPU name, temperature and memory usage. + +Requires nvidia-smi +""" + import subprocess import bumblebee.input import bumblebee.output