Blame SOURCES/oprofile-remap.patch

d5df0a
commit 1c54c9a3d96dd8d9d1d579baaeabc94d0f923ee8
d5df0a
Author: William Cohen <wcohen@redhat.com>
d5df0a
Date:   Fri Jul 10 15:41:33 2015 -0400
d5df0a
d5df0a
    Improve handling of remapped anon regions across processes
d5df0a
    
d5df0a
    Java runtime environments use dynamically allocated memory in
d5df0a
    anonymous regions to store Just-In-Time translated code.  The Java
d5df0a
    runtime system may change the access permissions for portions of mmap
d5df0a
    regions during execution and operf needs to be tolerant of those
d5df0a
    change to a portion of the mmap.  operf also needs to keep the anon
d5df0a
    memory maps distinct between processes to avoid confusion about the
d5df0a
    sizes of the memory regions.
d5df0a
    
d5df0a
    Signed-off-by: William Cohen <wcohen@redhat.com>
d5df0a
d5df0a
diff --git a/libperf_events/operf_process_info.h b/libperf_events/operf_process_info.h
d5df0a
index f98591f..3138ffb 100644
d5df0a
--- a/libperf_events/operf_process_info.h
d5df0a
+++ b/libperf_events/operf_process_info.h
d5df0a
@@ -25,6 +25,7 @@ struct operf_mmap {
d5df0a
 	u64 start_addr;
d5df0a
 	u64 end_addr;
d5df0a
 	u64 pgoff;
d5df0a
+	u32 pid;
d5df0a
 	bool is_anon_mapping;
d5df0a
 	bool is_hypervisor;
d5df0a
 	char filename[PATH_MAX];
d5df0a
diff --git a/libperf_events/operf_utils.cpp b/libperf_events/operf_utils.cpp
d5df0a
index 90a0765..ff972d4 100644
d5df0a
--- a/libperf_events/operf_utils.cpp
d5df0a
+++ b/libperf_events/operf_utils.cpp
d5df0a
@@ -275,7 +275,10 @@ static void __handle_mmap_event(event_t * event)
d5df0a
 	range = all_images_map.equal_range(image_basename);
d5df0a
 	for (it = range.first; it != range.second; it++) {
d5df0a
 		if (((strcmp((*it).second->filename, image_basename.c_str())) == 0)
d5df0a
-				&& ((*it).second->start_addr == event->mmap.start)) {
d5df0a
+		    && ((*it).second->pid == 0 || (*it).second->pid == event->mmap.pid)
d5df0a
+		    && ((*it).second->start_addr <= event->mmap.start
d5df0a
+			&& ((*it).second->end_addr >= event->mmap.start + event->mmap.len)))
d5df0a
+		{
d5df0a
 			mapping = (*it).second;
d5df0a
 			break;
d5df0a
 		}
d5df0a
@@ -291,12 +294,15 @@ static void __handle_mmap_event(event_t * event)
d5df0a
 		 */
d5df0a
 		if (mapping->filename[0] == '[') {
d5df0a
 			mapping->is_anon_mapping = true;
d5df0a
+			mapping->pid = event->mmap.pid;
d5df0a
 		} else if ((strncmp(mapping->filename, "//anon",
d5df0a
 		                    strlen("//anon")) == 0)) {
d5df0a
 			mapping->is_anon_mapping = true;
d5df0a
+			mapping->pid = event->mmap.pid;
d5df0a
 			strcpy(mapping->filename, "anon");
d5df0a
 		} else if ((strncmp(mapping->filename, "/anon_hugepage",
d5df0a
 		                    strlen("/anon_hugepage")) == 0)) {
d5df0a
+			mapping->pid = event->mmap.pid;
d5df0a
 			mapping->is_anon_mapping = true;
d5df0a
 			strcpy(mapping->filename, "anon");
d5df0a
 		}