resource: process-group: Add additional memory attributes 81/275981/5
authorDongwoo Lee <dwoo08.lee@samsung.com>
Thu, 12 May 2022 05:45:29 +0000 (14:45 +0900)
committerDongwoo Lee <dwoo08.lee@samsung.com>
Tue, 28 Jun 2022 10:56:29 +0000 (19:56 +0900)
This adds new memory attributes:
 - PROCESS_GROUP_ATTR_MEM_PSS
 - PROCESS_GROUP_ATTR_MEM_SWAP
 - PROCESS_GROUP_ATTR_MEM_SWAP_PSS

Change-Id: I78062afa487d186489e4b9a7eea479f7b5f1be72
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
lib/resource-monitor/resource-monitor.h
src/resource/resource-process-group.c

index 5bfbb3f..8956376 100644 (file)
@@ -134,6 +134,9 @@ extern "C" {
 #define PROCESS_GROUP_ATTR_DISK_WRITE_BPS      BIT(4)  /* DATA_TYPE_UINT */
 #define PROCESS_GROUP_ATTR_MEM_VIRT            BIT(5)  /* DATA_TYPE_UINT64 */
 #define PROCESS_GROUP_ATTR_MEM_RSS             BIT(6)  /* DATA_TYPE_UINT64 */
+#define PROCESS_GROUP_ATTR_MEM_PSS             BIT(7)  /* DATA_TYPE_UINT64 */
+#define PROCESS_GROUP_ATTR_MEM_SWAP            BIT(8)  /* DATA_TYPE_UINT64 */
+#define PROCESS_GROUP_ATTR_MEM_SWAP_PSS                BIT(9)  /* DATA_TYPE_UINT64 */
 
 #define PROCESS_GROUP_CTRL_ROOT_PID            BIT(0)
 
index caab3a0..81565e0 100644 (file)
@@ -41,6 +41,9 @@ struct process_group_context {
                u_int64_t mem_virt;
                u_int32_t disk_rbps;
                u_int32_t disk_wbps;
+               u_int64_t mem_pss;
+               u_int64_t mem_swap;
+               u_int64_t mem_swap_pss;
        } info;
        u_int64_t prev_total_time;
 };
@@ -174,15 +177,20 @@ static int process_group_get_mem(const struct resource *res,
 
        switch (attr->id) {
        case PROCESS_GROUP_ATTR_MEM_RSS:
-       {
                *mem = ctx->info.mem_rss;
                break;
-       }
        case PROCESS_GROUP_ATTR_MEM_VIRT:
-       {
                *mem = ctx->info.mem_virt;
                break;
-       }
+       case PROCESS_GROUP_ATTR_MEM_PSS:
+               *mem = ctx->info.mem_pss;
+               break;
+       case PROCESS_GROUP_ATTR_MEM_SWAP:
+               *mem = ctx->info.mem_swap;
+               break;
+       case PROCESS_GROUP_ATTR_MEM_SWAP_PSS:
+               *mem = ctx->info.mem_swap_pss;
+               break;
        default:
                return -EINVAL;
        }
@@ -227,8 +235,7 @@ static const struct resource_attribute process_group_attrs[] = {
                        .get = process_group_get_pid_list,
                        .is_supported = resource_attr_supported_always,
                },
-       },
-       {
+       }, {
                .name   = "PROCESS_GROUP_ATTR_COMM_LIST",
                .id     = PROCESS_GROUP_ATTR_COMM_LIST,
                .type   = DATA_TYPE_ARRAY,
@@ -236,8 +243,7 @@ static const struct resource_attribute process_group_attrs[] = {
                        .get = process_group_get_comm_list,
                        .is_supported = resource_attr_supported_always,
                },
-       },
-       {
+       }, {
                .name   = "PROCESS_GROUP_ATTR_CPU_UTIL",
                .id     = PROCESS_GROUP_ATTR_CPU_UTIL,
                .type   = DATA_TYPE_DOUBLE,
@@ -277,6 +283,30 @@ static const struct resource_attribute process_group_attrs[] = {
                        .get = process_group_get_mem,
                        .is_supported = resource_attr_supported_always,
                },
+       }, {
+               .name   = "PROCESS_GROUP_ATTR_MEM_PSS",
+               .id     = PROCESS_GROUP_ATTR_MEM_PSS,
+               .type   = DATA_TYPE_UINT64,
+               .ops    = {
+                       .get = process_group_get_mem,
+                       .is_supported = resource_attr_supported_always,
+               },
+       }, {
+               .name   = "PROCESS_GROUP_ATTR_MEM_SWAP",
+               .id     = PROCESS_GROUP_ATTR_MEM_SWAP,
+               .type   = DATA_TYPE_UINT64,
+               .ops    = {
+                       .get = process_group_get_mem,
+                       .is_supported = resource_attr_supported_always,
+               },
+       }, {
+               .name   = "PROCESS_GROUP_ATTR_MEM_SWAP_PSS",
+               .id     = PROCESS_GROUP_ATTR_MEM_SWAP_PSS,
+               .type   = DATA_TYPE_UINT64,
+               .ops    = {
+                       .get = process_group_get_mem,
+                       .is_supported = resource_attr_supported_always,
+               },
        },
 };
 
@@ -358,6 +388,7 @@ static int update_aggr_taskstats(struct process_group_context *ctx)
 {
        struct process_info_node *node;
        struct taskstats *prev, *curr;
+       struct proc_map_info map_info;
        u_int64_t total_time;
        int online, nproc;
        double cpu_period;
@@ -399,6 +430,13 @@ static int update_aggr_taskstats(struct process_group_context *ctx)
                        continue;
                }
 
+               ret = kernel_get_thread_group_map_info(&map_info, pid);
+               if (ret < 0) {
+                       free(curr);
+                       g_hash_table_iter_remove(&iter);
+                       continue;
+               }
+
                if (cpu_period >= 1E-6) {
                        double util;
 
@@ -416,6 +454,11 @@ static int update_aggr_taskstats(struct process_group_context *ctx)
                                        / (curr->ac_etime - prev->ac_etime);
                ctx->info.disk_wbps += ((curr->write_bytes - prev->write_bytes) * 1000000)
                                        / (curr->ac_etime - prev->ac_etime);
+
+               ctx->info.mem_pss += (u_int64_t)map_info.pss * 1024;
+               ctx->info.mem_swap += (u_int64_t)map_info.swap * 1024;
+               ctx->info.mem_swap_pss += (u_int64_t)map_info.swap_pss * 1024;
+
                free(prev);
                node->prev = curr;
        }