[PATCH v2 1/3] eal: add function rte_size_to_str
Morten Brørup
mb at smartsharesystems.com
Tue Mar 11 17:21:14 CET 2025
> + return snprintf(buf, buf_size, "%.*f%c%s", precision,
> + (double)count / powi, *prefix, use_iec ? "i" : "");
I prefer a space between the number and the postfix (if a postfix is present), e.g. "1.23 M", so when followed by the unit, it becomes "1.23 Mbit/s" rather than "1.23M bit/s".
> +/**
> + * Converts the uint64_t value provided to a human-readable string.
> + * It null-terminates the string, truncating the data if needed.
Please add some examples showing the output formatting.
E.g.: "123 M", "12.3 M",
"12 M", " 12 M" or "12.0 M",
"1.00 ", " 1.00", or " 1", or something else?
> + *
> + * @param buf
> + * Buffer to write the string to.
> + * @param buf_size
> + * Size of the buffer.
> + * @param count
> + * Number to convert.
> + * @param use_iec
> + * If true, use IEC units (1024-based), otherwise use SI units
> (1000-based).
> + * @return
> + * Number of characters written (not including the null-
> terminator),
> + * or that would have been required when the buffer is too small.
> + */
> +int
> +rte_size_to_str(char *buf, int buf_size,
> + uint64_t count, bool use_iec);
> +
More information about the dev
mailing list