Loading...
tools/malloc_replay.cpp libmalloc-283.100.6 libmalloc-166.220.1
--- libmalloc/libmalloc-283.100.6/tools/malloc_replay.cpp
+++ libmalloc/libmalloc-166.220.1/tools/malloc_replay.cpp
@@ -91,9 +91,6 @@
 //
 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)
 {
@@ -480,10 +477,6 @@
 		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;
@@ -578,8 +571,11 @@
 					if (disposition & (VM_PAGE_QUERY_PAGE_COPIED|VM_PAGE_QUERY_PAGE_DIRTY)) {
 						magazine.pages_dirty++;
 					}
-				} else if (disposition & VM_PAGE_QUERY_PAGE_PAGED_OUT) {
+
+					magazine.pages_resident++;
+				} else if (disposition & VM_PAGE_QUERY_PAGE_PAGED_OUT){
 					magazine.pages_dirty++;
+					magazine.pages_resident++;
 				}
 			}
 		}
@@ -685,13 +681,7 @@
 	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) {
@@ -776,7 +766,7 @@
 		//
 		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");
@@ -840,7 +830,9 @@
 			pdwriter_end_extension(perfDataWriter, jsonW);
 		}
 	}
-}
+	return true;
+}
+
 
 ////////////////////////////////////////////////////////////////////////////////
 //
@@ -930,7 +922,6 @@
 	}
 
 	timespec beginTime = {0};
-	timespec endTime = {0};
 
     pdwriter_t writer = NULL;
     if (outputPerfData) {
@@ -968,34 +959,29 @@
 
 		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");
 		}
+	}
+
+	if (beginTime.tv_sec) {
+		timespec endTime;
 		clock_gettime(CLOCK_MONOTONIC_RAW, &endTime);
-	}
-
-	if (beginTime.tv_sec) {
 		printf("\n\nRuntime: %ld ms\n", ((endTime.tv_sec - beginTime.tv_sec) * 1000) + (endTime.tv_nsec - beginTime.tv_nsec)/1000000);
 	}