From daf7c86c01b17de2705a8410691c7b13693a7878 Mon Sep 17 00:00:00 2001 From: Jim Warner Date: Thu, 7 Sep 2017 00:00:00 -0500 Subject: [PATCH] library: add delta values with swap too, api As an oversight, delta values for SWAP amounts weren't included in the 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 --- proc/meminfo.c | 14 +++++++++++++- proc/meminfo.h | 7 ++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/proc/meminfo.c b/proc/meminfo.c index a03afe66..3fc3b36d 100644 --- a/proc/meminfo.c +++ b/proc/meminfo.c @@ -233,6 +233,11 @@ MEM_set(SWAP_FREE, ul_int, SwapFree) MEM_set(SWAP_TOTAL, ul_int, SwapTotal) 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 MEM_set #undef HST_set @@ -358,13 +363,18 @@ static struct { { RS(SWAP_TOTAL), 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 ... { NULL, NULL } }; /* please note, * 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 RS @@ -646,6 +656,8 @@ static int meminfo_read_failed ( if (mHr(SwapFree) < mHr(SwapTotal)) mHr(derived_swap_used) = mHr(SwapTotal) - mHr(SwapFree); + else + mHr(derived_swap_used) = 0; return 0; #undef mHr diff --git a/proc/meminfo.h b/proc/meminfo.h index 673d0414..1e363846 100644 --- a/proc/meminfo.h +++ b/proc/meminfo.h @@ -126,7 +126,12 @@ enum meminfo_item { MEMINFO_SWAP_CACHED, // ul_int MEMINFO_SWAP_FREE, // 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 };