diff options
author | Kan Liang <kan.liang@intel.com> | 2015-06-17 09:51:10 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2015-06-19 17:20:15 -0400 |
commit | 930e6fcd2bcce9bcd9d4aa7e755678d33f3fe6f4 (patch) | |
tree | 5f85d268437a01f2a2982be31c82cb00a81efd85 /tools/perf/util/event.c | |
parent | c05676c06232e6459a6106ddf0d4e154ce6cd859 (diff) |
perf tools: Add time out to force stop proc map processing
System wide sampling like 'perf top' or 'perf record -a' read all
threads /proc/xxx/maps before sampling. If there are any threads which
generating a keeping growing huge maps, perf will do infinite loop
during synthesizing. Nothing will be sampled.
This patch fixes this issue by adding per-thread timeout to force stop
this kind of endless proc map processing.
PERF_RECORD_MISC_PROC_MAP_PARSE_TIME_OUT is introduced to indicate that
the mmap record are truncated by time out. User will get warning
notification when truncated mmap records are detected.
Reported-by: Ying Huang <ying.huang@intel.com>
Signed-off-by: Kan Liang <kan.liang@intel.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Ying Huang <ying.huang@intel.com>
Link: http://lkml.kernel.org/r/1434549071-25611-1-git-send-email-kan.liang@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/event.c')
-rw-r--r-- | tools/perf/util/event.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c index 793b1503d437..416ba80c628f 100644 --- a/tools/perf/util/event.c +++ b/tools/perf/util/event.c | |||
@@ -213,6 +213,8 @@ static int perf_event__synthesize_fork(struct perf_tool *tool, | |||
213 | return 0; | 213 | return 0; |
214 | } | 214 | } |
215 | 215 | ||
216 | #define PROC_MAP_PARSE_TIMEOUT (500 * 1000000ULL) | ||
217 | |||
216 | int perf_event__synthesize_mmap_events(struct perf_tool *tool, | 218 | int perf_event__synthesize_mmap_events(struct perf_tool *tool, |
217 | union perf_event *event, | 219 | union perf_event *event, |
218 | pid_t pid, pid_t tgid, | 220 | pid_t pid, pid_t tgid, |
@@ -222,6 +224,8 @@ int perf_event__synthesize_mmap_events(struct perf_tool *tool, | |||
222 | { | 224 | { |
223 | char filename[PATH_MAX]; | 225 | char filename[PATH_MAX]; |
224 | FILE *fp; | 226 | FILE *fp; |
227 | unsigned long long t; | ||
228 | bool truncation = false; | ||
225 | int rc = 0; | 229 | int rc = 0; |
226 | 230 | ||
227 | if (machine__is_default_guest(machine)) | 231 | if (machine__is_default_guest(machine)) |
@@ -240,6 +244,7 @@ int perf_event__synthesize_mmap_events(struct perf_tool *tool, | |||
240 | } | 244 | } |
241 | 245 | ||
242 | event->header.type = PERF_RECORD_MMAP2; | 246 | event->header.type = PERF_RECORD_MMAP2; |
247 | t = rdclock(); | ||
243 | 248 | ||
244 | while (1) { | 249 | while (1) { |
245 | char bf[BUFSIZ]; | 250 | char bf[BUFSIZ]; |
@@ -253,6 +258,12 @@ int perf_event__synthesize_mmap_events(struct perf_tool *tool, | |||
253 | if (fgets(bf, sizeof(bf), fp) == NULL) | 258 | if (fgets(bf, sizeof(bf), fp) == NULL) |
254 | break; | 259 | break; |
255 | 260 | ||
261 | if ((rdclock() - t) > PROC_MAP_PARSE_TIMEOUT) { | ||
262 | pr_warning("Reading %s time out.\n", filename); | ||
263 | truncation = true; | ||
264 | goto out; | ||
265 | } | ||
266 | |||
256 | /* ensure null termination since stack will be reused. */ | 267 | /* ensure null termination since stack will be reused. */ |
257 | strcpy(execname, ""); | 268 | strcpy(execname, ""); |
258 | 269 | ||
@@ -301,6 +312,10 @@ int perf_event__synthesize_mmap_events(struct perf_tool *tool, | |||
301 | event->header.misc |= PERF_RECORD_MISC_MMAP_DATA; | 312 | event->header.misc |= PERF_RECORD_MISC_MMAP_DATA; |
302 | } | 313 | } |
303 | 314 | ||
315 | out: | ||
316 | if (truncation) | ||
317 | event->header.misc |= PERF_RECORD_MISC_PROC_MAP_PARSE_TIMEOUT; | ||
318 | |||
304 | if (!strcmp(execname, "")) | 319 | if (!strcmp(execname, "")) |
305 | strcpy(execname, anonstr); | 320 | strcpy(execname, anonstr); |
306 | 321 | ||
@@ -319,6 +334,9 @@ int perf_event__synthesize_mmap_events(struct perf_tool *tool, | |||
319 | rc = -1; | 334 | rc = -1; |
320 | break; | 335 | break; |
321 | } | 336 | } |
337 | |||
338 | if (truncation) | ||
339 | break; | ||
322 | } | 340 | } |
323 | 341 | ||
324 | fclose(fp); | 342 | fclose(fp); |