Skip to main content

Subsystem

Struct Subsystem 

Source
pub struct Subsystem { /* private fields */ }
Expand description

Handler of a Cpuacct subsystem.

Implementations§

Source§

impl Subsystem

Source

pub fn stat(&self) -> Result<Stat>

Reads the statistics about how much CPU time is consumed by this cgroup (in USER_HZ unit) from cpuacct.stat file. The CPU time is further divided into user and system times.

See the kernel’s documentation for more information about this field.

§Errors

Returns an error if failed to read and parse cpuacct.stat file of this cgroup.

§Examples
use std::path::PathBuf;
use controlgroup::v1::{cpuacct, Cgroup, CgroupPath, SubsystemKind};

let cgroup = cpuacct::Subsystem::new(
    CgroupPath::new(SubsystemKind::Cpuacct, PathBuf::from("students/charlie")));

let stat = cgroup.stat()?;
Source

pub fn usage(&self) -> Result<u64>

Reads the total CPU time consumed by this cgroup (in nanoseconds) from cpuacct.usage file.

See the kernel’s documentation for more information about this field.

§Errors

Returns an error if failed to read and parse cpuacct.usage file of this cgroup.

§Examples
use std::path::PathBuf;
use controlgroup::v1::{cpuacct, Cgroup, CgroupPath, SubsystemKind};

let cgroup = cpuacct::Subsystem::new(
    CgroupPath::new(SubsystemKind::Cpuacct, PathBuf::from("students/charlie")));

let usage = cgroup.usage()?;
Source

pub fn usage_all(&self) -> Result<Vec<Stat>>

Reads the per-CPU total CPU time consumed by this cgroup (in nanoseconds) from cpuacct.usage_all file. The CPU time is further divided into user and system times.

See the kernel’s documentation for more information about this field.

§Errors

Returns an error if failed to read and parse cpuacct.usage_all file of this cgroup.

§Examples
use std::path::PathBuf;
use controlgroup::v1::{cpuacct, Cgroup, CgroupPath, SubsystemKind};

let cgroup = cpuacct::Subsystem::new(
    CgroupPath::new(SubsystemKind::Cpuacct, PathBuf::from("students/charlie")));

let usage_all = cgroup.usage_all()?;
Source

pub fn usage_percpu(&self) -> Result<Vec<u64>>

Reads the per-CPU total CPU times consumed by this cgroup (in nanoseconds) from cpuacct.usage_percpu file.

See the kernel’s documentation for more information about this field.

§Errors

Returns an error if failed to read and parse cpuacct.usage_percpu file of this cgroup.

§Examples
use std::path::PathBuf;
use controlgroup::v1::{cpuacct, Cgroup, CgroupPath, SubsystemKind};

let cgroup = cpuacct::Subsystem::new(
    CgroupPath::new(SubsystemKind::Cpuacct, PathBuf::from("students/charlie")));

let usage_percpu = cgroup.usage_percpu()?;
Source

pub fn usage_percpu_sys(&self) -> Result<Vec<u64>>

Reads the per-CPU total CPU times consumed by this cgroup in the system (kernel) mode (in nanoseconds) from cpuacct.usage_percpu_sys file.

See the kernel’s documentation for more information about this field.

§Errors

Returns an error if failed to read and parse cpuacct.usage_percpu_sys file of this cgroup.

§Examples
use std::path::PathBuf;
use controlgroup::v1::{cpuacct, Cgroup, CgroupPath, SubsystemKind};

let cgroup = cpuacct::Subsystem::new(
    CgroupPath::new(SubsystemKind::Cpuacct, PathBuf::from("students/charlie")));

let usage_percpu_sys = cgroup.usage_percpu_sys()?;
Source

pub fn usage_percpu_user(&self) -> Result<Vec<u64>>

Reads the per-CPU total CPU times consumed by this cgroup in the user mode (in nanoseconds) from cpuacct.usage_percpu_user file.

See the kernel’s documentation for more information about this field.

§Errors

Returns an error if failed to read and parse cpuacct.usage_percpu_user file of this cgroup.

§Examples
use std::path::PathBuf;
use controlgroup::v1::{cpuacct, Cgroup, CgroupPath, SubsystemKind};

let cgroup = cpuacct::Subsystem::new(
    CgroupPath::new(SubsystemKind::Cpuacct, PathBuf::from("students/charlie")));

let usage_percpu_user = cgroup.usage_percpu_user()?;
Source

pub fn usage_sys(&self) -> Result<u64>

Reads the total CPU time consumed by this cgroup in the system (kernel) mode (in nanoseconds) from cpuacct.usage_sys file.

See the kernel’s documentation for more information about this field.

§Errors

Returns an error if failed to read and parse cpuacct.usage_sys file of this cgroup.

§Examples
use std::path::PathBuf;
use controlgroup::v1::{cpuacct, Cgroup, CgroupPath, SubsystemKind};

