Skip to content

Commit e5adfc3

Browse files
koct9iacmel
authored andcommitted
perf map: Synthesize maps only for thread group leader
Threads share map_groups, all map events are merged into it. Thus we could send mmaps only for thread group leader. Otherwise it took ages to attach and record something from processes with many vmas and threads. Thread group leader could be already dead, but it seems perf cannot handle this case anyway. Testing dummy: #include <stdio.h> #include <stdlib.h> #include <sys/mman.h> #include <pthread.h> #include <unistd.h> void *thread(void *arg) { pause(); } int main(int argc, char **argv) { int threads = 10000; int vmas = 50000; pthread_t th; for (int i = 0; i < threads; i++) pthread_create(&th, NULL, thread, NULL); for (int i = 0; i < vmas; i++) mmap(NULL, 4096, (i & 1) ? PROT_READ : PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, -1, 0); sleep(60); return 0; } Comment by Jiri Olsa: We actualy synthesize the group leader (if we found one) for the thread even if it's not present in the thread_map, so the process maps are always in data. Signed-off-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru> Acked-by: Jiri Olsa <jolsa@kernel.org> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/153363294102.396323.6277944760215058174.stgit@buzz Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 88cf708 commit e5adfc3

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

‎tools/perf/util/event.c‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -541,10 +541,17 @@ static int __event__synthesize_thread(union perf_event *comm_event,
541541
tgid, process, machine) < 0)
542542
return -1;
543543

544+
/*
545+
* send mmap only for thread group leader
546+
* see thread__init_map_groups
547+
*/
548+
if (pid == tgid &&
549+
perf_event__synthesize_mmap_events(tool, mmap_event, pid, tgid,
550+
process, machine, mmap_data,
551+
proc_map_timeout))
552+
return -1;
544553

545-
return perf_event__synthesize_mmap_events(tool, mmap_event, pid, tgid,
546-
process, machine, mmap_data,
547-
proc_map_timeout);
554+
return 0;
548555
}
549556

550557
if (machine__is_default_guest(machine))

0 commit comments

Comments
 (0)