protected override void OnProcessOutputSchema(MutableObject newSchema) { foreach (var entry in TraceScope.GetEntries(newSchema)) { foreach (var subentry in AllocateScope.GetEntries(entry)) { AllocatePositionTarget.SetValue(4f, subentry); AllocateSizeTarget.SetValue(.4f, subentry); AllocateColorTarget.SetValue(Color.magenta, subentry); AllocateEndIndexTarget.SetValue((int)12, subentry); } foreach (var subentry in ReadScope.GetEntries(entry)) { ReadPositionTarget.SetValue(4f, subentry); ReadSizeTarget.SetValue(.4f, subentry); ReadColorTarget.SetValue(Color.magenta, subentry); } foreach (var subentry in WriteScope.GetEntries(entry)) { WritePositionTarget.SetValue(4f, subentry); WriteSizeTarget.SetValue(.4f, subentry); WriteColorTarget.SetValue(Color.magenta, subentry); } } GridLinesTarget.SetValue(new List <MutableObject> { new MutableObject { { "Visual Position", .5f }, { "Visual Weight", .2f } }, new MutableObject { { "Visual Position", 1f }, { "Visual Weight", .1f } } }, newSchema); Router.TransmitAllSchema(newSchema); }
public override IEnumerator ReceivePayload(VisualPayload payload) { //var outOfBoundsColor = OutOfBoundsColor.GetFirstValue( payload.Data ); var outOfBoundsReadColor = OutOfBoundsReadColor.GetFirstValue(payload.Data); var outOfBoundsWriteColor = OutOfBoundsWriteColor.GetFirstValue(payload.Data); var allocatedAlpha = AllocationAlpha.GetFirstValue(payload.Data); var valueStepSize = ValueStepSize.GetFirstValue(payload.Data); var allocationColor = AllocationColor.GetFirstValue(payload.Data); float allocH, allocS, allocV; ColorUtility.RGBToHSV(allocationColor, out allocH, out allocS, out allocV); //var readWriteDifferentiation = ReadWriteDifferentiation.GetFirstValue( payload.Data ); foreach (var entry in TraceScope.GetEntries(payload.Data)) { var memSpace = new MemorySpace(); //var saturation = Saturation.GetValue( entry ); //var hueStep = HueStepSize.GetValue( entry ); //var value = Value.GetValue( entry ); int maxIndex = MaxIndex.GetValue(entry); // match allocations and frees var allocations = new Dictionary <uint, MemorySpacePoint>(); foreach (var allocation in AllocateScope.GetEntries(entry)) { var address = AllocateAddress.GetValue(allocation); var size = AllocateSize.GetValue(allocation); var index = AllocateIndex.GetValue(allocation); var newPoint = memSpace.AddMemoryAllocation(address, size); newPoint.StartIndex = index; newPoint.EndPoint.StartIndex = index; newPoint.EndIndex = maxIndex; newPoint.EndPoint.EndIndex = maxIndex; allocations.Add(newPoint.Address, newPoint); } // assign the end indices of any allocates with matched frees foreach (var free in FreeScope.GetEntries(entry)) { var index = FreeIndex.GetValue(free); var address = FreeAddress.GetValue(free); if (allocations.ContainsKey(address)) { var matchedAllocation = allocations[address]; matchedAllocation.EndIndex = index; matchedAllocation.EndPoint.EndIndex = index; } } // import reads to the memory space var readPoints = new Dictionary <int, MemorySpacePoint>(); foreach (var read in ReadScope.GetEntries(entry)) { var address = ReadAddress.GetValue(read); var size = ReadSize.GetValue(read); var index = ReadIndex.GetValue(read); var readPoint = MemorySpacePoint.GeneratePoint(address, size); readPoint.AllIndices = index; MemorySpacePoint containingPoint; if (memSpace.IsAccessContained(readPoint, readPoint.EndPoint, out containingPoint)) { readPoint.ContainingAllocation = containingPoint; } else { var outOfBoundsAlloc = memSpace.AddMemoryAllocation(address, size, 0, maxIndex); outOfBoundsAlloc.IsOutOfBounds = true; readPoint.ContainingAllocation = outOfBoundsAlloc; } readPoints.Add(index, readPoint); } // import Writes to the memory space var writePoints = new Dictionary <int, MemorySpacePoint>(); foreach (var write in WriteScope.GetEntries(entry)) { var address = WriteAddress.GetValue(write); var size = WriteSize.GetValue(write); var index = WriteIndex.GetValue(write); var writePoint = MemorySpacePoint.GeneratePoint(address, size); writePoint.AllIndices = index; MemorySpacePoint containingPoint; if (memSpace.IsAccessContained(writePoint, writePoint.EndPoint, out containingPoint)) { writePoint.ContainingAllocation = containingPoint; } else { var outOfBoundsAlloc = memSpace.AddMemoryAllocation(address, size, 0, maxIndex); outOfBoundsAlloc.IsOutOfBounds = true; writePoint.ContainingAllocation = outOfBoundsAlloc; } writePoints.Add(index, writePoint); } // generate visual space for memory allocations (include out of bounds allocations) memSpace.SetVisualBounding(); // set colors for memory allocations (inclde out of bounds allocations with special color) //var hueRotor = HueStart.GetValue( entry ); foreach (var allocation in memSpace.RegisteredSpace.Where(s => s.IsStart)) { Color nextColor = ColorUtility.HsvtoRgb(allocH, allocS, allocV); allocV = .3f + (allocV + valueStepSize) % .7f; /*(allocation.IsOutOfBounds)? * outOfBoundsColor: * ColorUtility.HsvtoRgb(hueRotor, saturation, * value);*/ nextColor.a = allocatedAlpha; //if ( !allocation.IsOutOfBounds ) // hueRotor += hueStep; allocation.VisualColor = nextColor; } // set colors and visual locations for all reads foreach (var read in readPoints) { if (read.Value.ContainingAllocation == null) { Debug.LogError("Danger will robinson! Danger!"); } read.Value.VisualColor = outOfBoundsReadColor; // read.Value.ContainingAllocation.VisualColor == outOfBoundsColor? // outOfBoundsReadColor: // Color.Lerp( // read.Value.ContainingAllocation.VisualColor, // Color.white, readWriteDifferentiation); //read.Value.VisualStart = memSpace.AddressToVisualPosition( read.Value.Address ); //read.Value.VisualEnd = memSpace.AddressToVisualPosition( read.Value.EndPoint.Address ); read.Value.ComputeVisualPositionsFromContainer(); } // set colors and visual locations for all writes foreach (var write in writePoints) { if (write.Value.ContainingAllocation == null) { Debug.LogError("Danger will robinson! Danger!"); } write.Value.VisualColor = outOfBoundsWriteColor; // write.Value.ContainingAllocation.VisualColor == outOfBoundsColor? // outOfBoundsWriteColor: // Color.Lerp( // write.Value.ContainingAllocation.VisualColor, // Color.black, readWriteDifferentiation); write.Value.ComputeVisualPositionsFromContainer(); //write.Value.VisualStart = memSpace.AddressToVisualPosition(write.Value.Address); //write.Value.VisualEnd = memSpace.AddressToVisualPosition(write.Value.EndPoint.Address); } // FINALLY, write this information into the corresponding targets foreach (var allocation in AllocateScope.GetEntries(entry)) { var targetAddress = AllocateAddress.GetValue(allocation); //var targetIndex = AllocateIndex.GetValue( allocation ); if (!allocations.ContainsKey(targetAddress)) { throw new Exception("Allocation address not found!"); } var foundAllocation = allocations[targetAddress]; AllocateColorTarget.SetValue(foundAllocation.VisualColor, allocation); AllocatePositionTarget.SetValue(foundAllocation.VisualStart, allocation); AllocateSizeTarget.SetValue(foundAllocation.VisualEnd - foundAllocation.VisualStart, allocation); AllocateEndIndexTarget.SetValue(foundAllocation.EndIndex, allocation); } foreach (var read in ReadScope.GetEntries(entry)) { var targetIndex = ReadIndex.GetValue(read); if (!readPoints.ContainsKey(targetIndex)) { throw new Exception("Read index not found!"); } var foundRead = readPoints[targetIndex]; ReadColorTarget.SetValue(foundRead.VisualColor, read); ReadPositionTarget.SetValue(foundRead.VisualStart, read); ReadSizeTarget.SetValue(foundRead.VisualEnd - foundRead.VisualStart, read); } foreach (var write in WriteScope.GetEntries(entry)) { var targetIndex = WriteIndex.GetValue(write); if (!writePoints.ContainsKey(targetIndex)) { throw new Exception("Write index not found!"); continue; } var foundwrite = writePoints[targetIndex]; WriteColorTarget.SetValue(foundwrite.VisualColor, write); WritePositionTarget.SetValue(foundwrite.VisualStart, write); WriteSizeTarget.SetValue(foundwrite.VisualEnd - foundwrite.VisualStart, write); } // write grid lines var gridLines = new List <MutableObject>(); uint priorAddress = memSpace.RegisteredSpace.First().Address; gridLines.Add(new MutableObject { { "Visual Position", 0f }, { "Visual Weight", 1000f } }); foreach (var space in memSpace.RegisteredSpace) { if (space.IsEnd) { continue; } var newGridLine = new MutableObject { { "Visual Position", space.VisualStart }, { "Visual Weight", (float)(Mathf.Max(0, priorAddress - space.StartPoint.Address) + 1) } }; priorAddress = space.EndPoint.Address; gridLines.Add(newGridLine); } gridLines.Add(new MutableObject { { "Visual Position", 1f }, { "Visual Weight", 1000f } }); GridLinesTarget.SetValue(gridLines, entry); } var iterator = Router.TransmitAll(payload); while (iterator.MoveNext()) { yield return(null); } }