Measure performance of Silverlight / Moonlight applications
I'm interested in high level performance measurement of Silverlight especially in comparison to Moonlight. I've browsed around and came up with some tools (SilverliightSpy among others) but there has to be other tools or ways to do this.
The high level questions I'd like to investigate are
- How does moonlight and silverlight compare wrt performance
- How should I design my app to get best performance (on SL, ML or both)
The performance characteristics I'm interested in are
- How does my test app utilize the CPU (rough comparison) - i.e. does it off load work to the GPU
- Rendering time. Not only FPS but also latency - "if I modify some visual element's properties..."
- "...how long before they get updated on the screen"
- "...how much is the CPU utilized during that time"
Any suggestions? It would be nice to be able to do this in-app, so that I can just run the app on Silverlight and then on Moonlight and compare its output. A cros开发者_运维技巧s platform profiler would also work though.
Since nobody has answered yet I figured I could post my own findings since asking the question. I still haven't figured out how to measure how much time it took from modifying a visual's appearance until it has been drawn on screen.
To calculate CPU utilization inside your app you can use the Analytics class. To calculate the framerate, just hook in to the static rendering event of the CompositionTarget class.
private DispatcherTimer fpsTimer = new DispatcherTimer();
private DateTime lastFpsUpdate;
private Analytics analyzer = new System.Windows.Analytics();
private int frameCount;
public MyClass()
{
fpsTimer.Interval = TimeSpan.FromSeconds(1);
fpsTimer.Tick += new EventHandler(fpsTimer_Tick);
fpsTimer.Start();
lastFpsUpdate = DateTime.Now;
CompositionTarget.Rendering += new EventHandler(CompositionTarget_Rendering);
}
// Called every second
void fpsTimer_Tick(object sender, EventArgs e)
{
double framerate = 0;
framerate = frameCount / (DateTime.Now - lastFpsUpdate).TotalSeconds;
c_statusMessage.Text = String.Format("Framerate: {0:0} fps, CPU utilization: {1:0.0}%", framerate, analyzer.AverageProcessLoad);
lastFpsUpdate = DateTime.Now;
frameCount = 0;
}
// Called by the framework on every frame
void CompositionTarget_Rendering(object sender, EventArgs e)
{
frameCount++;
}
精彩评论