Loading...
tools/malloc_replay.cpp libmalloc-166.220.1 libmalloc-521.100.59
--- libmalloc/libmalloc-166.220.1/tools/malloc_replay.cpp
+++ libmalloc/libmalloc-521.100.59/tools/malloc_replay.cpp
@@ -48,6 +48,9 @@
 
 #endif // TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR
 
+// Opt out malloc_replay from PGM
+asm(".section __DATA, __pgm_opt_out\n.long 0\n");
+
 static void (*s_funcMagSetThreadIndex)(unsigned int index);
 
 extern "C" int thread_selfcounts(int type, void *buf, size_t nbytes);
@@ -90,6 +93,9 @@
 //Our allocator to allocate from a specific zone.
 //
 malloc_zone_t* s_zone = NULL;
+
+// The magazine number to use for non-replayed allocations.
+#define NON_REPLAY_MAGAZINE 0
 
 static void
 configure_ktrace_session(ktrace_session_t s)
@@ -477,6 +483,10 @@
 		break;
     };
 
+	if (s_funcMagSetThreadIndex){
+		s_funcMagSetThreadIndex(NON_REPLAY_MAGAZINE);
+	}
+
 	if (config & (CONFIG_REC_COUNTERS | CONFIG_REC_STATS)) {
 		uint64_t diff = postICount - preICount;
 		uint16_t instrCount = diff <= UINT16_MAX ? diff : UINT16_MAX;
@@ -571,11 +581,8 @@
 					if (disposition & (VM_PAGE_QUERY_PAGE_COPIED|VM_PAGE_QUERY_PAGE_DIRTY)) {
 						magazine.pages_dirty++;
 					}
-
-					magazine.pages_resident++;
-				} else if (disposition & VM_PAGE_QUERY_PAGE_PAGED_OUT){
+				} else if (disposition & VM_PAGE_QUERY_PAGE_PAGED_OUT) {
 					magazine.pages_dirty++;
-					magazine.pages_resident++;
 				}
 			}
 		}
@@ -681,7 +688,13 @@
 	s_addressMap.clear();
 	ktrace_session_destroy(s);
 
-    //
+	return true;
+}
+
+static void
+report_results(pdwriter_t perfDataWriter, replay_config_t config)
+{
+	//
     //If passed a writer, output performance data.
     //
     if (perfDataWriter) {
@@ -765,8 +778,7 @@
 		//Write out the fragmentation in DefaultMallocZone as a primary metric.
 		//
 		pdwriter_new_value(perfDataWriter, _DefaultFragMetricName, PDUNIT_CUSTOM(FragmentedPercent), defaultFrag);
-		pdwriter_record_variable(perfDataWriter, kPCFailureThresholdPctVar, 10);
-	} else if (config & CONFIG_REC_STATS){
+	} else if (config & CONFIG_REC_STATS) {
 		printf("\n\n\n");
 		printf("Call       Cycles (mean)\n");
 		printf("=====================\n");
@@ -818,7 +830,6 @@
 						// operation enum is indexed from 1, adjust index for mcall_to_name.
 						snprintf(full_name, sizeof(full_name), "%s-mean", mcall_to_name(i + 1));
 						pdwriter_new_value(perfDataWriter, full_name, pdunit_instructions, mean);
-						pdwriter_record_variable(perfDataWriter, kPCFailureThresholdPctVar, 100);
 					} else {
 						printf("%9s  %6llu\n", mcall_to_name(i + 1), mean);
 					}
@@ -830,9 +841,7 @@
 			pdwriter_end_extension(perfDataWriter, jsonW);
 		}
 	}
-	return true;
-}
-
+}
 
 ////////////////////////////////////////////////////////////////////////////////
 //
@@ -922,6 +931,7 @@
 	}
 
 	timespec beginTime = {0};
+	timespec endTime = {0};
 
     pdwriter_t writer = NULL;
     if (outputPerfData) {
@@ -959,29 +969,34 @@
 
 		if (!s_funcMagSetThreadIndex) {
 			printf("\n****Couldn't load mag_set_thread_index, replay won't honor core****\n\n");
+		} else {
+			s_funcMagSetThreadIndex(NON_REPLAY_MAGAZINE);
 		}
 
 		clock_gettime(CLOCK_MONOTONIC_RAW, &beginTime);
-
 
 		if (!run_malloc_replay(inputMTrace, writer, config)) {
 			return -1;
 		}
+
+		clock_gettime(CLOCK_MONOTONIC_RAW, &endTime);
+
+		report_results(writer, config);
 	} else if (config & CONFIG_CONVERT_FILE) {
 		clock_gettime(CLOCK_MONOTONIC_RAW, &beginTime);
 		if (!run_ktrace(inputKtrace, outputMTrace)) {
 			printf("\n****Couldn't record mtrace file.\n");
 		}
+		clock_gettime(CLOCK_MONOTONIC_RAW, &endTime);
 	} else if (outputMTrace) {
 		clock_gettime(CLOCK_MONOTONIC_RAW, &beginTime);
 		if (!run_ktrace(NULL, outputMTrace)) {
 			printf("\n****Couldn't record mtrace file.\n");
 		}
+		clock_gettime(CLOCK_MONOTONIC_RAW, &endTime);
 	}
 
 	if (beginTime.tv_sec) {
-		timespec endTime;
-		clock_gettime(CLOCK_MONOTONIC_RAW, &endTime);
 		printf("\n\nRuntime: %ld ms\n", ((endTime.tv_sec - beginTime.tv_sec) * 1000) + (endTime.tv_nsec - beginTime.tv_nsec)/1000000);
 	}