Print PSS usage after loading preload libraries 44/233244/1
authorHwankyu Jhun <h.jhun@samsung.com>
Wed, 13 May 2020 07:28:49 +0000 (16:28 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Wed, 13 May 2020 07:28:49 +0000 (16:28 +0900)
Change-Id: I48fb1ee0266ed3624302a8e0f4cfcc7e06c37c40
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/common/inc/launchpad_proc.h [new file with mode: 0644]
src/common/src/launchpad_proc.c [new file with mode: 0644]
src/launchpad/inc/launchpad_proc.h [deleted file]
src/launchpad/src/launchpad_proc.c [deleted file]
src/loader/src/launchpad_loader.c

diff --git a/src/common/inc/launchpad_proc.h b/src/common/inc/launchpad_proc.h
new file mode 100644 (file)
index 0000000..eaff0f6
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __LAUNCHPAD_PROC_H__
+#define __LAUNCHPAD_PROC_H__
+
+int _proc_get_mem_used_ratio(unsigned int *mem_used_ratio);
+
+int _proc_get_mem_pss(int pid, unsigned int *mem_pss);
+
+#endif /* __LAUNCHPAD_PROC_H__ */
diff --git a/src/common/src/launchpad_proc.c b/src/common/src/launchpad_proc.c
new file mode 100644 (file)
index 0000000..e491cff
--- /dev/null
@@ -0,0 +1,145 @@
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define _GNU_SOURCE
+#include <errno.h>
+#include <limits.h>
+#include <linux/limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "launchpad_proc.h"
+#include "log_private.h"
+
+#define auto_ptr(x) __attribute__ ((__cleanup__(x)))
+
+static unsigned int __convert_string(const char *str)
+{
+       while (*str < '0' || *str > '9')
+               str++;
+
+       return atoi(str);
+}
+
+static int __open_file(const char *file, FILE **fp)
+{
+       int ret;
+
+       *fp = fopen(file, "r");
+       if (!*fp) {
+               ret = -errno;
+               _E("Failed to open %s. errno(%d)", file, errno);
+               return ret;
+       }
+
+       return 0;
+}
+
+static void __close_file(FILE **fp)
+{
+       if (!fp || !*fp)
+               return;
+
+       fclose(*fp);
+}
+
+int _proc_get_mem_used_ratio(unsigned int *mem_used_ratio)
+{
+       auto_ptr(__close_file) FILE *fp = NULL;
+       char buf[LINE_MAX];
+       char *str;
+       unsigned int mem_free = 0;
+       unsigned int mem_total = 0;
+       unsigned int mem_available = 0;
+       unsigned int cached = 0;
+       unsigned int used;
+       unsigned int used_ratio;
+       int ret;
+
+       if (!mem_used_ratio) {
+               _E("Invalid parameter");
+               return -EINVAL;
+       }
+
+       ret = __open_file("/proc/meminfo", &fp);
+       if (ret != 0)
+               return ret;
+
+       while (fgets(buf, sizeof(buf), fp) != NULL) {
+               if ((str = strstr(buf, "MemTotal:"))) {
+                       str += strlen("MemTotal:");
+                       mem_total = __convert_string(str);
+               } else if ((str = strstr(buf, "MemFree:"))) {
+                       str += strlen("MemFree:");
+                       mem_free = __convert_string(str);
+               } else if ((str = strstr(buf, "MemAvailable:"))) {
+                       str += strlen("MemAvailable:");
+                       mem_available = __convert_string(str);
+               } else if ((str = strstr(buf, "Cached:")) &&
+                               !strstr(buf, "Swap")) {
+                       str += strlen("Cached:");
+                       cached = atoi(str);
+                       break;
+               }
+       }
+
+       if (mem_total == 0) {
+               _E("Failed to get total memory size");
+               return -1;
+       }
+
+       if (mem_available == 0)
+               mem_available = mem_free + cached;
+
+       used = mem_total - mem_available;
+       used_ratio = used * 100 / mem_total;
+
+       *mem_used_ratio = used_ratio;
+
+       return 0;
+}
+
+int _proc_get_mem_pss(int pid, unsigned int *mem_pss)
+{
+       auto_ptr(__close_file) FILE *fp = NULL;
+       char path[PATH_MAX];
+       char buf[LINE_MAX];
+       unsigned int pss = 0;
+       unsigned int total_pss = 0;
+       int ret;
+
+       if (pid < 1 || !mem_pss) {
+               _E("Invalid parameter");
+               return -EINVAL;
+       }
+
+       snprintf(path, sizeof(path), "/proc/%d/smaps", pid);
+       ret = __open_file(path, &fp);
+       if (ret != 0)
+               return ret;
+
+       while (fgets(buf, sizeof(buf), fp) != NULL) {
+               if (sscanf(buf, "Pss: %d kB", &pss) == 1) {
+                       total_pss += pss;
+                       pss = 0;
+               }
+       }
+
+       *mem_pss = total_pss;
+
+       return 0;
+}
diff --git a/src/launchpad/inc/launchpad_proc.h b/src/launchpad/inc/launchpad_proc.h
deleted file mode 100644 (file)
index eaff0f6..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __LAUNCHPAD_PROC_H__
-#define __LAUNCHPAD_PROC_H__
-
-int _proc_get_mem_used_ratio(unsigned int *mem_used_ratio);
-
-int _proc_get_mem_pss(int pid, unsigned int *mem_pss);
-
-#endif /* __LAUNCHPAD_PROC_H__ */
diff --git a/src/launchpad/src/launchpad_proc.c b/src/launchpad/src/launchpad_proc.c
deleted file mode 100644 (file)
index daad003..0000000
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define _GNU_SOURCE
-#include <errno.h>
-#include <limits.h>
-#include <linux/limits.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "launchpad_proc.h"
-#include "log_private.h"
-
-#define auto_ptr(x) __attribute__ ((__cleanup__(x)))
-
-static unsigned int __convert_string(const char *str)
-{
-       while (*str < '0' || *str > '9')
-               str++;
-
-       return atoi(str);
-}
-
-static int __open_file(const char *file, FILE **fp)
-{
-       int ret;
-
-       *fp = fopen(file, "r");
-       if (!*fp) {
-               ret = -errno;
-               _E("Failed to open %s. errno(%d)", file, errno);
-               return ret;
-       }
-
-       return 0;
-}
-
-static void __close_file(FILE **fp)
-{
-       if (!fp || !*fp)
-               return;
-
-       fclose(*fp);
-}
-
-int _proc_get_mem_used_ratio(unsigned int *mem_used_ratio)
-{
-       auto_ptr(__close_file) FILE *fp = NULL;
-       char buf[LINE_MAX];
-       char *str;
-       unsigned int mem_free = 0;
-       unsigned int mem_total = 0;
-       unsigned int mem_available = 0;
-       unsigned int cached = 0;
-       unsigned int used;
-       unsigned int used_ratio;
-       int ret;
-
-       if (!mem_used_ratio) {
-               _E("Invalid parameter");
-               return -EINVAL;
-       }
-
-       ret = __open_file("/proc/meminfo", &fp);
-       if (ret != 0)
-               return ret;
-
-       while (fgets(buf, sizeof(buf), fp) != NULL) {
-               if ((str = strstr(buf, "MemTotal:"))) {
-                       str += strlen("MemTotal:");
-                       mem_total = __convert_string(str);
-               } else if ((str = strstr(buf, "MemFree:"))) {
-                       str += strlen("MemFree:");
-                       mem_free = __convert_string(str);
-               } else if ((str = strstr(buf, "MemAvailable:"))) {
-                       str += strlen("MemAvailable:");
-                       mem_available = __convert_string(str);
-               } else if ((str = strstr(buf, "Cached:")) &&
-                               !strstr(buf, "Swap")) {
-                       str += strlen("Cached:");
-                       cached = atoi(str);
-                       break;
-               }
-       }
-
-       if (mem_total == 0) {
-               _E("Failed to get total memory size");
-               return -1;
-       }
-
-       if (mem_available == 0)
-               mem_available = mem_free + cached;
-
-       used = mem_total - mem_available;
-       used_ratio = used * 100 / mem_total;
-       _I("memory used ratio: %u %%", used_ratio);
-
-       *mem_used_ratio = used_ratio;
-
-       return 0;
-}
-
-int _proc_get_mem_pss(int pid, unsigned int *mem_pss)
-{
-       auto_ptr(__close_file) FILE *fp = NULL;
-       char path[PATH_MAX];
-       char buf[LINE_MAX];
-       unsigned int pss = 0;
-       unsigned int total_pss = 0;
-       int ret;
-
-       if (pid < 1 || !mem_pss) {
-               _E("Invalid parameter");
-               return -EINVAL;
-       }
-
-       snprintf(path, sizeof(path), "/proc/%d/smaps", pid);
-       ret = __open_file(path, &fp);
-       if (ret != 0)
-               return ret;
-
-       while (fgets(buf, sizeof(buf), fp) != NULL) {
-               if (sscanf(buf, "Pss: %d kB", &pss) == 1) {
-                       total_pss += pss;
-                       pss = 0;
-               }
-       }
-
-       *mem_pss = total_pss;
-       _I("[%d] PSS: %u kB", pid, total_pss);
-
-       return 0;
-}
index fee50e61b83039d6868975f6e4f1d5eab9c7dbcf..b67484d4ea39478f5364e58c1a2af6438a2d5e0d 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "launchpad_common.h"
 #include "launchpad_types.h"
+#include "launchpad_proc.h"
 #include "launchpad.h"
 #include "key.h"
 
@@ -150,6 +151,7 @@ static void __preload_lib(bundle *b)
        int i;
        int len = 0;
        const char **so_array;
+       unsigned int mem_pss = 0;
 
        if (!b)
                return;
@@ -159,6 +161,8 @@ static void __preload_lib(bundle *b)
        if (!so_array)
                return;
 
+       _proc_get_mem_pss(getpid(), &mem_pss);
+       _W("PSS: %u kB", mem_pss);
        for (i = 0; i < len; i++) {
                if (!so_array[i]) {
                        _E("so_array[%d] is nullptr", i);
@@ -174,7 +178,9 @@ static void __preload_lib(bundle *b)
                        _E("failed to load: %s, err: %s",
                                so_array[i], dlerror());
                } else {
-                       _D("preload %s# - handle : %p", so_array[i], handle);
+                       _proc_get_mem_pss(getpid(), &mem_pss);
+                       _W("preload %s# - handle : %p, PSS: %u kB",
+                                       so_array[i], handle, mem_pss);
                }
        }
 }