All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/7] rteval: rteval-cmd: Use "with" with open
@ 2022-06-03 16:12 John Kacur
  2022-06-03 16:12 ` [PATCH 2/7] rteval: misc.py: Use "with" for resource allocation John Kacur
                   ` (5 more replies)
  0 siblings, 6 replies; 8+ messages in thread
From: John Kacur @ 2022-06-03 16:12 UTC (permalink / raw)
  To: RT
  Cc: Clark Williams, Leah Leshchinsky, Valentin Schneider,
	Manasi Godse, John Kacur

Use "with" for resource allocating operation open

Signed-off-by: John Kacur <jkacur@redhat.com>
---
 rteval-cmd | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/rteval-cmd b/rteval-cmd
index 2c775ee52f69..4598ba514ddc 100755
--- a/rteval-cmd
+++ b/rteval-cmd
@@ -72,15 +72,13 @@ def summarize(repfile, xslt):
         isarchive = True
 
     # Load the XSLT template
-    xsltfp = open(xslt, "r")
-    xsltdoc = lxml.etree.parse(xsltfp)
-    xsltprs = lxml.etree.XSLT(xsltdoc)
-    xsltfp.close()
+    with open(xslt, "r") as xsltfp:
+        xsltdoc = lxml.etree.parse(xsltfp)
+        xsltprs = lxml.etree.XSLT(xsltdoc)
 
     # Load the summay.xml report - with some simple sanity checks
-    xmlfp = open(summaryfile, "r")
-    xmldoc = lxml.etree.parse(xmlfp)
-    xmlfp.close()
+    with open(summaryfile, "r") as xmlfp:
+        xmldoc = lxml.etree.parse(xmlfp)
 
     if xmldoc.docinfo.root_name != 'rteval':
         raise RuntimeError("The report doesn't seem like a rteval summary report")
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/7] rteval: misc.py: Use "with" for resource allocation
  2022-06-03 16:12 [PATCH 1/7] rteval: rteval-cmd: Use "with" with open John Kacur
@ 2022-06-03 16:12 ` John Kacur
  2022-06-03 16:12 ` [PATCH 3/7] rteval: stressng.py: Remove unnecessary list John Kacur
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: John Kacur @ 2022-06-03 16:12 UTC (permalink / raw)
  To: RT
  Cc: Clark Williams, Leah Leshchinsky, Valentin Schneider,
	Manasi Godse, John Kacur

- Use "with" for resource allocation.
- Add docstrings to the module and to functions

Signed-off-by: John Kacur <jkacur@redhat.com>
---
 rteval/misc.py | 28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/rteval/misc.py b/rteval/misc.py
index 6fdb24261bec..a7c515b0d293 100755
--- a/rteval/misc.py
+++ b/rteval/misc.py
@@ -15,6 +15,7 @@
 # You should have received a copy of the GNU General Public License
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+''' Functions for operating on a cpulists '''
 
 
 import os
@@ -36,6 +37,7 @@ def expand_cpulist(cpulist):
     return [str(i) for i in list(set(result))]
 
 def online_cpus():
+    ''' Collapse a list of cpu numbers into a string range '''
     online_cpus = []
     # Check for the online file with cpu1 since cpu0 can't always be offlined
     if os.path.exists('/sys/devices/system/cpu/cpu1/online'):
@@ -56,27 +58,31 @@ def online_cpus():
     return online_cpus
 
 def invert_cpulist(cpulist):
+    ''' return a list of online cpus not in cpulist '''
     return [c for c in online_cpus() if c not in cpulist]
 
 def compress_cpulist(cpulist):
+    ''' return a string representation of cpulist '''
     if isinstance(cpulist[0], int):
         return ",".join(str(e) for e in cpulist)
     return ",".join(cpulist)
 
 def cpuinfo():
+    ''' return a dictionary of cpu keys with various cpu information '''
     core = -1
     info = {}
