rteval cross-distribution patch
cover rteval cross-distribution patch
Hi Clark,
Here are the patches to make rteval working independently of the used distribution.
Let me know if you have any comments/corrections,
-- Raphaël
---
Raphaël Beamonte (3):
Rewrite of the get_kthreads method to make it cross-distribution Adds getcmdpath method to use which to locate the used commands Rewrite of the get_services method to make it cross-distribution
rteval/rteval.py | 91 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 72 insertions(+), 19 deletions(-)
Signature · 6 lines
1.7.10.4 -- To unsubscribe from this list: send the line "unsubscribe linux-rt-users" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 1/3 Rewrite of the get_kthreads method to make it cross-distribution
--- rteval/rteval.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
rteval/rteval.py +3 -4
@@ -248,16 +248,15 @@ class RtEval(object): def get_kthreads(self): policies = {'FF':'fifo', 'RR':'rrobin', 'TS':'other', '?':'unknown' } ret_kthreads = {} - if not os.path.exists('/etc/rc.d/init.d/rtctl'): - return ret_kthreads self.debug("getting kthread status") - cmd = '/sbin/service rtctl status' + cmd = '/bin/ps -eocommand,pid,policy,rtprio,comm' self.debug("cmd: %s" % cmd) c = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) for p in c.stdout: v = p.strip().split() + kcmd = v.pop(0) try: - if int(v[0]) > 0: + if int(v[0]) > 0 and kcmd.startswith('[') and kcmd.endswith(']'): ret_kthreads[v[0]] = {'policy' : policies[v[1]], 'priority' : v[2], 'name' : v[3] } except ValueError:
Signature · 6 lines
1.7.10.4 -- To unsubscribe from this list: send the line "unsubscribe linux-rt-users" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 2/3 Adds getcmdpath method to use which to locate the used commands
In reply to Raphaël Beamonte--- rteval/rteval.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
rteval/rteval.py +12 -1
@@ -63,6 +63,17 @@ import rtevalMailer from cputopology import CPUtopology +pathSave={} +def getcmdpath(which): + if not pathSave.has_key(which): + cmd = '/usr/bin/which %s' % which + c = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) + pathSave[which] = c.stdout.read().strip() + if not pathSave[which]: + raise RuntimeError, "Command '%s' is unknown on this system" % which + return pathSave[which] + + sigint_received = False def sigint_handler(signum, frame): global sigint_received
@@ -249,7 +260,7 @@ class RtEval(object): policies = {'FF':'fifo', 'RR':'rrobin', 'TS':'other', '?':'unknown' } ret_kthreads = {} self.debug("getting kthread status") - cmd = '/bin/ps -eocommand,pid,policy,rtprio,comm' + cmd = '%s -eocommand,pid,policy,rtprio,comm' % getcmdpath('ps') self.debug("cmd: %s" % cmd) c = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) for p in c.stdout:
Signature · 6 lines
1.7.10.4 -- To unsubscribe from this list: send the line "unsubscribe linux-rt-users" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 3/3 Rewrite of the get_services method to make it cross-distribution
In reply to Raphaël BeamonteChanges the get_services method to call the new created __get_services_sysvinit and __get_services_systemd methods to be able to manage the two different init daemons.
--- rteval/rteval.py | 73 +++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 58 insertions(+), 15 deletions(-)
rteval/rteval.py +58 -15
@@ -48,6 +48,9 @@ import signal import rtevalclient import ethtool import xmlrpclib +import platform +import fnmatch +import glob from datetime import datetime from distutils import sysconfig
@@ -92,6 +95,7 @@ class RtEval(object): self.inifile = None self.cmd_options = {} self.start = datetime.now() + self.init = 'unknown' default_config = { 'rteval': {
@@ -239,22 +243,61 @@ class RtEval(object): topology.getCPUsockets())) return topology.getXMLdata() - - - def get_services(self): - rejects = ('capi', 'firstboot', 'functions', 'halt', 'iptables', 'ip6tables', - 'killall', 'lm_sensors', 'microcode_ctl', 'network', 'ntpdate', - 'rtctl', 'udev-post') - service_list = filter(lambda x: x not in rejects, os.listdir('/etc/rc.d/init.d')) + def __get_services_sysvinit(self): + reject = ('functions', 'halt', 'killall', 'single', 'linuxconf', 'kudzu', + 'skeleton', 'README', '*.dpkg-dist', '*.dpkg-old', 'rc', 'rcS', + 'single', 'reboot', 'bootclean.sh') + for sdir in ('/etc/init.d', '/etc/rc.d/init.d'): + if os.path.isdir(sdir): + servicesdir = sdir + break + if not servicesdir: + raise RuntimeError, "No services dir (init.d) found on your system" + self.debug("Services located in %s, going through each service file to check status" % servicesdir) ret_services = {} - self.debug("getting services status") - for s in service_list: - cmd = ['/sbin/service', s, 'status'] - c = subprocess.Popen(cmd, stdout=subprocess.PIPE) - status = c.stdout.read().strip().translate(self.transtable, self.junk) - ret_services[s] = status + for service in glob.glob(os.path.join(servicesdir, '*')): + servicename = os.path.basename(service) + if not [1 for p in reject if fnmatch.fnmatch(servicename, p)] and os.access(service, os.X_OK): + cmd = '%s -qs "\(^\|\W\)status)" %s' % (getcmdpath('grep'), service) + c = subprocess.Popen(cmd, shell=True) + c.wait() + if c.returncode == 0: + cmd = ['env', '-i', 'LANG="%s"' % os.environ['LANG'], 'PATH="%s"' % os.environ['PATH'], 'TERM="%s"' % os.environ['TERM'], service, 'status'] + c = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + c.wait() + if c.returncode == 0 and (c.stdout.read() or c.stderr.read()): + ret_services[servicename] = 'running' + else: + ret_services[servicename] = 'not running' + else: + ret_services[servicename] = 'unknown' return ret_services - + + def __get_services_systemd(self): + ret_services = {} + cmd = '%s list-unit-files -t service --no-legend' % getcmdpath('systemctl') + self.debug("cmd: %s" % cmd) + c = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + for p in c.stdout: + # p are lines like "servicename.service status" + v = p.strip().split() + ret_services[v[0].split('.')[0]] = v[1] + return ret_services + + def get_services(self): + cmd = [getcmdpath('ps'), '-ocomm=', '1'] + c = subprocess.Popen(cmd, stdout=subprocess.PIPE) + self.init = c.stdout.read().strip() + if self.init == 'systemd': + self.debug("Using systemd to get services status") + return self.__get_services_systemd() + elif self.init == 'init': + self.init = 'sysvinit' + self.debug("Using sysvinit to get services status") + return self.__get_services_sysvinit() + else: + raise RuntimeError, "Unknown init system (%s)" % self.init + return {} def get_kthreads(self): policies = {'FF':'fifo', 'RR':'rrobin', 'TS':'other', '?':'unknown' }
@@ -434,7 +477,7 @@ class RtEval(object): self.xmlreport.taggedvalue('memory_size', "%.3f" % self.memsize[0], {"unit": self.memsize[1]}) self.xmlreport.closeblock() - self.xmlreport.openblock('services') + self.xmlreport.openblock('services', {'init': self.init}) for s in self.services: self.xmlreport.taggedvalue("service", self.services[s], {"name": s}) self.xmlreport.closeblock()
Signature · 6 lines
1.7.10.4 -- To unsubscribe from this list: send the line "unsubscribe linux-rt-users" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 11 lines · On Tue, 23 Oct 2012 11:45:02 -0400 Raphaël Beamonte…
Hi Clark,
Here are the patches to make rteval working independently of the used distribution.
Let me know if you have any comments/corrections,
-- Raphaël
---
Raphaël,
Thanks, I've applied your patches and pushed v.36 back to kernel.org.
Clark