Ejemplo n.º 1
0
    protected override void OnUpdate()
    {
        foreach (GraphStream graphStream in m_GraphStreams)
        {
            graphStream.CompleteInputDependencies();
            DebuggerTracer.GraphTrace graphTrace = DebuggerTracer.GetGraphData(graphStream.GraphId, createIfAbsent: true);
            var reader = graphStream.AsReader();
            var frame  = Time.frameCount;

            DebuggerTracer.FrameData frameData = null;
            for (int i = 0; i < reader.ForEachCount; i++)
            {
                reader.BeginForEachIndex(i);
                DebuggerTracer.EntityFrameTrace entityData = null;
                while (reader.RemainingItemCount > 0)
                {
                    if (frameData == null)
                    {
                        frameData = graphTrace.GetFrameData(frame, createIfAbsent: true);
                    }

                    var   callFrame = reader.Read <DataType>();
                    ulong nodeId1, nodeId2;
                    switch (callFrame)
                    {
                    case DataType.Entity:
                        var e = ReadEntity(ref reader);
                        entityData = frameData.GetEntityFrameTrace(e.Index, createIfAbsent: true);
                        break;

                    case DataType.Step:
                        Assert.IsTrue(entityData != null);
                        ReadStepRecord(ref reader, out nodeId1, out nodeId2, out var stepOffset, out var progress);
                        entityData.SetLastCallFrame(nodeId1, nodeId2, stepOffset, progress);
                        break;

                    case DataType.Data:
                    {
                        Assert.IsTrue(entityData != null);
                        ReadValueRecord(ref reader, out nodeId1, out nodeId2, out var value);
                        entityData.RecordValue(value, nodeId1, nodeId2);
                        break;
                    }
                    }
                }

                reader.EndForEachIndex();
            }

            graphStream.Dispose();
        }
        m_GraphStreams.Clear();
    }
Ejemplo n.º 2
0
    public static DebuggerTracer.EntityFrameTrace GetRecorder(int graphId, int targetIndex)
    {
        Assert.IsTrue(InternalEditorUtility.CurrentThreadIsMainThread());
        // TODO cache graphdata/frametrace
        var frame = Time.frameCount;

        DebuggerTracer.GraphTrace graphTrace = DebuggerTracer.GetGraphData(graphId, true);
        var frameData = graphTrace.GetFrameData(frame, createIfAbsent: true);

        var entityData = frameData.GetEntityFrameTrace(targetIndex, createIfAbsent: true);

        return(entityData);
    }
        public void OnGUI(Rect timeRect)
        {
            // sync timeline and tracing toolbar state both ways
            m_State.CurrentTime = TimelineState.FrameToTime(m_VSWindowState.currentTracingFrame);

            if (EditorApplication.isPlaying && !EditorApplication.isPaused)
            {
                if (m_State.MaxVisibleTime < m_State.CurrentTime + k_MinTimeVisibleOnTheRight)
                {
                    m_TimeArea.SetShownRange(m_State.CurrentTime + k_MinTimeVisibleOnTheRight - m_State.MaxVisibleTime);
                }
            }

            m_Overlay.HandleEvents();
            int timeChangedByTimeline = TimelineState.TimeToFrame(m_State.CurrentTime);

            // force graph update
            if (timeChangedByTimeline != m_VSWindowState.currentTracingFrame)
            {
                m_VSWindowState.currentTracingStep = -1;
            }
            m_VSWindowState.currentTracingFrame = timeChangedByTimeline;

            // time scales
            GUILayout.BeginArea(timeRect);
            m_TimeArea.Draw(timeRect);
            GUILayout.EndArea();
            GUI.BeginGroup(timeRect);

            DebuggerTracer.GraphTrace trace = DebuggerTracer.GetGraphData((m_VSWindowState?.AssetModel as Object)?.GetInstanceID() ?? -1, false);
            var frameHasDataColor           = new Color32(68, 192, 255, 255);

            if (trace != null && trace.AllFrames.Count > 0)
            {
                float frameDeltaToPixel        = m_TimeArea.FrameDeltaToPixel();
                DebuggerTracer.FrameData first = trace.AllFrames[0];
                DebuggerTracer.FrameData last  = trace.AllFrames[trace.AllFrames.Count - 1];
                float start = m_TimeArea.FrameToPixel(first.Frame);
                float width = frameDeltaToPixel * Mathf.Max(last.Frame - first.Frame, 1);

                EditorGUI.DrawRect(new Rect(start, k_FrameRectangleHeight, width, k_FrameRectangleWidth), frameHasDataColor);
            }

            // playing head
            m_Overlay.OnGUI(timeRect, timeRect);
            GUI.EndGroup();
        }
        public virtual void OptionsMenu(GenericMenu menu)
        {
            MenuItem("Tracing/Clear", false, () => DebuggerTracer.LoadData(null));

            MenuItem("Tracing/Load", false, () =>
            {
                if (!GetAssetAndTracePath(out var assetModel, out var _, out var traceName))
                {
                    return;
                }
                TraceDump traceDump;
                using (var traceStream = File.OpenRead(traceName))
                    traceDump = TraceDump.Deserialize(new BinaryReader(traceStream));
                var graphTrace = new DebuggerTracer.GraphTrace(traceDump.FrameData);
                DebuggerTracer.GraphReference graphReference = DebuggerTracer.GraphReference.FromId(assetModel.GetInstanceID());
                DebuggerTracer.LoadData(new Dictionary <DebuggerTracer.GraphReference, DebuggerTracer.GraphTrace>
                {
                    [graphReference] = graphTrace
                });
            });
Ejemplo n.º 5
0
        public void TestCircularBufferHasRightValues()
        {
            DebuggerTracer.GraphTrace recorder = new DebuggerTracer.GraphTrace(10);
            const int entityId = 0;

            for (int i = 0; i < 20; i++)
            {
                DebuggerTracer.FrameData        frameData  = recorder.GetFrameData(i, true);
                DebuggerTracer.EntityFrameTrace entityData = frameData.GetEntityFrameTrace(entityId, true);
                entityData.RecordValue(i, 0, 0);
            }
            for (int i = 0; i < 20; i++)
            {
                if (i < 10)
                {
                    Assert.That(recorder.GetFrameData(i, false), Is.Null);
                }
                else
                {
                    Assert.That(recorder.GetFrameData(i, false).GetEntityFrameTrace(entityId, false).values[0].Single().readableValue, Is.EqualTo(i.ToString()));
                }
            }
        }