Skip to content

Commit ef66599

Browse files
committed
更新内存占用统计方法
1 parent 6045b7e commit ef66599

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/sysapp/shell.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,19 @@ extern uint32_t phy_mem_size;
149149
static void sys_info(){
150150
cpu_t *cpu = get_cpuid();
151151

152-
uint32_t mb = get_kernel_memory_usage() / 1024;
152+
extern void* program_break;
153+
extern void* program_break_end;
154+
uint32_t bytes = get_kernel_memory_usage() + (uint32_t)program_break + (uint32_t)program_break_end;
155+
156+
extern pcb_t *running_proc_head;
157+
pcb_t *pcb = running_proc_head;
158+
while(pcb != NULL){
159+
pcb = pcb->next;
160+
if(pcb->task_level != TASK_KERNEL_LEVEL){
161+
bytes += (uint32_t)pcb->program_break + (uint32_t)pcb->program_break_end;
162+
}
163+
}
164+
int memory = (bytes > 10485760) ? bytes/1048576 : bytes/1024;
153165

154166
printk(" -*&@@@&*- \n");
155167
printk(" =&@@@@@@@@@:\033[36m-----\033[39m -----------------\n");
@@ -161,7 +173,7 @@ static void sys_info(){
161173
printk("&@@@@@+ \033[36m&@@@@@=:\033[39m@@@& Time: %s\n",get_date_time());
162174
printk("@@@@@@: \033[36m#&&&&=:\033[39m@@@@@ Console: os_terminal\n");
163175
printk("&@@@@@+ +@@@@@& Kernel: %s\n",KERNEL_NAME);
164-
printk("*@@@@@@ @@@@@@* Memory Usage: %dKB / %dMB\n",mb,(int)(phy_mem_size));
176+
printk("*@@@@@@ @@@@@@* Memory Usage: %d%s / %dMB\n",memory,bytes > 10485760 ? "MB" : "KB",(int)(phy_mem_size));
165177
printk("-@@@@@@* #@@@@@@: 32-bit operating system, x86-based processor\n");
166178
printk(" &@@@@@@*. .#@@@@@@& \n");
167179
printk(" =@@@@@@@@*---*@@@@@@@@- \n");

0 commit comments

Comments
 (0)