Check the value at idle time for debugging the cpu usage issue
[platform/core/multimedia/mmsvc-core.git] / core / src / muse_core.c
index f330c21..1b91d5a 100644 (file)
@@ -793,6 +793,34 @@ void muse_core_log_process_cpu_memory(int pid)
        muse_core_log_cmd_info(cmd);
 }
 
+int muse_core_get_process_cpu_usage(int pid)
+{
+       FILE *fp = NULL;
+       int cpu = 0;
+       int idx = 0;
+       char cmd[MUSE_MSG_LEN_MAX];
+       char buf[MUSE_MSG_LEN_MAX];
+
+       snprintf(cmd, sizeof(cmd), "/bin/ps -Lo pcpu,pmem,tid,comm -p %d", pid);
+
+       fp = popen(cmd, "r");
+
+       if (fp) {
+               while (fgets(buf, MUSE_MSG_LEN_MAX, fp)) {
+                       LOGW("%s", buf);
+                       if (idx++ == 1) {
+                               cpu = atoi(g_strstrip(buf));
+                               break;
+                       }
+               }
+
+               if (pclose(fp) == -1)
+                       LOGE("Fail to pclose");
+       }
+
+       return cpu;
+}
+
 void muse_core_log_file_list(const char *path)
 {
        char cmd[MUSE_MSG_LEN_MAX];