Skip to content

Commit

Permalink
Added a separate diagnostics graph to track Update method timing (Ava…
Browse files Browse the repository at this point in the history
  • Loading branch information
kekekeks authored Mar 25, 2024
1 parent bb6005b commit 029daf7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ internal class CompositionTargetOverlays
{
private FpsCounter? _fpsCounter;
private FrameTimeGraph? _renderTimeGraph;
private FrameTimeGraph? _updateTimeGraph;
private FrameTimeGraph? _layoutTimeGraph;
private Rect? _oldFpsCounterRect;
private long _updateStarted;
Expand All @@ -35,6 +36,11 @@ private FrameTimeGraph? LayoutTimeGraph

private FrameTimeGraph? RenderTimeGraph
=> _renderTimeGraph ??= CreateTimeGraph("Render");

private FrameTimeGraph? UpdateTimeGraph
=> _updateTimeGraph ??= CreateTimeGraph("RUpdate");



public bool RequireLayer => DebugOverlays.HasAnyFlag(RendererDebugOverlays.DirtyRects);

Expand Down Expand Up @@ -91,7 +97,17 @@ public void Draw(IDrawingContextImpl targetContext, bool hasLayer)
}
}

public void MarkUpdateCallStart() => _updateStarted = CaptureTiming ? Stopwatch.GetTimestamp() : 0L;
public void MarkUpdateCallStart()
{
if (CaptureTiming)
_updateStarted = CaptureTiming ? Stopwatch.GetTimestamp() : 0L;
}

public void MarkUpdateCallEnd()
{
if (CaptureTiming)
UpdateTimeGraph?.AddFrameValue(StopwatchHelper.GetElapsedTime(_updateStarted).TotalMilliseconds);
}

private void DrawOverlays(ImmediateDrawingContext targetContext, bool hasLayer, Size logicalSize)
{
Expand Down Expand Up @@ -129,7 +145,10 @@ void DrawTimeGraph(FrameTimeGraph? graph)
DrawTimeGraph(LayoutTimeGraph);

if (DebugOverlays.HasFlag(RendererDebugOverlays.RenderTimeGraph))
{
DrawTimeGraph(RenderTimeGraph);
DrawTimeGraph(UpdateTimeGraph);
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ public void Render()
_updateRequested = false;
Readback.CompleteWrite(Revision);

_overlays.MarkUpdateCallEnd();

if (!_redrawRequested)
return;
_redrawRequested = false;
Expand Down

0 comments on commit 029daf7

Please sign in to comment.