-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
include/types: format decimal numbers with decimal factor #19117
Conversation
I also changed the following based on @chardan suggestion:
|
src/include/types.h
Outdated
@@ -337,15 +337,46 @@ inline ostream& operator<<(ostream& out, const prettybyte_t& b) | |||
return out << b.v << " bytes"; | |||
} | |||
|
|||
namespace { |
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.
Yay! Anonymous namespaces are generally more expressive than "static".
src/include/types.h
Outdated
const int index, const uint64_t mult) | ||
{ | ||
char buffer[32]; | ||
char u = " KMGTPE"[index]; |
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.
Is the leading space intentional? (This may deserve a comment.)
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.
The namespace opens a new block so I indented everything in it. Not correct?
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.
Sorry, I should have been specific-- I meant the one in the string in line 345. Looking at it again, I see that you're using the index to select from the array, so it almost certainly is.
jenkins retest this please |
Anything blocking this @gregsfortytwo @liewegas ? |
Hmm, should we get pedantic here and add the 'i' (e.g. GiB instead of GB) for the 1024 units? |
The thing that worries me about this is that it's totally unclear to the user which is being used unless they've read the source. Currently we're consistently using powers of 2 at least. |
I'd be ok with this.
Well maybe not totally unclear. This was actually reported by a user who expected bytes to use powers of 2 but counts (like object counts) to use powers of 10. Imho this is a reasonable assumption and could in any case be a reasonable convention. I'm also happy to send an email to the lists to see what people think. |
An email to ceph-devel and ceph-users with the specific proposal would be great! Thanks |
How about we go with two new macros that entirely replace the old si_t:
that way it's painfully obvious from the code which the programmer is using. (Suggestions for a more compact name welcome!) |
We should also update src/common/strtol.cc helpers to parse Ki Mi etc suffixes (and possibly rename the functions that have "si" in the name since that's not very accurate any more) |
Sounds all good to me. Will alter PR accordingly. |
3caf7b4
to
97fb318
Compare
Ok I replaced Also I would propose to replace the pretty print types |
97fb318
to
cf96b41
Compare
oh and I forgot about |
aside: why is 12.2KiB incorrect? Because 2/10ths of 1024 isn't a whole number of bytes? |
Sounds good! I don't think we need to worry too much about output.. anything that relies on stable formatting should be consuming the json/xml output, not anything rendered. |
src/include/types.h
Outdated
}; | ||
|
||
inline ostream& operator<<(ostream& out, const si_t& b) | ||
inline ostream& operator<<(ostream& out, const dec_u_t& b) |
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.
looks like dec_u and bin_u implementations are swapped
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.
yes, thx.
src/include/types.h
Outdated
uint64_t n = b.v; | ||
uint64_t mult = 1; | ||
int index = 0; | ||
const char* u[] = {" ", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB"}; |
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.
hmm, is this always going to be B (bytes)? I guess so?
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.
yes bin_u_t
should only be used for bits and bytes. I haven't encountered a place where bits are printed so adding the unit seemed reasonable. Will add comments to the structs.
Sorry that was a little unclear. The old pretty* structs always printed say 12kB (without anything past the decimal point) whereas |
cf96b41
to
eb6962a
Compare
Regarding Also for the pretty print structs I'm wondering if these should be named |
I'm good with si_u_t and iec_u_t. For the latter, though, since it's always bytes, maybe it should just be bytes_u_t or bytes_t? The parsing change makes sense, though we probably want a different helper that does strict SI units that we use for non-bytes-based config options? |
5a669ed
to
2fd3850
Compare
OK I added |
src/common/strtol.cc
Outdated
@@ -16,6 +16,7 @@ | |||
|
|||
#include <climits> | |||
#include <limits> | |||
#include <math.h> |
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.
Prefer C++ inclusion with , because it will place things into the std:: namespace.
src/common/strtol.cc
Outdated
{ | ||
std::string s(str); | ||
if (s.empty()) { | ||
*err = "strict_sistrtoll: value not specified"; | ||
*err = "strict_iecstrtoll: value not specified"; |
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.
The name of the function no longer matches.
2fd3850
to
059b89e
Compare
24f909d
to
cd566d0
Compare
Signed-off-by: Jan Fajerski <jfajerski@suse.com>
As the option represents a byte count, TYPE_SIZE is appropriate and the correct IEC unit prefixes will be parsed. Signed-off-by: Jan Fajerski <jfajerski@suse.com>
cd566d0
to
f931942
Compare
errStr << "The option value '" << str << "' contains invalid digits"; | ||
*err = errStr.str(); | ||
return 0; | ||
} |
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.
this code is broken for string of hex number
commit "include/types: format decimal numbers with decimal factor" breaks parsing of hex number string |
Note: this PR broke RBD test cases (and upgrade:luminous-x test cases in the luminous branch). |
... for future reference, if a PR touches something in RBD-land, it really should undergo an RBD suite run |
Addressing failing RBD test cases under PR #21564 |
Until now bytes and objects were formatted using si_t which used 1024 as
the factor to pretty print large numbers. For object counts a factor of
1000 is better.
Fixes: http://tracker.ceph.com/issues/22095
Signed-off-by: Jan Fajerski jfajerski@suse.com