Profiling Guide - davidortinau/ControlGallery GitHub Wiki

💬 Copilot Chat Prompt

Walk me through collecting a CPU performance trace for my .NET MAUI app using dotnet-trace. Then help me analyze the speedscope output to identify hot paths and methods running on the UI thread.

Use dotnet-trace, Speedscope, and PerfView to capture CPU or memory traces.

🔧 How to Collect

# Install once
 dotnet tool install -g dotnet-trace

# Run tracing (find your app PID first)
 dotnet-trace collect --process-id <PID> --profile cpu-sampling --format speedscope

🔍 How to Analyze

  • Open the .nettrace file in https://www.speedscope.app
  • Switch to Left Heavy or Flamegraph view
  • Look for:
    • Methods near the top of the graph that consume a large % of time
    • Any work done on the main/UI thread (e.g., MainThread, SynchronizationContext, DispatcherQueue)
    • Repeated calls to layout, rendering, or navigation methods

🧠 Tips

  • If the UI thread is busy, the app will appear frozen. Try to reduce layout passes, animations, or sync IO
  • If GC is very frequent, review allocations and memory leaks

📚 Additional Resources


➡️ Next: Apply Fixes

⚠️ **GitHub.com Fallback** ⚠️