Navigation

Search

Categories

On this page

How Windows Performance Counters of "Average" Types Linked to Their Bases
Vista ReadyBoost - Caching the Page File

Archive

Blogroll

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

RSS 2.0 | Atom 1.0 | CDF

Send mail to the author(s) E-mail

Total Posts: 48
This Year: 15
This Month: 0
This Week: 0
Comments: 8

Sign In
Pick a theme:

 Thursday, March 20, 2008
Thursday, March 20, 2008 5:04:21 PM (Eastern Standard Time, UTC-05:00) (  |  |  |  )

Some time ago I added performance counters to the application I was working on, and for some inexplicable reason all counters of "Average" type, like AverageCount64 or AverageTimer32, didn't work at all, always having 0 value. Then I had no time to find out why it was not working, but today I did. As you may know, "Average" counters are made of two distinct counters: the base counter and the average counter itself. The mystery was that by looking at all the samples returned by Google, it was unclear how the Base and the Average itself are linked together. It looked like you create the Base and the Average, add them to the collection and somehow magically Windows figures they need to be linked together when averages are calculated. After some research it looks like the two are linked by counter name! It appears that base's name should be the name of real counter, plus word " base". For example, when you define your counter category that has average performance counter, you do something like this:

   counters.Add(
new CounterCreationData("whatever", "whatever desc", PerformanceCounterType.AverageCount64));
   counters.Add(new CounterCreationData("whatever base", "whatever base desc", PerformanceCounterType.AverageBase));

To my surprise, changing the "whatever basevalue of the counter name in both CounterCreationData and PerformanceCounter to something like "whatever base1" breaks the perf counter! It looks like there is a naming convention requiring that AverageBase proformance counter has the CounterName property value on both CounterCreationData and PerformanceCounter to be counter name plus " base", but I never saw this mentioned anywhere - neither by MSDN, nor by Codeproject articles. So, since average perf counters always come in pairs, linked by name, these helpers should make creating average perf counters simpler (uinsg C#/.NET):

        private static void AddAverageCounterDefinition(CounterCreationDataCollection counters,

                        string counterName, string counterDescription, PerformanceCounterType averageType)

        {

            counters.Add(new CounterCreationData(counterName, counterDescription, averageType));

            counters.Add(new CounterCreationData(counterName + " base", string.Empty, PerformanceCounterType.AverageBase));

        }

 

        public class AveragePerfCounter

        {

            private PerformanceCounter averageCounter;

            private PerformanceCounter averageCounterBase;

 

            public AveragePerfCounter(string categoryName, string counterName)

            {

                this.averageCounter = new PerformanceCounter(categoryName, counterName, false);

                this.averageCounterBase = new PerformanceCounter(categoryName, counterName + " base", false);

            }

 

            public void IncrementBy(long val)

            {

                this.averageCounter.IncrementBy(val);

                this.averageCounterBase.Increment();

            }

        }

 

After this, when creating performance counter definition, you could use following code instead of the one shown by the very first snippet:
      AddAverageCounterDefinition(counters, "whatever", "whatever desc", PerformanceCounterType.AverageCount64);
It will add " base" to the name of the sidekick automatically.

And to create corresponding performance counter, you now can do this:
      AveragePerfCounter avgCount = new AveragePerfCounter("MyCategory", "whatever");
     
avgCount.IncrementBy(new Random().Next(100));

 

Comments [0] | | # 
 Thursday, December 28, 2006
Thursday, December 28, 2006 10:21:39 PM (Eastern Standard Time, UTC-05:00) (  |  )

I wanted to try new Vista's feature called ReadyBoost (how many marketing brainstorming sessions did it take to come up with the name?). It's essentially a copy of Vista's virtual memory page file on a flash drive, which is about 10 times faster than the hard drive when it comes to readying small non-sequential chunks of data.

My new Cingular 3125 Windows Smartphone rejected a 1GB MicroSD card made by Kingston, so I found nothing better to do with the flash as to make it a ReadyBoost drive. There are a couple of ways to turn a flash drive into a ReadyBoost storage:
   1. Bring up volume's properties dialog and go to the ReadyBoost property page;
   2. Select appropriate option from the auto-play dialog box after you inserted the drive into the usb port.
I read somewhere that card readers will not work as ReadyBoost drives, that only actual thumb drives will, but my experience is actually opposite: 256MB thumb drive from Dine-Elec was reported by Vista as too slow for ReadyBoost, but Kingston's MicroSD in the USB card reader passed the speed test and was made a ReadyBoost drive.

Well, I didn't notice any difference in performance after ReadyBoost was up. May be it's because my system has 1.5 Gig of memory and 7200 RPM drive, which means on those rare occasions when it needs to swap pages, it is fast. But notebooks will probably benefit much more: on laptops with limited memory and slow 5400 RPM hard drives fast flash card is much more likely to deliver some performance benefits.

Comments [0] | | #