Skip to content

Commit b23f7ef

Browse files
committed
feat: add some log
1 parent 67bba1f commit b23f7ef

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

src/catbox.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ fn redirect_io(option: &CatBoxOption) -> Result<(), CatBoxError> {
126126
fn set_alarm(option: &CatBoxOption) {
127127
let time_limit = (option.time_limit() as f64 / 1000.0 as f64).ceil() as c_uint;
128128
alarm::set(time_limit + 1);
129-
debug!("Set alarm {} seconds", time_limit + 1);
129+
info!("Set alarm {} seconds", time_limit + 1);
130130
}
131131

132132
/// 调用 setrlimit

src/cgroup.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use cgroups_rs::cpuacct::{CpuAcct, CpuAcctController};
66
use cgroups_rs::memory::{MemController, MemSwap, Memory};
77
use cgroups_rs::pid::PidController;
88
use cgroups_rs::{Cgroup, CgroupPid, Controller, MaxValue};
9-
use log::{debug, error, warn};
9+
use log::{debug, error, warn, info};
1010
use nix::sys::resource::{getrusage, UsageWho};
1111
use nix::sys::time::TimeVal;
1212
use nix::unistd::Pid;
@@ -33,6 +33,15 @@ impl CatBoxCgroup {
3333
pub fn new(option: &CatBoxOption, child: Pid) -> Result<Self, CatBoxError> {
3434
let hierarchy = cgroups_rs::hierarchies::auto();
3535

36+
info!(
37+
"Support cgroup subsystems: {:?}",
38+
hierarchy
39+
.subsystems()
40+
.iter()
41+
.map(|subsystem| subsystem.controller_name())
42+
.collect::<Vec<String>>()
43+
);
44+
3645
let mut enable_cpuacct = hierarchy
3746
.subsystems()
3847
.iter()
@@ -53,7 +62,7 @@ impl CatBoxCgroup {
5362

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

56-
debug!("Init cgroup {}", cgroup_name);
65+
info!("Start initializing cgroup {}", cgroup_name);
5766

5867
let builder = CgroupBuilder::new(cgroup_name.as_str());
5968
let builder = if enable_memory {
@@ -159,6 +168,8 @@ impl CatBoxCgroup {
159168
}
160169
}
161170

171+
info!("Finish initializing cgroup {}", cgroup_name);
172+
162173
// 默认回退到不使用 cgroup,force 模式下报错
163174
if !enable_cpuacct {
164175
if option.force() {

src/context/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::cmp::max;
44
use std::path::PathBuf;
55
use std::slice::Iter;
66

7+
use log::info;
78
use nix::libc::STDOUT_FILENO;
89
use nix::sys::signal::Signal;
910
use nix::unistd::{isatty, Gid, Uid};
@@ -100,6 +101,8 @@ impl CatBox {
100101
/// Run all the commands
101102
pub fn start(&mut self) -> Result<(), CatBoxError> {
102103
for option in self.options.iter() {
104+
info!("Run catbox with options: {:?}", &option);
105+
103106
let result = crate::run(&option)?;
104107
if !self.context.add_result(&option.label.clone(), result) {
105108
break;

0 commit comments

Comments
 (0)