This is an archive of the discontinued LLVM Phabricator instance.

Support: Add llvm::format_memory_size to convert number of bytes to human readable string.
Needs ReviewPublic

Authored by marsupial on Jul 11 2017, 5:41 PM.

Details

Reviewers
ruiu
Summary

Adds ability to write suffixed values instead of number of bytes

Diff Detail

Event Timeline

marsupial created this revision.Jul 11 2017, 5:41 PM
marsupial updated this revision to Diff 106126.Jul 11 2017, 5:43 PM

Fix typo in documentation.

ruiu edited edge metadata.Jul 11 2017, 6:00 PM

You can use SI prefixes (i.e. K/M/G/T/etc.) with other units than M, so combining the two and call it FormattedMemory doesn't sound like a good idea. In addition to that, SI prefixes are not correct as they represents powers of 10 instead of powers of 2.

How about adding FormattedBinaryPrefix class which prints out Ki/Mi/Gi/... for 2^10/2^20/2^30/.... ? For Ki/Mi/Gi, see https://en.wikipedia.org/wiki/Binary_prefix.

I appreciate the differences, but this is specifically to output an amount of memory in a human readable form.
Using KiB, MiB, etc may be pedantically correct, but it limits the usefulness of this to format text for a user who may have little knowledge of the differences between SI and IEC suffixes.
Every operating system I'm aware of does it this way and having output correlate to how the OS reports memory is more important.

@ruiu
What about an optional argument to specific IEC suffixes.
Using IEC by default is fine by me, just that there is a way to not do so.

I agree the name is probably too general, but format_binary_prefix is a bit obtuse.
What about format_memory_size instead?

Added support for IEC, SI, and Customary output.

ruiu added a comment.Jul 13 2017, 3:54 PM

I'd like to listen to other people as to Mi/Ki/Gi or M/K/G.

marsupial retitled this revision from Support: Add llvm::format_memory to convert number of bytes to human readable string. to Support: Add llvm::format_memory_size to convert number of bytes to human readable string..Jul 18 2017, 8:53 AM
marsupial edited the summary of this revision. (Show Details)