-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
arcstat: Fix integer division with python3 #12603
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Making this behave consistently with both Python 2 and 3 will be good, but not all of these values need to be integers. There's a reasonable justification that you can't have half a hit or read half a byte, but half a percent should be perfectly valid.
prettynum()
also divides by the scale, and has an explicit format string for floating point values. It seems like whether all integers or some floating point values are preferred, that function needs to be adjusted one way or another as well.
To clarify, |
@freqlabs
I agree with you that not all of these values need to be integers. In particular, I really don't like to write hit%=100 and miss=0 when there are 1000 hits and 1 miss. The idea for this PR was only to fix the wrong values when running under python3 compared to what it writes under python2; under python2 it does not (and will not, as I will detail below) write half a percent either.
What you are requesting is a bit of an overhaul - one I agree with but can't write anytime soon - because I considered printing "miss: <1" and "hit%: >99" for these cases, but
Yep!
The numbers seem to be correct (to +/- 1 unit) after restoring integer division. We simply can do better in how we present them. I'd rather fix this immediate python3 issue in this PR and open an issue for the other changes I intend to make before I take the time to write the code. Is this acceptable? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, this is ok for now.
The arcstat script requests compatibility with python2 and python3, but PEP 238 modified the / operator and results in erroneous output when run under python3. This commit replaces instances of / with //, yielding the expected result in both versions of Python. Signed-off-by: Valmiky Arquissandas <foss@kayvlim.com>
Motivation and Context
The arcstat script requests compatibility with python2 and python3.
When using python2, int/int yields an int and calculations are correct.
PEP 238 modified this behavior in python3: int/int yields a float, and results in erroneous output when running under options like
arcstat -a 3
."Erroneous output" includes cases where hits + miss < reads, or hit% is 1.0K instead of 100, or hit%=99 and 0 misses.
Description
This PR replaces instances of
/
with//
, yielding the expected result in both versions of Python.How Has This Been Tested?
Since this a utility script, it was tested on my machine by running the utility and verifying that its results make sense.
I also inserted debug prints to peek the internal values, but removed them on the commit.
Types of changes
Checklist:
Signed-off-by
.