public static void LogObjectsLoaded() { if (MemoryTracker.tracked.Count == 0) { Log.Message("No objects tracked, memory tracker markup may not be applied."); return; } GC.Collect(); MemoryTracker.LockTracking(); try { foreach (HashSet <WeakReference> current in MemoryTracker.tracked.Values) { MemoryTracker.CullNulls(current); } StringBuilder stringBuilder = new StringBuilder(); foreach (KeyValuePair <Type, HashSet <WeakReference> > current2 in from kvp in MemoryTracker.tracked orderby - kvp.Value.Count select kvp) { stringBuilder.AppendLine(string.Format("{0,6} {1}", current2.Value.Count, current2.Key)); } Log.Message(stringBuilder.ToString()); } finally { MemoryTracker.UnlockTracking(); } }
private static void ObjectsLoaded() { if (MemoryTracker.tracked.Count == 0) { Log.Message("No objects tracked, memory tracker markup may not be applied.", false); } else { GC.Collect(); MemoryTracker.LockTracking(); try { foreach (HashSet <WeakReference> table in MemoryTracker.tracked.Values) { MemoryTracker.CullNulls(table); } StringBuilder stringBuilder = new StringBuilder(); foreach (KeyValuePair <Type, HashSet <WeakReference> > keyValuePair in from kvp in MemoryTracker.tracked orderby - kvp.Value.Count select kvp) { stringBuilder.AppendLine(string.Format("{0,6} {1}", keyValuePair.Value.Count, keyValuePair.Key)); } Log.Message(stringBuilder.ToString(), false); } finally { MemoryTracker.UnlockTracking(); } } }
private static void ObjectHoldPaths() { if (MemoryTracker.tracked.Count == 0) { Log.Message("No objects tracked, memory tracker markup may not be applied.", false); } else { GC.Collect(); MemoryTracker.LockTracking(); try { foreach (HashSet <WeakReference> table in MemoryTracker.tracked.Values) { MemoryTracker.CullNulls(table); } List <Type> list = new List <Type>(); list.Add(typeof(Map)); List <FloatMenuOption> list2 = new List <FloatMenuOption>(); foreach (Type type in list.Concat(from kvp in MemoryTracker.tracked orderby - kvp.Value.Count select kvp.Key).Take(30)) { Type type2 = type; HashSet <WeakReference> trackedBatch = MemoryTracker.tracked.TryGetValue(type2, null); if (trackedBatch == null) { trackedBatch = new HashSet <WeakReference>(); } list2.Add(new FloatMenuOption(string.Format("{0} ({1})", type2, trackedBatch.Count), delegate() { MemoryTracker.LogObjectHoldPathsFor(trackedBatch, (WeakReference _) => 1); }, MenuOptionPriority.Default, null, null, 0f, null, null)); if (list2.Count == 30) { break; } } Find.WindowStack.Add(new FloatMenu(list2)); } finally { MemoryTracker.UnlockTracking(); } } }
public static void LogObjectHoldPaths() { if (MemoryTracker.tracked.Count == 0) { Log.Message("No objects tracked, memory tracker markup may not be applied."); } else { GC.Collect(); MemoryTracker.LockTracking(); try { foreach (HashSet <WeakReference> value in MemoryTracker.tracked.Values) { MemoryTracker.CullNulls(value); } List <FloatMenuOption> list = new List <FloatMenuOption>(); foreach (KeyValuePair <Type, HashSet <WeakReference> > item in from kvp in MemoryTracker.tracked orderby - kvp.Value.Count select kvp) { KeyValuePair <Type, HashSet <WeakReference> > elementLocal = item; list.Add(new FloatMenuOption(string.Format("{0} ({1})", item.Key, item.Value.Count), delegate { MemoryTracker.LogObjectHoldPathsFor(elementLocal.Value, (WeakReference _) => 1); }, MenuOptionPriority.Default, null, null, 0f, null, null)); if (list.Count == 30) { break; } } Find.WindowStack.Add(new FloatMenu(list)); } finally { MemoryTracker.UnlockTracking(); } } }
public static void LogObjectHoldPathsFor(IEnumerable <WeakReference> elements, Func <WeakReference, int> weight) { GC.Collect(); MemoryTracker.LockTracking(); try { Dictionary <object, MemoryTracker.ReferenceData> dictionary = new Dictionary <object, MemoryTracker.ReferenceData>(); HashSet <object> hashSet = new HashSet <object>(); MemoryTracker.foundCollections.Clear(); Queue <object> queue = new Queue <object>(); foreach (object current in from weakref in MemoryTracker.tracked.SelectMany((KeyValuePair <Type, HashSet <WeakReference> > kvp) => kvp.Value) where weakref.IsAlive select weakref.Target) { if (!hashSet.Contains(current)) { hashSet.Add(current); queue.Enqueue(current); } } foreach (Type current2 in GenTypes.AllTypes.Union(MemoryTracker.tracked.Keys)) { if (!current2.FullName.Contains("MemoryTracker") && !current2.FullName.Contains("CollectionsTracker")) { if (!current2.ContainsGenericParameters) { MemoryTracker.AccumulateStaticMembers(current2, dictionary, hashSet, queue); } } } int num = 0; while (queue.Count > 0) { if (num % 10000 == 0) { UnityEngine.Debug.LogFormat("{0} / {1} (to process: {2})", new object[] { num, num + queue.Count, queue.Count }); } num++; MemoryTracker.AccumulateReferences(queue.Dequeue(), dictionary, hashSet, queue); } if (elements != null && weight != null) { int num2 = 0; MemoryTracker.CalculateReferencePaths(dictionary, from kvp in dictionary where !kvp.Value.path.NullOrEmpty() select kvp.Key, num2); num2 += 1000; MemoryTracker.CalculateReferencePaths(dictionary, from kvp in dictionary where kvp.Value.path.NullOrEmpty() && kvp.Value.referredBy.Count == 0 select kvp.Key, num2); foreach (object current3 in from kvp in dictionary where kvp.Value.path.NullOrEmpty() select kvp.Key) { num2 += 1000; MemoryTracker.CalculateReferencePaths(dictionary, new object[] { current3 }, num2); } Dictionary <string, int> dictionary2 = new Dictionary <string, int>(); foreach (WeakReference current4 in elements) { if (current4.IsAlive) { string path = dictionary[current4.Target].path; if (!dictionary2.ContainsKey(path)) { dictionary2[path] = 0; } Dictionary <string, int> dictionary3; string key; (dictionary3 = dictionary2)[key = path] = dictionary3[key] + weight(current4); } } StringBuilder stringBuilder = new StringBuilder(); foreach (KeyValuePair <string, int> current5 in from kvp in dictionary2 orderby - kvp.Value select kvp) { stringBuilder.AppendLine(string.Format("{0}: {1}", current5.Value, current5.Key)); } Log.Message(stringBuilder.ToString()); } } finally { MemoryTracker.UnlockTracking(); } }