pub struct Client { /* private fields */ }
Expand description
Interface to access kernel taskstats API through the netlink socket.
Implementations§
Source§impl Client
impl Client
Sourcepub fn open() -> Result<Self>
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
Sourcepub fn pid_stats(&self, tid: u32) -> Result<TaskStats>
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
Sourcepub fn tgid_stats(&self, tgid: u32) -> Result<TaskStats>
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
Sourcepub fn register_cpumask(&self, cpu_mask: &str) -> Result<()>
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”.
Sourcepub fn deregister_cpumask(&self, cpu_mask: &str) -> Result<()>
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”.
Sourcepub fn listen_registered(&self) -> Result<Vec<TaskStats>>
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
Sourcepub fn set_rx_buf_sz<T>(&self, payload: T) -> Result<()>
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.
Sourcepub fn get_rx_buf_sz(&self) -> Result<usize>
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]