public inbox for linux-rt-users@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] rt-tests: hwlatdetect.py Covert to f-strings
@ 2022-11-02 14:35 Leah Leshchinsky
  2022-11-02 20:30 ` John Kacur
  0 siblings, 1 reply; 2+ messages in thread
From: Leah Leshchinsky @ 2022-11-02 14:35 UTC (permalink / raw)
  To: jkacur; +Cc: linux-rt-users

Add f-strings where applicable for readability.

Signed-off-by: Leah Leshchinsky <lleshchi@redhat.com>

diff --git a/src/hwlatdetect/hwlatdetect.py b/src/hwlatdetect/hwlatdetect.py
index 9ef50f862127..3b20f664a536 100755
--- a/src/hwlatdetect/hwlatdetect.py
+++ b/src/hwlatdetect/hwlatdetect.py
@@ -59,7 +59,7 @@ class DebugFS:
         if self.premounted or self.mounted:
             debug("not mounting debugfs")
             return True
-        debug("mounting debugfs at %s" % path)
+        debug(f"mounting debugfs at {path}")
         self.mountpoint = path
         cmd = ['/bin/mount', '-t', 'debugfs', 'none', path]
         self.mounted = (subprocess.call(cmd) == 0)
@@ -90,7 +90,7 @@ class DebugFS:
             try:
                 val = f.readline()
             except OSError as e:
-                print("errno: %s" % e)
+                print(f"errno: {e}")
                 if e.errno == errno.EAGAIN:
                     val = None
                 else:
@@ -192,13 +192,13 @@ class Detector:
         count = 0
         threshold = int(self.get("threshold"))
         self.c_states_off()
-        debug("enabling detector module (threshold: %d)" % threshold)
+        debug(f"enabling detector module (threshold: {threshold})")
         self.set("enable", 1)
         while self.get("enable") == 0:
             debug("still disabled, retrying in a bit")
             count += 1
             time.sleep(0.1)
-            debug("retrying enable of detector module (%d)" % count)
+            debug(f"retrying enable of detector module ({count})")
             self.set("enable", 1)
         if self.get("threshold") != threshold:
             debug("start: threshold reset by start, fixing")
@@ -214,7 +214,7 @@ class Detector:
             debug("still enabled, retrying in a bit")
             count += 1
             time.sleep(0.1)
-            debug("retrying disable of detector module(%d)" % count)
+            debug(f"retrying disable of detector module({count})")
             self.set("enable", 0)
         self.c_states_on()
         debug("detector module disabled")
@@ -248,7 +248,7 @@ class Tracer(Detector):
             self.outer = int(o)
 
         def __str__(self):
-            return "ts: %s, inner:%d, outer:%d" % (self.timestamp, self.inner, self.outer)
+            return f"ts: {self.timestamp}, inner:{self.inner}, outer:{self.outer}"
 
         def display(self):
             """ convert object to string and print """
@@ -352,7 +352,7 @@ def seconds(sval):
         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)
+    raise RuntimeError(f"invalid input for seconds: '{sval}'")
 
 
 def milliseconds(sval):
@@ -367,7 +367,7 @@ def milliseconds(sval):
         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)
+    raise RuntimeError(f"invalid input for milliseconds: {sval}")
 
 
 def microseconds(sval):
@@ -380,7 +380,7 @@ def microseconds(sval):
         return int(sval[0:-2])
     if sval[-1:] == 's':
         return int(sval[0:-1]) * 1000 * 1000
-    raise RuntimeError("invalid input for microseconds: '%s'" % sval)
+    raise RuntimeError(f"invalid input for microseconds: '{sval}'")
 
 
 if __name__ == '__main__':
@@ -518,7 +518,7 @@ if __name__ == '__main__':
     info("Samples recorded: %d" % len(detect.samples))
 
     exceeding = detect.get("count")
-    info("Samples exceeding threshold: %d" % exceeding)
+    info(f"Samples exceeding threshold: {exceeding}")
 
     if detect.have_msr:
         finishsmi = detect.getsmicounts()
@@ -527,8 +527,8 @@ if __name__ == '__main__':
             if count > detect.initsmi[i]:
                 smis = count - detect.initsmi[i]
                 total_smis += smis
-                print("%d SMIs occured on cpu %d" % (smis, i))
-        info("SMIs during run: %d" % total_smis)
+                print(f"{smis} SMIs occured on cpu {i}")
+        info(f"SMIs during run: {total_smis}")
 
     maxlatency = int(detect.get("max"))
 
-- 
2.31.1


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

* Re: [PATCH] rt-tests: hwlatdetect.py Covert to f-strings
  2022-11-02 14:35 [PATCH] rt-tests: hwlatdetect.py Covert to f-strings Leah Leshchinsky
@ 2022-11-02 20:30 ` John Kacur
  0 siblings, 0 replies; 2+ messages in thread
