()
| 90 | } |
| 91 | |
| 92 | fn run_memory_analysis() { |
| 93 | // Wait for gc |
| 94 | axtask::yield_now(); |
| 95 | cleanup_task_tables(); |
| 96 | clear_elf_cache(); |
| 97 | |
| 98 | ax_println!( |
| 99 | "Alive tasks: {:?}", |
| 100 | tasks().iter().map(|it| it.id_name()).collect::<Vec<_>>() |
| 101 | ); |
| 102 | |
| 103 | let from = STAMPED_GENERATION.load(Ordering::SeqCst); |
| 104 | let to = axalloc::current_generation(); |
| 105 | |
| 106 | let mut allocations: BTreeMap<MemoryCategory, Vec<Layout>> = BTreeMap::new(); |
| 107 | axalloc::allocations_in(from..to, |info| { |
| 108 | let category = MemoryCategory::new(&info.backtrace); |
| 109 | allocations.entry(category).or_default().push(info.layout); |
| 110 | }); |
| 111 | let mut allocations = allocations |
| 112 | .into_iter() |
| 113 | .map(|(category, layouts)| { |
| 114 | let total_size = layouts.iter().map(|l| l.size()).sum::<usize>(); |
| 115 | (category, layouts, total_size) |
| 116 | }) |
| 117 | .collect::<Vec<_>>(); |
| 118 | allocations.sort_by_key(|it| cmp::Reverse(it.2)); |
| 119 | if !allocations.is_empty() { |
| 120 | ax_println!("==========================="); |
| 121 | ax_println!("Memory usage:"); |
| 122 | for (category, layouts, total_size) in allocations { |
| 123 | ax_println!( |
| 124 | " {} bytes, {} allocations, {:?}, {category}", |
| 125 | total_size, |
| 126 | layouts.len(), |
| 127 | layouts[0], |
| 128 | ); |
| 129 | } |
| 130 | ax_println!("=========================="); |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | pub(crate) struct MemTrack; |
| 135 |
no test coverage detected