Merge remote-tracking branch 'clrkwllms/hwlatdetect_py3' into unstable/devel/v1.2

Signed-off-by: John Kacur <jkacur@redhat.com>
This commit is contained in:
John Kacur 2018-04-24 13:45:26 +01:00
commit fa97bdab61
1 changed files with 66 additions and 65 deletions

View File

@ -1,5 +1,6 @@
#!/usr/bin/python
#!/usr/bin/python3
# (C) 2018 Clark Williams <williams@redhat.com>
# (C) 2015,2016 Clark Williams <williams@redhat.com>
# (C) 2009 Clark Williams <williams@redhat.com>
#
@ -16,7 +17,7 @@ import subprocess
import errno
import os.path
version = "0.7"
version = "0.8"
debugging = False
quiet = False
watch = False
@ -145,9 +146,9 @@ class Kmod(object):
def __init__(self, name):
if name not in Kmod.names:
raise RuntimeError, "unsupported module name: %s" % name
raise RuntimeError("unsupported module name: %s" % name)
if name == "smi_detector":
raise RuntimeError, "smi_detector module no longer supported!"
raise RuntimeError("smi_detector module no longer supported!")
self.name = name
self.preloaded = False
self.builtin = False
@ -165,7 +166,7 @@ class Kmod(object):
debug("using already loaded %s" % self.name)
return
if not self.__find_module():
raise DetectorNotAvailable, name, "module %s does not exist!" % self.name
raise DetectorNotAvailable(name, "module %s does not exist!" % self.name)
def load(self):
if self.builtin:
@ -213,23 +214,23 @@ class Detector(object):
return counts
def cleanup(self):
raise RuntimeError, "must override base method 'cleanup'!"
raise RuntimeError("must override base method 'cleanup'!")
def get(self, field):
'''get the value of a debugfs field'''
raise RuntimeError, "must override base method 'get'!"
raise RuntimeError("must override base method 'get'!")
def set(self, field, val):
'''set a value in a debugfs field'''
raise RuntimeError, "must override base method 'set'!"
raise RuntimeError("must override base method 'set'!")
def save(self, reportfile=None):
'''save sample data to reportfile'''
raise RuntimeError, "must override base method 'save'!"
raise RuntimeError("must override base method 'save'!")
def display(self):
'''output the sample data as a string'''
raise RuntimeError, "must override base method 'display'!"
raise RuntimeError("must override base method 'display'!")
def start(self):
count = 0
@ -261,7 +262,7 @@ class Detector(object):
def detect(self):
'''get detector output'''
raise RuntimeError, "must override base method 'detect'!"
raise RuntimeError("must override base method 'detect'!")
#
# class to handle running the hwlat tracer module of ftrace
#
@ -306,7 +307,7 @@ class Tracer(Detector):
super(Tracer, self).__init__()
path = self.debugfs.getpath('tracing/hwlat_detector')
if not os.path.exists(path):
raise DetectorNotAvailable, "hwlat", "hwlat tracer not available"
raise DetectorNotAvailable("hwlat", "hwlat tracer not available")
self.type = "tracer"
self.samples = []
self.set("enable", 0)
@ -484,108 +485,108 @@ def microseconds(str):
#
if __name__ == '__main__':
from optparse import OptionParser
from argparse import ArgumentParser
parser = OptionParser()
parser.add_option("--duration", default=None, type="string",
dest="duration",
help="total time to test for hardware latency (<n>{smdw})")
parser = ArgumentParser()
parser.add_argument("--duration", default=None,
dest="duration",
help="total time to test for hardware latency: <n>{smdw}")
parser.add_option("--threshold", default=None, type="string",
dest="threshold",
help="value above which is considered an hardware latency")
parser.add_argument("--threshold", default=None,
dest="threshold",
help="value above which is considered an hardware latency")
parser.add_option("--hardlimit", default=None, type="string",
dest="hardlimit",
help="value above which the test is considered to fail")
parser.add_argument("--hardlimit", default=None,
dest="hardlimit",
help="value above which the test is considered to fail")
parser.add_option("--window", default=None, type="string",
dest="window",
help="time between samples")
parser.add_argument("--window", default=None,
dest="window",
help="time between samples")
parser.add_option("--width", default=None, type="string",
dest="width",
help="time to actually measure")
parser.add_argument("--width", default=None,
dest="width",
help="time to actually measure")
parser.add_option("--report", default=None, type="string",
dest="report",
help="filename for sample data")
parser.add_argument("--report", default=None,
dest="report",
help="filename for sample data")
parser.add_option("--debug", action="store_true", default=False,
dest="debug",
help="turn on debugging prints")
parser.add_argument("--debug", action="store_true", default=False,
dest="debug",
help="turn on debugging prints")
parser.add_option("--quiet", action="store_true", default=False,
dest="quiet",
help="turn off all screen output")
parser.add_argument("--quiet", action="store_true", default=False,
dest="quiet",
help="turn off all screen output")
parser.add_option("--watch", action="store_true", default=False,
dest="watch",
help="print sample data to stdout as it arrives")
parser.add_argument("--watch", action="store_true", default=False,
dest="watch",
help="print sample data to stdout as it arrives")
parser.add_option("--kmodule", action="store_true", default=False,
dest="kmodule",
help="force using the kernel module")
parser.add_argument("--kmodule", action="store_true", default=False,
dest="kmodule",
help="force using the kernel module")
(o, a) = parser.parse_args()
args = parser.parse_args()
# need these before creating detector instance
if o.debug:
if args.debug:
debugging = True
quiet = False
debug("debugging prints turned on")
if o.quiet:
if args.quiet:
quiet = True
debugging = False
if o.kmodule:
if args.kmodule:
detect = Hwlat()
else:
try:
detect = Tracer()
except DetectorNotAvailable, err:
except DetectorNotAvailable as err:
detect = HwLat()
if o.threshold:
t = microseconds(o.threshold)
if args.threshold:
t = microseconds(args.threshold)
detect.set("threshold", t)
debug("threshold set to %dus" % t)
if o.hardlimit:
hardlimit = microseconds(o.hardlimit)
if args.hardlimit:
hardlimit = microseconds(args.hardlimit)
else:
hardlimit = detect.get("threshold")
debug("hardlimit set to %dus" % int(hardlimit))
hardlimit = int(detect.get("threshold"))
debug("hardlimit set to %dus" % hardlimit)
if o.window:
w = microseconds(o.window)
if w < detect.get("width"):
if args.window:
w = microseconds(args.window)
if w < int(detect.get("width")):
debug("shrinking width to %d for new window of %d" % (w/2, w))
detect.set("width", w/2)
debug("window parameter = %d" % w)
detect.set("window", w)
debug("window for sampling set to %dus" % w)
if o.width:
w = microseconds(o.width)
if w > detect.get("window"):
if args.width:
w = microseconds(args.width)
if w > int(detect.get("window")):
debug("widening window to %d for new width of %d" % (w*2, w))
detect.set("window", w*2)
debug("width parameter = %d" % w)
detect.set("width", w)
debug("sample width set to %dus" % w)
if o.duration:
detect.testduration = seconds(o.duration)
if args.duration:
detect.testduration = seconds(args.duration)
else:
detect.testduration = 120 # 2 minutes
debug("test duration is %ds" % detect.testduration)
if o.watch:
if args.watch:
watch = True
reportfile = o.report
reportfile = args.report
info("hwlatdetect: test duration %d seconds" % detect.testduration)
info(" detector: %s" % detect.type)