procps/proc/stat.h
Jim Warner 6671a3a8b7 library: refactored some header file items and origins
This commit is intended as a refinement of the patches
mentioned below, where origins/sources of newlib items
were added to the header files for user documentation.

However, if those additions are to be truly effective,
along with kernel documentation (where available), the
following prerequisites must also have been satisfied:
. our identifiers closely align with linux field names
. our derived items are documented or self-documenting

Satisfying those prerequisites prompted this patch and
for these changes, kernel sources were emphasized over
available documentation (shame on me, it should always
have been so). And, while some 'new' fields were found
to be conditional, they were included unconditionally.

These changes appear more extensive than they actually
need be since I have attempted to enforce some spacing
conventions. So, I've summarize the significant things
in the sections that follow. For a proper perspective,
use: 'git diff --ignore-space-change' (good as alias).

___________________________________________ <PIDS> api
This api is unique in that there exists many different
file/directory origins subordinate to /proc/<pid>. And
our item identifiers are sometimes coerced so as to be
able to group related or similar enumerators together.

So, users needed more help relating our identifiers to
an actual documented field. Thus, we will now also add
the field names as with 'stat: delayacct_blkio_ticks'.

Each item ending with a '_C' now consistently includes
both the parent's count/time plus waited for children.

That 'RTPRIO' guy was renamed/relocated as PRIORITY_RT
since its original name is an implementation artifact.

___________________________________________ <STAT> api
The only api change was to correct a typo ('dervied').

_________________________________________ <VMSTAT> api
Even ignoring white space, this interface received the
largest number of changes. Mostly, this was because of
deficiencies in the proc(5) documentation. Recall that
this documentation already sorely lacks any substance.
Usually, just kernel releases are noted, not contents.

When compared to kernel source, that proc(5) contained
many non-existent fields and also omitted many others.

________________________________________ <MEMINFO> api
Sadly, with this api many of the changes were simply a
correction of some earlier 'human error' where several
fields where hashed then tracked but never represented
with an item enumerator in this meminfo.h header file.

_______________________________________ <SLABINFO> api
The 'SLABS' (summary) & 'SLABNODE' items were reversed
since the former are derived from the separate caches.

More significantly, those 'SLABNODE' guys were renamed
to 'SLAB' since they concern individual caches and the
concept of 'nodes' is really an implementation detail.

Also, several enumerators were changed to more closely
agree with official slabinfo(5) documentation referred
to in what we're treating as a base document: proc(5).

Lastly, while those 'SLABS' items are solely a product
of our library and not represented in slabinfo(5), the
names attempt to parallel those found as 'SLAB' items.

______________________________________ <DISKSTATS> api
One enumeration identifier was changed so as to better
reflect its relationship to that actual documentation:
'Documentation/iostats.txt', as referenced in proc(5).

Reference(s):
. 12/2018, item origins added (and commit msg history)
commit 96d59cbf46
. 01/2019, <stat> origins tweaked
commit 201e816b26

Signed-off-by: Jim Warner <james.warner@comcast.net>
2019-03-26 19:55:30 +11:00

167 lines
5.6 KiB
C

