Message ID | 20221110153527.553524-1-lleshchi@redhat.com |
---|---|
State | New |
Headers | show |
Series | rt-tests: hwlatdetect: Update to integer division | expand |
On Thu, 10 Nov 2022, Leah Leshchinsky wrote: > In Python 3, "/" is a float division operator, as opposed to Python 2, > which defaults to integer division. This results in an error when > calculating width, which assumes an integer. What kind of error? Is there a traceback, or merely an incorrect value? > > Update width division to integer division with the "//" operator. > > Signed-off-by: Leah Leshchinsky <lleshchi@redhat.com> > > diff --git a/src/hwlatdetect/hwlatdetect.py b/src/hwlatdetect/hwlatdetect.py > index 7b1ae646577a..929107f9c252 100755 > --- a/src/hwlatdetect/hwlatdetect.py > +++ b/src/hwlatdetect/hwlatdetect.py > @@ -454,9 +454,10 @@ if __name__ == '__main__': > > if args.window: > w = microseconds(args.window) > + width = w//2 > if w < int(detect.get("width")): > - debug(f"shrinking width to {w//2} for new window of {w}") > - detect.set("width", w/2) > + debug(f"shrinking width to {width} for new window of {w}") > + detect.set("width", width) > debug(f"window parameter = {w}") > detect.set("window", w) > debug(f"window for sampling set to {w}us") > -- Signed-off-by: John Kacur <jkacur@redhat.com>
diff --git a/src/hwlatdetect/hwlatdetect.py b/src/hwlatdetect/hwlatdetect.py index 7b1ae646577a..929107f9c252 100755 --- a/src/hwlatdetect/hwlatdetect.py +++ b/src/hwlatdetect/hwlatdetect.py @@ -454,9 +454,10 @@ if __name__ == '__main__': if args.window: w = microseconds(args.window) + width = w//2 if w < int(detect.get("width")): - debug(f"shrinking width to {w//2} for new window of {w}") - detect.set("width", w/2) + debug(f"shrinking width to {width} for new window of {w}") + detect.set("width", width) debug(f"window parameter = {w}") detect.set("window", w) debug(f"window for sampling set to {w}us")
In Python 3, "/" is a float division operator, as opposed to Python 2, which defaults to integer division. This results in an error when calculating width, which assumes an integer. Update width division to integer division with the "//" operator. Signed-off-by: Leah Leshchinsky <lleshchi@redhat.com>