Man page - sg_get_cpu_stats_diff_between(3)
Packages contains this manual
- sg_get_error_details(3)
- sg_vector_create(3)
- statgrab(3)
- sg_free_load_stats(3)
- sg_get_page_stats_r(3)
- sg_comp_destroy(3)
- sg_get_swap_stats_r(3)
- sg_get_cpu_stats_r(3)
- sg_init(3)
- sg_get_disk_io_stats_r(3)
- sg_get_network_io_stats(3)
- sg_free_network_io_stats(3)
- sg_set_valid_filesystems(3)
- sg_free_swap_stats(3)
- sg_get_swap_stats(3)
- sg_get_network_iface_stats(3)
- sg_get_error_arg(3)
- sg_get_disk_io_stats(3)
- sg_get_valid_filesystems(3)
- sg_internal-intro(3)
- sg_get_cpu_stats_diff(3)
- sg_strperror(3)
- sg_str_error(3)
- sg_get_cpu_stats_diff_between(3)
- sg_free_network_iface_stats(3)
- sg_vector_clear(3)
- sg_get_host_info(3)
- sg_comp_init(3)
- sg_get_page_stats_diff(3)
- sg_process_compare_size(3)
- sg_process_compare_cpu(3)
- sg_unlock_mutex(3)
- sg_fs_compare_device_name(3)
- sg_fs_compare_mnt_point(3)
- sg_free_user_stats(3)
- sg_free_host_info(3)
- sg_get_user_stats(3)
- sg_get_fs_stats_diff_between(3)
- sg_set_error(3)
- sg_get_fs_stats_diff(3)
- sg_free_mem_stats(3)
- sg_vector_compute_diff(3)
- sg_get_page_stats_diff_between(3)
- sg_vector_clone_into(3)
- sg_get_network_io_stats_diff(3)
- sg_get_network_io_stats_diff_between(3)
- sg_free_cpu_stats(3)
- sg_get_cpu_percents_r(3)
- sg_get_process_count_r(3)
- sg_get_network_iface_stats_r(3)
- sg_get_error(3)
- sg_get_fs_stats(3)
- sg_intro(3)
- sg_get_network_io_stats_r(3)
- sg_snapshot(3)
- sg_vector_clone(3)
- sg_get_mem_stats(3)
- sg_get_cpu_percents_of(3)
- sg_process_compare_pid(3)
- sg_free_page_stats(3)
- sg_get_error_errno(3)
- sg_get_process_stats_r(3)
- sg_get_process_count(3)
- sg_free_process_count(3)
- sg_process_compare_name(3)
- sg_get_mem_stats_r(3)
- sg_lock_mutex(3)
- sg_set_error_with_errno_code(3)
- libstatgrab(3)
- sg_free_stats_buf(3)
- sg_get_load_stats_r(3)
- sg_shutdown(3)
- sg_vector_resize(3)
- sg_get_page_stats(3)
- sg_get_process_count_of(3)
- sg_vector_free(3)
- sg_get_process_stats(3)
- sg_network_io_compare_name(3)
- sg_prove_vector(3)
- sg_network_iface_compare_name(3)
- sg_process_compare_gid(3)
- sg_disk_io_compare_traffic(3)
- sg_comp_get_tls(3)
- sg_disk_io_compare_name(3)
- sg_get_cpu_stats(3)
- sg_get_nelements(3)
- sg_process_compare_res(3)
- sg_drop_privileges(3)
- sg_get_load_stats(3)
- sg_get_fs_stats_r(3)
- sg_process_compare_uid(3)
- sg_global_lock(3)
- sg_free_disk_io_stats(3)
- sg_get_disk_io_stats_diff(3)
- sg_process_compare_time(3)
- sg_clear_error(3)
- sg_set_error_with_errno(3)
- sg_free_fs_stats(3)
- sg_get_cpu_percents(3)
- sg_get_user_stats_r(3)
- sg_get_host_info_r(3)
- sg_get_disk_io_stats_diff_between(3)
- sg_global_unlock(3)
apt-get install libstatgrab-dev
Manual
sg_get_cpu_stats
NAMESYNOPSIS
DESCRIPTION
RETURN VALUES
SEE ALSO
WEBSITE
NAME
sg_get_cpu_stats, sg_get_cpu_stats_r, sg_get_cpu_stats_diff, sg_get_cpu_stats_diff_between, sg_get_cpu_percents, sg_get_cpu_percents_of, sg_get_cpu_percents_r, sg_free_cpu_stats - get cpu usage
SYNOPSIS
#include <statgrab.h>
sg_cpu_percents * sg_get_cpu_percents (size_t * entries );
sg_cpu_percents * sg_get_cpu_percents_of (sg_cpu_percent_source cps , size_t * entries );
sg_cpu_percents * sg_get_cpu_percents_r (const sg_cpu_stats * whereof , size_t * entries );
void sg_free_cpu_percents (sg_cpu_percents * data );
sg_cpu_stats * sg_get_cpu_stats (size_t * entries );
sg_cpu_stats * sg_get_cpu_stats_diff (size_t * entries );
sg_cpu_stats * sg_get_cpu_stats_r (size_t * entries );
sg_cpu_stats * sg_get_cpu_stats_diff_between (const sg_cpu_stats * cpu_now , const sg_cpu_stats * cpu_last , size_t * entries );
sg_error sg_free_cpu_stats (sg_cpu_stats * data );
DESCRIPTION
These are the categories of data delivered by the cpu stats module: sg_get_cpu_stats () and sg_get_cpu_stats_r () deliver native cpu counters since the machine has been started, sg_get_cpu_stats_diff () and sg_get_cpu_stats_diff_between () deliver native cpu counters between two sg_get_cpu_stats () calls and sg_get_cpu_percents_of () and sg_get_cpu_percents_r () deliver correlated relative cpu counters (where total is 100%).
|
API Shortcut |
The sg_cpu_stats buffer received from sg_get_cpu_stats_r () and the sg_get_cpu_stats_diff_between () as well as the sg_cpu_percents buffer received from sg_get_cpu_percents_r () must be freed using sg_free_cpu_stats () or the sg_free_cpu_percents (), respectively, when not needed any more. The caller is responsible for doing it.
The value stored (the "ticks") will vary between operating systems. For example Solaris has a total of 100 per second, while Linux has substantially more. Also, different operating systems store different information - you wonβt find nice cpu on Solaris for example.
Modern systems shall provide information about the clock tick resolution by invoking sysconf(_SC_CLK_TCK).
RETURN VALUES
There are two structures returned by the CPU statistics functions.
typedef struct {
unsigned long long user;
unsigned long long kernel;
unsigned long long idle;
unsigned long long iowait;
unsigned long long swap;
unsigned long long nice;
unsigned long long total;
unsigned long
long context_switches;
unsigned long long voluntary_context_switches;
unsigned long long involuntary_context_switches;
unsigned long long syscalls;
unsigned long long interrupts;
unsigned long long soft_interrupts;
time_t systime;
} sg_cpu_stats;
typedef struct {
double user;
double kernel;
double idle;
double iowait;
double swap;
double nice;
time_t time_taken;
} sg_cpu_percents;
user kernel idle iowait swap nice total
The different CPU states.
context_switches
voluntary_context_switches
involuntary_context_switches syscalls interrupts
soft_interrupts
The different program actions on CPU.
systime time_taken
The time taken in seconds since the last call of the function, or the system time.
SEE ALSO
statgrab (3)
WEBSITE
β¨ https://libstatgrab.org/β©