title: Correct use of "% Time in GC" performance counter
body: <p>I am trying to get the "% Time in GC" performance counter in ".NET CLR Memory" category programmatically. </p>
  
  <p>According to the description in PerfMon, </p>
  
  <blockquote>
    <p>% Time in GC is the percentage of elapsed time that was spent in
    performing a garbage collection (GC) since the last GC cycle. This
    counter is usually an indicator of the work done by the Garbage
    Collector on behalf of the application to collect and compact memory.
    This counter is updated only at the end of every GC and the counter
    value reflects the last observed value; its not an average.</p>
  </blockquote>
  
  <p>So based on that description, my understanding is that I will have to get the performance counter periodically and calculate the average value myself. </p>
  
  <p>The way I get the performance counter is </p>
  
  <pre><code>     string category = ".NET CLR Memory";
       string counter  = "% Time in GC";
       string instance = Process.GetCurrentProcess().ProcessName;
       PerformanceCounter gcPerf;
  
       // make sure the performance counter is available to query
       if (PerformanceCounterCategory.Exists(category) &amp;&amp;
           PerformanceCounterCategory.CounterExists(counter, category) &amp;&amp;
           PerformanceCounterCategory.InstanceExists(instance, category))
       {
          gcPerf = new PerformanceCounter(category, counter, instance);
       }
  </code></pre>
  
  <p>However, when I look at <a href="http://msdn.microsoft.com/en-us/library/xb29hack(v=vs.90).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/xb29hack(v=vs.90).aspx</a>, my understanding is that gcPerf.NextValue() will do the sampling and calculate the average for you.</p>
  
  <p>So what exactly is the correct use of "% Time in GC"? Is calling gcPerf.NextValue() returning the average value since the method was called last time? </p>