-    for l in open('/proc/cpuinfo'):
-        l = l.strip()
-        if not l:
-            continue
-        # Split a maximum of one time. In case a model name has ':' in it
-        key, val = [i.strip() for i in l.split(':', 1)]
-        if key == 'processor':
-            core = val
-            info[core] = {}
-            continue
-        info[core][key] = val
+    with open('/proc/cpuinfo') as fp:
+        for l in fp:
+            l = l.strip()
+            if not l:
+                continue
+            # Split a maximum of one time. In case a model name has ':' in it
+            key, val = [i.strip() for i in l.split(':', 1)]
+            if key == 'processor':
+                core = val
+                info[core] = {}
+                continue
+            info[core][key] = val
 
     for (core, pcdict) in info.items():
         if not 'model name' in pcdict:
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/7] rteval: stressng.py: Remove unnecessary list
  2022-06-03 16:12 [PATCH 1/7] rteval: rteval-cmd: Use "with" with open John Kacur
  2022-06-03 16:12 ` [PATCH 2/7] rteval: misc.py: Use "with" for resource allocation John Kacur
@ 2022-06-03 16:12 ` John Kacur
  2022-06-03 16:12 ` [PATCH 4/7] rteval: cyclictest.py: Use "with" with resource allocation John Kacur
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: John Kacur @ 2022-06-03 16:12 UTC (permalink / raw)
  To: RT
  Cc: Clark Williams, Leah Leshchinsky, Valentin Schneider,
	Manasi Godse, John Kacur

Remove unnecessary word list around cpus.items()

Signed-off-by: John Kacur <jkacur@redhat.com>
---
 rteval/modules/loads/stressng.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/rteval/modules/loads/stressng.py b/rteval/modules/loads/stressng.py
index d084814142fb..d0772ce77662 100644
--- a/rteval/modules/loads/stressng.py
+++ b/rteval/modules/loads/stressng.py
@@ -69,7 +69,7 @@ class Stressng(CommandLineLoad):
                 cpus[n] = [c for c in cpus[n] if str(c) in expand_cpulist(self.cpulist)]
 
         # remove nodes with no cpus available for running
-        for node, cpu in list(cpus.items()):
+        for node, cpu in cpus.items():
             if not cpu:
                 nodes.remove(node)
                 self._log(Log.DEBUG, "node %s has no available cpus, removing" % node)
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 4/7] rteval: cyclictest.py: Use "with" with resource allocation
  2022-06-03 16:12 [PATCH 1/7] rteval: rteval-cmd: Use "with" with open John Kacur
  2022-06-03 16:12 ` [PATCH 2/7] rteval: misc.py: Use "with" for resource allocation John Kacur
  2022-06-03 16:12 ` [PATCH 3/7] rteval: stressng.py: Remove unnecessary list John Kacur
@ 2022-06-03 16:12 ` John Kacur
  2022-06-03 16:12 ` [PATCH 5/7] rteval: systopology.py: Use "with" for " John Kacur
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: John Kacur @ 2022-06-03 16:12 UTC (permalink / raw)
  To: RT
  Cc: Clark Williams, Leah Leshchinsky, Valentin Schneider,
	Manasi Godse, John Kacur

- Use "with" with open
- Add a module docstring

Signed-off-by: John Kacur <jkacur@redhat.com>
---
 rteval/modules/measurement/cyclictest.py | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/rteval/modules/measurement/cyclictest.py b/rteval/modules/measurement/cyclictest.py
index 8fdd5341794a..4c8d510c4a34 100644
--- a/rteval/modules/measurement/cyclictest.py
+++ b/rteval/modules/measurement/cyclictest.py
@@ -24,6 +24,7 @@
 #   including keys needed to generate an equivalently functional executable
 #   are deemed to be part of the source code.
 #
+""" cyclictest.py - object to manage a cyclictest executable instance """
 
 import os
 import subprocess
@@ -254,14 +255,13 @@ class Cyclictest(rtevalModulePrototype):
     @staticmethod
     def __get_debugfs_mount():
         ret = None
-        mounts = open('/proc/mounts')
-        for l in mounts:
-            field = l.split()
-            if field[2] == "debugfs":
-                ret = field[1]
-                break
-        mounts.close()
-        return ret
+        with open('/proc/mounts') as mounts:
+            for l in mounts:
+                field = l.split()
+                if field[2] == "debugfs":
+                    ret = field[1]
+                    break
+            return ret
 
 
     def _WorkloadSetup(self):
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 5/7] rteval: systopology.py: Use "with" for resource allocation
  2022-06-03 16:12 [PATCH 1/7] rteval: rteval-cmd: Use "with" with open John Kacur
                   ` (2 preceding siblings ...)
  2022-06-03 16:12 ` [PATCH 4/7] rteval: cyclictest.py: Use "with" with resource allocation John Kacur
@ 2022-06-03 16:12 ` John Kacur
  2022-06-03 16:12 ` [PATCH 6/7] rteval: kcompile: Fix regular expression to match kernel prefix John Kacur
  2022-06-03 16:12 ` [PATCH 7/7] rteval: stressng: The stressng option should not be a string John Kacur
  5 siblings, 0 replies; 8+ messages in thread