/*
* libprocps - Library to read proc filesystem
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef PROCPS_STAT_H
#define PROCPS_STAT_H
#ifdef __cplusplus
extern "C" {
#endif
enum stat_item {
STAT_noop, // ( never altered )
STAT_extra, // ( reset to zero )
// returns origin, see proc(5)
// ------- -------------------
STAT_TIC_ID, // s_int /proc/stat
STAT_TIC_NUMA_NODE, // s_int [ ID based, see: numa(3) ]
STAT_TIC_NUM_CONTRIBUTORS, // s_int [ total CPUs contributing to TIC counts ]
STAT_TIC_USER, // ull_int /proc/stat
STAT_TIC_NICE, // ull_int "
STAT_TIC_SYSTEM, // ull_int "
STAT_TIC_IDLE, // ull_int "
STAT_TIC_IOWAIT, // ull_int "
STAT_TIC_IRQ, // ull_int "
STAT_TIC_SOFTIRQ, // ull_int "
STAT_TIC_STOLEN, // ull_int "
STAT_TIC_GUEST, // ull_int "
STAT_TIC_GUEST_NICE, // ull_int "
STAT_TIC_DELTA_USER, // sl_int derived from above
STAT_TIC_DELTA_NICE, // sl_int "
STAT_TIC_DELTA_SYSTEM, // sl_int "
STAT_TIC_DELTA_IDLE, // sl_int "
STAT_TIC_DELTA_IOWAIT, // sl_int "
STAT_TIC_DELTA_IRQ, // sl_int "
STAT_TIC_DELTA_SOFTIRQ, // sl_int "
STAT_TIC_DELTA_STOLEN, // sl_int "
STAT_TIC_DELTA_GUEST, // sl_int "
STAT_TIC_DELTA_GUEST_NICE, // sl_int "
STAT_TIC_SUM_TOTAL, // ull_int derived from all except GUEST tics
STAT_TIC_SUM_IDLE, // ull_int derived from IDLE + IOWAIT + STOLEN tics
STAT_TIC_SUM_USER, // ull_int derived from USER + NICE tics
STAT_TIC_SUM_BUSY, // ull_int derived from SUM_TOTAL - SUM_IDLE tics
STAT_TIC_SUM_SYSTEM, // ull_int derived from SUM_BUSY - SUM_USER tics
STAT_TIC_SUM_DELTA_TOTAL, // sl_int derived from above
STAT_TIC_SUM_DELTA_IDLE, // sl_int "
STAT_TIC_SUM_DELTA_USER, // sl_int "
STAT_TIC_SUM_DELTA_BUSY, // sl_int "
STAT_TIC_SUM_DELTA_SYSTEM, // sl_int "
STAT_SYS_CTX_SWITCHES, // ul_int /proc/stat
STAT_SYS_INTERRUPTS, // ul_int "
STAT_SYS_PROC_BLOCKED, // ul_int "
STAT_SYS_PROC_CREATED, // ul_int "
STAT_SYS_PROC_RUNNING, // ul_int "
STAT_SYS_TIME_OF_BOOT, // ul_int "
STAT_SYS_DELTA_CTX_SWITCHES, // s_int derived from above
STAT_SYS_DELTA_INTERRUPTS, // s_int "
STAT_SYS_DELTA_PROC_BLOCKED, // s_int "
STAT_SYS_DELTA_PROC_CREATED, // s_int "
STAT_SYS_DELTA_PROC_RUNNING // s_int "
};
enum stat_reap_type {
STAT_REAP_CPUS_ONLY,
STAT_REAP_CPUS_AND_NODES
};
enum stat_sort_order {
STAT_SORT_ASCEND = +1,
STAT_SORT_DESCEND = -1
};
struct stat_result {
enum stat_item item;
union {
signed int s_int;
signed long sl_int;
unsigned long ul_int;
unsigned long long ull_int;
} result;
};
struct stat_stack {
struct stat_result *head;
};
struct stat_reap {
int total;
struct stat_stack **stacks;
};
struct stat_reaped {
struct stat_stack *summary;
struct stat_reap *cpus;
struct stat_reap *nodes;
};
#define STAT_SUMMARY_ID -11111
#define STAT_NODE_INVALID -22222
#define STAT_GET( info, actual_enum, type ) ( { \
struct stat_result *r = procps_stat_get( info, actual_enum ); \
r ? r->result . type : 0; } )
#define STAT_VAL( relative_enum, type, stack, info ) \
stack -> head [ relative_enum ] . result . type
struct stat_info;
int procps_stat_new (struct stat_info **info);
int procps_stat_ref (struct stat_info *info);
int procps_stat_unref (struct stat_info **info);
struct stat_result *procps_stat_get (
struct stat_info *info,
enum stat_item item);
struct stat_reaped *procps_stat_reap (
struct stat_info *info,
enum stat_reap_type what,
enum stat_item *items,
int numitems);
struct stat_stack *procps_stat_select (
struct stat_info *info,
enum stat_item *items,
int numitems);
struct stat_stack **procps_stat_sort (
struct stat_info *info,
struct stat_stack *stacks[],
int numstacked,
enum stat_item sortitem,
enum stat_sort_order order);
#ifdef XTRA_PROCPS_DEBUG
# include <proc/xtra-procps-debug.h>
#endif
#ifdef __cplusplus
}
#endif
#endif