From: John Kacur @ 2022-11-02 20:30 UTC (permalink / raw)
  To: Leah Leshchinsky; +Cc: linux-rt-users



On Wed, 2 Nov 2022, Leah Leshchinsky wrote:

> Add f-strings where applicable for readability.
> 
> Signed-off-by: Leah Leshchinsky <lleshchi@redhat.com>
> 
> diff --git a/src/hwlatdetect/hwlatdetect.py b/src/hwlatdetect/hwlatdetect.py
> index 9ef50f862127..3b20f664a536 100755
> --- a/src/hwlatdetect/hwlatdetect.py
> +++ b/src/hwlatdetect/hwlatdetect.py
> @@ -59,7 +59,7 @@ class DebugFS:
>          if self.premounted or self.mounted:
>              debug("not mounting debugfs")
>              return True
> -        debug("mounting debugfs at %s" % path)
> +        debug(f"mounting debugfs at {path}")
>          self.mountpoint = path
>          cmd = ['/bin/mount', '-t', 'debugfs', 'none', path]
>          self.mounted = (subprocess.call(cmd) == 0)
> @@ -90,7 +90,7 @@ class DebugFS:
>              try:
>                  val = f.readline()
>              except OSError as e:
> -                print("errno: %s" % e)
> +                print(f"errno: {e}")
>                  if e.errno == errno.EAGAIN:
>                      val = None
>                  else:
> @@ -192,13 +192,13 @@ class Detector:
>          count = 0
>          threshold = int(self.get("threshold"))
>          self.c_states_off()
> -        debug("enabling detector module (threshold: %d)" % threshold)
> +        debug(f"enabling detector module (threshold: {threshold})")
>          self.set("enable", 1)
>          while self.get("enable") == 0:
>              debug("still disabled, retrying in a bit")
>              count += 1
>              time.sleep(0.1)
> -            debug("retrying enable of detector module (%d)" % count)
> +            debug(f"retrying enable of detector module ({count})")
>              self.set("enable", 1)
>          if self.get("threshold") != threshold:
>              debug("start: threshold reset by start, fixing")
> @@ -214,7 +214,7 @@ class Detector:
>              debug("still enabled, retrying in a bit")
>              count += 1
>              time.sleep(0.1)
> -            debug("retrying disable of detector module(%d)" % count)
> +            debug(f"retrying disable of detector module({count})")
>              self.set("enable", 0)
>          self.c_states_on()
>          debug("detector module disabled")
> @@ -248,7 +248,7 @@ class Tracer(Detector):
>              self.outer = int(o)
>  
>          def __str__(self):
> -            return "ts: %s, inner:%d, outer:%d" % (self.timestamp, self.inner, self.outer)
> +            return f"ts: {self.timestamp}, inner:{self.inner}, outer:{self.outer}"
>  
>          def display(self):
>              """ convert object to string and print """
> @@ -352,7 +352,7 @@ def seconds(sval):
>          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)
> +    raise RuntimeError(f"invalid input for seconds: '{sval}'")
>  
>  
>  def milliseconds(sval):
> @@ -367,7 +367,7 @@ def milliseconds(sval):
>          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)
> +    raise RuntimeError(f"invalid input for milliseconds: {sval}")
>  
>  
>  def microseconds(sval):
> @@ -380,7 +380,7 @@ def microseconds(sval):
>          return int(sval[0:-2])
>      if sval[-1:] == 's':
>          return int(sval[0:-1]) * 1000 * 1000
> -    raise RuntimeError("invalid input for microseconds: '%s'" % sval)
> +    raise RuntimeError(f"invalid input for microseconds: '{sval}'")
>  
>  
>  if __name__ == '__main__':
> @@ -518,7 +518,7 @@ if __name__ == '__main__':
>      info("Samples recorded: %d" % len(detect.samples))
>  
>      exceeding = detect.get("count")
> -    info("Samples exceeding threshold: %d" % exceeding)
> +    info(f"Samples exceeding threshold: {exceeding}")
>  
>      if detect.have_msr:
>          finishsmi = detect.getsmicounts()
> @@ -527,8 +527,8 @@ if __name__ == '__main__':
>              if count > detect.initsmi[i]:
>                  smis = count - detect.initsmi[i]
>                  total_smis += smis
> -                print("%d SMIs occured on cpu %d" % (smis, i))
> -        info("SMIs during run: %d" % total_smis)
> +                print(f"{smis} SMIs occured on cpu {i}")
> +        info(f"SMIs during run: {total_smis}")
>  
>      maxlatency = int(detect.get("max"))
>  
> -- 

This looks fine, but there are others that could be converted too.

Signed-off-by: John Kacur <jkacur@redhat.com>


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

end of thread, other threads:[~2022-11-02 20:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-02 14:35 [PATCH] rt-tests: hwlatdetect.py Covert to f-strings Leah Leshchinsky
2022-11-02 20:30 ` John Kacur

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox