smaps_lcnt = get_smaps_lcnt();
}
+
+typedef struct {
+ char name[256];
+ unsigned long size;
+ unsigned long pss;
+ unsigned long sh_mem_clean;
+ unsigned long sh_mem_dirty;
+} mapinfo_section_t;
+
/* b6e82000-b6e83000 rw-p 00020000 b3:19 714 /usr/lib/ld-2.20-2014.11.so : TM1
* 7fae2e4b2000-7fae2e4b3000 r--p 00021000 fe:01 603 /usr/lib64/ld-2.20-2014.11.so : x86-64 Emulator
* 7f9389d000-7f9389e000 rw-p 0001f000 b3:12 618 /usr/lib64/ld-2.20-2014.11.so : Note4
* 0 1 2 3 4 5 6 7
*/
#define NAME_OFFSET 49
-int read_mapinfo_section(FILE* fp, proc_t *proc)
+static int read_mapinfo_section(FILE* fp, mapinfo_section_t *map)
{
char* line;
int len;
int tmp;
int line_cnt;
char buf[LARGE_BUFFER];
+ const size_t name_size = sizeof(map->name);
+ char *name_buf = map->name;
line_cnt = smaps_lcnt;
if ((--line_cnt <= 0) || (line = fgets(buf, sizeof(buf), fp)) == 0)
if (len < 1)
return 0;
+ /* map name fill */
if (len < NAME_OFFSET + 1) {
- strncpy(proc->command, "[anon]", strlen("[anon]")+1);
+ strncpy(name_buf, "[anon]", name_size);
} else {
len = strnlen(buf + NAME_OFFSET, sizeof(buf) - NAME_OFFSET);
- strncpy(proc->command, buf + NAME_OFFSET, len + 1);
+ strncpy(name_buf, buf + NAME_OFFSET, name_size);
}
-
+ name_buf[name_size - 1] = '\0';
while (line_cnt-- && (line = fgets(buf, sizeof(buf), fp))) {
- if (sscanf(line, "Size: %lu kB", &proc->size) == 1) {}
+ if (sscanf(line, "Size: %lu kB", &map->size) == 1) {}
else if (sscanf(line, "Rss: %d kB", &tmp) == 1) {}
- else if (sscanf(line, "Pss: %lu kB", &proc->pss) == 1) {}
+ else if (sscanf(line, "Pss: %lu kB", &map->pss) == 1) {}
else if (sscanf(line, "Shared_Clean: %lu kB",
- &proc->sh_mem_clean) == 1) {}
+ &map->sh_mem_clean) == 1) {}
else if (sscanf(line, "Shared_Dirty: %lu kB",
- &proc->sh_mem_dirty) == 1) {}
+ &map->sh_mem_dirty) == 1) {}
else if (sscanf(line, "Private_Clean: %d kB", &tmp) == 1) {}
else if (sscanf(line, "Private_Dirty: %d kB", &tmp) == 1) {}
else if (sscanf(line, "Swap: %d kB", &tmp) == 1) {}
#define MIN_SMAP_BLOCKLINE 50
char path_smaps[PROCPATH_MAX];
- proc_t proc_tmp;
+ mapinfo_section_t map;
FILE* fp;
// reset pss size of proc_t
return -1;
}
- while (read_mapinfo_section(fp, &proc_tmp) == 0) {
- if (strstr(proc_tmp.command, DA_PROBE_TIZEN_SONAME)) {
+ while (read_mapinfo_section(fp, &map) == 0) {
+ const char *map_name = map.name;
+
+ if (strstr(map_name, DA_PROBE_TIZEN_SONAME)) {
/* We should skeep this section */
continue;
- } else if (strstr(proc_tmp.command, STR_SGX_PATH)) {
- P->graphic_3d += proc_tmp.pss;
- } else if (strstr(proc_tmp.command, STR_3D_PATH1) ||
- strstr(proc_tmp.command, STR_3D_PATH2)) {
- P->graphic_3d += proc_tmp.size;
+ } else if (strstr(map_name, STR_SGX_PATH)) {
+ P->graphic_3d += map.pss;
+ } else if (strstr(map_name, STR_3D_PATH1) ||
+ strstr(map_name, STR_3D_PATH2)) {
+ P->graphic_3d += map.size;
} else {
- P->pss += proc_tmp.pss;
- P->sh_mem_clean += proc_tmp.sh_mem_clean;
- P->sh_mem_dirty += proc_tmp.sh_mem_dirty;
+ P->pss += map.pss;
+ P->sh_mem_clean += map.sh_mem_clean;
+ P->sh_mem_dirty += map.sh_mem_dirty;
}
}
// TODO that probe_so_size calculation maybe wrong. check it. fix it