resource: process: Add additional memory attributes 51/276451/3
authorDongwoo Lee <dwoo08.lee@samsung.com>
Thu, 16 Jun 2022 04:52:37 +0000 (13:52 +0900)
committerDongwoo Lee <dwoo08.lee@samsung.com>
Tue, 28 Jun 2022 10:56:29 +0000 (19:56 +0900)
This adds new memory attributes:
     - PROCESS_ATTR_MEM_PSS
     - PROCESS_ATTR_MEM_SWAP
     - PROCESS_ATTR_MEM_SWAP_PSS

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

index 8956376..2d52243 100644 (file)
@@ -123,6 +123,9 @@ extern "C" {
 #define PROCESS_ATTR_COMM                      BIT(6)  /* DATA_TYPE_STRING */
 #define PROCESS_ATTR_PGID                      BIT(7)  /* DATA_TYPE_INT */
 #define PROCESS_ATTR_PPID                      BIT(8)  /* DATA_TYPE_INT */
+#define PROCESS_ATTR_MEM_PSS                   BIT(9)  /* DATA_TYPE_UINT64 */
+#define PROCESS_ATTR_MEM_SWAP                  BIT(10) /* DATA_TYPE_UINT64 */
+#define PROCESS_ATTR_MEM_SWAP_PSS              BIT(11) /* DATA_TYPE_UINT64 */
 
 #define PROCESS_CTRL_TGID                      BIT(0)
 
index 052f43d..beb3db3 100644 (file)
@@ -32,6 +32,7 @@ struct process_context {
        char comm[TS_COMM_LEN];
        struct taskstats prev;
        struct taskstats curr;
+       struct proc_map_info map_info;
 
        u_int64_t prev_total_time;
        double cpu_period;
@@ -90,23 +91,33 @@ static int process_get_mem_attrs(const struct resource *res,
                return -EINVAL;
        }
 
-       curr = &ctx->curr;
-
        switch (attr->id) {
        case PROCESS_ATTR_MEM_VIRT:
+               curr = &ctx->curr;
                *mem = (curr->virtmem * 1024 * 1024) / curr->ac_stime;
                break;
        case PROCESS_ATTR_MEM_RSS:
+               curr = &ctx->curr;
                *mem = (curr->coremem * 1024 * 1024) / curr->ac_stime;
                break;
        case PROCESS_ATTR_MEM_RSS_PERCENT:
        {
                double *percent = (double *)data;
 
+               curr = &ctx->curr;
                *percent = (curr->coremem * 1024 * 1024) / curr->ac_stime;
                *percent /= ctx->total_memory * 100.0;
                break;
        }
+       case PROCESS_ATTR_MEM_PSS:
+               *mem = (u_int64_t)ctx->map_info.pss * 1024;
+               break;
+       case PROCESS_ATTR_MEM_SWAP:
+               *mem = (u_int64_t)ctx->map_info.swap * 1024;
+               break;
+       case PROCESS_ATTR_MEM_SWAP_PSS:
+               *mem = (u_int64_t)ctx->map_info.swap_pss * 1024;
+               break;
        default:
                return -EINVAL;
        }
@@ -268,6 +279,30 @@ static const struct resource_attribute process_attrs[] = {
                        .get = process_get_context_data,
                        .is_supported = resource_attr_supported_always,
                },
+       }, {
+               .name   = "PROCESS_ATTR_MEM_PSS",
+               .id     = PROCESS_ATTR_MEM_PSS,
+               .type   = DATA_TYPE_UINT64,
+               .ops    = {
+                       .get = process_get_mem_attrs,
+                       .is_supported = resource_attr_supported_always,
+               },
+       }, {
+               .name   = "PROCESS_ATTR_MEM_SWAP",
+               .id     = PROCESS_ATTR_MEM_SWAP,
+               .type   = DATA_TYPE_UINT64,
+               .ops    = {
+                       .get = process_get_mem_attrs,
+                       .is_supported = resource_attr_supported_always,
+               },
+       }, {
+               .name   = "PROCESS_ATTR_MEM_SWAP_PSS",
+               .id     = PROCESS_ATTR_MEM_SWAP_PSS,
+               .type   = DATA_TYPE_UINT64,
+               .ops    = {
+                       .get = process_get_mem_attrs,
+                       .is_supported = resource_attr_supported_always,
+               },
        },
 };
 
@@ -316,6 +351,10 @@ static int process_setup_tgid(const struct resource *res,
        if (ret < 0)
                return ret;
 
+       ret = kernel_get_thread_group_map_info(&ctx->map_info, ctx->tgid);
+       if (ret < 0)
+               return ret;
+
        memcpy(ctx->comm, ctx->curr.ac_comm, strlen(ctx->curr.ac_comm) + 1);
 
        ctx->pgid = -1;
@@ -346,6 +385,10 @@ static int process_prepare_update(struct resource *res)
        if (ret < 0)
                return ret;
 
+       ret = kernel_get_thread_group_map_info(&ctx->map_info, ctx->tgid);
+       if (ret < 0)
+               return ret;
+
        online = kernel_get_online_cpu_num();
        total_time = get_total_cpu_time();