mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-06-13 07:32:23 -07:00
moved memory and count string formatters to the main layer and
replaced str8_from_memory_size with more accurate data size units
This commit is contained in:
+111
-11
@@ -565,21 +565,121 @@ try_s64_from_str8_c_rules(String8 string, S64 *x){
|
||||
//- rjf: integer -> string
|
||||
|
||||
internal String8
|
||||
str8_from_memory_size(Arena *arena, U64 z){
|
||||
String8 result = {0};
|
||||
if (z < KB(1)){
|
||||
result = push_str8f(arena, "%llu b", z);
|
||||
str8_from_memory_size(Arena *arena, U64 size)
|
||||
{
|
||||
String8 result;
|
||||
|
||||
if(size < KB(1))
|
||||
{
|
||||
result = push_str8f(arena, "%llu Bytes", size);
|
||||
}
|
||||
else if (z < MB(1)){
|
||||
result = push_str8f(arena, "%llu.%02llu Kb", z/KB(1), ((100*z)/KB(1))%100);
|
||||
else if(size < MB(1))
|
||||
{
|
||||
result = push_str8f(arena, "%llu.%02llu KiB", size / KB(1), ((size * 100) / KB(1)) % 100);
|
||||
}
|
||||
else if (z < GB(1)){
|
||||
result = push_str8f(arena, "%llu.%02llu Mb", z/MB(1), ((100*z)/MB(1))%100);
|
||||
else if(size < GB(1))
|
||||
{
|
||||
result = push_str8f(arena, "%llu.%02llu MiB", size / MB(1), ((size * 100) / MB(1)) % 100);
|
||||
}
|
||||
else{
|
||||
result = push_str8f(arena, "%llu.%02llu Gb", z/GB(1), ((100*z)/GB(1))%100);
|
||||
else if(size < TB(1))
|
||||
{
|
||||
result = push_str8f(arena, "%llu.%02llu GiB", size / GB(1), ((size * 100) / GB(1)) % 100);
|
||||
}
|
||||
return(result);
|
||||
else
|
||||
{
|
||||
result = push_str8f(arena, "%llu.%02llu TiB", size / TB(1), ((size * 100) / TB(1)) % 100);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
internal String8
|
||||
str8_from_count(Arena *arena, U64 count)
|
||||
{
|
||||
String8 result;
|
||||
|
||||
if(count < 1 * 1000)
|
||||
{
|
||||
result = push_str8f(arena, "%llu", count);
|
||||
}
|
||||
else if(count < 1000000)
|
||||
{
|
||||
U64 frac = ((count * 100) / 1000) % 100;
|
||||
if(frac > 0)
|
||||
{
|
||||
result = push_str8f(arena, "%llu.%02lluK", count / 1000, frac);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = push_str8f(arena, "%lluK", count / 1000);
|
||||
}
|
||||
}
|
||||
else if(count < 1000000000)
|
||||
{
|
||||
U64 frac = ((count * 100) / 1000000) % 100;
|
||||
if(frac > 0)
|
||||
{
|
||||
result = push_str8f(arena, "%llu.%02lluM", count / 1000000, frac);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = push_str8f(arena, "%lluM", count / 1000000);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
U64 frac = ((count * 100) * 1000000000) % 100;
|
||||
if(frac > 0)
|
||||
{
|
||||
result = push_str8f(arena, "%llu.%02lluB", count / 1000000000, frac);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = push_str8f(arena, "%lluB", count / 1000000000, frac);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
internal String8
|
||||
str8_from_bits_u32(Arena *arena, U32 x)
|
||||
{
|
||||
U8 c0 = 'a' + ((x >> 28) & 0xf);
|
||||
U8 c1 = 'a' + ((x >> 24) & 0xf);
|
||||
U8 c2 = 'a' + ((x >> 20) & 0xf);
|
||||
U8 c3 = 'a' + ((x >> 16) & 0xf);
|
||||
U8 c4 = 'a' + ((x >> 12) & 0xf);
|
||||
U8 c5 = 'a' + ((x >> 8) & 0xf);
|
||||
U8 c6 = 'a' + ((x >> 4) & 0xf);
|
||||
U8 c7 = 'a' + ((x >> 0) & 0xf);
|
||||
String8 result = push_str8f(arena, "%c%c%c%c%c%c%c%c", c0, c1, c2, c3, c4, c5, c6, c7);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal String8
|
||||
str8_from_bits_u64(Arena *arena, U64 x)
|
||||
{
|
||||
U8 c0 = 'a' + ((x >> 60) & 0xf);
|
||||
U8 c1 = 'a' + ((x >> 56) & 0xf);
|
||||
U8 c2 = 'a' + ((x >> 52) & 0xf);
|
||||
U8 c3 = 'a' + ((x >> 48) & 0xf);
|
||||
U8 c4 = 'a' + ((x >> 44) & 0xf);
|
||||
U8 c5 = 'a' + ((x >> 40) & 0xf);
|
||||
U8 c6 = 'a' + ((x >> 36) & 0xf);
|
||||
U8 c7 = 'a' + ((x >> 32) & 0xf);
|
||||
U8 c8 = 'a' + ((x >> 28) & 0xf);
|
||||
U8 c9 = 'a' + ((x >> 24) & 0xf);
|
||||
U8 ca = 'a' + ((x >> 20) & 0xf);
|
||||
U8 cb = 'a' + ((x >> 16) & 0xf);
|
||||
U8 cc = 'a' + ((x >> 12) & 0xf);
|
||||
U8 cd = 'a' + ((x >> 8) & 0xf);
|
||||
U8 ce = 'a' + ((x >> 4) & 0xf);
|
||||
U8 cf = 'a' + ((x >> 0) & 0xf);
|
||||
String8 result = push_str8f(arena,
|
||||
"%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",
|
||||
c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, ca, cb, cc, cd, ce, cf);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal String8
|
||||
|
||||
@@ -239,7 +239,10 @@ internal B32 try_u64_from_str8_c_rules(String8 string, U64 *x);
|
||||
internal B32 try_s64_from_str8_c_rules(String8 string, S64 *x);
|
||||
|
||||
//- rjf: integer -> string
|
||||
internal String8 str8_from_memory_size(Arena *arena, U64 z);
|
||||
internal String8 str8_from_memory_size(Arena *arena, U64 size);
|
||||
internal String8 str8_from_count(Arena *arena, U64 count);
|
||||
internal String8 str8_from_bits_u32(Arena *arena, U32 x);
|
||||
internal String8 str8_from_bits_u64(Arena *arena, U64 x);
|
||||
internal String8 str8_from_u64(Arena *arena, U64 u64, U32 radix, U8 min_digits, U8 digit_group_separator);
|
||||
internal String8 str8_from_s64(Arena *arena, S64 s64, U32 radix, U8 min_digits, U8 digit_group_separator);
|
||||
|
||||
|
||||
@@ -136,46 +136,6 @@ str8_list_push_many(Arena *arena, String8List *list, U64 count)
|
||||
return arr;
|
||||
}
|
||||
|
||||
internal String8
|
||||
str8_from_bits_u32(Arena *arena, U32 x)
|
||||
{
|
||||
U8 c0 = 'a' + ((x >> 28) & 0xf);
|
||||
U8 c1 = 'a' + ((x >> 24) & 0xf);
|
||||
U8 c2 = 'a' + ((x >> 20) & 0xf);
|
||||
U8 c3 = 'a' + ((x >> 16) & 0xf);
|
||||
U8 c4 = 'a' + ((x >> 12) & 0xf);
|
||||
U8 c5 = 'a' + ((x >> 8) & 0xf);
|
||||
U8 c6 = 'a' + ((x >> 4) & 0xf);
|
||||
U8 c7 = 'a' + ((x >> 0) & 0xf);
|
||||
String8 result = push_str8f(arena, "%c%c%c%c%c%c%c%c", c0, c1, c2, c3, c4, c5, c6, c7);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal String8
|
||||
str8_from_bits_u64(Arena *arena, U64 x)
|
||||
{
|
||||
U8 c0 = 'a' + ((x >> 60) & 0xf);
|
||||
U8 c1 = 'a' + ((x >> 56) & 0xf);
|
||||
U8 c2 = 'a' + ((x >> 52) & 0xf);
|
||||
U8 c3 = 'a' + ((x >> 48) & 0xf);
|
||||
U8 c4 = 'a' + ((x >> 44) & 0xf);
|
||||
U8 c5 = 'a' + ((x >> 40) & 0xf);
|
||||
U8 c6 = 'a' + ((x >> 36) & 0xf);
|
||||
U8 c7 = 'a' + ((x >> 32) & 0xf);
|
||||
U8 c8 = 'a' + ((x >> 28) & 0xf);
|
||||
U8 c9 = 'a' + ((x >> 24) & 0xf);
|
||||
U8 ca = 'a' + ((x >> 20) & 0xf);
|
||||
U8 cb = 'a' + ((x >> 16) & 0xf);
|
||||
U8 cc = 'a' + ((x >> 12) & 0xf);
|
||||
U8 cd = 'a' + ((x >> 8) & 0xf);
|
||||
U8 ce = 'a' + ((x >> 4) & 0xf);
|
||||
U8 cf = 'a' + ((x >> 0) & 0xf);
|
||||
String8 result = push_str8f(arena,
|
||||
"%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",
|
||||
c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, ca, cb, cc, cd, ce, cf);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal String8Node *
|
||||
str8_list_pop_front(String8List *list)
|
||||
{
|
||||
@@ -190,55 +150,6 @@ str8_list_pop_front(String8List *list)
|
||||
return node;
|
||||
}
|
||||
|
||||
internal String8
|
||||
str8_from_memory_size2(Arena *arena, U64 size)
|
||||
{
|
||||
String8 result;
|
||||
if (size < KB(1)) {
|
||||
result = push_str8f(arena, "%llu Bytes", size);
|
||||
} else if (size < MB(1)) {
|
||||
result = push_str8f(arena, "%llu.%02llu KiB", size / KB(1), ((size * 100) / KB(1)) % 100);
|
||||
} else if (size < GB(1)) {
|
||||
result = push_str8f(arena, "%llu.%02llu MiB", size / MB(1), ((size * 100) / MB(1)) % 100);
|
||||
} else if (size < TB(1)) {
|
||||
result = push_str8f(arena, "%llu.%02llu GiB", size / GB(1), ((size * 100) / GB(1)) % 100);
|
||||
} else {
|
||||
result = push_str8f(arena, "%llu.%02llu TiB", size / TB(1), ((size * 100) / TB(1)) % 100);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
internal String8
|
||||
str8_from_count(Arena *arena, U64 count)
|
||||
{
|
||||
String8 result;
|
||||
if (count < 1000) {
|
||||
result = push_str8f(arena, "%llu", count);
|
||||
} else if (count < 1000000) {
|
||||
U64 frac = ((count * 100) / 1000) % 100;
|
||||
if (frac) {
|
||||
result = push_str8f(arena, "%llu.%02lluK", count / 1000, frac);
|
||||
} else {
|
||||
result = push_str8f(arena, "%lluK", count / 1000);
|
||||
}
|
||||
} else if (count < 1000000000) {
|
||||
U64 frac = ((count * 100) / 1000000) % 100;
|
||||
if (frac) {
|
||||
result = push_str8f(arena, "%llu.%02lluM", count / 1000000, frac);
|
||||
} else {
|
||||
result = push_str8f(arena, "%lluM", count / 1000000);
|
||||
}
|
||||
} else {
|
||||
U64 frac = ((count * 100) * 1000000000) % 100;
|
||||
if (frac) {
|
||||
result = push_str8f(arena, "%llu.%02lluB", count / 1000000000, frac);
|
||||
} else {
|
||||
result = push_str8f(arena, "%lluB", count / 1000000000, frac);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
internal U64
|
||||
hash_from_str8(String8 string)
|
||||
{
|
||||
|
||||
@@ -20,14 +20,8 @@ internal U64 str8_list_push_pad_front(Arena *arena, String8List *list,
|
||||
internal String8List str8_list_arr_concat(String8List *v, U64 count);
|
||||
internal String8Node * str8_list_push_many(Arena *arena, String8List *list, U64 count);
|
||||
|
||||
internal String8 str8_from_bits_u32(Arena *arena, U32 x);
|
||||
internal String8 str8_from_bits_u64(Arena *arena, U64 x);
|
||||
|
||||
// TODO: remove
|
||||
internal String8Node * str8_list_pop_front(String8List *list);
|
||||
|
||||
internal String8 str8_from_memory_size2(Arena *arena, U64 size);
|
||||
internal String8 str8_from_count(Arena *arena, U64 count);
|
||||
|
||||
internal U64 hash_from_str8(String8 string);
|
||||
|
||||
|
||||
+4
-4
@@ -3018,8 +3018,8 @@ lnk_log_size_breakdown(LNK_SectionTable *st, LNK_SymbolTable *symtab)
|
||||
U64 pe_opt_header_size = lnk_file_size_from_chunk_ref(sect_id_map, pe_opt_header_chunk->ref);
|
||||
U64 pe_directories_size = lnk_file_size_from_chunk_ref(sect_id_map, pe_directories_chunk->ref);
|
||||
|
||||
String8 code_size_str = str8_from_memory_size2(scratch.arena, code_size);
|
||||
String8 data_size_str = str8_from_memory_size2(scratch.arena, data_size);
|
||||
String8 code_size_str = str8_from_memory_size(scratch.arena, code_size);
|
||||
String8 data_size_str = str8_from_memory_size(scratch.arena, data_size);
|
||||
|
||||
String8List output_list; MemoryZeroStruct(&output_list);
|
||||
str8_list_pushf(scratch.arena, &output_list, "--- Image Size Breakdown -------------------------------------------------------");
|
||||
@@ -3640,7 +3640,7 @@ lnk_run(int argc, char **argv)
|
||||
for (U64 i = 0; i < obj_node_arr.count; ++i) {
|
||||
input_size += obj_node_arr.v[i].data.data.size;
|
||||
}
|
||||
String8 input_size_string = str8_from_memory_size2(scratch.arena, input_size);
|
||||
String8 input_size_string = str8_from_memory_size(scratch.arena, input_size);
|
||||
lnk_log(LNK_Log_InputObj, "[ Obj Input Size %S ]", input_size_string);
|
||||
}
|
||||
|
||||
@@ -3717,7 +3717,7 @@ lnk_run(int argc, char **argv)
|
||||
for (U64 i = 0; i < lib_arr.count; ++i) {
|
||||
input_size += lib_arr.v[i].data.data.size;
|
||||
}
|
||||
String8 input_size_string = str8_from_memory_size2(scratch.arena, input_size);
|
||||
String8 input_size_string = str8_from_memory_size(scratch.arena, input_size);
|
||||
lnk_log(LNK_Log_InputObj, "[ Lib Input Size %S ]", input_size_string);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -396,9 +396,9 @@ lnk_make_code_view_input(TP_Context *tp, TP_Arena *tp_arena, String8List lib_dir
|
||||
total_debug_p_size += chunk->data->u.leaf.size;
|
||||
}
|
||||
}
|
||||
String8 total_debug_s_size_string = str8_from_memory_size2(scratch.arena, total_debug_s_size);
|
||||
String8 total_debug_t_size_string = str8_from_memory_size2(scratch.arena, total_debug_t_size);
|
||||
String8 total_debug_p_size_string = str8_from_memory_size2(scratch.arena, total_debug_p_size);
|
||||
String8 total_debug_s_size_string = str8_from_memory_size(scratch.arena, total_debug_s_size);
|
||||
String8 total_debug_t_size_string = str8_from_memory_size(scratch.arena, total_debug_t_size);
|
||||
String8 total_debug_p_size_string = str8_from_memory_size(scratch.arena, total_debug_p_size);
|
||||
if (lnk_get_log_status(LNK_Log_Debug)) {
|
||||
lnk_log(LNK_Log_Debug, "[Total .debug$S Input Size %S]", total_debug_s_size_string);
|
||||
lnk_log(LNK_Log_Debug, "[Total .debug$T Input Size %S]", total_debug_t_size_string);
|
||||
|
||||
+2
-2
@@ -57,7 +57,7 @@ internal void
|
||||
lnk_log_read(String8 path, U64 size)
|
||||
{
|
||||
Temp scratch = scratch_begin(0,0);
|
||||
String8 size_str = str8_from_memory_size2(scratch.arena, size);
|
||||
String8 size_str = str8_from_memory_size(scratch.arena, size);
|
||||
lnk_log(LNK_Log_IO_Read, "Read from \"%S\" %S", path, size_str);
|
||||
scratch_end(scratch);
|
||||
}
|
||||
@@ -195,7 +195,7 @@ lnk_write_data_list_to_file_path(String8 path, String8List data)
|
||||
if (is_written) {
|
||||
if (lnk_get_log_status(LNK_Log_IO_Write)) {
|
||||
Temp scratch = scratch_begin(0,0);
|
||||
String8 size_str = str8_from_memory_size2(scratch.arena, data.total_size);
|
||||
String8 size_str = str8_from_memory_size(scratch.arena, data.total_size);
|
||||
lnk_log(LNK_Log_IO_Write, "File \"%S\" %S written", path, size_str);
|
||||
scratch_end(scratch);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user