aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorNamhyung Kim <namhyung@kernel.org>2012-11-11 09:20:50 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2012-11-14 14:51:40 -0500
commit6064803313bad9ae4cae233a9d56678adb2b6e7c (patch)
tree599a60fbd594921acc0357df2d01370c10e45fea /tools
parent0020ce23864d16f66e5667013b8b43d1df3e142e (diff)
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>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/util/event.c74
1 files changed, 31 insertions, 43 deletions
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index ca9ca285406a..3cf2c3e0605f 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -193,55 +193,43 @@ static int perf_event__synthesize_mmap_events(struct perf_tool *tool,
193 event->header.misc = PERF_RECORD_MISC_USER; 193 event->header.misc = PERF_RECORD_MISC_USER;
194 194
195 while (1) { 195 while (1) {
196 char bf[BUFSIZ], *pbf = bf; 196 char bf[BUFSIZ];
197 int n; 197 char prot[5];
198 char execname[PATH_MAX];
199 char anonstr[] = "//anon";
198 size_t size; 200 size_t size;
201
199 if (fgets(bf, sizeof(bf), fp) == NULL) 202 if (fgets(bf, sizeof(bf), fp) == NULL)
200 break; 203 break;
201 204
205 /* ensure null termination since stack will be reused. */
206 strcpy(execname, "");
207
202 /* 00400000-0040c000 r-xp 00000000 fd:01 41038 /bin/cat */ 208 /* 00400000-0040c000 r-xp 00000000 fd:01 41038 /bin/cat */
203 n = hex2u64(pbf, &event->mmap.start); 209 sscanf(bf, "%"PRIx64"-%"PRIx64" %s %"PRIx64" %*x:%*x %*u %s\n",
204 if (n < 0) 210 &event->mmap.start, &event->mmap.len, prot,
205 continue; 211 &event->mmap.pgoff, execname);
206 pbf += n + 1; 212
207 n = hex2u64(pbf, &event->mmap.len); 213 if (prot[2] != 'x')
208 if (n < 0)
209 continue; 214 continue;
210 pbf += n + 3; 215
211 if (*pbf == 'x') { /* vm_exec */ 216 if (!strcmp(execname, ""))
212 char anonstr[] = "//anon\n"; 217 strcpy(execname, anonstr);
213 char *execname = strchr(bf, '/'); 218
214 219 size = strlen(execname) + 1;
215 /* Catch VDSO */ 220 memcpy(event->mmap.filename, execname, size);
216 if (execname == NULL) 221 size = PERF_ALIGN(size, sizeof(u64));
217 execname = strstr(bf, "[vdso]"); 222 event->mmap.len -= event->mmap.start;
218 223 event->mmap.header.size = (sizeof(event->mmap) -
219 /* Catch anonymous mmaps */ 224 (sizeof(event->mmap.filename) - size));
220 if ((execname == NULL) && !strstr(bf, "[")) 225 memset(event->mmap.filename + size, 0, machine->id_hdr_size);
221 execname = anonstr; 226 event->mmap.header.size += machine->id_hdr_size;
222 227 event->mmap.pid = tgid;
223 if (execname == NULL) 228 event->mmap.tid = pid;
224 continue; 229
225 230 if (process(tool, event, &synth_sample, machine) != 0) {
226 pbf += 3; 231 rc = -1;
227 n = hex2u64(pbf, &event->mmap.pgoff); 232 break;
228
229 size = strlen(execname);
230 execname[size - 1] = '\0'; /* Remove \n */
231 memcpy(event->mmap.filename, execname, size);
232 size = PERF_ALIGN(size, sizeof(u64));
233 event->mmap.len -= event->mmap.start;
234 event->mmap.header.size = (sizeof(event->mmap) -
235 (sizeof(event->mmap.filename) - size));
236 memset(event->mmap.filename + size, 0, machine->id_hdr_size);
237 event->mmap.header.size += machine->id_hdr_size;
238 event->mmap.pid = tgid;
239 event->mmap.tid = pid;
240
241 if (process(tool, event, &synth_sample, machine) != 0) {
242 rc = -1;
243 break;
244 }
245 } 233 }
246 } 234 }
247 235