diff options
author | Sung-hun Kim <sfoon.kim@samsung.com> | 2023-02-07 19:30:25 +0900 |
---|---|---|
committer | Sung-hun Kim <sfoon.kim@samsung.com> | 2023-02-07 20:45:30 +0900 |
commit | 33d5fe691e99d4ce2025980cb620552d92bde577 (patch) | |
tree | 40237fc93abcd8f2e6407329a654892819ecc8c7 | |
parent | f870732b3fa18a5a1de57568ba922c27b4f6733a (diff) | |
download | memps-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.c | 64 |
1 files changed, 20 insertions, 44 deletions
@@ -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) |