MCPcopy Create free account
hub / github.com/Starry-OS/StarryOS / run_memory_analysis

Function run_memory_analysis

api/src/vfs/dev/memtrack.rs:92–132  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

90}
91
92fn 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
134pub(crate) struct MemTrack;
135

Callers 1

write_atMethod · 0.85

Calls 5

cleanup_task_tablesFunction · 0.85
clear_elf_cacheFunction · 0.85
loadMethod · 0.80
pushMethod · 0.80
is_emptyMethod · 0.80

Tested by

no test coverage detected