library: add delta values with swap too, <meminfo> api

As an oversight, delta values for SWAP amounts weren't
included in the <meminfo> API. Since any runtime costs
of including them only amount to slightly more storage
this commit will simply correct the earlier oversight.

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner 2017-09-07 00:00:00 -05:00 committed by Craig Small
parent ccbd818cb4
commit daf7c86c01
2 changed files with 19 additions and 2 deletions

View File

@ -233,6 +233,11 @@ MEM_set(SWAP_FREE, ul_int, SwapFree)
MEM_set(SWAP_TOTAL, ul_int, SwapTotal) MEM_set(SWAP_TOTAL, ul_int, SwapTotal)
MEM_set(SWAP_USED, ul_int, derived_swap_used) MEM_set(SWAP_USED, ul_int, derived_swap_used)
HST_set(SWAP_DELTA_CACHED, s_int, SwapCached)
HST_set(SWAP_DELTA_FREE, s_int, SwapFree)
HST_set(SWAP_DELTA_TOTAL, s_int, SwapTotal)
HST_set(SWAP_DELTA_USED, s_int, derived_swap_used)
#undef setDECL #undef setDECL
#undef MEM_set #undef MEM_set
#undef HST_set #undef HST_set
@ -358,13 +363,18 @@ static struct {
{ RS(SWAP_TOTAL), TS(ul_int) }, { RS(SWAP_TOTAL), TS(ul_int) },
{ RS(SWAP_USED), TS(ul_int) }, { RS(SWAP_USED), TS(ul_int) },
{ RS(SWAP_DELTA_CACHED), TS(s_int) },
{ RS(SWAP_DELTA_FREE), TS(s_int) },
{ RS(SWAP_DELTA_TOTAL), TS(s_int) },
{ RS(SWAP_DELTA_USED), TS(s_int) },
// dummy entry corresponding to MEMINFO_logical_end ... // dummy entry corresponding to MEMINFO_logical_end ...
{ NULL, NULL } { NULL, NULL }
}; };
/* please note, /* please note,
* this enum MUST be 1 greater than the highest value of any enum */ * this enum MUST be 1 greater than the highest value of any enum */
enum meminfo_item MEMINFO_logical_end = MEMINFO_SWAP_USED + 1; enum meminfo_item MEMINFO_logical_end = MEMINFO_SWAP_DELTA_USED + 1;
#undef setNAME #undef setNAME
#undef RS #undef RS
@ -646,6 +656,8 @@ static int meminfo_read_failed (
if (mHr(SwapFree) < mHr(SwapTotal)) if (mHr(SwapFree) < mHr(SwapTotal))
mHr(derived_swap_used) = mHr(SwapTotal) - mHr(SwapFree); mHr(derived_swap_used) = mHr(SwapTotal) - mHr(SwapFree);
else
mHr(derived_swap_used) = 0;
return 0; return 0;
#undef mHr #undef mHr

View File

@ -126,7 +126,12 @@ enum meminfo_item {
MEMINFO_SWAP_CACHED, // ul_int MEMINFO_SWAP_CACHED, // ul_int
MEMINFO_SWAP_FREE, // ul_int MEMINFO_SWAP_FREE, // ul_int
MEMINFO_SWAP_TOTAL, // ul_int MEMINFO_SWAP_TOTAL, // ul_int
MEMINFO_SWAP_USED // ul_int MEMINFO_SWAP_USED, // ul_int
MEMINFO_SWAP_DELTA_CACHED, // s_int
MEMINFO_SWAP_DELTA_FREE, // s_int
MEMINFO_SWAP_DELTA_TOTAL, // s_int
MEMINFO_SWAP_DELTA_USED // s_int
}; };