mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-19 02:04:19 +08:00
perf tools: Use sscanf for parsing /proc/pid/maps
When reading those files to synthesize MMAP events. It makes the code shorter and cleaner. Signed-off-by: Namhyung Kim <namhyung@kernel.org> Cc: Ingo Molnar <mingo@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/r/1352643651-13891-1-git-send-email-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
0020ce2386
commit
6064803313
@ -193,41 +193,30 @@ static int perf_event__synthesize_mmap_events(struct perf_tool *tool,
|
||||
event->header.misc = PERF_RECORD_MISC_USER;
|
||||
|
||||
while (1) {
|
||||
char bf[BUFSIZ], *pbf = bf;
|
||||
int n;
|
||||
char bf[BUFSIZ];
|
||||
char prot[5];
|
||||
char execname[PATH_MAX];
|
||||
char anonstr[] = "//anon";
|
||||
size_t size;
|
||||
|
||||
if (fgets(bf, sizeof(bf), fp) == NULL)
|
||||
break;
|
||||
|
||||
/* ensure null termination since stack will be reused. */
|
||||
strcpy(execname, "");
|
||||
|
||||
/* 00400000-0040c000 r-xp 00000000 fd:01 41038 /bin/cat */
|
||||
n = hex2u64(pbf, &event->mmap.start);
|
||||
if (n < 0)
|
||||
continue;
|
||||
pbf += n + 1;
|
||||
n = hex2u64(pbf, &event->mmap.len);
|
||||
if (n < 0)
|
||||
continue;
|
||||
pbf += n + 3;
|
||||
if (*pbf == 'x') { /* vm_exec */
|
||||
char anonstr[] = "//anon\n";
|
||||
char *execname = strchr(bf, '/');
|
||||
sscanf(bf, "%"PRIx64"-%"PRIx64" %s %"PRIx64" %*x:%*x %*u %s\n",
|
||||
&event->mmap.start, &event->mmap.len, prot,
|
||||
&event->mmap.pgoff, execname);
|
||||
|
||||
/* Catch VDSO */
|
||||
if (execname == NULL)
|
||||
execname = strstr(bf, "[vdso]");
|
||||
|
||||
/* Catch anonymous mmaps */
|
||||
if ((execname == NULL) && !strstr(bf, "["))
|
||||
execname = anonstr;
|
||||
|
||||
if (execname == NULL)
|
||||
if (prot[2] != 'x')
|
||||
continue;
|
||||
|
||||
pbf += 3;
|
||||
n = hex2u64(pbf, &event->mmap.pgoff);
|
||||
if (!strcmp(execname, ""))
|
||||
strcpy(execname, anonstr);
|
||||
|
||||
size = strlen(execname);
|
||||
execname[size - 1] = '\0'; /* Remove \n */
|
||||
size = strlen(execname) + 1;
|
||||
memcpy(event->mmap.filename, execname, size);
|
||||
size = PERF_ALIGN(size, sizeof(u64));
|
||||
event->mmap.len -= event->mmap.start;
|
||||
@ -243,7 +232,6 @@ static int perf_event__synthesize_mmap_events(struct perf_tool *tool,
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
return rc;
|
||||
|
Loading…
Reference in New Issue
Block a user