Navigation Menu

Skip to content

Commit

Permalink
Adding support for CPU graph in FreeBSD
Browse files Browse the repository at this point in the history
This commit adds support for CPUGraph in FreeBSD. And to make tests
complete in FreeBSD I also added support for the MemoryGraph.

There are other means of getting cpu and mem stats, but this is the
most similar to the vanilla graph.

For this to work in FreeBSD linprocfs needs to be mounted.

Since linprocfs uses an older model of the kernel not all
fields are available, hence removing some of the fields
for FreeBSD.

In FreeBSD /proc stuff is located in
/compat/linux/proc , but it lacks some of the features
of a modern linux kernel. Hence the platform.system(checks).

This should maintain compatibility with Linux, but please test
it so I don't break anything.

Cheers!

Closes #796
  • Loading branch information
dinapappor authored and flacjacket committed Nov 4, 2015
1 parent f593a06 commit fd2b45a
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions libqtile/widget/graph.py
Expand Up @@ -36,6 +36,7 @@
from . import base
from os import statvfs
import time
import platform

__all__ = [
'CPUGraph',
Expand Down Expand Up @@ -200,7 +201,11 @@ def __init__(self, **config):
self.oldvalues = self._getvalues()

def _getvalues(self):
with open('/proc/stat') as file:
proc = '/proc/stat'
if platform.system() == "FreeBSD":
proc = '/compat/linux' + proc

with open(proc) as file:
lines = file.readlines()

# default to all cores (first line)
Expand All @@ -214,8 +219,10 @@ def _getvalues(self):

if not line.startswith("cpu%s" % self.core):
raise ValueError("No such core: %s" % self.core)

name, user, nice, sys, idle, iowait, tail = line.split(None, 6)
if platform.system() == 'FreeBSD':
name, user, nice, sys, idle = line.split(None, 4)
else:
name, user, nice, sys, idle, iowait, tail = line.split(None, 6)

return (int(user), int(nice), int(sys), int(idle))

Expand All @@ -237,12 +244,19 @@ def update_graph(self):


def get_meminfo():
with open('/proc/meminfo') as file:
val = {}
val = {}
proc = '/proc/meminfo'
if platform.system() == "FreeBSD":
proc = "/compat/linux" + proc
with open(proc) as file:
for line in file:
key, tail = line.split(':')
uv = tail.split()
val[key] = int(uv[0])
if line.lstrip().startswith("total"):
pass
else:
key, tail = line.strip().split(':')
uv = tail.split()
val[key] = int(uv[0])
val['MemUsed'] = val['MemTotal'] - val['MemFree']
return val


Expand Down

0 comments on commit fd2b45a

Please sign in to comment.