locked
Performance Counter Question: How to convert CounterDelta64 into percentage? RRS feed

  • Question

  • I was trying to read % total time of Hyper-V using a C# application. But the NextValue() returned from performance counter ("hyperv","% total time", "_total")
    are all typed "CounterDelta64" and are some numbers (e.g. 1112345).

    If I read "Processor % Total Time", it returns a percentage number and is just fine.

    How do I translate these into percentages? Or did I do anything wrong?

    Thanks a lot!!!
    Friday, April 4, 2008 10:54 PM

Answers

  • As they're CounterDelta types (as in CounterDelta64 or CounterDelta32), you would need to have the previous values to translate these into a percentage, as CounterDelta types only return the "Change" in value of the particular item you're requesting. 

     

    For instance:

     

    The first value we receive is 4.

    The second value we receive is 8.

     

    This is a delta of 4 ( 8 - 4 = 4 ).

     

    So, all that to say, the performance counters with the PerformanceCounterType of Delta simply represents a change in the value, and not the value itself, so you would need to have the previous value to translate into a percentage, and even then, it's only a percentage of change, and not a percentage of processor total usage.

     

    Friday, April 4, 2008 11:07 PM
  • SKY.SKY,

     

    In my opinion, the reply by David M Morton has pointed the clear definition of CounterDelta64 of Performance Counter. This is the "Change in a value but not the value itself". I would like to provide you the following example Implementing a Simple Performance Counter

     

    Code Snippet

            public PerformanceCounter CreateSimpleCounter(string counterName, string counterHelp,

        System.Diagnostics.PerformanceCounterType counterType, string categoryName,

        string categoryHelp)

            {

                CounterCreationDataCollection counterCollection =

                        new CounterCreationDataCollection();

     

                // Create the custom counter object and add it to the collection of counters.

                CounterCreationData counter = new CounterCreationData(counterName, counterHelp,

                        counterType);

                counterCollection.Add(counter);

     

                // Create category.

                if (PerformanceCounterCategory.Exists(categoryName))

                {

                    PerformanceCounterCategory.Delete(categoryName);

                }

     

                PerformanceCounterCategory appCategory =

                    PerformanceCounterCategory.Create(categoryName, categoryHelp,

                        PerformanceCounterCategoryType.SingleInstance, counterCollection);

                // Create the counter and initialize it.

                PerformanceCounter appCounter =

                    new PerformanceCounter(categoryName, counterName, false);

     

                appCounter.RawValue = 0;

     

                return (appCounter);

            }

     

     

     

    Hope that can provide you some idea.

    Monday, April 7, 2008 7:54 AM

All replies

  • As they're CounterDelta types (as in CounterDelta64 or CounterDelta32), you would need to have the previous values to translate these into a percentage, as CounterDelta types only return the "Change" in value of the particular item you're requesting. 

     

    For instance:

     

    The first value we receive is 4.

    The second value we receive is 8.

     

    This is a delta of 4 ( 8 - 4 = 4 ).

     

    So, all that to say, the performance counters with the PerformanceCounterType of Delta simply represents a change in the value, and not the value itself, so you would need to have the previous value to translate into a percentage, and even then, it's only a percentage of change, and not a percentage of processor total usage.

     

    Friday, April 4, 2008 11:07 PM
  • Thanks for replying.

     

    I understand it's a delta. My questions remains:

     

    first of all, this "% total run time" counter returns a delta64, how do I trans late it into real percentage % of total time?

     

    secondly, is it a microsoft bug?

    It's strange, but in MS perfmon, it shows percentage in the chart (if added this exact same performance counter).

     

     

     

    Friday, April 4, 2008 11:12 PM
  • SKY.SKY,

     

    In my opinion, the reply by David M Morton has pointed the clear definition of CounterDelta64 of Performance Counter. This is the "Change in a value but not the value itself". I would like to provide you the following example Implementing a Simple Performance Counter

     

    Code Snippet

            public PerformanceCounter CreateSimpleCounter(string counterName, string counterHelp,

        System.Diagnostics.PerformanceCounterType counterType, string categoryName,

        string categoryHelp)

            {

                CounterCreationDataCollection counterCollection =

                        new CounterCreationDataCollection();

     

                // Create the custom counter object and add it to the collection of counters.

                CounterCreationData counter = new CounterCreationData(counterName, counterHelp,

                        counterType);

                counterCollection.Add(counter);

     

                // Create category.

                if (PerformanceCounterCategory.Exists(categoryName))

                {

                    PerformanceCounterCategory.Delete(categoryName);

                }

     

                PerformanceCounterCategory appCategory =

                    PerformanceCounterCategory.Create(categoryName, categoryHelp,

                        PerformanceCounterCategoryType.SingleInstance, counterCollection);

                // Create the counter and initialize it.

                PerformanceCounter appCounter =

                    new PerformanceCounter(categoryName, counterName, false);

     

                appCounter.RawValue = 0;

     

                return (appCounter);

            }

     

     

     

    Hope that can provide you some idea.

    Monday, April 7, 2008 7:54 AM