Re: [PATCH] rt-tests: hwlatdetect.py Covert to f-strings

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On Wed, 2 Nov 2022, Leah Leshchinsky wrote:

> Add f-strings where applicable for readability.
> 
> Signed-off-by: Leah Leshchinsky <lleshchi@xxxxxxxxxx>
> 
> 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@xxxxxxxxxx>




[Index of Archives]     [RT Stable]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux