-
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
libzutil: allow to display powers of 1000 bytes #16579
base: master
Are you sure you want to change the base?
Conversation
7516b6b
to
89ef8f6
Compare
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.
There should also be a testcase for this new formatting.
This PR works when the value is a byte value, but there are other places where we use ZFS_NICENUM_1024 (perhaps incorrectly) that wont be affected. For example, the JSON code uses ZFS_NICENUM_1024 in an bunch of places: Line 9177 in ca0141f
|
Hello and thanks for the feedback @mcmilk :
Sure. Could you direct me to an existing test case that I could use as a base?
Sorry I missed that.
In this example, it seems weird to express a number of errors in powers of 1024. (I think nobody expects "100K errors" to be 100Ki = 102400 errors). Maybe a new unit like |
@jcassette - Sorry, there is currently no such test case, I thought I had seen such test. So no - it seems that this is not needed. Sorry for the noise by me. |
I suspect we historically went with the ambiguous K/M/G/T prefixes to get a more precision in the One possible solution could consist of:
I'm fine with just number 1 being tacked in this PR, but you can try to fix the other ones if you want. |
In broader context referencing PR #14598 |
@jumbi77 thanks for the heads-up on that PR. I think we may need to be even more careful about
So we may want to rename the envar to something that wouldn't be ambiguous for those cases. Like include the word "display" or "output" in the envar name or something. |
ZFS displays bytes with K/M/G/T/P/E prefixes. They represent powers of 1024 bytes, i.e. KiB, MiB, GiB, TiB, PiB, EiB. Some users may want these prefixes to represent powers of 1000 bytes, i.e. KB, MB, GB, TB, PB, EB. This adds the new unit format and allows to use such display by defining an environment variable. Signed-off-by: Julien Cassette <[email protected]>
c8adac6
to
a8980aa
Compare
I have addressed the requested changes. Ready for review. |
@@ -64,19 +65,22 @@ zfs_nicenum_format(uint64_t num, char *buf, size_t buflen, | |||
uint64_t n = num; | |||
int index = 0; | |||
const char *u; | |||
const char *units[3][7] = { | |||
const char *units[6][7] = { |
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.
Should this be?
- const char *units[6][7]
+ const char *units[4][7]
[ZFS_NICENUM_1024] = {"", "K", "M", "G", "T", "P", "E"}, | ||
[ZFS_NICENUM_BYTES] = {"B", "K", "M", "G", "T", "P", "E"}, | ||
[ZFS_NICENUM_TIME] = {"ns", "us", "ms", "s", "?", "?", "?"} | ||
[ZFS_NICENUM_TIME] = {"ns", "us", "ms", "s", "?", "?", "?"}, | ||
[ZFS_NICENUM_1000] = {"B", "K", "M", "G", "T", "P", "E"} |
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.
Just thinking ahead - can you rename ZFS_NICENUM_1000
to ZFS_NICENUM_BYTES_1000
? That way we could potentially add a SI base 1000 prefix for non-byte values, like:
[ZFS_NICENUM_1000] = {"", "K", "M", "G", "T", "P", "E"}
[ZFS_NICENUM_BYTES_1000] = {"B", "K", "M", "G", "T", "P", "E"}
I can imagine in the future that we make all non-byte values SI powers of 1000 by default. It's kind of silly that we report zpool status error counters in powers of 1024, for example.
.Bl -tag -width "ZFS_OUTPUT_BYTES_SI" | ||
.\" Shared with zfs.8 and zpool.8 | ||
.It Sy ZFS_OUTPUT_BYTES_SI | ||
Make K/M/G/T/P/E prefixes in |
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.
What do you think about rewording these lines to make it explicitly clear this is for byte values only?:
When printing byte values, make all prefixes (like KB, MB, GB, TB, PB, EB)
represent powers of 1000, not 1024.
is there anyone actually asking for such functionality? with what rationale if I may? "may want to use" is at least for me personally not really enough :) what good is it going to be if it's hidden behind an envvar nobody knows about? this is an added code, added maintenance burden one might say, but very little benefit? just because someone "may want"? ;) |
Motivation and Context
ZFS displays bytes with K/M/G/T/P/E prefixes. They represent powers of 1024 bytes, i.e. KiB, MiB, GiB, TiB, PiB, EiB.
Some users may want these prefixes to represent powers of 1000 bytes, i.e. KB, MB, GB, TB, PB, EB.
Description
This adds the new unit format and allows to use such display by defining an environment variable.
How Has This Been Tested?
Not tested. If this draft gathers interest then I will add tests.
Types of changes
Checklist:
Signed-off-by
.