library: improve/normalize an interface, <MEMINFO> api
This represents the refinement of this interface after the <stat> API was redesigned. We now follow a pattern of 'get' for single item retrieval & 'select' for when multiple items are desired, with just 1 function call. And again following the <stat> lead this interface now provides for delta values encompassing most items. The reason I went cuckoo nuts with those deltas is because they are essentially free. At the cost of a little RAM and just one memcpy there's no other price to be paid. Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
parent
5ec5002b0d
commit
407f1b71de
@ -16,13 +16,10 @@ global:
|
|||||||
procps_linux_version;
|
procps_linux_version;
|
||||||
procps_loadavg;
|
procps_loadavg;
|
||||||
procps_meminfo_new;
|
procps_meminfo_new;
|
||||||
procps_meminfo_read;
|
|
||||||
procps_meminfo_ref;
|
procps_meminfo_ref;
|
||||||
procps_meminfo_unref;
|
procps_meminfo_unref;
|
||||||
procps_meminfo_get;
|
procps_meminfo_get;
|
||||||
procps_meminfo_getstack;
|
procps_meminfo_select;
|
||||||
procps_meminfo_stack_fill;
|
|
||||||
procps_meminfo_stack_alloc;
|
|
||||||
procps_ns_get_name;
|
procps_ns_get_name;
|
||||||
procps_ns_get_id;
|
procps_ns_get_id;
|
||||||
procps_ns_read_pid;
|
procps_ns_read_pid;
|
||||||
|
1242
proc/meminfo.c
1242
proc/meminfo.c
File diff suppressed because it is too large
Load Diff
157
proc/meminfo.h
157
proc/meminfo.h
@ -1,9 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* meminfo - Memory statistics part of procps
|
* libprocps - Library to read proc filesystem
|
||||||
*
|
|
||||||
* Copyright (C) 1992-1998 by Michael K. Johnson <johnsonm@redhat.com>
|
|
||||||
* Copyright (C) 1998-2003 Albert Cahalan
|
|
||||||
* Copyright (C) 2015 Craig Small <csmall@enc.com.au>
|
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
@ -23,31 +19,106 @@
|
|||||||
#ifndef PROC_MEMINFO_H
|
#ifndef PROC_MEMINFO_H
|
||||||
#define PROC_MEMINFO_H
|
#define PROC_MEMINFO_H
|
||||||
|
|
||||||
#include <features.h>
|
|
||||||
|
|
||||||
__BEGIN_DECLS
|
__BEGIN_DECLS
|
||||||
|
|
||||||
enum meminfo_item {
|
enum meminfo_item {
|
||||||
PROCPS_MEMHI_FREE, // ul_int
|
PROCPS_MEMINFO_noop, // n/a ( never altered )
|
||||||
PROCPS_MEMHI_TOTAL, // ul_int
|
PROCPS_MEMINFO_extra, // n/a ( reset to zero )
|
||||||
PROCPS_MEMHI_USED, // ul_int
|
/*
|
||||||
PROCPS_MEMLO_FREE, // ul_int
|
note: all of the following values are exressed as KiB
|
||||||
PROCPS_MEMLO_TOTAL, // ul_int
|
*/
|
||||||
PROCPS_MEMLO_USED, // ul_int
|
PROCPS_MEMINFO_MEM_ACTIVE, // ul_int
|
||||||
PROCPS_MEM_ACTIVE, // ul_int
|
PROCPS_MEMINFO_MEM_ACTIVE_ANON, // ul_int
|
||||||
PROCPS_MEM_AVAILABLE, // ul_int
|
PROCPS_MEMINFO_MEM_ACTIVE_FILE, // ul_int
|
||||||
PROCPS_MEM_BUFFERS, // ul_int
|
PROCPS_MEMINFO_MEM_ANON, // ul_int
|
||||||
PROCPS_MEM_CACHED, // ul_int
|
PROCPS_MEMINFO_MEM_AVAILABLE, // ul_int
|
||||||
PROCPS_MEM_FREE, // ul_int
|
PROCPS_MEMINFO_MEM_BOUNCE, // ul_int
|
||||||
PROCPS_MEM_INACTIVE, // ul_int
|
PROCPS_MEMINFO_MEM_BUFFERS, // ul_int
|
||||||
PROCPS_MEM_SHARED, // ul_int
|
PROCPS_MEMINFO_MEM_CACHED, // ul_int
|
||||||
PROCPS_MEM_TOTAL, // ul_int
|
PROCPS_MEMINFO_MEM_COMMIT_LIMIT, // ul_int
|
||||||
PROCPS_MEM_USED, // ul_int
|
PROCPS_MEMINFO_MEM_COMMITTED_AS, // ul_int
|
||||||
PROCPS_SWAP_FREE, // ul_int
|
PROCPS_MEMINFO_MEM_HARD_CORRUPTED, // ul_int
|
||||||
PROCPS_SWAP_TOTAL, // ul_int
|
PROCPS_MEMINFO_MEM_DIRTY, // ul_int
|
||||||
PROCPS_SWAP_USED, // ul_int
|
PROCPS_MEMINFO_MEM_FREE, // ul_int
|
||||||
PROCPS_MEM_noop, // n/a
|
PROCPS_MEMINFO_MEM_HUGE_ANON, // ul_int
|
||||||
PROCPS_MEM_stack_end // n/a
|
PROCPS_MEMINFO_MEM_HUGE_FREE, // ul_int
|
||||||
|
PROCPS_MEMINFO_MEM_HUGE_RSVD, // ul_int
|
||||||
|
PROCPS_MEMINFO_MEM_HUGE_SIZE, // ul_int
|
||||||
|
PROCPS_MEMINFO_MEM_HUGE_SURPLUS, // ul_int
|
||||||
|
PROCPS_MEMINFO_MEM_HUGE_TOTAL, // ul_int
|
||||||
|
PROCPS_MEMINFO_MEM_INACTIVE, // ul_int
|
||||||
|
PROCPS_MEMINFO_MEM_INACTIVE_ANON, // ul_int
|
||||||
|
PROCPS_MEMINFO_MEM_INACTIVE_FILE, // ul_int
|
||||||
|
PROCPS_MEMINFO_MEM_KERNEL_STACK, // ul_int
|
||||||
|
PROCPS_MEMINFO_MEM_LOCKED, // ul_int
|
||||||
|
PROCPS_MEMINFO_MEM_MAPPED, // ul_int
|
||||||
|
PROCPS_MEMINFO_MEM_NFS_UNSTABLE, // ul_int
|
||||||
|
PROCPS_MEMINFO_MEM_PAGE_TABLES, // ul_int
|
||||||
|
PROCPS_MEMINFO_MEM_SHARED, // ul_int
|
||||||
|
PROCPS_MEMINFO_MEM_SLAB, // ul_int
|
||||||
|
PROCPS_MEMINFO_MEM_SLAB_RECLAIM, // ul_int
|
||||||
|
PROCPS_MEMINFO_MEM_SLAB_UNRECLAIM, // ul_int
|
||||||
|
PROCPS_MEMINFO_MEM_TOTAL, // ul_int
|
||||||
|
PROCPS_MEMINFO_MEM_UNEVICTABLE, // ul_int
|
||||||
|
PROCPS_MEMINFO_MEM_USED, // ul_int
|
||||||
|
PROCPS_MEMINFO_MEM_VM_ALLOC_CHUNK, // ul_int
|
||||||
|
PROCPS_MEMINFO_MEM_VM_ALLOC_TOTAL, // ull_int
|
||||||
|
PROCPS_MEMINFO_MEM_VM_ALLOC_USED, // ul_int
|
||||||
|
PROCPS_MEMINFO_MEM_WRITEBACK, // ul_int
|
||||||
|
PROCPS_MEMINFO_MEM_WRITEBACK_TMP, // ul_int
|
||||||
|
|
||||||
|
PROCPS_MEMINFO_DELTA_ACTIVE, // s_int
|
||||||
|
PROCPS_MEMINFO_DELTA_ACTIVE_ANON, // s_int
|
||||||
|
PROCPS_MEMINFO_DELTA_ACTIVE_FILE, // s_int
|
||||||
|
PROCPS_MEMINFO_DELTA_ANON, // s_int
|
||||||
|
PROCPS_MEMINFO_DELTA_AVAILABLE, // s_int
|
||||||
|
PROCPS_MEMINFO_DELTA_BOUNCE, // s_int
|
||||||
|
PROCPS_MEMINFO_DELTA_BUFFERS, // s_int
|
||||||
|
PROCPS_MEMINFO_DELTA_CACHED, // s_int
|
||||||
|
PROCPS_MEMINFO_DELTA_COMMIT_LIMIT, // s_int
|
||||||
|
PROCPS_MEMINFO_DELTA_COMMITTED_AS, // s_int
|
||||||
|
PROCPS_MEMINFO_DELTA_HARD_CORRUPTED, // s_int
|
||||||
|
PROCPS_MEMINFO_DELTA_DIRTY, // s_int
|
||||||
|
PROCPS_MEMINFO_DELTA_FREE, // s_int
|
||||||
|
PROCPS_MEMINFO_DELTA_HUGE_ANON, // s_int
|
||||||
|
PROCPS_MEMINFO_DELTA_HUGE_FREE, // s_int
|
||||||
|
PROCPS_MEMINFO_DELTA_HUGE_RSVD, // s_int
|
||||||
|
PROCPS_MEMINFO_DELTA_HUGE_SIZE, // s_int
|
||||||
|
PROCPS_MEMINFO_DELTA_HUGE_SURPLUS, // s_int
|
||||||
|
PROCPS_MEMINFO_DELTA_HUGE_TOTAL, // s_int
|
||||||
|
PROCPS_MEMINFO_DELTA_INACTIVE, // s_int
|
||||||
|
PROCPS_MEMINFO_DELTA_INACTIVE_ANON, // s_int
|
||||||
|
PROCPS_MEMINFO_DELTA_INACTIVE_FILE, // s_int
|
||||||
|
PROCPS_MEMINFO_DELTA_KERNEL_STACK, // s_int
|
||||||
|
PROCPS_MEMINFO_DELTA_LOCKED, // s_int
|
||||||
|
PROCPS_MEMINFO_DELTA_MAPPED, // s_int
|
||||||
|
PROCPS_MEMINFO_DELTA_NFS_UNSTABLE, // s_int
|
||||||
|
PROCPS_MEMINFO_DELTA_PAGE_TABLES, // s_int
|
||||||
|
PROCPS_MEMINFO_DELTA_SHARED, // s_int
|
||||||
|
PROCPS_MEMINFO_DELTA_SLAB, // s_int
|
||||||
|
PROCPS_MEMINFO_DELTA_SLAB_RECLAIM, // s_int
|
||||||
|
PROCPS_MEMINFO_DELTA_SLAB_UNRECLAIM, // s_int
|
||||||
|
PROCPS_MEMINFO_DELTA_TOTAL, // s_int
|
||||||
|
PROCPS_MEMINFO_DELTA_UNEVICTABLE, // s_int
|
||||||
|
PROCPS_MEMINFO_DELTA_USED, // s_int
|
||||||
|
PROCPS_MEMINFO_DELTA_VM_ALLOC_CHUNK, // s_int
|
||||||
|
PROCPS_MEMINFO_DELTA_VM_ALLOC_TOTAL, // sl_int
|
||||||
|
PROCPS_MEMINFO_DELTA_VM_ALLOC_USED, // s_int
|
||||||
|
PROCPS_MEMINFO_DELTA_WRITEBACK, // s_int
|
||||||
|
PROCPS_MEMINFO_DELTA_WRITEBACK_TMP, // s_int
|
||||||
|
|
||||||
|
PROCPS_MEMINFO_MEMHI_FREE, // ul_int
|
||||||
|
PROCPS_MEMINFO_MEMHI_TOTAL, // ul_int
|
||||||
|
PROCPS_MEMINFO_MEMHI_USED, // ul_int
|
||||||
|
|
||||||
|
PROCPS_MEMINFO_MEMLO_FREE, // ul_int
|
||||||
|
PROCPS_MEMINFO_MEMLO_TOTAL, // ul_int
|
||||||
|
PROCPS_MEMINFO_MEMLO_USED, // ul_int
|
||||||
|
|
||||||
|
PROCPS_MEMINFO_SWAP_CACHED, // ul_int
|
||||||
|
PROCPS_MEMINFO_SWAP_FREE, // ul_int
|
||||||
|
PROCPS_MEMINFO_SWAP_TOTAL, // ul_int
|
||||||
|
PROCPS_MEMINFO_SWAP_USED // ul_int
|
||||||
};
|
};
|
||||||
|
|
||||||
struct procps_meminfo;
|
struct procps_meminfo;
|
||||||
@ -55,7 +126,10 @@ struct procps_meminfo;
|
|||||||
struct meminfo_result {
|
struct meminfo_result {
|
||||||
enum meminfo_item item;
|
enum meminfo_item item;
|
||||||
union {
|
union {
|
||||||
unsigned long ul_int;
|
signed int s_int;
|
||||||
|
signed long sl_int;
|
||||||
|
unsigned long ul_int;
|
||||||
|
unsigned long long ull_int;
|
||||||
} result;
|
} result;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -64,28 +138,25 @@ struct meminfo_stack {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
int procps_meminfo_new (struct procps_meminfo **info);
|
#define PROCPS_MEMINFO_VAL(rel_enum,type,stack) \
|
||||||
int procps_meminfo_read (struct procps_meminfo *info);
|
stack -> head [ rel_enum ] . result . type
|
||||||
|
|
||||||
int procps_meminfo_ref (struct procps_meminfo *info);
|
|
||||||
|
struct procps_meminfo;
|
||||||
|
|
||||||
|
int procps_meminfo_new (struct procps_meminfo **info);
|
||||||
|
int procps_meminfo_ref (struct procps_meminfo *info);
|
||||||
int procps_meminfo_unref (struct procps_meminfo **info);
|
int procps_meminfo_unref (struct procps_meminfo **info);
|
||||||
|
|
||||||
unsigned long procps_meminfo_get (
|
signed long procps_meminfo_get (
|
||||||
struct procps_meminfo *info,
|
struct procps_meminfo *info,
|
||||||
enum meminfo_item item);
|
enum meminfo_item item);
|
||||||
|
|
||||||
int procps_meminfo_getstack (
|
struct meminfo_stack *procps_meminfo_select (
|
||||||
struct procps_meminfo *info,
|
struct procps_meminfo *info,
|
||||||
struct meminfo_result *these);
|
enum meminfo_item *items,
|
||||||
|
int numitems);
|
||||||
int procps_meminfo_stack_fill (
|
|
||||||
struct procps_meminfo *info,
|
|
||||||
struct meminfo_stack *stack);
|
|
||||||
|
|
||||||
struct meminfo_stack *procps_meminfo_stack_alloc (
|
|
||||||
struct procps_meminfo *info,
|
|
||||||
int maxitems,
|
|
||||||
enum meminfo_item *items);
|
|
||||||
|
|
||||||
__END_DECLS
|
__END_DECLS
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user