зеркало из https://github.com/microsoft/Tx.git
Performance Counter fixes
This commit is contained in:
Родитель
fa88250244
Коммит
c8cc771614
|
@ -5,5 +5,5 @@ using System.Reflection;
|
|||
[assembly: AssemblyCompany("MS Open Tech")]
|
||||
[assembly: AssemblyProduct("Tx (LINQ to Traces)")]
|
||||
[assembly: AssemblyCopyright("Copyright © MS Open Tech 2012")]
|
||||
[assembly: AssemblyVersion("1.0.30626.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.30626.0")]
|
||||
[assembly: AssemblyVersion("1.0.30627.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.30627.0")]
|
|
@ -66,7 +66,7 @@ namespace Tx.Windows
|
|||
}
|
||||
}
|
||||
|
||||
protected void AddCounter(string counterPath)
|
||||
protected void AddCounter(string counterPath, int index)
|
||||
{
|
||||
PdhCounterHandle counter;
|
||||
PdhStatus status = PdhNativeMethods.PdhAddCounter(_query, counterPath, IntPtr.Zero, out counter);
|
||||
|
@ -75,7 +75,7 @@ namespace Tx.Windows
|
|||
|
||||
PdhUtils.CheckStatus(status, PdhStatus.PDH_CSTATUS_VALID_DATA);
|
||||
|
||||
var counterInfo = new PerfCounterInfo(counterPath, counter);
|
||||
var counterInfo = new PerfCounterInfo(counterPath, counter, index);
|
||||
_counters.Add(counterInfo);
|
||||
}
|
||||
|
||||
|
|
|
@ -21,9 +21,9 @@ namespace Tx.Windows
|
|||
PdhStatus status = PdhNativeMethods.PdhOpenQuery(file, IntPtr.Zero, out _query);
|
||||
PdhUtils.CheckStatus(status, PdhStatus.PDH_CSTATUS_VALID_DATA);
|
||||
|
||||
foreach (string counter in counterPaths)
|
||||
for (int i = 0; i < counterPaths.Length; i++)
|
||||
{
|
||||
AddCounter(counter);
|
||||
AddCounter(counterPaths[i], i);
|
||||
}
|
||||
|
||||
Read();
|
||||
|
|
|
@ -11,21 +11,35 @@ namespace Tx.Windows
|
|||
private readonly string _counterName;
|
||||
private readonly string _counterSet;
|
||||
private readonly string _instance;
|
||||
private readonly int _index; // this is the sequence # in which the counter was added
|
||||
|
||||
public PerfCounterInfo(string counterPath, PdhCounterHandle handle)
|
||||
public PerfCounterInfo(string counterPath, PdhCounterHandle handle, int index)
|
||||
{
|
||||
_index = index;
|
||||
|
||||
string[] tokens = counterPath.Split(new[] {'\\'}, StringSplitOptions.RemoveEmptyEntries);
|
||||
_machine = tokens[0];
|
||||
_counterSet = tokens[1];
|
||||
_counterName = tokens[2];
|
||||
_counterHandle = handle;
|
||||
if (tokens.Length < 3)
|
||||
{
|
||||
_machine = Environment.MachineName;
|
||||
_counterSet = tokens[0];
|
||||
_counterName = tokens[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
_machine = tokens[0];
|
||||
_counterSet = tokens[1];
|
||||
_counterName = tokens[2];
|
||||
_counterHandle = handle;
|
||||
}
|
||||
|
||||
if (_counterSet.EndsWith(")"))
|
||||
{
|
||||
int index = _counterSet.LastIndexOf('(');
|
||||
_instance = _counterSet.Substring(index + 1, _counterSet.Length - index - 2);
|
||||
_counterSet = _counterSet.Substring(0, index);
|
||||
int openIndex = _counterSet.LastIndexOf('(');
|
||||
_instance = _counterSet.Substring(openIndex + 1, _counterSet.Length - openIndex - 2);
|
||||
_counterSet = _counterSet.Substring(0, openIndex);
|
||||
}
|
||||
|
||||
_counterHandle = handle;
|
||||
}
|
||||
|
||||
public string CounterSet
|
||||
|
@ -53,6 +67,11 @@ namespace Tx.Windows
|
|||
get { return _machine; }
|
||||
}
|
||||
|
||||
public int Index
|
||||
{
|
||||
get { return _index; }
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_counterHandle.Dispose();
|
||||
|
|
|
@ -16,9 +16,9 @@ namespace Tx.Windows
|
|||
PdhStatus status = PdhNativeMethods.PdhOpenQuery(null, IntPtr.Zero, out _query);
|
||||
PdhUtils.CheckStatus(status, PdhStatus.PDH_CSTATUS_VALID_DATA);
|
||||
|
||||
foreach (string counter in counterPaths)
|
||||
for (int i=0; i<counterPaths.Length; i++)
|
||||
{
|
||||
AddCounter(counter);
|
||||
AddCounter(counterPaths[i], i);
|
||||
}
|
||||
|
||||
_timer = new Timer(OnTimer, null, TimeSpan.Zero, samplingRate);
|
||||
|
|
|
@ -56,5 +56,10 @@ namespace Tx.Windows
|
|||
{
|
||||
get { return _value; }
|
||||
}
|
||||
|
||||
public int Index
|
||||
{
|
||||
get { return _counterInfo.Index; }
|
||||
}
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче