Blame SOURCES/oprofile-remap.patch

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