Display memory usage

This commit is contained in:
jaby 2023-07-26 21:49:47 +02:00
parent 23000d1d17
commit 5fcb0c8330
3 changed files with 33 additions and 8 deletions

View File

@ -82,7 +82,7 @@
"", "",
"--help", "--help",
"--list -o ../Tests/Test_Planschbecken psx bin-cue ../Tests/ISO_Planschbecken.xml", "--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": "", "default": "",
"description": "Argument options to pass to cargo run" "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> { 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) 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)) .gauge_style(Style::default().fg(Color::White).bg(Color::Black).add_modifier(Modifier::BOLD))
.line_set(symbols::line::THICK) .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> { fn create_exit_message<'a>() -> Paragraph<'a> {
@ -222,7 +227,8 @@ pub struct ConsoleUIData {
} }
impl 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> { pub fn new(memory_map: &MemoryMap) -> Result<ConsoleUIData, Error> {
let mut ui_data = ConsoleUIData::default(); let mut ui_data = ConsoleUIData::default();
@ -231,9 +237,16 @@ impl ConsoleUIData {
Ok(ui_data) 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(()) Ok(())
} }
} }

View File

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