--- /dev/null
+/*
+ * 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__ */
--- /dev/null
+/*
+ * 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;
+}
+++ /dev/null
-/*
- * 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__ */
+++ /dev/null
-/*
- * 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;
-}
#include "launchpad_common.h"
#include "launchpad_types.h"
+#include "launchpad_proc.h"
#include "launchpad.h"
#include "key.h"
int i;
int len = 0;
const char **so_array;
+ unsigned int mem_pss = 0;
if (!b)
return;
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);
_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);
}
}
}