2
0
mirror of https://github.com/m-labs/artiq.git synced 2024-12-25 03:08:27 +08:00

runtime: print a heap dump on out-of-memory condition.

This commit is contained in:
whitequark 2017-04-21 14:48:10 +00:00
parent fd994ceef3
commit 0e68eaa879
3 changed files with 42 additions and 5 deletions

View File

@ -2,7 +2,7 @@
#![no_std]
#![allocator]
use core::{mem, ptr, cmp};
use core::{mem, ptr, cmp, fmt};
// The minimum alignment guaranteed by the architecture.
const MIN_ALIGN: usize = 4;
@ -122,3 +122,37 @@ pub extern fn __rust_reallocate_inplace(_ptr: *mut u8, old_size: usize, _size: u
pub extern fn __rust_usable_size(size: usize, _align: usize) -> usize {
size
}
pub fn debug_dump(f: &mut fmt::Write) -> fmt::Result {
unsafe {
let mut total_busy = 0;
let mut total_idle = 0;
let mut total_meta = 0;
write!(f, "Heap view:\n")?;
let mut curr = ROOT;
while !curr.is_null() {
total_meta += mem::size_of::<Header>();
let desc = match (*curr).magic {
MAGIC_FREE => { total_idle += (*curr).size; "IDLE" },
MAGIC_BUSY => { total_busy += (*curr).size; "BUSY" },
_ => "!!!!"
};
write!(f, "{} {:p} + {:#x} + {:#x} -> {:p}\n",
desc, curr, mem::size_of::<Header>(), (*curr).size, (*curr).next)?;
match (*curr).magic {
MAGIC_FREE | MAGIC_BUSY => (),
_ => break
}
curr = (*curr).next;
}
write!(f, " === busy: {:#x} idle: {:#x} meta: {:#x} total: {:#x}\n",
total_busy, total_idle, total_meta,
total_busy + total_idle + total_meta)
}
}

View File

@ -1,5 +1,6 @@
#![no_std]
#![feature(compiler_builtins_lib, alloc, oom, repr_simd, lang_items, const_fn)]
#![feature(compiler_builtins_lib, alloc, oom, repr_simd, lang_items, const_fn,
closure_to_fn_coercion)]
extern crate compiler_builtins;
extern crate alloc;
@ -169,8 +170,10 @@ pub extern fn main() -> i32 {
alloc_artiq::seed(&mut _fheap as *mut u8,
&_eheap as *const u8 as usize - &_fheap as *const u8 as usize);
fn oom() -> ! { panic!("out of memory") }
alloc::oom::set_oom_handler(oom);
alloc::oom::set_oom_handler(|| {
alloc_artiq::debug_dump(&mut board::uart_console::Console).unwrap();
panic!("out of memory");
});
static mut LOG_BUFFER: [u8; 65536] = [0; 65536];
logger_artiq::BufferLogger::new(&mut LOG_BUFFER[..]).register(startup);

View File

@ -158,7 +158,7 @@ fn kern_recv_dotrace(reply: &kern::Message) {
&kern::LogSlice(_) => debug!("comm<-kern LogSlice(...)"),
&kern::DmaRecordAppend(data) => {
if data.len() > 100 {
debug!("comm<-kern DmaRecordAppend(...)")
debug!("comm<-kern DmaRecordAppend([_; {:#x}])", data.len())
} else {
debug!("comm<-kern {:?}", reply)
}