From: Dongwoo Lee Date: Tue, 5 Jul 2022 10:09:51 +0000 (+0900) Subject: util: kernel: Fix to check memory map info precisely X-Git-Tag: accepted/tizen/unified/20220708.132851^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F35%2F277435%2F1;p=platform%2Fcore%2Fsystem%2Fpass.git util: kernel: Fix to check memory map info precisely Since both "Pss:" and "SwapPss:" nodes has "Pss:" as substring, so just strstr() cannot distinguish them. To fix it, not just check section including node name, but check section starting with node name. Change-Id: Ia113d57b84414b9483b098920634c7f9f4b7461d Signed-off-by: Dongwoo Lee --- diff --git a/src/util/kernel.c b/src/util/kernel.c index e53e2fb..0a64734 100644 --- a/src/util/kernel.c +++ b/src/util/kernel.c @@ -454,6 +454,8 @@ new_entry: return mem_size; } +#define strstart(str1, str2) (strstr(str1, str2) == str1) + int kernel_get_thread_group_map_info(struct proc_map_info *map_info, pid_t tgid, bool include_gpu_mem) { @@ -476,13 +478,13 @@ int kernel_get_thread_group_map_info(struct proc_map_info *map_info, if (include_gpu_mem && is_new_entry(buffer)) map_info->gpu_mem += get_gpu_mem_size(smaps_fd, buffer); - if (strstr(buffer, "Rss:")) + if (strstart(buffer, "Rss:")) map_info->rss += strtol(buffer + 4, NULL, 10); - else if (strstr(buffer, "Pss:")) + else if (strstart(buffer, "Pss:")) map_info->pss += strtol(buffer + 4, NULL, 10); - else if (strstr(buffer, "Swap:")) + else if (strstart(buffer, "Swap:")) map_info->swap += strtol(buffer + 5, NULL, 10); - else if (strstr(buffer, "SwapPss:")) + else if (strstart(buffer, "SwapPss:")) map_info->swap_pss += strtol(buffer + 8, NULL, 10); }