2012-01-09 8 views
1

我正在使用性能監視器來收集計數器數據並將其保存到數據庫。這裏是在MSDN http://msdn.microsoft.com/en-us/library/windows/desktop/aa371915(v=VS.85).aspxPerfmon,如何組合FirstValueA和FirstValueB?

定義DB結構基於DB結構,這裏是FirstValueA的定義:

結合與FirstValueB的值這32位值來創建 FirstValue構件的PDH_RAW_COUNTER。 FirstValueA包含低位 命令位。

而FirstValueB:

與FirstValueA的值來創建PDH_RAW_COUNTER的 FirstValue構件結合這32位值。 FirstValueB包含高位 命令位。

字段FirstValueA和FirstValueB應該結合起來創建FirstValue,並且類似地創建SecondValue。

如何將FirstValueA和FirstValueB結合起來獲取SQL Server中的FirstValue?

回答

3

那麼他們說的是,你需要comingle兩個,像這樣:

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

它所要表達的是,我們需要將兩者結合起來。它說A是低階,B是高階。

讓我們參考維基百科的http://en.wikipedia.org/wiki/Least_significant_bit,看看low order is on the --> righthigh order is on the <-- left

low order -> right 
high order <- left 

A -> right 
B <- left 

因此,我們將與(我們上面的例子)

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

成爲

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

現在,如果值這個樣子不行就結了:

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

你給的不是兩個比納ry字符串,但是有兩個整數。所以你必須將左邊的值乘以2 ** 32並將其加到正確的值。 (這是一個64位字段的方式)

讓我們來看看壽,爲什麼低位在右邊,而高位在左邊:

二進制寫入就像阿拉伯數字。在阿拉伯數字中,數字:

123456 

表示一百二十三千四百五十六。十萬是最重要的部分(因爲我們將這個縮短爲「超過10萬美元」而不是「超過6美元」),而這六個部分是我們最自由放棄的部分。所以我們可以說這個數字是:

123是包含高階比特的值,456是包含低階比特的值。在這裏,我們將通過10^3相乘,將它們添加到一起(這是一個數學的事實,而不是猜測,所以相信我這一點),因爲它是這樣的:

123 
    456 

,並因此對於同樣的作品二進制:

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

TL; DR:

乘乙除以2^32,並添加到甲

+0

1用於通過那些總低科技降價te顯示器! – Josh 2012-01-09 21:21:43

0
Console.WriteLine("{0} {1} {2} : {3} {4}", p.CategoryName, p.InstanceName, p.CounterName, p.RawValue, p.CounterType.GetHashCode()); 
float FirstValue = p.NextValue(); 
Console.WriteLine("FirstValueA :{0}", (ulong)FirstValue & 4294967295); 
Console.WriteLine("FirstValueB :{0}", (ulong)FirstValue >> 32); 
Console.WriteLine("SecondValueA :{0}", p.NextSample().TimeStamp & 4294967295); 
Console.WriteLine("SecondValueB :{0}", p.NextSample().TimeStamp >> 32);