Struct Client

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

Interface to access kernel taskstats API through the netlink socket.

Implementations§

Source§

impl Client

Source

pub fn open() -> Result<Self>

Open netlink socket against kernel and create a new instance of Client

§Errors
  • when netlink socket initialization failed
  • when kernel doesn’t offer family id for taskstats
Source

pub fn pid_stats(&self, tid: u32) -> Result<TaskStats>

Obtain taskstats for given task ID (e.g. single thread of a multithreaded process)

§Arguments
  • tid - Kernel task ID (“pid”, “tid” and “task” are used interchangeably and refer to the standard Linux task defined by struct task_struct)
§Return
  • TaskStats storing the target task’s stats
§Errors
  • when netlink socket failed
  • when kernel responded error
  • when the returned data couldn’t be interpreted
Source

pub fn tgid_stats(&self, tgid: u32) -> Result<TaskStats>

Obtain taskstats for given thread group ID (e.g. cumulated statistics of a multithreaded process)

§Arguments
  • tgid - Kernel thread group ID (“tgid”, “process” and “thread group” are used interchangeably and refer to the traditional Unix process)
§Return
  • TaskStats storing the target thread group’s aggregated stats
§Errors
  • when netlink socket failed
  • when kernel responded error
  • when the returned data couldn’t be interpreted
Source

pub fn register_cpumask(&self, cpu_mask: &str) -> Result<()>

Register listener with the specific cpumask

§Arguments
  • cpu_mask - cpumask is specified as an ascii string of comma-separated cpu ranges e.g. to listen to exit data from cpus 1,2,3,5,7,8 the cpumask would be “1-3,5,7-8”.
Source

pub fn deregister_cpumask(&self, cpu_mask: &str) -> Result<()>

Deregister listener with the specific cpumask If userspace forgets to deregister interest in cpus before closing the listening socket, the kernel cleans up its interest set over time. However, for the sake of efficiency, an explicit deregistration is advisable.

§Arguments
  • cpu_mask - cpumask is specified as an ascii string of comma-separated cpu ranges e.g. to listen to exit data from cpus 1,2,3,5,7,8 the cpumask would be “1-3,5,7-8”.
Source

pub fn listen_registered(&self) -> Result<Vec<TaskStats>>

Listen registered cpumask’s. If no messages are available at the socket, the receive call wait for a message to arrive, unless the socket is nonblocking.

§Return
  • Ok(Vec<TaskStats>): vector with stats messages. If the current task is NOT the last one in its thread group, only one message is returned in the vector. However, if it is the last task, an additional element containing the per-thread group ID (tgid) statistics is also included. This additional element sums up the statistics for all threads within the thread group, both past and present
Source

pub fn set_rx_buf_sz<T>(&self, payload: T) -> Result<()>

Set receiver buffer size in bytes (SO_RCVBUF socket option, see socket(7))

§Arguments
  • payload - buffer size in bytes. The kernel doubles this value (to allow space for bookkeeping overhead). The default value is set by the /proc/sys/net/core/rmem_default file, and the maximum allowed value is set by the /proc/sys/net/core/rmem_max file. The minimum (doubled) value for this option is 256.
Source

pub fn get_rx_buf_sz(&self) -> Result<usize>

Get receiver buffer size in bytes (SO_RCVBUF socket option, see socket(7))

§Return
  • usize buffer size in bytes. Kernel returns doubled value, that have been set using [set_rx_buf_sz]
Source

pub fn send(&self, taskstats_cmd: u16, data: &[u8]) -> Result<()>

Auto Trait Implementations§

§

impl Freeze for Client

§

impl RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl UnwindSafe for Client

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.