public void EnumerateAllPathCancel() { using DataTarget dataTarget = TestTargets.GCRoot.LoadFullDump(); using ClrRuntime runtime = dataTarget.ClrVersions.Single().CreateRuntime(); ClrHeap heap = runtime.Heap; GCRoot gcroot = new GCRoot(heap); CancellationTokenSource cancelSource = new CancellationTokenSource(); cancelSource.Cancel(); GetKnownSourceAndTarget(runtime.Heap, out ulong source, out ulong target); Assert.Throws <OperationCanceledException>(() => gcroot.EnumerateAllPaths(source, target, false, cancelSource.Token).ToArray()); }
private void FindAllPathsImpl(GCRoot gcroot) { ClrHeap heap = gcroot.Heap; GetKnownSourceAndTarget(heap, out ulong source, out ulong target); LinkedList <ClrObject>[] paths = gcroot.EnumerateAllPaths(source, target, false, CancellationToken.None).ToArray(); // There are exactly three paths to the object in the test target Assert.Equal(3, paths.Length); foreach (LinkedList <ClrObject> path in paths) { AssertPathIsCorrect(heap, path.ToImmutableArray(), source, target); } }
public void FindAllPaths() { using DataTarget dataTarget = TestTargets.GCRoot.LoadFullDump(); using ClrRuntime runtime = dataTarget.ClrVersions.Single().CreateRuntime(); ClrHeap heap = runtime.Heap; GCRoot gcroot = new GCRoot(heap); GetKnownSourceAndTarget(heap, out ulong source, out ulong target); LinkedList <ClrObject>[] paths = gcroot.EnumerateAllPaths(source, target, false, CancellationToken.None).ToArray(); // There are exactly three paths to the object in the test target Assert.Equal(3, paths.Length); foreach (LinkedList <ClrObject> path in paths) { AssertPathIsCorrect(heap, path.ToImmutableArray(), source, target); } }
public void EnumerateAllPathshCancel() { using (DataTarget dataTarget = TestTargets.GCRoot.LoadFullDump()) { ClrRuntime runtime = dataTarget.ClrVersions.Single().CreateRuntime(); ClrHeap heap = runtime.Heap; heap.StackwalkPolicy = ClrRootStackwalkPolicy.SkipStack; GCRoot gcroot = new GCRoot(runtime.Heap); CancellationTokenSource cancelSource = new CancellationTokenSource(); cancelSource.Cancel(); GetKnownSourceAndTarget(runtime.Heap, out ulong source, out ulong target); try { gcroot.EnumerateAllPaths(source, target, false, cancelSource.Token).ToArray(); Assert.Fail("Should have been cancelled!"); } catch (OperationCanceledException) { } } }
/// <summary> /// Returns the path from the start object to the end object (or null if no such path exists). /// </summary> /// <param name="source">The initial object to start the search from.</param> /// <param name="target">The object we are searching for.</param> /// <param name="unique">Whether to only enumerate fully unique paths.</param> /// <param name="cancelToken">A cancellation token to stop enumeration.</param> /// <returns>A path from 'source' to 'target' if one exists, null if one does not.</returns> /// <inheritdoc /> public IEnumerable <IList <IClrObject> > EnumerateAllPaths(ulong source, ulong target, bool unique, CancellationToken cancelToken) => Root.EnumerateAllPaths(source, target, unique, cancelToken) .Select(ll => ll.Select(Converter.Convert).ToList());