Search code examples
sql-serverperformanceperformancecounterperfmon

Perfmon, how to combine Combine FirstValueA and FirstValueB?


I am using performance monitor to collect the counters data and save it to the DB. Here is the DB structure defined in the msdn http://msdn.microsoft.com/en-us/library/windows/desktop/aa371915(v=VS.85).aspx

Based on DB structure, here is the definition of the FirstValueA:

Combine this 32-bit value with the value of FirstValueB to create the FirstValue member of PDH_RAW_COUNTER. FirstValueA contains the low order bits.

And the FirstValueB:

Combine this 32-bit value with the value of FirstValueA to create the FirstValue member of PDH_RAW_COUNTER. FirstValueB contains the high order bits.

The fields FirstValueA and FirstValueB should be combined to create the FirstValue, and similarly the SecondValue.

How do you combine FirstValueA and FirstValueB to get the FirstValue in SQL Server?


Solution

  • So what they're saying is that you need to comingle the two, like this:

    //for reference, this is 32 bits
    12345678901234567890123456789012
    000000000000000000000FirstValueA
    000000000000000000000FirstValueB
    

    What it says is we need to combine the two. It says that A is the low order, and B is the high order.

    Let's refer to Wikipedia for http://en.wikipedia.org/wiki/Least_significant_bit and see that the low order is on the --> right, and the high order is on the <-- left.

    low order -> right
    high order <- left
    
    A -> right
    B <- left
    

    So we're going to end up with (our previous example)

    //for reference, this is 32 bits
    12345678901234567890123456789012
    000000000000000000000FirstValueA
    000000000000000000000FirstValueB
    

    becomes

    //for reference, this is 32 bits
    12345678901234567890123456789012
    000000000000000000000FirstValueB000000000000000000000FirstValueA
    

    Now, that doesn't work if the values look like this:

    //for reference, this is 32 bits
    12345678901234567890123456789012
    1001101100110100101011010001010100101000010110000101010011101010
    //the above string of 1's and 0's is more correct for the example
    

    What you're given is not two binary strings, but two integers. So you have to multiply the left value by 2**32 and add it to the right value. (that's a 64 bit field by the way)

    let's examine tho, why the low order bit is on the right and the high order is on the left:

    Binary is written just like Arabic numerals. In Arabic numerals, the number:

    123456
    

    means one hundred twenty three thousand, four hundred fifty six. The one hundred thousand is the most significant part (given as we would shorten this to "just over one hundred thousand dollars" instead of "a lot over 6 dollars") and the six is the part we most freely drop. So we could say that the number were:

    123 is the value that contains the high order bits, and 456 is the value that contains the low order bits. Here we would multiply by 10^3 to add them together (this is a mathematical fact, not a guess, so trust me on this) because it would look like this:

     123
        456
    

    and so the same works for the binary:

    //for reference, this is 32 bits
    12345678901234567890123456789012
    000000000000000000000FirstValueB
                                    000000000000000000000FirstValueA
    

    tl;dr:

    Multiply B by 2^32 and add to A