From 1b4cf33ce8020b54403f4e8b0fc12c033e1d5d97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=B3=E5=85=89=E5=B0=91=E5=B9=B4?= <849317537@qq.com> Date: Sat, 10 Aug 2024 03:41:34 +0000 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=90=AF=E5=8A=A8=E7=94=A8?= =?UTF-8?q?=E6=97=B6=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index ae043c5..204e35d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,9 +1,10 @@ -use std::{io, fs, fmt, os, path, process}; +use std::{io, fs, fmt, os, path, process, time}; use io::Read; use fmt::Display; use os::fd::{AsFd, AsRawFd}; use os::unix::{fs::PermissionsExt, process::CommandExt}; use path::{Path, PathBuf}; +use std::sync::OnceLock; use nix::sched::{clone, CloneCb, CloneFlags, setns}; use nix::sys::{signal::{kill, Signal}, wait::{waitpid, WaitPidFlag}}; @@ -25,6 +26,8 @@ static INFO_FILE: &str = "info.toml"; static mut STACK: [u8; 1024*1024*1] = [0; 1024*1024*1]; static CLONE_FLAG: i32 = 0b1101100000000100000000000000000; // CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWPID | CLONE_NEWIPC | CLONE_NEWNET; +static START_T: OnceLock = OnceLock::new(); + #[derive(Parser, Debug)] #[command(version, about, long_about = None)] struct RockerArgs { @@ -348,6 +351,7 @@ fn start(is_wait: bool, cb: CloneCb, clong_flags: CloneFlags, container_id: &Str break; } } + println!("启动用时: {}ms", START_T.get().unwrap().elapsed().as_millis()); // wait if is_wait { @@ -611,6 +615,9 @@ fn stop_container(containers_id: &str, is_remove: bool) -> Result<()> { fn main() -> Result<()>{ + START_T.get_or_init(|| { + time::Instant::now() + }); let mut args = RockerArgs::parse(); if args.image.is_some() || args.restart.is_some() { let volume_path;