From: John Kacur @ 2022-06-03 16:12 UTC (permalink / raw)
  To: RT
  Cc: Clark Williams, Leah Leshchinsky, Valentin Schneider,
	Manasi Godse, John Kacur

- Use "with" with open

Signed-off-by: John Kacur <jkacur@redhat.com>
---
 rteval/systopology.py | 30 ++++++++++++++++--------------
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/rteval/systopology.py b/rteval/systopology.py
index b2da7bba7de0..e852f86e450f 100644
--- a/rteval/systopology.py
+++ b/rteval/systopology.py
@@ -180,13 +180,14 @@ class NumaNode:
     def getmeminfo(self):
         """ read info about memory attached to this node """
         self.meminfo = {}
-        for l in open(os.path.join(self.path, "meminfo"), "r"):
-            elements = l.split()
-            key = elements[2][0:-1]
-            val = int(elements[3])
-            if len(elements) == 5 and elements[4] == "kB":
-                val *= 1024
-            self.meminfo[key] = val
+        with open(os.path.join(self.path, "meminfo"), "r") as fp:
+            for l in fp:
+                elements = l.split()
+                key = elements[2][0:-1]
+                val = int(elements[3])
+                if len(elements) == 5 and elements[4] == "kB":
+                    val *= 1024
+                self.meminfo[key] = val
 
     def getcpustr(self):
         """ return list of cpus for this node as a string """
@@ -212,13 +213,14 @@ class SimNumaNode(NumaNode):
 
     def getmeminfo(self):
         self.meminfo = {}
-        for l in open(SimNumaNode.mempath, "r"):
-            elements = l.split()
-            key = elements[0][0:-1]
-            val = int(elements[1])
-            if len(elements) == 3 and elements[2] == "kB":
-                val *= 1024
-            self.meminfo[key] = val
+        with open(SimNumaNode.mempath, "r") as fp:
+            for l in fp:
+                elements = l.split()
+                key = elements[0][0:-1]
+                val = int(elements[1])
+                if len(elements) == 3 and elements[2] == "kB":
+                    val *= 1024
+                self.meminfo[key] = val
 
 #
 # Class to abstract the system topology of numa nodes and cpus
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 6/7] rteval: kcompile: Fix regular expression to match kernel prefix
  2022-06-03 16:12 [PATCH 1/7] rteval: rteval-cmd: Use "with" with open John Kacur
                   ` (3 preceding siblings ...)
  2022-06-03 16:12 ` [PATCH 5/7] rteval: systopology.py: Use "with" for " John Kacur
@ 2022-06-03 16:12 ` John Kacur
  2022-06-06 10:59   ` Valentin Schneider
  2022-06-03 16:12 ` [PATCH 7/7] rteval: stressng: The stressng option should not be a string John Kacur
  5 siblings, 1 reply; 8+ messages in thread
From: John Kacur @ 2022-06-03 16:12 UTC (permalink / raw)
  To: RT
  Cc: Clark Williams, Leah Leshchinsky, Valentin Schneider,
	Manasi Godse, John Kacur

If the user specifies a kernel to compile as a load other than the
default kernel, the kernel prefix is obtained with a regular expression.

Currently the regular expression does not accomodate two digit numbers
in the kernel version.
Fix that regular expression to accomodate different kernel versions,
with room to grow for the future.

Signed-off-by: John Kacur <jkacur@redhat.com>
---
 rteval/modules/loads/kcompile.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/rteval/modules/loads/kcompile.py b/rteval/modules/loads/kcompile.py
index 2701a0dcba91..3d9b882d8810 100644
--- a/rteval/modules/loads/kcompile.py
+++ b/rteval/modules/loads/kcompile.py
@@ -169,7 +169,7 @@ class Kcompile(CommandLineLoad):
             if not os.path.exists(tarfile):
                 raise rtevalRuntimeError(self, " tarfile %s does not exist!" % tarfile)
             self.source = tarfile
-            kernel_prefix = re.search(r"linux-\d\.\d", self.source).group(0)
+            kernel_prefix = re.search(r"linux-\d{1,2}\.\d{1,3}", self.source).group(0)
         else:
             tarfiles = glob.glob(os.path.join(self.srcdir, "%s*" % DEFAULT_KERNEL_PREFIX))
             if tarfiles:
@@ -177,6 +177,7 @@ class Kcompile(CommandLineLoad):
             else:
                 raise rtevalRuntimeError(self, " no kernel tarballs found in %s" % self.srcdir)
             kernel_prefix = DEFAULT_KERNEL_PREFIX
+        self._log(Log.DEBUG, f"kernel_prefix = {kernel_prefix}")
 
         # check for existing directory
         kdir = None
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 7/7] rteval: stressng: The stressng option should not be a string
  2022-06-03 16:12 [PATCH 1/7] rteval: rteval-cmd: Use "with" with open John Kacur
                   ` (4 preceding siblings ...)
  2022-06-03 16:12 ` [PATCH 6/7] rteval: kcompile: Fix regular expression to match kernel prefix John Kacur
@ 2022-06-03 16:12 ` John Kacur
  5 siblings, 0 replies; 8+ messages in thread
