summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSung-hun Kim <sfoon.kim@samsung.com>2023-02-07 19:30:25 +0900
committerSung-hun Kim <sfoon.kim@samsung.com>2023-02-07 20:45:30 +0900
commit33d5fe691e99d4ce2025980cb620552d92bde577 (patch)
tree40237fc93abcd8f2e6407329a654892819ecc8c7
parentf870732b3fa18a5a1de57568ba922c27b4f6733a (diff)
downloadmemps-33d5fe691e99d4ce2025980cb620552d92bde577.tar.gz
memps-33d5fe691e99d4ce2025980cb620552d92bde577.tar.bz2
memps-33d5fe691e99d4ce2025980cb620552d92bde577.zip
Refactor load_maps and load_maps_rollup functions
Change-Id: I8140c6c2cb58f8eeddb89cce5fef6d22a5c51936 Signed-off-by: Sung-hun Kim <sfoon.kim@samsung.com>
-rw-r--r--memps.c64
1 files changed, 20 insertions, 44 deletions
diff --git a/memps.c b/memps.c
index 4e3863d..26be129 100644
--- a/memps.c
+++ b/memps.c
@@ -775,26 +775,20 @@ static int get_tmpfs_info(FILE *output_fp)
return 0;
}
-mapinfo *load_maps_rollup(int pid)
+static inline mapinfo *__load_maps(const char *path)
{
- char* smaps_rollup;
- char tmp[128];
+ char* smaps;
mapinfo *milist = 0;
mapinfo *mi;
- /*
- * use smaps_rollup instead of traversing smaps
- * for getting values quickly
- */
- snprintf(tmp, sizeof(tmp), "/proc/%d/smaps_rollup", pid);
- if (access(tmp, F_OK) < 0)
+ if (!path)
return 0;
- smaps_rollup = cread(tmp);
- if (smaps_rollup == NULL)
+ smaps = cread(path);
+ if (smaps == NULL)
return 0;
- while ((mi = read_mapinfo(&smaps_rollup)) != 0) {
+ while ((mi = read_mapinfo(&smaps)) != 0) {
if (milist) {
if ((!strcmp(mi->name, milist->name)
&& (mi->name[0] != '['))) {
@@ -822,44 +816,26 @@ mapinfo *load_maps_rollup(int pid)
return milist;
}
-mapinfo *load_maps(int pid)
+mapinfo *load_maps_rollup(int pid)
{
- char* smaps;
char tmp[128];
- mapinfo *milist = 0;
- mapinfo *mi;
- snprintf(tmp, sizeof(tmp), "/proc/%d/smaps", pid);
- smaps = cread(tmp);
- if (smaps == NULL)
+ /*
+ * use smaps_rollup instead of traversing smaps
+ * for getting values quickly
+ */
+ snprintf(tmp, sizeof(tmp), "/proc/%d/smaps_rollup", pid);
+ if (access(tmp, F_OK) < 0)
return 0;
+ return __load_maps(tmp);
+}
- while ((mi = read_mapinfo(&smaps)) != 0) {
- if (milist) {
- if ((!strcmp(mi->name, milist->name)
- && (mi->name[0] != '['))) {
- milist->size += mi->size;
- milist->swap += mi->swap;
- milist->rss += mi->rss;
- milist->pss += mi->pss;
- milist->shared_clean += mi->shared_clean;
- milist->shared_dirty += mi->shared_dirty;
- milist->private_clean += mi->private_clean;
- milist->private_dirty += mi->private_dirty;
-
- milist->end = mi->end;
- strncpy(milist->perm, mi->perm, 4);
- free(mi->perm);
- free(mi->name);
- free(mi);
- continue;
- }
- }
- mi->next = milist;
- milist = mi;
- }
+mapinfo *load_maps(int pid)
+{
+ char tmp[128];
- return milist;
+ snprintf(tmp, sizeof(tmp), "/proc/%d/smaps", pid);
+ return __load_maps(tmp);
}
static void init_trib_mapinfo(trib_mapinfo *tmi)