mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-04 00:03:54 -06:00
util/cutils: Introduce freq_to_str() to display Hertz units
Introduce freq_to_str() to convert frequency values in human friendly units using the SI units for Hertz. Suggested-by: Luc Michel <luc@lmichel.fr> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Reviewed-by: Luc Michel <luc@lmichel.fr> Message-Id: <20201012095804.3335117-2-f4bug@amsat.org>
This commit is contained in:
parent
7daf8f8d01
commit
709616c713
2 changed files with 26 additions and 0 deletions
|
@ -885,6 +885,20 @@ char *size_to_str(uint64_t val)
|
|||
return g_strdup_printf("%0.3g %sB", (double)val / div, suffixes[i]);
|
||||
}
|
||||
|
||||
char *freq_to_str(uint64_t freq_hz)
|
||||
{
|
||||
static const char *const suffixes[] = { "", "K", "M", "G", "T", "P", "E" };
|
||||
double freq = freq_hz;
|
||||
size_t idx = 0;
|
||||
|
||||
while (freq >= 1000.0 && idx < ARRAY_SIZE(suffixes)) {
|
||||
freq /= 1000.0;
|
||||
idx++;
|
||||
}
|
||||
|
||||
return g_strdup_printf("%0.3g %sHz", freq, suffixes[idx]);
|
||||
}
|
||||
|
||||
int qemu_pstrcmp0(const char **str1, const char **str2)
|
||||
{
|
||||
return g_strcmp0(*str1, *str2);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue