Realign cache/memory size & bandwidth on line 3-6 for better readability. Add a new flag in printf to add a space between number in unit in %k mode

This commit is contained in:
Sam Demeulemeester 2022-04-08 03:21:18 +02:00 committed by Sam Demeulemeester
parent 5580f7562d
commit 1afcd08951
3 changed files with 37 additions and 24 deletions

View File

@ -42,28 +42,28 @@
prints(1, 20, str)
#define display_l1_cache_size(size) \
printf(2, 10, "%kB", (uintptr_t)(size))
printf(2, 9, "%6kB", (uintptr_t)(size));
#define display_l2_cache_size(size) \
printf(3, 10, "%kB", (uintptr_t)(size))
printf(3, 9, "%6kB", (uintptr_t)(size));
#define display_l3_cache_size(size) \
printf(4, 10, "%kB", (uintptr_t)(size))
#define display_l1_cache_speed(size) \
printf(2, 19, "%kB/s", (uintptr_t)(size))
#define display_l2_cache_speed(size) \
printf(3, 19, "%kB/s", (uintptr_t)(size))
#define display_l3_cache_speed(size) \
printf(4, 19, "%kB/s", (uintptr_t)(size))
#define display_ram_speed(size) \
printf(5, 19, "%kB/s", (uintptr_t)(size))
printf(4, 9, "%6kB", (uintptr_t)(size));
#define display_memory_size(size) \
printf(5, 10, "%kB", (uintptr_t)(size))
printf(5, 9, "%6kB", (uintptr_t)(size));
#define display_l1_cache_speed(size) \
printf(2, 18, "%S6kB/s", (uintptr_t)(size))
#define display_l2_cache_speed(size) \
printf(3, 18, "%S6kB/s", (uintptr_t)(size))
#define display_l3_cache_speed(size) \
printf(4, 18, "%S6kB/s", (uintptr_t)(size))
#define display_ram_speed(size) \
printf(5, 18, "%S6kB/s", (uintptr_t)(size))
#define display_dmi_mb(sys_ma, sys_sku) \
dmicol = prints(23, dmicol, sys_man); \

View File

@ -148,7 +148,7 @@ int printx(int row, int col, uintptr_t value, int field_length, bool pad, bool l
return print_in_field(row, col, buffer, -length, field_length, left);
}
int printk(int row, int col, uintptr_t value, int field_length, bool pad, bool left)
int printk(int row, int col, uintptr_t value, int field_length, bool pad, bool left, bool add_space)
{
static const char suffix[4] = { 'K', 'M', 'G', 'T' };
@ -186,6 +186,11 @@ int printk(int row, int col, uintptr_t value, int field_length, bool pad, bool l
int length = 0;
buffer[length++] = suffix[scale];
if(add_space) {
buffer[length++] = ' ';
}
if (fract_length > 0) {
length += int_to_dec_str(&buffer[length], fract, fract_length, fract_length);
buffer[length++] = '.';
@ -219,13 +224,18 @@ int vprintf(int row, int col, const char *fmt, va_list args)
continue;
}
bool pad = false;
bool left = false;
bool pad = false;
bool left = false;
bool add_space = false;
int length = 0;
if (*fmt == '-') {
left = true;
fmt++;
}
if (*fmt == 'S') {
add_space = true;
fmt++;
}
if (*fmt == '0') {
pad = !left;
fmt++;
@ -263,7 +273,7 @@ int vprintf(int row, int col, const char *fmt, va_list args)
col = printx(row, col, va_arg(args, uintptr_t), length, pad, left);
break;
case 'k':
col = printk(row, col, va_arg(args, uintptr_t), length, pad, left);
col = printk(row, col, va_arg(args, uintptr_t), length, pad, left, add_space);
break;
}
fmt++;

View File

@ -52,11 +52,13 @@ int printx(int row, int col, uintptr_t value, int length, bool pad, bool left);
/**
* Prints a K<unit> value on screen starting at location (row,col) in a field of
* at least length characters, optionally padding the number with leading zeros,
* and optionally left-justifying instead of right-justifying in the field. The
* value is shown to 3 significant figures in the nearest K/M/G/T units. Returns
* the next column after the formatted value.
* optionally left-justifying instead of right-justifying in the field, and
* optionnaly adding a space between number and unit. The value is shown to
* 3 significant figures in the nearest K/M/G/T units. Returns the next column
* after the formatted value.
*/
int printk(int row, int col, uintptr_t value, int length, bool pad, bool left);
int printk(int row, int col, uintptr_t value, int length,
bool pad, bool left, bool add_space);
/**
* Emulates the standard printf function. Printing starts at location (row,col).
@ -64,6 +66,7 @@ int printk(int row, int col, uintptr_t value, int length, bool pad, bool left);
* The conversion flags supported are:
* - left justify
* 0 pad with leading zeros
* S add space between number and unit (k specifier only)
*
* The conversion specifiers supported are:
* c character (int type)