resource: memory: Add MEMORY_ATTR_SWAP_TOTAL and MEMORY_ATTR_SWAP_FREE attributes 88/275688/3 submit/tizen/20220530.230210
authorSung-hun Kim <sfoon.kim@samsung.com>
Mon, 30 May 2022 06:59:21 +0000 (15:59 +0900)
committerSung-hun Kim <sfoon.kim@samsung.com>
Mon, 30 May 2022 07:04:52 +0000 (16:04 +0900)
Change-Id: I8f6e3ff274c429fe2e5d2f9378ea4e8ae18dccaf
Signed-off-by: Sung-hun Kim <sfoon.kim@samsung.com>
lib/resource-monitor/resource-monitor.h
src/resource/resource-memory.c

index 4644d96..5bfbb3f 100644 (file)
@@ -86,6 +86,8 @@ extern "C" {
 #define MEMORY_ATTR_CACHED                     BIT(4)  /* DATA_TYPE_UINT64 */
 #define MEMORY_ATTR_CMA_TOTAL                  BIT(5)  /* DATA_TYPE_UINT64 */
 #define MEMORY_ATTR_CMA_FREE                   BIT(6)  /* DATA_TYPE_UINT64 */
+#define MEMORY_ATTR_SWAP_TOTAL                 BIT(7)  /* DATA_TYPE_UINT64 */
+#define MEMORY_ATTR_SWAP_FREE                  BIT(8)  /* DATA_TYPE_UINT64 */
 
 /* Battery Resource */
 #define BATTERY_ATTR_CAPACITY                  BIT(0)  /* DATA_TYPE_INT */
index f0b8782..48c627d 100644 (file)
@@ -38,6 +38,7 @@
 #define PROC_MEM_INFO_BUFFER "Buffers"
 #define PROC_MEM_INFO_CACHED "Cached"
 #define PROC_MEM_INFO_CMA_FREE "CmaFree"
+#define PROC_MEM_INFO_SWAP_FREE "SwapFree"
 
 static int memory_get_cma_total(u_int64_t *val)
 {
@@ -57,6 +58,24 @@ static int memory_get_cma_total(u_int64_t *val)
        return 0;
 }
 
+static int memory_get_swap_total(u_int64_t *val)
+{
+       static u_int64_t swap_total = 0;
+       int ret;
+
+       if (!swap_total) {
+               ret = kernel_get_memory_info("SwapTotal", &swap_total);
+               if (ret < 0) {
+                       _E("failed to get system SWAP total memory\n");
+                       return -EINVAL;
+               }
+       }
+
+       *val = swap_total;
+
+       return 0;
+}
+
 static int memory_get_memory_info(const struct resource *res,
                                const struct resource_attribute *attr,
                                void *data)
@@ -89,6 +108,12 @@ static int memory_get_memory_info(const struct resource *res,
        case MEMORY_ATTR_CMA_FREE:
                ret = kernel_get_memory_info(PROC_MEM_INFO_CMA_FREE, val);
                break;
+       case MEMORY_ATTR_SWAP_TOTAL:
+               ret = memory_get_swap_total(val);
+               break;
+       case MEMORY_ATTR_SWAP_FREE:
+               ret = kernel_get_memory_info(PROC_MEM_INFO_SWAP_FREE, val);
+               break;
        default:
                _E("wrong memory resource attribute\n");
                ret = -EINVAL;
@@ -149,6 +174,20 @@ static const struct resource_attribute memory_attrs[] = {
                .ops    = {
                        .get = memory_get_memory_info,
                }
+       }, {
+               .name   = "MEMORY_ATTR_SWAP_TOTAL",
+               .id     = MEMORY_ATTR_SWAP_TOTAL,
+               .type   = DATA_TYPE_UINT64,
+               .ops    = {
+                       .get = memory_get_memory_info,
+               }
+       }, {
+               .name   = "MEMORY_ATTR_SWAP_FREE",
+               .id     = MEMORY_ATTR_SWAP_FREE,
+               .type   = DATA_TYPE_UINT64,
+               .ops    = {
+                       .get = memory_get_memory_info,
+               }
        },
 };