From 5c156b4999ba6d99816cf4e23a6c7635772f7a1b Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Mon, 6 Jan 2025 14:33:20 +0100 Subject: [PATCH] tools/litex_client: Display size on Bytes/KB/MB/GB in Memory Regions. --- litex/tools/litex_client.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/litex/tools/litex_client.py b/litex/tools/litex_client.py index 3718d1449a..b199148af7 100644 --- a/litex/tools/litex_client.py +++ b/litex/tools/litex_client.py @@ -282,6 +282,19 @@ def gen_xadc_data(get_cls, n): # Memory. # ------- + def convert_size(size_bytes): + """ + Convert the size from bytes to a more human-readable format. + """ + if size_bytes < 1024: + return f"{size_bytes} Bytes" + elif size_bytes < 1024**2: + return f"{size_bytes / 1024:.2f} KB" + elif size_bytes < 1024**3: + return f"{size_bytes / (1024 ** 2):.2f} MB" + else: + return f"{size_bytes / (1024 ** 3):.2f} GB" + def read_memory_chunk(base, length): """Reads `length` bytes from `base` address (word-aligned).""" if length <= 0: @@ -412,7 +425,7 @@ def led_callback(sender): with dpg.table_row(): dpg.add_text(f"{region_name}") dpg.add_text(f"0x{region_obj.base:08X}") - dpg.add_text(f"{region_obj.size}") + dpg.add_text(f"{convert_size(region_obj.size)}") dpg.add_text(f"{region_obj.type}") # Memory Read.