Commit 60648033 authored by Namhyung Kim's avatar Namhyung Kim Committed by Arnaldo Carvalho de Melo

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: default avatarNamhyung 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.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 0020ce23
...@@ -193,55 +193,43 @@ static int perf_event__synthesize_mmap_events(struct perf_tool *tool, ...@@ -193,55 +193,43 @@ static int perf_event__synthesize_mmap_events(struct perf_tool *tool,
event->header.misc = PERF_RECORD_MISC_USER; event->header.misc = PERF_RECORD_MISC_USER;
while (1) { while (1) {
char bf[BUFSIZ], *pbf = bf; char bf[BUFSIZ];
int n; char prot[5];
char execname[PATH_MAX];
char anonstr[] = "//anon";
size_t size; size_t size;
if (fgets(bf, sizeof(bf), fp) == NULL) if (fgets(bf, sizeof(bf), fp) == NULL)
break; break;
/* ensure null termination since stack will be reused. */
strcpy(execname, "");
/* 00400000-0040c000 r-xp 00000000 fd:01 41038 /bin/cat */ /* 00400000-0040c000 r-xp 00000000 fd:01 41038 /bin/cat */
n = hex2u64(pbf, &event->mmap.start); sscanf(bf, "%"PRIx64"-%"PRIx64" %s %"PRIx64" %*x:%*x %*u %s\n",
if (n < 0) &event->mmap.start, &event->mmap.len, prot,
continue; &event->mmap.pgoff, execname);
pbf += n + 1;
n = hex2u64(pbf, &event->mmap.len); if (prot[2] != 'x')
if (n < 0)
continue; continue;
pbf += n + 3;
if (*pbf == 'x') { /* vm_exec */ if (!strcmp(execname, ""))
char anonstr[] = "//anon\n"; strcpy(execname, anonstr);
char *execname = strchr(bf, '/');
size = strlen(execname) + 1;
/* Catch VDSO */ memcpy(event->mmap.filename, execname, size);
if (execname == NULL) size = PERF_ALIGN(size, sizeof(u64));
execname = strstr(bf, "[vdso]"); event->mmap.len -= event->mmap.start;
event->mmap.header.size = (sizeof(event->mmap) -
/* Catch anonymous mmaps */ (sizeof(event->mmap.filename) - size));
if ((execname == NULL) && !strstr(bf, "[")) memset(event->mmap.filename + size, 0, machine->id_hdr_size);
execname = anonstr; event->mmap.header.size += machine->id_hdr_size;
event->mmap.pid = tgid;
if (execname == NULL) event->mmap.tid = pid;
continue;
if (process(tool, event, &synth_sample, machine) != 0) {
pbf += 3; rc = -1;
n = hex2u64(pbf, &event->mmap.pgoff); break;
size = strlen(execname);
execname[size - 1] = '\0'; /* Remove \n */
memcpy(event->mmap.filename, execname, size);
size = PERF_ALIGN(size, sizeof(u64));
event->mmap.len -= event->mmap.start;
event->mmap.header.size = (sizeof(event->mmap) -
(sizeof(event->mmap.filename) - size));
memset(event->mmap.filename + size, 0, machine->id_hdr_size);
event->mmap.header.size += machine->id_hdr_size;
event->mmap.pid = tgid;
event->mmap.tid = pid;
if (process(tool, event, &synth_sample, machine) != 0) {
rc = -1;
break;
}
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment