-
Notifications
You must be signed in to change notification settings - Fork 351
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from Furisto/info-cmd
Add info command
- Loading branch information
Showing
9 changed files
with
167 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use std::{collections::HashMap, path::PathBuf}; | ||
|
||
use anyhow::{anyhow, Result}; | ||
use procfs::process::Process; | ||
|
||
use super::controller_type::CONTROLLERS; | ||
|
||
pub fn list_subsystem_mount_points() -> Result<HashMap<String, PathBuf>> { | ||
let mut mount_paths = HashMap::with_capacity(CONTROLLERS.len()); | ||
|
||
for controller in CONTROLLERS { | ||
if let Ok(mount_point) = get_subsystem_mount_points(&controller.to_string()) { | ||
mount_paths.insert(controller.to_string(), mount_point); | ||
} | ||
} | ||
|
||
Ok(mount_paths) | ||
} | ||
|
||
pub fn get_subsystem_mount_points(subsystem: &str) -> Result<PathBuf> { | ||
Process::myself()? | ||
.mountinfo()? | ||
.into_iter() | ||
.find(|m| { | ||
if m.fs_type == "cgroup" { | ||
// Some systems mount net_prio and net_cls in the same directory | ||
// other systems mount them in their own diretories. This | ||
// should handle both cases. | ||
if subsystem == "net_cls" { | ||
return m.mount_point.ends_with("net_cls,net_prio") | ||
|| m.mount_point.ends_with("net_prio,net_cls") | ||
|| m.mount_point.ends_with("net_cls"); | ||
} else if subsystem == "net_prio" { | ||
return m.mount_point.ends_with("net_cls,net_prio") | ||
|| m.mount_point.ends_with("net_prio,net_cls") | ||
|| m.mount_point.ends_with("net_prio"); | ||
} | ||
|
||
if subsystem == "cpu" { | ||
return m.mount_point.ends_with("cpu,cpuacct") | ||
|| m.mount_point.ends_with("cpu"); | ||
} | ||
} | ||
m.mount_point.ends_with(&subsystem) | ||
}) | ||
.map(|m| m.mount_point) | ||
.ok_or_else(|| anyhow!("could not find mountpoint for {}", subsystem)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ mod io; | |
pub mod manager; | ||
mod memory; | ||
mod pids; | ||
pub mod util; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use std::path::PathBuf; | ||
|
||
use anyhow::{anyhow, Result}; | ||
use procfs::process::Process; | ||
|
||
pub fn get_unified_mount_point() -> Result<PathBuf> { | ||
Process::myself()? | ||
.mountinfo()? | ||
.into_iter() | ||
.find(|m| m.fs_type == "cgroup2") | ||
.map(|m| m.mount_point) | ||
.ok_or_else(|| anyhow!("could not find mountpoint for unified")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters