Present memory usage
This commit is contained in:
parent
f21210c042
commit
9b7df3c910
|
@ -237,6 +237,6 @@ SECTIONS {
|
||||||
__bss_end = .;
|
__bss_end = .;
|
||||||
__heap_start = __heap_base;
|
__heap_start = __heap_base;
|
||||||
|
|
||||||
. = ADDR(.text) - 0x800;
|
/*. = ADDR(.text) - 0x800;*/
|
||||||
__end = .;
|
__end = .;
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,6 +70,10 @@ impl ConsoleUI {
|
||||||
Event::Input(event) => {
|
Event::Input(event) => {
|
||||||
match event.code {
|
match event.code {
|
||||||
KeyCode::Char('q') => Ok(UIState::Terminated),
|
KeyCode::Char('q') => Ok(UIState::Terminated),
|
||||||
|
KeyCode::Char('s') => {
|
||||||
|
self.menu_selection = MenuSelection::Stats;
|
||||||
|
Ok(UIState::Render)
|
||||||
|
},
|
||||||
KeyCode::Left => {
|
KeyCode::Left => {
|
||||||
self.menu_selection = self.menu_selection.prev();
|
self.menu_selection = self.menu_selection.prev();
|
||||||
Ok(UIState::Render)
|
Ok(UIState::Render)
|
||||||
|
@ -102,7 +106,7 @@ impl ConsoleUI {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render(&mut self) -> Result<(), Error> {
|
pub fn render(&mut self, data: &ConsoleUIData) -> Result<(), Error> {
|
||||||
self.terminal.draw(|frame| {
|
self.terminal.draw(|frame| {
|
||||||
Self::update_sub_frames(&mut self.main_chunks, &mut self.stats_chunks, &mut self.cur_size, frame.size());
|
Self::update_sub_frames(&mut self.main_chunks, &mut self.stats_chunks, &mut self.cur_size, frame.size());
|
||||||
|
|
||||||
|
@ -110,7 +114,7 @@ impl ConsoleUI {
|
||||||
frame.render_widget(Self::create_menu(&self.menu_selection), self.main_chunks[1]);
|
frame.render_widget(Self::create_menu(&self.menu_selection), self.main_chunks[1]);
|
||||||
match self.menu_selection {
|
match self.menu_selection {
|
||||||
MenuSelection::Stats => {
|
MenuSelection::Stats => {
|
||||||
Self::render_stats(frame, &self.stats_chunks);
|
Self::render_stats(frame, &self.stats_chunks, data);
|
||||||
},
|
},
|
||||||
MenuSelection::Quit => {
|
MenuSelection::Quit => {
|
||||||
frame.render_widget(Self::create_exit_message(), self.main_chunks[2]);
|
frame.render_widget(Self::create_exit_message(), self.main_chunks[2]);
|
||||||
|
@ -176,7 +180,7 @@ impl ConsoleUI {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_stats(frame: &mut ConsoleFrame, frames: &Vec<Rect>) {
|
fn render_stats(frame: &mut ConsoleFrame, frames: &Vec<Rect>, data: &ConsoleUIData) {
|
||||||
let content_text = Paragraph::new("<EMPTY>")
|
let content_text = Paragraph::new("<EMPTY>")
|
||||||
.style(Style::default().fg(Color::White))
|
.style(Style::default().fg(Color::White))
|
||||||
.alignment(Alignment::Center)
|
.alignment(Alignment::Center)
|
||||||
|
@ -185,18 +189,18 @@ impl ConsoleUI {
|
||||||
.style(Style::default().fg(Color::White))
|
.style(Style::default().fg(Color::White))
|
||||||
.border_type(BorderType::Plain)
|
.border_type(BorderType::Plain)
|
||||||
);
|
);
|
||||||
let mem_gauge = Self::create_overall_mem_gauge();
|
let mem_gauge = Self::create_overall_mem_gauge(data.highest_adr);
|
||||||
|
|
||||||
frame.render_widget(content_text, frames[0]);
|
frame.render_widget(content_text, frames[0]);
|
||||||
frame.render_widget(mem_gauge, frames[1]);
|
frame.render_widget(mem_gauge, frames[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_overall_mem_gauge<'a>() -> LineGauge<'a> {
|
fn create_overall_mem_gauge<'a>(highest_adr: u64) -> LineGauge<'a> {
|
||||||
|
LineGauge::default().block(Block::default().borders(Borders::ALL)
|
||||||
LineGauge::default().block(Block::default().borders(Borders::ALL).title("Progress"))
|
.title(format!("Memory Usage (0x{:x}/0x{:x})", 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(0.4)
|
.ratio(highest_adr as f64/ConsoleUIData::HIGHEST_RAM_ADDRESS as f64)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_exit_message<'a>() -> Paragraph<'a> {
|
fn create_exit_message<'a>() -> Paragraph<'a> {
|
||||||
|
@ -211,6 +215,28 @@ impl ConsoleUI {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
pub struct ConsoleUIData {
|
||||||
|
highest_adr: u64
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ConsoleUIData {
|
||||||
|
pub const HIGHEST_RAM_ADDRESS:u64 = 0x80000000 + (2*1024*1024);
|
||||||
|
|
||||||
|
pub fn new(memory_map: &MemoryMapInfo) -> Result<ConsoleUIData, Error> {
|
||||||
|
let mut ui_data = ConsoleUIData::default();
|
||||||
|
|
||||||
|
ui_data.update(memory_map)?;
|
||||||
|
Ok(ui_data)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn update(&mut self, memory_map: &MemoryMapInfo) -> Result<(), Error> {
|
||||||
|
|
||||||
|
self.highest_adr = memory_map.highest_address;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn load_memory_map(file_path: Option<PathBuf>) -> Result<MemoryMapInfo, Error> {
|
pub fn load_memory_map(file_path: Option<PathBuf>) -> Result<MemoryMapInfo, Error> {
|
||||||
readmap::scan(tool_helper::open_input(file_path)?)
|
readmap::scan(tool_helper::open_input(file_path)?)
|
||||||
}
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use crossterm::{event::{self, Event as CEvent, KeyboardEnhancementFlags, KeyEventKind, PushKeyboardEnhancementFlags}, execute, terminal};
|
use crossterm::{event::{self, Event as CEvent, KeyboardEnhancementFlags, KeyEventKind, PushKeyboardEnhancementFlags}, execute, terminal};
|
||||||
use psxreadmap::{ConsoleUI, Event, EventReceiver, Terminal, load_memory_map, UIState};
|
use psxreadmap::{ConsoleUI, ConsoleUIData, Event, EventReceiver, Terminal, load_memory_map, UIState};
|
||||||
use std::{io, path::PathBuf, sync::mpsc, thread, time::{Duration, Instant}};
|
use std::{io, path::PathBuf, sync::mpsc, thread, time::{Duration, Instant}};
|
||||||
use tool_helper::{Error, exit_with_error};
|
use tool_helper::{Error, exit_with_error};
|
||||||
use tui::backend::CrosstermBackend;
|
use tui::backend::CrosstermBackend;
|
||||||
|
@ -27,15 +27,16 @@ pub fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_main(cmd: CommandLine) -> Result<(), Error> {
|
fn run_main(cmd: CommandLine) -> Result<(), Error> {
|
||||||
let _sections = load_memory_map(Some(cmd.input))?;
|
let memory_map = load_memory_map(Some(cmd.input))?;
|
||||||
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 mut console_ui = ConsoleUI::new(rx, terminal);
|
let mut console_ui = ConsoleUI::new(rx, terminal);
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
match console_ui.update()? {
|
match console_ui.update()? {
|
||||||
UIState::Alive => (),
|
UIState::Alive => (),
|
||||||
UIState::Render => {console_ui.render()?;}
|
UIState::Render => {console_ui.render(&ui_data)?;}
|
||||||
UIState::Terminated => break
|
UIState::Terminated => break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,7 +56,7 @@ fn start_event_loop() -> EventReceiver {
|
||||||
let timeout = tick_rate.checked_sub(last_tick.elapsed()).unwrap_or_else(|| Duration::from_secs(0));
|
let timeout = tick_rate.checked_sub(last_tick.elapsed()).unwrap_or_else(|| Duration::from_secs(0));
|
||||||
if event::poll(timeout).expect("Event poll working") {
|
if event::poll(timeout).expect("Event poll working") {
|
||||||
if let CEvent::Key(key) = event::read().expect("Can read key input") {
|
if let CEvent::Key(key) = event::read().expect("Can read key input") {
|
||||||
if key.kind == KeyEventKind::Press {
|
if key.kind == KeyEventKind::Release {
|
||||||
tx.send(Event::Input(key)).expect("Can send KeyInput");
|
tx.send(Event::Input(key)).expect("Can send KeyInput");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,7 +80,7 @@ fn setup_console() -> Result<Terminal, Error> {
|
||||||
let stdout = {
|
let stdout = {
|
||||||
let mut stdout = io::stdout();
|
let mut stdout = io::stdout();
|
||||||
if let Err(_) = execute!(stdout, PushKeyboardEnhancementFlags(KeyboardEnhancementFlags::REPORT_EVENT_TYPES)) {
|
if let Err(_) = execute!(stdout, PushKeyboardEnhancementFlags(KeyboardEnhancementFlags::REPORT_EVENT_TYPES)) {
|
||||||
// When this fails it fails
|
// This fails under Windows but is required for Linux
|
||||||
}
|
}
|
||||||
stdout
|
stdout
|
||||||
};
|
};
|
||||||
|
@ -88,4 +89,50 @@ fn setup_console() -> Result<Terminal, Error> {
|
||||||
|
|
||||||
terminal.clear()?;
|
terminal.clear()?;
|
||||||
Ok(terminal)
|
Ok(terminal)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
use std::{fs::File, io::{BufWriter, Write}};
|
||||||
|
use readmap::types::{Content::*, Section};
|
||||||
|
fn _write_main(cmd: CommandLine) -> Result<(), Error> {
|
||||||
|
fn value_to_hex<T: std::fmt::UpperHex>(value: T) -> String {
|
||||||
|
return format!("0x{:X}", value);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn option_to_hex<T: std::fmt::UpperHex>(value: Option<T>) -> String {
|
||||||
|
if let Some(value) = value {
|
||||||
|
return value_to_hex(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
return String::from("<None>");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let memory_map = load_memory_map(Some(cmd.input))?;
|
||||||
|
let mut file = tool_helper::open_output_file(&PathBuf::from("./planschi.d"))?;
|
||||||
|
|
||||||
|
for section in memory_map.sections {
|
||||||
|
fn print_content(tab_level: usize, file: &mut BufWriter<File>, section: Section) -> Result<(), Error> {
|
||||||
|
for content in section.content {
|
||||||
|
match content {
|
||||||
|
Fill(fill) => {
|
||||||
|
writeln!(file, "{:>tab_level$}*fill* @{}, {}", ' ', value_to_hex(fill.adr), value_to_hex(fill.size), tab_level=tab_level*4)?;
|
||||||
|
},
|
||||||
|
Section(section) => {
|
||||||
|
writeln!(file, "{:>tab_level$} {} @{}, {}", ' ', section.name, option_to_hex(section.adr), option_to_hex(section.size), tab_level=tab_level*4)?;
|
||||||
|
print_content(tab_level + 1, file, section)?;
|
||||||
|
},
|
||||||
|
Symbol(symbol) => {
|
||||||
|
writeln!(file, "{:>tab_level$}{} @{}", ' ', symbol.name, value_to_hex(symbol.adr), tab_level=tab_level*4)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
writeln!(file, "{}: @{}, {}", section.name, option_to_hex(section.adr), option_to_hex(section.size))?;
|
||||||
|
print_content(1, &mut file, section)?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue