Silverlight 3 Quick Tip: Analytics

July 10, 2009

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:

image

 

 

Enjoy,

Alex

Add comment
facebook linkedin twitter email

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*

2 comments

  1. SomebodyAugust 8, 2009 ב 11:59

    Just wondering – is device ID unique? Does it mean I can authenticate my users (or their machines)?

    Reply
  2. Alex GoleshAugust 9, 2009 ב 11:58

    Somebody:

    DeviceID is a GPU model identification (GForce 9300M, GForce 9800GTX, Intel 4500M, ATi Radeon HD 4850), VendorID is a GPU maker identification (NVidia, ATi, Intel, etc.)… It is not a chip number 🙂

    Regards,
    Alex

    Reply