Skip to content

Commit

Permalink
feat: add some log
Browse files Browse the repository at this point in the history
  • Loading branch information
yjl9903 committed Oct 6, 2023
1 parent 67bba1f commit b23f7ef
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/catbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ fn redirect_io(option: &CatBoxOption) -> Result<(), CatBoxError> {
fn set_alarm(option: &CatBoxOption) {
let time_limit = (option.time_limit() as f64 / 1000.0 as f64).ceil() as c_uint;
alarm::set(time_limit + 1);
debug!("Set alarm {} seconds", time_limit + 1);
info!("Set alarm {} seconds", time_limit + 1);
}

/// 调用 setrlimit
Expand Down
15 changes: 13 additions & 2 deletions src/cgroup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use cgroups_rs::cpuacct::{CpuAcct, CpuAcctController};
use cgroups_rs::memory::{MemController, MemSwap, Memory};
use cgroups_rs::pid::PidController;
use cgroups_rs::{Cgroup, CgroupPid, Controller, MaxValue};
use log::{debug, error, warn};
use log::{debug, error, warn, info};
use nix::sys::resource::{getrusage, UsageWho};
use nix::sys::time::TimeVal;
use nix::unistd::Pid;
Expand All @@ -33,6 +33,15 @@ impl CatBoxCgroup {
pub fn new(option: &CatBoxOption, child: Pid) -> Result<Self, CatBoxError> {
let hierarchy = cgroups_rs::hierarchies::auto();

info!(
"Support cgroup subsystems: {:?}",
hierarchy
.subsystems()
.iter()
.map(|subsystem| subsystem.controller_name())
.collect::<Vec<String>>()
);

let mut enable_cpuacct = hierarchy
.subsystems()
.iter()
Expand All @@ -53,7 +62,7 @@ impl CatBoxCgroup {

let cgroup_name = format!("{}/{}.{}", option.cgroup(), option.cgroup(), child.as_raw());

debug!("Init cgroup {}", cgroup_name);
info!("Start initializing cgroup {}", cgroup_name);

let builder = CgroupBuilder::new(cgroup_name.as_str());
let builder = if enable_memory {
Expand Down Expand Up @@ -159,6 +168,8 @@ impl CatBoxCgroup {
}
}

info!("Finish initializing cgroup {}", cgroup_name);

// 默认回退到不使用 cgroup,force 模式下报错
if !enable_cpuacct {
if option.force() {
Expand Down
3 changes: 3 additions & 0 deletions src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::cmp::max;
use std::path::PathBuf;
use std::slice::Iter;

use log::info;
use nix::libc::STDOUT_FILENO;
use nix::sys::signal::Signal;
use nix::unistd::{isatty, Gid, Uid};
Expand Down Expand Up @@ -100,6 +101,8 @@ impl CatBox {
/// Run all the commands
pub fn start(&mut self) -> Result<(), CatBoxError> {
for option in self.options.iter() {
info!("Run catbox with options: {:?}", &option);

let result = crate::run(&option)?;
if !self.context.add_result(&option.label.clone(), result) {
break;
Expand Down

0 comments on commit b23f7ef

Please sign in to comment.