Display memory usage

This commit is contained in:
Jaby 2023-07-26 21:49:47 +02:00
parent 0823d38d81
commit 0ad80909f3
3 changed files with 33 additions and 8 deletions

View File

@ -82,7 +82,7 @@
"",
"--help",
"--list -o ../Tests/Test_Planschbecken psx bin-cue ../Tests/ISO_Planschbecken.xml",
"--wsl ../../../examples/PoolBox/application/bin/PSX-release/PoolBox.elf"
"--wsl -o Planschbecken.bin ../../../examples/PoolBox/application/bin/PSX-release/PoolBox.elf"
],
"default": "",
"description": "Argument options to pass to cargo run"

View File

@ -197,11 +197,16 @@ impl ConsoleUI {
}
fn create_overall_mem_gauge<'a>(highest_adr: u64) -> LineGauge<'a> {
const RAM_TOP:u64 = ConsoleUIData::HIGHEST_RAM_ADDRESS & !ConsoleUIData::RAM_BASE_ADDRESS;
let highest_adr_masked = highest_adr & !ConsoleUIData::RAM_BASE_ADDRESS;
let adr_ratio = (highest_adr_masked as f64)/RAM_TOP as f64;
LineGauge::default().block(Block::default().borders(Borders::ALL)
.title(format!("Memory Usage (0x{:x}/0x{:x})", highest_adr, ConsoleUIData::HIGHEST_RAM_ADDRESS)))
.title(format!("Memory Usage: {}% [0x{:x}/0x{:x}]", adr_ratio*100.0f64, highest_adr, ConsoleUIData::HIGHEST_RAM_ADDRESS)))
.gauge_style(Style::default().fg(Color::White).bg(Color::Black).add_modifier(Modifier::BOLD))
.line_set(symbols::line::THICK)
.ratio(highest_adr as f64/ConsoleUIData::HIGHEST_RAM_ADDRESS as f64)
.ratio(adr_ratio)
}
fn create_exit_message<'a>() -> Paragraph<'a> {
@ -222,7 +227,8 @@ pub struct ConsoleUIData {
}
impl ConsoleUIData {
pub const HIGHEST_RAM_ADDRESS:u64 = 0x80000000 + (2*1024*1024);
pub const RAM_BASE_ADDRESS:u64 = 0x80000000;
pub const HIGHEST_RAM_ADDRESS:u64 = Self::RAM_BASE_ADDRESS + (2*1024*1024);
pub fn new(memory_map: &MemoryMap) -> Result<ConsoleUIData, Error> {
let mut ui_data = ConsoleUIData::default();
@ -231,9 +237,16 @@ impl ConsoleUIData {
Ok(ui_data)
}
pub fn update(&mut self, _memory_map: &MemoryMap) -> Result<(), Error> {
pub fn update(&mut self, memory_map: &MemoryMap) -> Result<(), Error> {
fn get_last_section_end_adr(memory_map: &MemoryMap) -> u64 {
if let Some(section) = memory_map.sections.last() {
return section.adr + section.size as u64;
}
self.highest_adr = 0;
0u64
}
self.highest_adr = get_last_section_end_adr(memory_map);
Ok(())
}
}

View File

@ -11,7 +11,9 @@ struct CommandLine {
#[clap(value_parser, help="Input MAP file for scannning")]
input: PathBuf,
#[clap(long="wsl", default_value_t=false)]
use_wsl: bool
use_wsl: bool,
#[clap(short='o')]
output: Option<PathBuf>
}
pub fn main() {
@ -29,7 +31,7 @@ pub fn main() {
}
fn run_main(cmd: CommandLine) -> Result<(), Error> {
let memory_map = load_memory_map(cmd.use_wsl, cmd.input)?;
let memory_map = load_memory_map(cmd.use_wsl, cmd.input)?; dump_memory_map(cmd.output, &memory_map)?;
let rx = start_event_loop();
let terminal = setup_console()?;
let ui_data = ConsoleUIData::new(&memory_map)?;
@ -46,6 +48,16 @@ fn run_main(cmd: CommandLine) -> Result<(), Error> {
console_ui.close()
}
fn dump_memory_map(output: Option<PathBuf>, memory_map: &readmap::types::MemoryMap) -> Result<(), Error> {
if let Some(output) = output {
let output = tool_helper::open_output(Some(output))?;
readmap::dump::write(output, &memory_map)?;
}
Ok(())
}
fn start_event_loop() -> EventReceiver {
// Set up a mpsc (multiproducer, single consumer) channel to communicate between the input handler and the rendering loop.
let (tx, rx) = mpsc::channel();