rt-tests:hwlatdetect: Remove useless object in class declaration
PATCH 1/17 rt-tests:hwlatdetect: Remove useless object in class declaration
There is no need to specify object in python3 when creating a class
--- src/hwlatdetect/hwlatdetect.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
src/hwlatdetect/hwlatdetect.py +4 -4
@@ -31,7 +31,7 @@ def info(str): # discovers that debugfs is already mounted, it will leave # it mounted. # -class DebugFS(object): +class DebugFS: '''class to manage mounting/umounting the debugfs''' def __init__(self): self.premounted = False
@@ -116,7 +116,7 @@ class DetectorNotAvailable(Exception): # above, if the module is already loaded, this class will # leave it alone when cleaning up. # -class Kmod(object): +class Kmod: ''' class to manage loading and unloading of kernel modules''' names = ("hwlat_detector", "smi_detector")
@@ -184,7 +184,7 @@ class Kmod(object): # # base class for detection modules # -class Detector(object): +class Detector: '''base class for detector modules''' def __init__(self): self.type = "unknown"
@@ -293,7 +293,7 @@ class Tracer(Detector): 'threshold' : "tracing_thresh", } - class Sample(object): + class Sample: 'private class for tracer sample data' __slots__ = 'timestamp', 'inner', 'outer', def __init__(self, line):
Signature · 1 line
2.31.1
PATCH 2/17 rt-tests:hwlatdetect.py: Remove multiple statements on one line
Remove multiple statements on one line
--- src/hwlatdetect/hwlatdetect.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
src/hwlatdetect/hwlatdetect.py +8 -4
@@ -19,10 +19,12 @@ quiet = False watch = False def debug(str): - if debugging: print(str) + if debugging: + print(str) def info(str): - if not quiet: print(str) + if not quiet: + print(str) # # Class used to manage mounting and umounting the debugfs
@@ -358,7 +360,8 @@ class Tracer(Detector): val = self.get_sample() while val: self.samples.append(val) - if watch: val.display() + if watch: + val.display() val = self.get_sample() time.sleep(0.1) except KeyboardInterrupt as e:
@@ -425,7 +428,8 @@ class Hwlat(Detector): while val: val = val.strip() self.samples.append(val) - if watch: print(val) + if watch: + print(val) val = self.get_sample() time.sleep(0.1) except KeyboardInterrupt as e:
Signature · 1 line
2.31.1
PATCH 3/17 rt-tests:hwlatdetect.py: Remove unnecessary 'not'
In reply to John KacurRemove unnecessary 'not'
--- src/hwlatdetect/hwlatdetect.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
src/hwlatdetect/hwlatdetect.py +1 -1
@@ -66,7 +66,7 @@ class DebugFS: return True debug("umounting debugfs") cmd = ['/bin/umount', self.mountpoint] - self.mounted = not (subprocess.call(cmd) == 0) + self.mounted = subprocess.call(cmd) != 0 if self.mounted: raise RuntimeError("Failed to umount debugfs") return not self.mounted
Signature · 1 line
2.31.1
PATCH 4/17 rt-tests: deadline_tests: Null check to prevent floating point exception
In reply to John KacurFix a floating point exception that can occur if sd->nr_adjust is 0 by checking it before performing a division by zero.
--- src/sched_deadline/deadline_test.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
src/sched_deadline/deadline_test.c +4 -2
@@ -2050,8 +2050,10 @@ int main(int argc, char **argv)printf ("missed deadlines = %d\n" , sd->missed_deadlines);printf ("missed periods = %d\n" , sd->missed_periods);printf ("Total adjustments = %lld us\n" , sd->total_adjust); -printf ("# adjustments = %lld avg: %lld us\n" , - sd->nr_adjust, sd->total_adjust / sd->nr_adjust); +if (sd->nr_adjust) { +printf ("# adjustments = %lld avg: %lld us\n" , + sd->nr_adjust, sd->total_adjust / sd->nr_adjust); + }printf ("deadline : %lld us\n" , sd->deadline_us);printf ("runtime : %lld us\n" , sd->runtime_us);printf ("nr_periods : %lld\n" , sd->nr_periods);
Signature · 1 line
2.31.1
PATCH 5/17 rt-tests: cyclictest: Check user supplies an value to histogram
In reply to John Kacurhistogram and histofall take a required argument.
If the user fails to supply one, display the help and exit with an error
--- src/cyclictest/cyclictest.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
src/cyclictest/cyclictest.c +4 -1
@@ -1089,7 +1089,10 @@ static void process_options(int argc, char *argv[], int max_cpus) histofall =1 ;/* fall through */ case 'h' :case OPT_HISTOGRAM : - histogram =atoi (optarg);break ; + histogram =atoi (optarg); +if (!histogram) +display_help (1 ); +break ;case OPT_HISTFILE : use_histfile =1 ;strncpy (histfile, optarg,strnlen (optarg,MAX_PATH -1 ));
Signature · 1 line
2.31.1
PATCH 6/17 rt-tests: get_cyclictest_snapshot: print_warning should be a classmethod
In reply to John KacurMake print_warning a class method since it only references a class variable and doesn't require self
--- src/cyclictest/get_cyclictest_snapshot.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
src/cyclictest/get_cyclictest_snapshot.py +4 -3
@@ -21,10 +21,11 @@ class Snapshot: warned = False - def print_warning(): + @classmethod + def print_warning(cls): """ print a warning one time only even if called multiple times """ - if not Snapshot.warned: - Snapshot.warned = True + if not cls.warned: + cls.warned = True print("No cyclictest instance found") def __init__(self):
Signature · 1 line
2.31.1
PATCH 7/17 rt-tests: hwlatdetect: Remove unnessary parens after return
In reply to John KacurRemove unnecessary parens after return
--- src/hwlatdetect/hwlatdetect.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
src/hwlatdetect/hwlatdetect.py +4 -4
@@ -174,14 +174,14 @@ class Kmod: debug("not loading %s (already loaded)" % self.name) return True cmd = ['/sbin/modprobe', self.name] - return (subprocess.call(cmd) == 0) + return subprocess.call(cmd) == 0 def unload(self): if self.preloaded or self.builtin: debug("Not unloading %s" % self.name) return True cmd = ['/sbin/modprobe', '-r', self.name] - return (subprocess.call(cmd) == 0) + return subprocess.call(cmd) == 0 # # base class for detection modules
@@ -494,11 +494,11 @@ def microseconds(str): if str.isdigit(): return int(str) elif str[-2:] == 'ms': - return (int(str[0:-2]) * 1000) + return int(str[0:-2]) * 1000 elif str[-2:] == 'us': return int(str[0:-2]) elif str[-1:] == 's': - return (int(str[0:-1]) * 1000 * 1000) + return int(str[0:-1]) * 1000 * 1000 else: raise RuntimeError("invalid input for microseconds: '%s'" % str)
Signature · 1 line
2.31.1
PATCH 8/17 rt-tests: hwlatdetect: Use "with" for opening files
In reply to John KacurUse "with" for opening files
--- src/hwlatdetect/hwlatdetect.py | 43 ++++++++++++++++------------------ 1 file changed, 20 insertions(+), 23 deletions(-)
src/hwlatdetect/hwlatdetect.py +20 -23
@@ -39,14 +39,13 @@ class DebugFS: self.premounted = False self.mounted = False self.mountpoint = '' - f = open('/proc/mounts') - for l in f: - field = l.split() - if field[2] == "debugfs": - self.premounted = True - self.mountpoint = field[1] - break - f.close() + with open('/proc/mounts') as f: + for l in f: + field = l.split() + if field[2] == "debugfs": + self.premounted = True + self.mountpoint = field[1] + break def mount(self, path='/sys/kernel/debug'): if self.premounted or self.mounted:
@@ -74,9 +73,8 @@ class DebugFS: def getval(self, item, nonblocking=False): path = os.path.join(self.mountpoint, item) if nonblocking == False: - f = open(path) - val = f.readline() - f.close() + with open(path) as f: + val = f.readline() else: f = os.fdopen(os.open(path, os.O_RDONLY|os.O_NONBLOCK), "r") try:
@@ -97,10 +95,9 @@ class DebugFS: def putval(self, item, value): path = os.path.join(self.mountpoint, item) - f = open(path, "w") - f.write(str(value)) - f.flush() - f.close() + with open(path, "w") as f: + f.write(str(value)) + f.flush() def getpath(self, item): return os.path.join(self.mountpoint, item)
@@ -378,10 +375,10 @@ class Tracer(Detector): def save(self, output=None): if output: - f = open(output, "w") - for s in self.samples: - f.write("%s\n" % str(s)) - print("report saved to %s (%d samples)" % (output, len(self.samples))) + with open(output, "w") as f: + for s in self.samples: + f.write("%s\n" % str(s)) + print("report saved to %s (%d samples)" % (output, len(self.samples))) def display(self): for s in self.samples:
@@ -443,10 +440,10 @@ class Hwlat(Detector): def save(self, output=None): if output: - f = open(output, "w") - for s in self.samples: - f.write("%s\n" % str(s)) - print("report saved to %s (%d samples)" % (output, len(self.samples))) + with open(output, "w") as f: + for s in self.samples: + f.write("%s\n" % str(s)) + print("report saved to %s (%d samples)" % (output, len(self.samples))) def cleanup(self): if not self.kmod.unload():
Signature · 1 line
2.31.1
PATCH 9/17 rt-tests: hwlatdetect: Use python3 style super()
In reply to John KacurUse python3 style super(), no need to specify __class__ and self
--- src/hwlatdetect/hwlatdetect.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
src/hwlatdetect/hwlatdetect.py +2 -2
@@ -321,7 +321,7 @@ class Tracer(Detector): return os.path.join(path, Tracer.__field_translation[field]) def __init__(self): - super(Tracer, self).__init__() + super().__init__() path = self.debugfs.getpath('tracing/hwlat_detector') if not os.path.exists(path): raise DetectorNotAvailable("hwlat", "hwlat tracer not available")
@@ -397,7 +397,7 @@ class Tracer(Detector): class Hwlat(Detector): '''class to wrap access to hwlat debugfs files''' def __init__(self): - super(Hwlat, self).__init__() + super().__init__() self.kmod = Kmod("hwlat_detector") self.type = "kmodule" self.kmod.load()
Signature · 1 line
2.31.1
PATCH 10/17 rt-tests: hwlatdetect: Keep consistent name from abstract method
In reply to John KacurKeep the variable name consistent between the abstract method and the method overriding it.
--- src/hwlatdetect/hwlatdetect.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
src/hwlatdetect/hwlatdetect.py +1 -1
@@ -239,7 +239,7 @@ class Detector: '''set a value in a debugfs field''' raise RuntimeError("must override base method 'set'!") - def save(self, reportfile=None): + def save(self, output=None): '''save sample data to reportfile''' raise RuntimeError("must override base method 'save'!")
Signature · 1 line
2.31.1
PATCH 11/17 rt-tests: hwlatdetect: Remove class Hwlat
In reply to John Kacurhwlatdetect converted to using ftrace a long time ago.
Since we no longer need to load a kernel module, the class Hwlat can be removed.
--- src/hwlatdetect/hwlatdetect.py | 61 +--------------------------------- 1 file changed, 1 insertion(+), 60 deletions(-)
src/hwlatdetect/hwlatdetect.py +1 -60
@@ -380,6 +380,7 @@ class Tracer(Detector): f.write("%s\n" % str(s)) print("report saved to %s (%d samples)" % (output, len(self.samples))) + def display(self): for s in self.samples: s.display()
@@ -391,66 +392,6 @@ class Tracer(Detector): raise RuntimeError("Failed to unmount debugfs") -# -# Class to simplify running the hwlat kernel module -# -class Hwlat(Detector): - '''class to wrap access to hwlat debugfs files''' - def __init__(self): - super().__init__() - self.kmod = Kmod("hwlat_detector") - self.type = "kmodule" - self.kmod.load() - - def get(self, field): - return int(self.debugfs.getval(os.path.join("hwlat_detector", field))) - - def set(self, field, val): - if field == "enable" and val: - val = 1 - self.debugfs.putval(os.path.join("hwlat_detector", field), str(val)) - - def get_sample(self): - return self.debugfs.getval("hwlat_detector/sample", nonblocking=True) - - def detect(self): - self.samples = [] - testend = time.time() + self.testduration - pollcnt = 0 - self.start() - try: - while time.time() < testend: - pollcnt += 1 - val = self.get_sample() - while val: - val = val.strip() - self.samples.append(val) - if watch: - print(val) - val = self.get_sample() - time.sleep(0.1) - except KeyboardInterrupt as e: - print("interrupted") - self.stop() - return self.samples - - def display(self): - for s in self.samples: - print(s) - - def save(self, output=None): - if output: - with open(output, "w") as f: - for s in self.samples: - f.write("%s\n" % str(s)) - print("report saved to %s (%d samples)" % (output, len(self.samples))) - - def cleanup(self): - if not self.kmod.unload(): - raise RuntimeError("Failed to unload %s" % self.name) - if not self.debugfs.umount(): - raise RuntimeError("Failed to unmount debugfs") - def seconds(str): "convert input string to value in seconds" if str.isdigit():
Signature · 1 line
2.31.1
PATCH 12/17 rt-tests: hwlatdetect: Use abstractmethod decorator
In reply to John Kacur- Use abstractmethod decorator instead of raising error if a method is not overridden.
- Remove unnecessary trailing comma
- fix import order
--- src/hwlatdetect/hwlatdetect.py | 37 ++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 17 deletions(-)
src/hwlatdetect/hwlatdetect.py +20 -17
@@ -1,4 +1,5 @@ #!/usr/bin/python3 +""" Module to detect smis """ # SPDX-License-Identifier: GPL-2.0-only
@@ -6,12 +7,13 @@ # (C) 2015,2016 Clark Williams <[email protected]> # (C) 2009 Clark Williams <[email protected]> -import sys -import os -import time -import subprocess +import abc import errno +import os import os.path +import subprocess +import sys +import time version = "0.8" debugging = False
@@ -72,7 +74,7 @@ class DebugFS: def getval(self, item, nonblocking=False): path = os.path.join(self.mountpoint, item) - if nonblocking == False: + if nonblocking is False: with open(path) as f: val = f.readline() else:
@@ -228,24 +230,25 @@ class Detector: os.close(self.dma_latency_handle) debug("c-states enabled") + @abc.abstractmethod def cleanup(self): - raise RuntimeError("must override base method 'cleanup'!") + ''' abstract cleanup method, must override ''' + @abc.abstractmethod def get(self, field): - '''get the value of a debugfs field''' - raise RuntimeError("must override base method 'get'!") + ''' get the value of a debugfs field ''' + @abc.abstractmethod def set(self, field, val): - '''set a value in a debugfs field''' - raise RuntimeError("must override base method 'set'!") + ''' set a value in a debugfs field ''' + @abc.abstractmethod def save(self, output=None): - '''save sample data to reportfile''' - raise RuntimeError("must override base method 'save'!") + ''' save sample data to output ''' + @abc.abstractmethod def display(self): - '''output the sample data as a string''' - raise RuntimeError("must override base method 'display'!") + ''' output the sample data as a string ''' def start(self): count = 0
@@ -277,9 +280,9 @@ class Detector: self.c_states_on() debug("detector module disabled") + @abc.abstractmethod def detect(self): - '''get detector output''' - raise RuntimeError("must override base method 'detect'!") + ''' get detector output ''' # # class to handle running the hwlat tracer module of ftrace #
@@ -294,7 +297,7 @@ class Tracer(Detector): class Sample: 'private class for tracer sample data' - __slots__ = 'timestamp', 'inner', 'outer', + __slots__ = 'timestamp', 'inner', 'outer' def __init__(self, line): fields = line.split() i,o = fields[6].split('/')
Signature · 1 line
2.31.1
PATCH 13/17 rt-tests: hwlatdetect: Remove unused class Kmod
In reply to John Kacur- Remove class Kmod
Kmod was used for loading and unloading of a kernel module, but hwlatdetect uses ftrace now so this class is unneeded.
- Improve the spacing in the code
--- src/hwlatdetect/hwlatdetect.py | 107 ++++++--------------------------- 1 file changed, 19 insertions(+), 88 deletions(-)
src/hwlatdetect/hwlatdetect.py +19 -88
@@ -20,14 +20,17 @@ debugging = False quiet = False watch = False + def debug(str): if debugging: print(str) + def info(str): if not quiet: print(str) + # # Class used to manage mounting and umounting the debugfs # filesystem. Note that if an instance of this class mounts
@@ -78,7 +81,7 @@ class DebugFS: with open(path) as f: val = f.readline() else: - f = os.fdopen(os.open(path, os.O_RDONLY|os.O_NONBLOCK), "r") + f = os.fdopen(os.open(path, os.O_RDONLY | os.O_NONBLOCK), "r") try: val = f.readline() except OSError as e:
@@ -104,89 +107,19 @@ class DebugFS: def getpath(self, item): return os.path.join(self.mountpoint, item) -# Exception class for when tracer is not available + class DetectorNotAvailable(Exception): + """ Exception class for when tracer is not available """ + def __init__(self, name, msg): self.args = (name, msg) self.name = name self.msg = msg -# -# Class used to manage loading and unloading of the -# hwlat kernel module. Like the debugfs class -# above, if the module is already loaded, this class will -# leave it alone when cleaning up. -# -class Kmod: - ''' class to manage loading and unloading of kernel modules''' - - names = ("hwlat_detector", "smi_detector") - - def __check_builtin(self): - for l in open(os.path.join('/lib/modules', os.uname()[2], 'modules.builtin'), "r"): - if self.name in l: - debug("found %s as builtin" % self.namename) - return True - return False - - def __find_module(self): - debug("looking for module %s" % self.name) - path = os.path.join("/lib/modules", - os.uname()[2], - "kernel/drivers/misc") - debug("module path: %s" % path) - mpath = os.path.join(path, self.name) + ".ko" - debug("checking %s" % mpath) - if os.path.exists(mpath): - return True - return False - - def __init__(self, name): - if name not in Kmod.names: - raise RuntimeError("unsupported module name: %s" % name) - if name == "smi_detector": - raise RuntimeError("smi_detector module no longer supported!") - self.name = name - self.preloaded = False - self.builtin = False - - # check for builtin - if self.__check_builtin(): - self.builtin = True - return - - # now look for already loaded module - for l in open('/proc/modules'): - field = l.split() - if self.name in field[0]: - self.preloaded = True - debug("using already loaded %s" % self.name) - return - if not self.__find_module(): - raise DetectorNotAvailable(name, "module %s does not exist!" % self.name) - - def load(self): - if self.builtin: - debug("not loading %s (builtin)" % self.name) - return True - if self.preloaded: - debug("not loading %s (already loaded)" % self.name) - return True - cmd = ['/sbin/modprobe', self.name] - return subprocess.call(cmd) == 0 - - def unload(self): - if self.preloaded or self.builtin: - debug("Not unloading %s" % self.name) - return True - cmd = ['/sbin/modprobe', '-r', self.name] - return subprocess.call(cmd) == 0 -# -# base class for detection modules -# class Detector: - '''base class for detector modules''' + """ base class for detector modules """ + def __init__(self): self.type = "unknown" if os.getuid() != 0:
@@ -195,7 +128,7 @@ class Detector: if not self.debugfs.mount(): raise RuntimeError("failed to mount debugfs") self.samples = [] - self.testduration = 30 # ten seconds + self.testduration = 30 # ten seconds self.have_msr = False self.initsmi = [] if os.path.exists('/usr/sbin/rdmsr'):
@@ -283,11 +216,11 @@ class Detector: @abc.abstractmethod def detect(self): ''' get detector output ''' -# -# class to handle running the hwlat tracer module of ftrace -# + + class Tracer(Detector): - '''class to wrap access to ftrace hwlat tracer''' + """ Class to handle running the hwlat tracer module of ftrace """ + __field_translation = { 'width' : "hwlat_detector/width", 'window' : "hwlat_detector/window",
@@ -298,9 +231,10 @@ class Tracer(Detector): class Sample: 'private class for tracer sample data' __slots__ = 'timestamp', 'inner', 'outer' + def __init__(self, line): fields = line.split() - i,o = fields[6].split('/') + i, o = fields[6].split('/') ts = fields[7][3:] self.timestamp = str(ts) self.inner = int(i)
@@ -383,7 +317,6 @@ class Tracer(Detector): f.write("%s\n" % str(s)) print("report saved to %s (%d samples)" % (output, len(self.samples))) - def display(self): for s in self.samples: s.display()
@@ -414,6 +347,7 @@ def seconds(str): else: raise RuntimeError("invalid input for seconds: '%s'" % str) + def milliseconds(str): "convert input string to millsecond value" if str.isdigit():
@@ -443,9 +377,6 @@ def microseconds(str): else: raise RuntimeError("invalid input for microseconds: '%s'" % str) -# -# main starts here -# if __name__ == '__main__': from argparse import ArgumentParser
@@ -533,7 +464,7 @@ if __name__ == '__main__': if args.duration: detect.testduration = seconds(args.duration) else: - detect.testduration = 120 # 2 minutes + detect.testduration = 120 # 2 minutes debug("test duration is %ds" % detect.testduration) if args.watch:
@@ -569,7 +500,7 @@ if __name__ == '__main__': if detect.have_msr: finishsmi = detect.getsmicounts() total_smis = 0 - for i,count in enumerate(finishsmi): + for i, count in enumerate(finishsmi): if count > detect.initsmi[i]: smis = count - detect.initsmi[i] total_smis += smis
Signature · 1 line
2.31.1
PATCH 14/17 rt-tests: hwlatdetect: Don't use built-in name str as a variable
In reply to John Kacur- Don't use built-in name "str" as a variable
- Add some more docstrings to methods
--- src/hwlatdetect/hwlatdetect.py | 122 +++++++++++++++++---------------- 1 file changed, 63 insertions(+), 59 deletions(-)
src/hwlatdetect/hwlatdetect.py +63 -59
@@ -21,14 +21,16 @@ quiet = False watch = False -def debug(str): +def debug(dstr): + """ print debugging string if debugging is on """ if debugging: - print(str) + print(dstr) -def info(str): +def info(istr): + " print info string if quiet is not on """ if not quiet: - print(str) + print(istr) #
@@ -39,7 +41,7 @@ def info(str): # it mounted. # class DebugFS: - '''class to manage mounting/umounting the debugfs''' + """ class to manage mounting/umounting the debugfs """ def __init__(self): self.premounted = False self.mounted = False
@@ -53,6 +55,7 @@ class DebugFS: break def mount(self, path='/sys/kernel/debug'): + """ mount debugfs unless already mounted """ if self.premounted or self.mounted: debug("not mounting debugfs") return True
@@ -65,6 +68,7 @@ class DebugFS: return self.mounted def umount(self): + """ unmount debugfs if not premounted """ if self.premounted or not self.mounted: debug("not umounting debugfs") return True
@@ -76,6 +80,7 @@ class DebugFS: return not self.mounted def getval(self, item, nonblocking=False): + """ get value of mountpoint/item """ path = os.path.join(self.mountpoint, item) if nonblocking is False: with open(path) as f:
@@ -90,21 +95,18 @@ class DebugFS: val = None else: raise - except IOError as e: - if e.errno == errno.EAGAIN: - val = None - else: - raise f.close() return val def putval(self, item, value): + """ write value to mountpoint/item """ path = os.path.join(self.mountpoint, item) with open(path, "w") as f: f.write(str(value)) f.flush() def getpath(self, item): + """ get mountpoint/item """ return os.path.join(self.mountpoint, item)
@@ -153,12 +155,14 @@ class Detector: # use c_states_on() to close the file descriptor and re-enable c-states # def c_states_off(self): + """ disable c-state transitions """ if os.path.exists("/dev/cpu_dma_latency"): self.dma_latency_handle = os.open("/dev/cpu_dma_latency", os.O_WRONLY) os.write(self.dma_latency_handle, b'\x00\x00\x00\x00') debug("c-states disabled") def c_states_on(self): + """ close the file descriptor and re-enable c-states """ if self.dma_latency_handle: os.close(self.dma_latency_handle) debug("c-states enabled")
@@ -184,6 +188,7 @@ class Detector: ''' output the sample data as a string ''' def start(self): + """ enable the detector """ count = 0 threshold = int(self.get("threshold")) self.c_states_off()
@@ -201,6 +206,7 @@ class Detector: debug("detector module enabled (threshold: %d)" % int(self.get("threshold"))) def stop(self): + """ disable the detector """ count = 0 debug("disabling detector module") self.set("enable", 0)
@@ -244,12 +250,12 @@ class Tracer(Detector): return "ts: %s, inner:%d, outer:%d" % (self.timestamp, self.inner, self.outer) def display(self): + """ convert object to string and print """ print(str(self)) def largest(self): - if self.inner > self.outer: - return self.inner - return self.outer + """ return largest value of inner or outer """ + return max(self.inner, self.outer) def translate(self, field): path = self.debugfs.getpath('tracing')
@@ -274,7 +280,7 @@ class Tracer(Detector): def get(self, field): if field == "count": return len(self.samples) - elif field == "max": + if field == "max": max = 0 for values in self.samples: s = int(values.largest())
@@ -311,6 +317,7 @@ class Tracer(Detector): return val def save(self, output=None): + """ save samples """ if output: with open(output, "w") as f: for s in self.samples:
@@ -328,54 +335,51 @@ class Tracer(Detector): raise RuntimeError("Failed to unmount debugfs") -def seconds(str): +def seconds(sval): "convert input string to value in seconds" - if str.isdigit(): - return int(str) - elif str[-2].isalpha(): - raise RuntimeError("illegal suffix for seconds: '%s'" % str[-2:-1]) - elif str[-1:] == 's': - return int(str[0:-1]) - elif str[-1:] == 'm': - return int(str[0:-1]) * 60 - elif str[-1:] == 'h': - return int(str[0:-1]) * 3600 - elif str[-1:] == 'd': - return int(str[0:-1]) * 86400 - elif str[-1:] == 'w': - return int(str[0:-1]) * 86400 * 7 - else: - raise RuntimeError("invalid input for seconds: '%s'" % str) - - -def milliseconds(str): + if sval.isdigit(): + return int(sval) + if sval[-2].isalpha(): + raise RuntimeError("illegal suffix for seconds: '%s'" % sval[-2:-1]) + if sval[-1:] == 's': + return int(sval[0:-1]) + if sval[-1:] == 'm': + return int(sval[0:-1]) * 60 + if sval[-1:] == 'h': + return int(sval[0:-1]) * 3600 + if sval[-1:] == 'd': + return int(sval[0:-1]) * 86400 + if sval[-1:] == 'w': + return int(sval[0:-1]) * 86400 * 7 + raise RuntimeError("invalid input for seconds: '%s'" % sval) + + +def milliseconds(sval): "convert input string to millsecond value" - if str.isdigit(): - return int(str) - elif str[-2:] == 'ms': - return int(str[0:-2]) - elif str[-1] == 's': - return int(str[0:-2]) * 1000 - elif str[-1] == 'm': - return int(str[0:-1]) * 1000 * 60 - elif str[-1] == 'h': - return int(str[0:-1]) * 1000 * 60 * 60 - else: - raise RuntimeError("invalid input for milliseconds: %s" % str) - - -def microseconds(str): + if sval.isdigit(): + return int(sval) + if sval[-2:] == 'ms': + return int(sval[0:-2]) + if sval[-1] == 's': + return int(sval[0:-2]) * 1000 + if sval[-1] == 'm': + return int(sval[0:-1]) * 1000 * 60 + if sval[-1] == 'h': + return int(sval[0:-1]) * 1000 * 60 * 60 + raise RuntimeError("invalid input for milliseconds: %s" % sval) + + +def microseconds(sval): "convert input string to microsecond value" - if str.isdigit(): - return int(str) - elif str[-2:] == 'ms': - return int(str[0:-2]) * 1000 - elif str[-2:] == 'us': - return int(str[0:-2]) - elif str[-1:] == 's': - return int(str[0:-1]) * 1000 * 1000 - else: - raise RuntimeError("invalid input for microseconds: '%s'" % str) + if sval.isdigit(): + return int(sval) + if sval[-2:] == 'ms': + return int(sval[0:-2]) * 1000 + if sval[-2:] == 'us': + return int(sval[0:-2]) + if sval[-1:] == 's': + return int(sval[0:-1]) * 1000 * 1000 + raise RuntimeError("invalid input for microseconds: '%s'" % sval) if __name__ == '__main__':
Signature · 1 line
2.31.1
PATCH 15/17 rt-tests: cyclictest: Drop unused defines
In reply to John KacurFrom: Punit Agrawal <[email protected]>
KVARS, KVARNAMELEN and KVALUELEN defines are not used in cyclictest. Drop them.
--- src/cyclictest/cyclictest.c | 4 ---- 1 file changed, 4 deletions(-)
src/cyclictest/cyclictest.c +0 -4
@@ -99,10 +99,6 @@ extern int clock_nanosleep(clockid_t __clock_id, int __flags,/* Must be power of 2 ! */ #define VALBUF_SIZE 16384 -#define KVARS 32 -#define KVARNAMELEN 32 -#define KVALUELEN 32 -#if (defined(__i386__) || defined(__x86_64__))#define ARCH_HAS_SMI_COUNTER #endif
Signature · 1 line
2.31.1
PATCH 16/17 rt-tests: cyclictest: Simplify duplicate initialization of "stop"
In reply to John KacurFrom: Punit Agrawal <[email protected]>
The timespec structure "stop" is initialised whether it is used or not as the compiler is not smart enough to figure out that it's use is always guarded by the "duration" variable. As a result, "stop" needs to be initialised whether it's used or not to avoid a compiler warning.
Replace the duplicate memset statements by initializing "stop" using structure initialiser.
--- src/cyclictest/cyclictest.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
src/cyclictest/cyclictest.c +1 -4
@@ -507,7 +507,7 @@ static void *timerthread(void *param)struct sigevent sigev;sigset_t sigset;timer_t timer; -struct timespec now, next, interval, stop; +struct timespec now, next, interval, stop = {0 };struct itimerval itimer;struct itimerspec tspec;struct thread_stat *stat = par->stats;
@@ -516,8 +516,6 @@ static void *timerthread(void *param)pthread_t thread;unsigned long smi_now, smi_old =0 ; -memset (&stop,0 ,sizeof (stop)); -/* if we're running in numa mode, set our memory node */ if (par->node !=-1 )rt_numa_set_numa_run_on_node (par->node, par->cpu);
@@ -598,7 +596,6 @@ static void *timerthread(void *param)tsnorm (&next);if (duration) { -memset (&stop,0 ,sizeof (stop));/* grrr */ stop = now; stop.tv_sec += duration; }
Signature · 1 line
2.31.1
PATCH 17/17 rt-tests: cyclictest: Drop unnecessary variable "bufsize"
In reply to John KacurFrom: Punit Agrawal <[email protected]>
Two copies of "bufsize", initialised with the same value are declared in enclosed blocks. Remove the redundant declaration.
--- src/cyclictest/cyclictest.c | 1 - 1 file changed, 1 deletion(-)
src/cyclictest/cyclictest.c +0 -1
@@ -2059,7 +2059,6 @@ int main(int argc, char **argv)memset (stat->values,0 , bufsize); par->bufmsk =VALBUF_SIZE -1 ;if (smi) { -int bufsize =VALBUF_SIZE *sizeof (long ); stat->smis =threadalloc (bufsize, node);if (!stat->smis) goto outall;
Signature · 1 line
2.31.1