Silverlight 3 Quick Tip: Analytics
Silverlight 3 has new feature which should help us to understand how good our application performs. This feature is Analytics class. It Has 2 read-only properties
AverageProcessLoad – average CPU used by this process across all the cores
AverageProcessorLoad – average CPU usage across all cores
In addition it has GpuCollection collection with objects of GpuInformation type. Each one of GpuInformation object provides information about:
DeviceId – device ID of the GPU
VendorId – vendor ID of the GPU
DriverVersion – video drivers version
Quick usage sample – show CPU usage:
Code behind:
public partial class MainPage : UserControl
{
private Analytics theAnalytics;
public MainPage()
{
InitializeComponent();
theAnalytics = new Analytics();
DispatcherTimer timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromSeconds(1);
timer.Tick += (s, e) =>
{
txtCPULoad.Text = theAnalytics.AverageProcessorLoad.ToString();
txtSLCPULoad.Text = theAnalytics.AverageProcessLoad.ToString();
};
timer.Start();
}
}
XAML:
<StackPanel x:Name="LayoutRoot">
<StackPanel Orientation="Horizontal">
<TextBlock Text="Average CPU Load:"/>
<TextBlock x:Name="txtCPULoad"/>
<TextBlock Text="%"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Average Silverlight CPU Load:"/>
<TextBlock x:Name="txtSLCPULoad"/>
<TextBlock Text="%"/>
</StackPanel>
</StackPanel>
Running application:
Enjoy,
Alex