private void FilterAddresses(CancellationToken token) { var addresses = AddressList.Addresses; int c = addresses.Count; const int batchSize = 1024; for (int i = 0; i < c && !token.IsCancellationRequested; i += batchSize) { Status($"Filtering: {i:###,###,###,##0} / {c:###,###,###,##0}"); ClrDump.Run(() => { int max = Math.Min(i + batchSize, c); for (int j = i; j < max; j++) { ulong address = addresses[j]; if (DoFilter(address)) { filteredAddresses.Add(address); } if (token.IsCancellationRequested) { filteredAddresses.Clear(); return; } } }); } }
internal static List <ArraysInformation> Analyse(ClrDump clrDump, MessageBus msgBus) { CancellationTokenSource token = new CancellationTokenSource(); var arrays = new List <ArraysInformation>(); msgBus.BeginTask("Analyzing arrays...", token); int n = 0; clrDump.Run(() => { var arrayTypes = clrDump.AllTypes.Where(t => t.IsArray); int nbArrayType = arrayTypes.Count(); foreach (var type in arrayTypes) { string typeName = type.Name; msgBus.Status($"Analyzing array type: {typeName} ({n:###,###,###,##0}/{nbArrayType:###,###,###,##0})"); if (token.IsCancellationRequested) { return; } n++; ulong nbInstances = 0; ulong totalSize = 0; ulong totalLength = 0; ulong maxLength = 0; foreach (var address in clrDump.EnumerateInstances(type)) { nbInstances++; var length = (ulong)(type.GetArrayLength(address)); maxLength = Math.Max(maxLength, length); totalSize += type.GetSize(address); totalLength += length; if (nbInstances % 512 == 0) { msgBus.Status($"Analyzing array: #{nbInstances:###,###,###,##0} for type: {typeName}"); if (token.IsCancellationRequested) { return; } } } arrays.Add(new ArraysInformation(new ClrDumpType(clrDump, type), nbInstances, totalLength, maxLength, totalSize)); } }); msgBus.EndTask($"Arrays analyzed. Types: {n:###,###,###,##0}"); return(arrays); }
internal static List <StringInformation> Analyse(ClrDump clrDump, MessageBus msgBus) { var stringType = clrDump.GetClrType(typeof(string).FullName); var stringInstances = clrDump.EnumerateInstances(stringType); int nbStrings = clrDump.CountInstances(stringType); Dictionary <string, List <ulong> > result = new Dictionary <string, List <ulong> >(); CancellationTokenSource token = new CancellationTokenSource(); msgBus.BeginTask("Analyzing strings...", token); int n = 0; clrDump.Run(() => { foreach (var address in stringInstances) { if (token.IsCancellationRequested) { return; } n++; var value = SimpleValueHelper.GetSimpleValue(address, stringType, false) as string; if (value == null) { continue; } List <ulong> addresses; if (!result.TryGetValue(value, out addresses)) { addresses = new List <ulong>(); result[value] = addresses; } addresses.Add(address); if (n % 1024 == 0) { float pct = (float)n / nbStrings; msgBus.Status($"Analyzing strings: {pct:p2}, n= {n:###,###,###,##0} / {nbStrings:###,###,###,##0}"); } } }); msgBus.EndTask($"Strings analyzed. Instances: {n:###,###,###,##0}, unique values: {result.Count:###,###,###,##0}"); var strings = result.Select(kvp => new StringInformation(kvp.Key, kvp.Value)).ToList(); return(strings); }
internal static List<ArraysInformation> Analyse(ClrDump clrDump, MessageBus msgBus) { CancellationTokenSource token = new CancellationTokenSource(); var arrays = new List<ArraysInformation>(); msgBus.BeginTask("Analyzing arrays...", token); int n = 0; clrDump.Run(() => { var arrayTypes = clrDump.AllTypes.Where(t => t.IsArray); int nbArrayType = arrayTypes.Count(); foreach (var type in arrayTypes) { string typeName = type.Name; msgBus.Status($"Analyzing array type: {typeName} ({n:###,###,###,##0}/{nbArrayType:###,###,###,##0})"); if ( token.IsCancellationRequested ) { return; } n++; ulong nbInstances = 0; ulong totalSize = 0; ulong totalLength = 0; ulong maxLength = 0; foreach (var address in clrDump.EnumerateInstances(type)) { nbInstances++; var length = (ulong)(type.GetArrayLength(address)); maxLength = Math.Max(maxLength, length); totalSize += type.GetSize(address); totalLength += length; if (nbInstances % 512 == 0) { msgBus.Status($"Analyzing array: #{nbInstances:###,###,###,##0} for type: {typeName}"); if (token.IsCancellationRequested) { return; } } } arrays.Add(new ArraysInformation(new ClrDumpType(clrDump, type), nbInstances, totalLength, maxLength, totalSize)); } }); msgBus.EndTask($"Arrays analyzed. Types: {n:###,###,###,##0}"); return arrays; }
internal static List<StringInformation> Analyse(ClrDump clrDump, MessageBus msgBus) { var stringType = clrDump.GetClrType(typeof(string).FullName); var stringInstances = clrDump.EnumerateInstances(stringType); int nbStrings = clrDump.CountInstances(stringType); Dictionary <string, List<ulong>> result = new Dictionary<string, List<ulong>>(); CancellationTokenSource token = new CancellationTokenSource(); msgBus.BeginTask("Analyzing strings...", token); int n = 0; clrDump.Run(() => { foreach (var address in stringInstances) { if( token.IsCancellationRequested) { return; } n++; var value = SimpleValueHelper.GetSimpleValue(address, stringType, false) as string; if (value == null) { continue; } List<ulong> addresses; if( ! result.TryGetValue(value, out addresses)) { addresses = new List<ulong>(); result[value] = addresses; } addresses.Add(address); if( n % 1024 == 0) { float pct = (float)n / nbStrings; msgBus.Status($"Analyzing strings: {pct:p2}, n= {n:###,###,###,##0} / {nbStrings:###,###,###,##0}"); } } }); msgBus.EndTask($"Strings analyzed. Instances: {n:###,###,###,##0}, unique values: {result.Count:###,###,###,##0}"); var strings = result.Select(kvp => new StringInformation(kvp.Key, kvp.Value)).ToList(); return strings; }
public ThreadInformation(ClrDump clrDump, ClrThread thread) { ClrDump = clrDump; Thread = thread; clrDump.Run(() => { OSThreadId = thread.OSThreadId; ManagedThreadId = thread.ManagedThreadId; CurrentException = thread.CurrentException?.Type?.Name; GcMode = thread.GcMode; IsAborted = thread.IsAborted; IsAbortRequested = thread.IsAbortRequested; IsAlive = thread.IsAlive; IsBackground = thread.IsBackground; IsCoInitialized = thread.IsCoInitialized; IsDebuggerHelper = thread.IsDebuggerHelper; IsDebugSuspended = thread.IsDebugSuspended; IsFinalizer = thread.IsFinalizer; IsGC = thread.IsGC; IsGCSuspendPending = thread.IsGCSuspendPending; IsMTA = thread.IsMTA; IsShutdownHelper = thread.IsShutdownHelper; IsSTA = thread.IsSTA; IsSuspendingEE = thread.IsSuspendingEE; IsThreadpoolCompletionPort = thread.IsThreadpoolCompletionPort; IsThreadpoolGate = thread.IsThreadpoolGate; IsThreadpoolTimer = thread.IsThreadpoolTimer; IsThreadpoolWait = thread.IsThreadpoolWait; IsThreadpoolWorker = thread.IsThreadpoolWorker; IsUnstarted = thread.IsUnstarted; IsUserSuspended = thread.IsUserSuspended; LockCount = thread.LockCount; var gcThreads = clrDump.Runtime.EnumerateGCThreads().ToList(); IsGCThread = gcThreads.Any(gcThreadId => gcThreadId == OSThreadId); }); }