Answered by:
PerformanceCounter Definition of sample interval

Question
-
The performance counters in the code sample below gives me this chart in Performance Monitor.
The documentation for PerformanceCounter class describes the Formulas for each counter type clearly.
But, the documentation uses the term sample interval. What is the definition of it?
In the diagram below it is obvious that some sliding time window is applied to the performance values.
I expected the performance counter to just keep the accumulated values after the last run.Some standard performance counter pseudocode:
_AverageDuration = new PerformanceCounter(); //PerformanceCounterType.AverageTimer32 _AverageDuration.CategoryName = "TimeTickCategory"; _AverageDuration.CounterName = "average time per operation"; _AverageDurationBase = new PerformanceCounter(); // PerformanceCounterType.AverageBase _AverageDurationBase.CategoryName = "TimeTickCategory"; _AverageDurationBase.CounterName = "average time per operation base";
for (int i = 1; i <= reps; i++) { _AverageDuration.IncrementBy(elapsedTicks); //PerformanceCounterType.AverageTimer32 _AverageDurationBase.Increment(); // PerformanceCounterType.AverageBase }
Regards OveMonday, December 2, 2013 9:17 AM
Answers
-
A sample is the data points collected when you query the counters. The sample interval is the frequency at which you collect samples. So if you are refreshing the UI every second then the sample interval is 1 second. As an example, this documentation uses a sample interval of 50 ms. Every 50ms it gets the counter values.
Michael Taylor
http://msmvps.com/blogs/p3net
- Proposed as answer by Christopher84 Monday, December 2, 2013 3:21 PM
- Marked as answer by Ove Kernell Monday, December 2, 2013 4:09 PM
Monday, December 2, 2013 1:45 PM
All replies
-
A sample is the data points collected when you query the counters. The sample interval is the frequency at which you collect samples. So if you are refreshing the UI every second then the sample interval is 1 second. As an example, this documentation uses a sample interval of 50 ms. Every 50ms it gets the counter values.
Michael Taylor
http://msmvps.com/blogs/p3net
- Proposed as answer by Christopher84 Monday, December 2, 2013 3:21 PM
- Marked as answer by Ove Kernell Monday, December 2, 2013 4:09 PM
Monday, December 2, 2013 1:45 PM -
That.
The only thing to add is that you should avoid setting the intervall too low (or at least buffer the results a bit before writing them). Writing to the UI caries quite a bit of Overhead as can be seen in this example:
public partial class Form1 : Form { public Form1() { InitializeComponent(); } int[] getNumbers(int upperLimit) { int[] ReturnValue = new int[upperLimit]; for (int i = 0; i < ReturnValue.Length; i++) ReturnValue[i] = i; return ReturnValue; } void printWithBuffer(int[] Values) { textBox1.Text = ""; string buffer = ""; foreach (int Number in Values) buffer += Number.ToString() + Environment.NewLine; textBox1.Text = buffer; } void printDirectly(int[] Values){ textBox1.Text = ""; foreach (int Number in Values) textBox1.Text += Number.ToString() + Environment.NewLine; } private void btnPrintBuffer_Click(object sender, EventArgs e) { MessageBox.Show("Generating Numbers"); int[] temp = getNumbers(1000); MessageBox.Show("Printing with buffer"); printWithBuffer(temp); MessageBox.Show("Printing done"); } private void btnPrintDirect_Click(object sender, EventArgs e) { MessageBox.Show("Generating Numbers"); int[] temp = getNumbers(1000); MessageBox.Show("Printing directly"); printDirectly(temp); MessageBox.Show("Printing done"); } }
Getting the Numbers and running "printWithBuffer" takes an eye blink fora single 2.2 GhZ core. Running printDirectly takes 8 Seconds during wich the UI is locked up.
Effective numbers may varry depending on DisplayTechnology CPU, GPU and wheter the ChartElement you have uses some buffering/intelligent redraw itself.Let's talk about MVVM: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b1a8bf14-4acd-4d77-9df8-bdb95b02dbe2 Please mark post as helpfull and answers respectively.
Monday, December 2, 2013 3:26 PM -
Thank you!
I had trouble separating the counter and its 2 values which only exist in one instance, from the observations taken. Working through the sample really helped./Ove
Monday, December 2, 2013 4:18 PM