util: kernel: Fix to check memory map info precisely 35/277435/1 accepted/tizen/unified/20220708.132851 submit/tizen/20220707.045609
authorDongwoo Lee <dwoo08.lee@samsung.com>
Tue, 5 Jul 2022 10:09:51 +0000 (19:09 +0900)
committerDongwoo Lee <dwoo08.lee@samsung.com>
Thu, 7 Jul 2022 02:54:31 +0000 (11:54 +0900)
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 <dwoo08.lee@samsung.com>
src/util/kernel.c

index e53e2fb..0a64734 100644 (file)
@@ -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);
        }