lib: resource-monitor: Add attribute to get resource name 91/278691/3 submit/tizen/20220726.004630 submit/tizen/20220802.012548
authorChanwoo Choi <cw00.choi@samsung.com>
Fri, 22 Jul 2022 07:54:33 +0000 (16:54 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Wed, 27 Jul 2022 08:26:18 +0000 (17:26 +0900)
[Newly added resource attributes]
- CPU_ATTR_NAME gets CPU resource name
- BUS_ATTR_NAME gets BUS resource name
- GPU_ATTR_NAME gets GPU resource name
- DISPLAY_ATTR_NAME gets Display resource name

[Renamed resource attributes]
- PROCESS_ATTR_COMM -> PROCESS_ATTR_NAME
- PROCESS_GROUP_ATTR_COMM_LIST -> PROCESS_GROUP_ATTR_NAME_LIST

Change-Id: I3f343b3aad2345bb4145fa85ed74d6764d9b43a1
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
lib/resource-monitor/resource-monitor.h
src/resource/resource-bus.c
src/resource/resource-cpu.c
src/resource/resource-display.c
src/resource/resource-gpu.c
src/resource/resource-process-group.c
src/resource/resource-process.c

index d31e730..08d7d11 100644 (file)
@@ -55,6 +55,7 @@ extern "C" {
 #define CPU_ATTR_AVAILABLE_MIN_FREQ            BIT(3)  /* DATA_TYPE_INT */
 #define CPU_ATTR_AVAILABLE_MAX_FREQ            BIT(4)  /* DATA_TYPE_INT */
 #define CPU_ATTR_CUR_GOVERNOR                  BIT(5)  /* DATA_TYPE_STRING */
+#define CPU_ATTR_NAME                          BIT(6)  /* DATA_TYPE_STRING */
 
 #define CPU_CTRL_CLUSTER_ID                    BIT(0)
 
@@ -65,6 +66,7 @@ extern "C" {
 #define BUS_ATTR_AVAILABLE_MIN_FREQ            BIT(3)  /* DATA_TYPE_INT */
 #define BUS_ATTR_AVAILABLE_MAX_FREQ            BIT(4)  /* DATA_TYPE_INT */
 #define BUS_ATTR_CUR_GOVERNOR                  BIT(5)  /* DATA_TYPE_STRING */
+#define BUS_ATTR_NAME                          BIT(6)  /* DATA_TYPE_STRING */
 
 #define BUS_CTRL_DEVICE_ID                     BIT(0)
 
@@ -75,6 +77,7 @@ extern "C" {
 #define GPU_ATTR_AVAILABLE_MIN_FREQ            BIT(3)  /* DATA_TYPE_INT */
 #define GPU_ATTR_AVAILABLE_MAX_FREQ            BIT(4)  /* DATA_TYPE_INT */
 #define GPU_ATTR_CUR_GOVERNOR                  BIT(5)  /* DATA_TYPE_STRING */
+#define GPU_ATTR_NAME                          BIT(6)  /* DATA_TYPE_STRING */
 
 #define GPU_CTRL_DEVICE_ID                     BIT(0)
 
@@ -100,6 +103,7 @@ extern "C" {
 
 /* Display Resource */
 #define DISPLAY_ATTR_FPS                       BIT(0)  /* DATA_TYPE_DOUBLE */
+#define DISPLAY_ATTR_NAME                      BIT(1)  /* DATA_TYPE_STRING */
 
 #define DISPLAY_CTRL_DEVICE_ID                 BIT(0)
 
@@ -120,7 +124,7 @@ extern "C" {
 #define PROCESS_ATTR_MEM_RSS_PERCENT           BIT(3)  /* DATA_TYPE_DOUBLE */
 #define PROCESS_ATTR_DISK_READ_BPS             BIT(4)  /* DATA_TYPE_UINT */
 #define PROCESS_ATTR_DISK_WRITE_BPS            BIT(5)  /* DATA_TYPE_UINT */
-#define PROCESS_ATTR_COMM                      BIT(6)  /* DATA_TYPE_STRING */
+#define PROCESS_ATTR_NAME                      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 */
@@ -132,7 +136,7 @@ extern "C" {
 
 /* Process List Resource */
 #define PROCESS_GROUP_ATTR_PID_LIST            BIT(0)  /* DATA_TYPE_ARRAY(INT) */
-#define PROCESS_GROUP_ATTR_COMM_LIST           BIT(1)  /* DATA_TYPE_ARRAY(STRING) */
+#define PROCESS_GROUP_ATTR_NAME_LIST           BIT(1)  /* DATA_TYPE_ARRAY(STRING) */
 #define PROCESS_GROUP_ATTR_CPU_UTIL            BIT(2)  /* DATA_TYPE_DOUBLE */
 #define PROCESS_GROUP_ATTR_DISK_READ_BPS       BIT(3)  /* DATA_TYPE_UINT */
 #define PROCESS_GROUP_ATTR_DISK_WRITE_BPS      BIT(4)  /* DATA_TYPE_UINT */
index a27482c..57c02c1 100644 (file)
@@ -89,11 +89,11 @@ static int bus_get_value_from_hal_power(struct resource *res,
        return 0;
 }
 
-static int bus_get_curr_governor(struct resource *res,
+static int bus_get_string_value(struct resource *res,
                                const struct resource_attribute *attr,
                                void *data)
 {
-       struct bus_context *ctx;;
+       struct bus_context *ctx;
        char *buf = (char *)data;
        int val;
 
@@ -110,10 +110,17 @@ static int bus_get_curr_governor(struct resource *res,
                return -EINVAL;
        }
 
-       val = hal_power_dvfs_get_curr_governor(get_resource_type(res),
-                                               ctx->device_name, buf);
-       if (val < 0)
-               return -EINVAL;
+       switch (attr->id) {
+       case BUS_ATTR_CUR_GOVERNOR:
+               val = hal_power_dvfs_get_curr_governor(get_resource_type(res),
+                                                       ctx->device_name, buf);
+               if (val < 0)
+                       return -EINVAL;
+               break;
+       case BUS_ATTR_NAME:
+               strncpy(buf, ctx->device_name, BUFF_MAX);
+               break;
+       }
 
        return 0;
 }
@@ -159,7 +166,14 @@ static const struct resource_attribute bus_attrs[] = {
                .id     = BUS_ATTR_CUR_GOVERNOR,
                .type   = DATA_TYPE_STRING,
                .ops    = {
-                       .get = bus_get_curr_governor,
+                       .get = bus_get_string_value,
+               }
+       }, {
+               .name   = "BUS_ATTR_NAME",
+               .id     = BUS_ATTR_NAME,
+               .type   = DATA_TYPE_STRING,
+               .ops    = {
+                       .get = bus_get_string_value,
                }
        },
 };
index 4613705..23cc507 100644 (file)
@@ -88,7 +88,7 @@ static int cpu_get_value_from_hal_power(struct resource *res,
        return 0;
 }
 
-static int cpu_get_curr_governor(struct resource *res,
+static int cpu_get_string_value(struct resource *res,
                                const struct resource_attribute *attr,
                                void *data)
 {
@@ -109,10 +109,17 @@ static int cpu_get_curr_governor(struct resource *res,
                return -EINVAL;
        }
 
-       val = hal_power_dvfs_get_curr_governor(get_resource_type(res),
-                                               ctx->device_name, buf);
-       if (val < 0)
-               return -EINVAL;
+       switch (attr->id) {
+       case CPU_ATTR_CUR_GOVERNOR:
+               val = hal_power_dvfs_get_curr_governor(get_resource_type(res),
+                                                       ctx->device_name, buf);
+               if (val < 0)
+                       return -EINVAL;
+               break;
+       case CPU_ATTR_NAME:
+               strncpy(buf, ctx->device_name, BUFF_MAX);
+               break;
+       }
 
        return 0;
 }
@@ -158,7 +165,14 @@ static const struct resource_attribute cpu_attrs[] = {
                .id     = CPU_ATTR_CUR_GOVERNOR,
                .type   = DATA_TYPE_STRING,
                .ops    = {
-                       .get = cpu_get_curr_governor,
+                       .get = cpu_get_string_value,
+               }
+       }, {
+               .name   = "CPU_ATTR_NAME",
+               .id     = CPU_ATTR_NAME,
+               .type   = DATA_TYPE_STRING,
+               .ops    = {
+                       .get = cpu_get_string_value,
                }
        },
 };
index 7cfebdb..0f5a82a 100644 (file)
 #define DBUS_ENLIGHTENMENT_INTERFACE   "org.enlightenment.wm.info"
 #define DBUS_ENLIGHTENMENT_FPS_FUNC    "get_fps_info"
 
+struct display_context {
+       char *device_name;
+       int index;
+};
+
 struct display_fps_data {
        unsigned int type;
        char output[128];
@@ -50,23 +55,23 @@ static int display_get_fps(struct resource *res,
                                const struct resource_attribute *attr,
                                void *data)
 {
+       struct display_context *ctx;
        GDBusConnection *conn;
        GDBusMessage *msg, *reply;
        GVariant *result, *value;
        GError *err = NULL;
        struct display_fps_data fps_data;
-       int *disp_id;
        double *fps = (double *)data;
        int ret = 0;
 
        if (!res || !attr || !data)
                return -EINVAL;
 
-       disp_id = get_resource_privdata(res);
-       if (!disp_id)
+       ctx = get_resource_privdata(res);
+       if (!ctx)
                return -EINVAL;
 
-       if (*disp_id < 0) {
+       if (!ctx->device_name) {
                _E("%s: DISPLAY_CTRL_DEVICE_ID is not yet initialized\n",
                                get_resource_name(res));
                return -EINVAL;
@@ -110,7 +115,7 @@ static int display_get_fps(struct resource *res,
        }
 
        /* Get the fps information according to the index of resource_device */
-       value = g_variant_get_child_value(result, *disp_id);
+       value = g_variant_get_child_value(result, ctx->index);
        g_variant_get(value, "(usiud)",
                        &fps_data.type, fps_data.output, &fps_data.zpos,
                        &fps_data.window, &fps_data.fps);
@@ -128,6 +133,31 @@ err_conn:
        return ret;
 }
 
+static int display_get_name(struct resource *res,
+                               const struct resource_attribute *attr,
+                               void *data)
+{
+       struct display_context *ctx;
+       char *buf = (char *)data;
+
+       if (!res || !attr || !data)
+               return -EINVAL;
+
+       ctx = get_resource_privdata(res);
+       if (!ctx)
+               return -EINVAL;
+
+       if (!ctx->device_name) {
+               _E("%s: DISPLAY_CTRL_DEVICE_ID is not yet initialized\n",
+                               get_resource_name(res));
+               return -EINVAL;
+       }
+
+       strncpy(buf, ctx->device_name, BUFF_MAX);
+
+       return 0;
+}
+
 static const struct resource_attribute display_attrs[] = {
        {
                .name   = "DISPLAY_ATTR_FPS",
@@ -136,6 +166,13 @@ static const struct resource_attribute display_attrs[] = {
                .ops    = {
                        .get = display_get_fps,
                },
+       }, {
+               .name   = "DISPLAY_ATTR_NAME",
+               .id     = DISPLAY_ATTR_NAME,
+               .type   = DATA_TYPE_STRING,
+               .ops    = {
+                       .get = display_get_name,
+               },
        },
 };
 
@@ -143,18 +180,29 @@ static int display_setup_device_id(struct resource *res,
                                const struct resource_control *ctrl,
                                const void *data)
 {
-       int *disp_id = NULL;
+       struct display_context *ctx;
+       const struct resource_device *device;
+       int resource_index = (int)(intptr_t)data;
 
        if (!res || !ctrl)
                return -EINVAL;
 
-       disp_id = get_resource_privdata(res);
-       if (!disp_id)
+       ctx = get_resource_privdata(res);
+       if (!ctx)
+               return -EINVAL;
+
+       device = find_resource_device(get_resource_type(res), resource_index);
+       if (!device) {
+               _E("Not available resource: type: %s, index: %d\n",
+                               get_resource_name(res), resource_index);
                return -EINVAL;
+       }
 
-       *disp_id = (int)(intptr_t)data;
+       if (ctx->device_name)
+               free(ctx->device_name);
 
-       set_resource_privdata(res, disp_id);
+       ctx->device_name = g_strdup(device->name);
+       ctx->index = resource_index;
 
        return 0;
 }
@@ -171,31 +219,34 @@ static const struct resource_control display_ctrls[] = {
 
 static int display_init(struct resource *res)
 {
-       int *disp_id;
+       struct display_context *ctx;
 
-       disp_id = malloc(sizeof(int));
-       if (!disp_id)
+       ctx = calloc(1, sizeof(struct display_context));
+       if (!ctx)
                return -ENOMEM;
 
-       *disp_id = -1;
+       ctx->index = -1;
 
-       set_resource_privdata(res, disp_id);
+       set_resource_privdata(res, ctx);
 
        return 0;
 }
 
 static void display_exit(struct resource *res)
 {
-       int *disp_id;
+       struct display_context *ctx;
 
        if (!res)
                return;
 
-       disp_id = get_resource_privdata(res);
-       if (!disp_id)
+       ctx = get_resource_privdata(res);
+       if (!ctx)
                return;
 
-       free(disp_id);
+       if (ctx->device_name)
+               free(ctx->device_name);
+
+       free(ctx);
        set_resource_privdata(res, NULL);
 }
 
index 4fdce6c..9112f3c 100644 (file)
@@ -89,7 +89,7 @@ static int gpu_get_value_from_hal_power(struct resource *res,
        return 0;
 }
 
-static int gpu_get_curr_governor(struct resource *res,
+static int gpu_get_string_value(struct resource *res,
                                const struct resource_attribute *attr,
                                void *data)
 {
@@ -110,10 +110,17 @@ static int gpu_get_curr_governor(struct resource *res,
                return -EINVAL;
        }
 
-       val = hal_power_dvfs_get_curr_governor(get_resource_type(res),
-                                               ctx->device_name, buf);
-       if (val < 0)
-               return -EINVAL;
+       switch (attr->id) {
+       case GPU_ATTR_CUR_GOVERNOR:
+               val = hal_power_dvfs_get_curr_governor(get_resource_type(res),
+                                                       ctx->device_name, buf);
+               if (val < 0)
+                       return -EINVAL;
+               break;
+       case GPU_ATTR_NAME:
+               strncpy(buf, ctx->device_name, BUFF_MAX);
+               break;
+       }
 
        return 0;
 }
@@ -159,7 +166,14 @@ static const struct resource_attribute gpu_attrs[] = {
                .id     = GPU_ATTR_CUR_GOVERNOR,
                .type   = DATA_TYPE_STRING,
                .ops    = {
-                       .get = gpu_get_curr_governor,
+                       .get = gpu_get_string_value,
+               }
+       }, {
+               .name   = "GPU_ATTR_NAME",
+               .id     = GPU_ATTR_NAME,
+               .type   = DATA_TYPE_STRING,
+               .ops    = {
+                       .get = gpu_get_string_value,
                }
        },
 };
index e6a2812..754f5e4 100644 (file)
@@ -92,7 +92,7 @@ static int process_group_get_pid_list(struct resource *res,
        return 0;
 }
 
-static int process_group_get_comm_list(struct resource *res,
+static int process_group_get_name_list(struct resource *res,
                                const struct resource_attribute *attr,
                                void *data)
 {
@@ -256,11 +256,11 @@ static const struct resource_attribute process_group_attrs[] = {
                        .is_supported = resource_attr_supported_always,
                },
        }, {
-               .name   = "PROCESS_GROUP_ATTR_COMM_LIST",
-               .id     = PROCESS_GROUP_ATTR_COMM_LIST,
+               .name   = "PROCESS_GROUP_ATTR_NAME_LIST",
+               .id     = PROCESS_GROUP_ATTR_NAME_LIST,
                .type   = DATA_TYPE_ARRAY,
                .ops    = {
-                       .get = process_group_get_comm_list,
+                       .get = process_group_get_name_list,
                        .is_supported = resource_attr_supported_always,
                },
        }, {
index 600d3d9..073b2eb 100644 (file)
@@ -194,7 +194,7 @@ static int process_get_context_data(struct resource *res,
        }
 
        switch (attr->id) {
-       case PROCESS_ATTR_COMM:
+       case PROCESS_ATTR_NAME:
                strncpy((char *)data, ctx->comm, TS_COMM_LEN);
                break;
        case PROCESS_ATTR_PGID:
@@ -277,8 +277,8 @@ static const struct resource_attribute process_attrs[] = {
                        .is_supported = resource_attr_supported_always,
                },
        }, {
-               .name   = "PROCESS_ATTR_COMM",
-               .id     = PROCESS_ATTR_COMM,
+               .name   = "PROCESS_ATTR_NAME",
+               .id     = PROCESS_ATTR_NAME,
                .type   = DATA_TYPE_STRING,
                .ops    = {
                        .get = process_get_context_data,