move func

This commit is contained in:
mii443
2024-10-17 08:06:41 +00:00
parent acdbb28448
commit d618ea6ea0

View File

@ -56,6 +56,8 @@ impl CGroup {
cgroup_root.join(&self.path) cgroup_root.join(&self.path)
} }
// cgroup files read
pub fn get_controllers(&self) -> Result<Vec<Controller>, std::io::Error> { pub fn get_controllers(&self) -> Result<Vec<Controller>, std::io::Error> {
self.inner_get_controllers("cgroup.controllers") self.inner_get_controllers("cgroup.controllers")
} }
@ -83,16 +85,6 @@ impl CGroup {
self.get_u32_list("cgroup.threads") self.get_u32_list("cgroup.threads")
} }
fn get_u32_list(&self, name: &str) -> Result<Vec<u32>, std::io::Error> {
let procs = self
.read(name)?
.lines()
.map(|proc| u32::from_str(proc.trim()).unwrap())
.collect();
Ok(procs)
}
pub fn get_stat(&self) -> Result<CGroupStat, std::io::Error> { pub fn get_stat(&self) -> Result<CGroupStat, std::io::Error> {
let stat = self.read("cgroup.stat")?; let stat = self.read("cgroup.stat")?;
@ -107,6 +99,16 @@ impl CGroup {
self.get_limit_value("cgroup.max.descendants") self.get_limit_value("cgroup.max.descendants")
} }
fn get_u32_list(&self, name: &str) -> Result<Vec<u32>, std::io::Error> {
let procs = self
.read(name)?
.lines()
.map(|proc| u32::from_str(proc.trim()).unwrap())
.collect();
Ok(procs)
}
fn get_limit_value<T>(&self, name: &str) -> Result<CGroupLimitValue<T>, std::io::Error> fn get_limit_value<T>(&self, name: &str) -> Result<CGroupLimitValue<T>, std::io::Error>
where where
T: FromStr, T: FromStr,