现在用户态每个应用会统计其消耗时间

ch5
zhangxinyu 2 years ago
parent 907d13e263
commit a0a0167af0

@ -11,7 +11,7 @@ const BS: u8 = 0x08u8;
use alloc::string::String; use alloc::string::String;
use user_lib::{ print, println, waitpid}; use user_lib::{ print, println, waitpid};
use user_lib::syscall::{sys_exec, sys_yield, sys_fork}; use user_lib::syscall::{sys_exec, sys_yield, sys_fork, sys_get_time};
use user_lib::user_console::getchar; use user_lib::user_console::getchar;
@ -32,6 +32,8 @@ pub fn main() -> i32 {
println!(""); println!("");
if !line.is_empty() { if !line.is_empty() {
line.push('\0'); line.push('\0');
let mut st = sys_get_time();
let pid = sys_fork(); let pid = sys_fork();
if pid == 0 { if pid == 0 {
// child process // child process
@ -46,7 +48,7 @@ pub fn main() -> i32 {
let mut exit_code: i32 = 0; let mut exit_code: i32 = 0;
let exit_pid = waitpid(pid as usize, &mut exit_code); let exit_pid = waitpid(pid as usize, &mut exit_code);
assert_eq!(pid, exit_pid); assert_eq!(pid, exit_pid);
println!("Shell: Process {} exited with code {}", pid, exit_code); println!("Shell: Process {} exited with code {}, use time: {}ms", pid, exit_code, sys_get_time()-st);
} }
line.clear(); line.clear();
} }

Loading…
Cancel
Save