From: John Kacur @ 2022-06-03 16:12 UTC (permalink / raw)
  To: RT
  Cc: Clark Williams, Leah Leshchinsky, Valentin Schneider,
	Manasi Godse, John Kacur

When rteval passes stressng a timeout option, it should not be
stringified.

Signed-off-by: John Kacur <jkacur@redhat.com>
---
 rteval/modules/loads/stressng.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/rteval/modules/loads/stressng.py b/rteval/modules/loads/stressng.py
index d0772ce77662..fe97189d3816 100644
--- a/rteval/modules/loads/stressng.py
+++ b/rteval/modules/loads/stressng.py
@@ -54,7 +54,8 @@ class Stressng(CommandLineLoad):
         if self.cfg.arg is not None:
             self.args.append(self.cfg.arg)
         if self.cfg.timeout is not None:
-            self.args.append('--timeout %s' % str(self.cfg.timeout))
+            self.args.append('--timeout')
+            self.args.append(self.cfg.timeout)
 
         systop = SysTopology()
         # get the number of nodes
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 6/7] rteval: kcompile: Fix regular expression to match kernel prefix
  2022-06-03 16:12 ` [PATCH 6/7] rteval: kcompile: Fix regular expression to match kernel prefix John Kacur
@ 2022-06-06 10:59   ` Valentin Schneider
  0 siblings, 0 replies; 8+ messages in thread
From: Valentin Schneider @ 2022-06-06 10:59 UTC (permalink / raw)
  To: John Kacur, RT; +Cc: Clark Williams, Leah Leshchinsky, Manasi Godse, John Kacur

On 03/06/22 12:12, John Kacur wrote:
> @@ -169,7 +169,7 @@ class Kcompile(CommandLineLoad):
>              if not os.path.exists(tarfile):
>                  raise rtevalRuntimeError(self, " tarfile %s does not exist!" % tarfile)
>              self.source = tarfile
> -            kernel_prefix = re.search(r"linux-\d\.\d", self.source).group(0)
> +            kernel_prefix = re.search(r"linux-\d{1,2}\.\d{1,3}", self.source).group(0)

Sorry about that one!
That looks OK to me, though why not go for "linux-\d+\.\d+" ?


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-06-06 11:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-03 16:12 [PATCH 1/7] rteval: rteval-cmd: Use "with" with open John Kacur
2022-06-03 16:12 ` [PATCH 2/7] rteval: misc.py: Use "with" for resource allocation John Kacur
2022-06-03 16:12 ` [PATCH 3/7] rteval: stressng.py: Remove unnecessary list John Kacur
2022-06-03 16:12 ` [PATCH 4/7] rteval: cyclictest.py: Use "with" with resource allocation John Kacur
2022-06-03 16:12 ` [PATCH 5/7] rteval: systopology.py: Use "with" for " John Kacur
2022-06-03 16:12 ` [PATCH 6/7] rteval: kcompile: Fix regular expression to match kernel prefix John Kacur
2022-06-06 10:59   ` Valentin Schneider
2022-06-03 16:12 ` [PATCH 7/7] rteval: stressng: The stressng option should not be a string John Kacur

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.