let cgroup = cpuacct::Subsystem::new(
    CgroupPath::new(SubsystemKind::Cpuacct, PathBuf::from("students/charlie")));

let usage_sys = cgroup.usage_sys()?;
Source

pub fn usage_user(&self) -> Result<u64>

Reads the total CPU time consumed by this cgroup in the user mode (in nanoseconds) from cpuacct.usage_user file.

See the kernel’s documentation for more information about this field.

§Errors

Returns an error if failed to read and parse cpuacct.usage_user file of this cgroup.

§Examples
use std::path::PathBuf;
use controlgroup::v1::{cpuacct, Cgroup, CgroupPath, SubsystemKind};

let cgroup = cpuacct::Subsystem::new(
    CgroupPath::new(SubsystemKind::Cpuacct, PathBuf::from("students/charlie")));

let usage_user = cgroup.usage_user()?;
Source

pub fn reset(&mut self) -> Result<()>

Resets the accounted CPU time of this cgroup by writing to cpuacct.usage file.

§Errors

Returns an error if failed to write to cpuacct.usage file of this cgroup.

§Examples
use std::path::PathBuf;
use controlgroup::v1::{cpuacct, Cgroup, CgroupPath, SubsystemKind};

let mut cgroup = cpuacct::Subsystem::new(
    CgroupPath::new(SubsystemKind::Cpuacct, PathBuf::from("students/charlie")));

cgroup.reset()?;

Trait Implementations§

Source§

impl Cgroup for Subsystem

Source§

fn apply(&mut self, _resources: &Resources) -> Result<()>

Does nothing as a Cpuacct subsystem is basically read-only.

Source§

fn new(path: CgroupPath) -> Self

Defines a new cgroup with a path. Read more
Source§

fn subsystem(&self) -> SubsystemKind

Returns the subsystem to which this cgroup belongs. Read more
Source§

fn path(&self) -> PathBuf

Returns the absolute path to this cgroup. Read more
Source§

fn is_root(&self) -> bool

Returns whether this cgroup is the root cgroup of a subsystem. Read more
Source§

fn root_cgroup(&self) -> Box<Self>

Returns the definition of the root cgroup for the subsystem of this cgroup. Read more
Source§

fn create(&mut self) -> Result<()>

Creates a new directory for this cgroup. Read more
Source§

fn delete(&mut self) -> Result<()>

Deletes the directory of this cgroup. Read more
Source§

fn tasks(&self) -> Result<Vec<Pid>>

Reads a list of tasks attached to this cgroup, from tasks file. The resulting tasks are represented by their thread IDs. Read more
Source§

fn add_task(&mut self, pid: impl Into<Pid>) -> Result<()>

Attaches a task to this cgroup by writing a thread ID to tasks file. Read more
Source§

fn remove_task(&mut self, pid: impl Into<Pid>) -> Result<()>

Removes a task from this cgroup by writing a thread ID to tasks file of the root cgroup. Read more
Source§

fn procs(&self) -> Result<Vec<Pid>>

Reads a list of processes attached to this cgroup, from cgroup.procs file. The resulting tasks are represented by their PIDs. Read more
Source§

fn add_proc(&mut self, pid: impl Into<Pid>) -> Result<()>

Attaches a process to this cgroup, with all threads in the same thread group at once, by writing a PID to cgroup.procs file. Read more
Source§

fn remove_proc(&mut self, pid: impl Into<Pid>) -> Result<()>

Removes a process from this cgroup, with all threads in the same thread group at once, by writing a PID to cgroup.procs file of the root cgroup. Read more
Source§

fn notify_on_release(&self) -> Result<bool>

Reads whether the system executes the executable written in release_agent file when this cgroup no longer has any task, from notify_on_release file. Read more
Source§

fn set_notify_on_release(&mut self, enable: bool) -> Result<()>

Sets whether the system executes the executable written in release_agent file when this cgroup no longer has any task, by writing to notify_on_release file. Read more
Source§

fn release_agent(&self) -> Result<String>

Reads the command to be executed when “notify on release” is triggered, i.e. this cgroup is emptied of all tasks, from release_agent file. Read more
Source§

fn set_release_agent(&mut self, agent_path: impl AsRef<[u8]>) -> Result<()>

Sets a command to be executed when “notify on release” is triggered, i.e. this cgroup is emptied of all tasks, by writing to release_agent file. Read more
Source§

fn sane_behavior(&self) -> Result<bool>

Reads whether the subsystem of this cgroup is forced to follow “sane behavior”, from cgroup.sane_behavior file. Read more
Source§

fn file_exists(&self, name: &str) -> bool

Returns whether a file with the given name exists in this cgroup. Read more
Source§

fn open_file_read(&self, name: &str) -> Result<File>

Low-level API that opens a file with read access. Read more
Source§

fn open_file_write(&mut self, name: &str) -> Result<File>

Low-level API that opens a file with write access. Read more
Source§

impl Debug for Subsystem

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.