예제 #1
0
        private readonly int _index;  // this is the sequence # in which the counter was added

        public PerfCounterInfo(string counterPath, PdhCounterHandle handle, int index)
        {
            _index = index;

            string[] tokens = counterPath.Split(new[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);
            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 openIndex = _counterSet.LastIndexOf('(');
                _instance   = _counterSet.Substring(openIndex + 1, _counterSet.Length - openIndex - 2);
                _counterSet = _counterSet.Substring(0, openIndex);
            }

            _counterHandle = handle;
        }
예제 #2
0
        private readonly int _index;  // this is the sequence # in which the counter was added

        public PerfCounterInfo(string counterPath, PdhCounterHandle handle, int index)
        {
            _counterPath = counterPath;
            _index       = index;
            string counterPattern = @"(\\\\){0,1}(?<machine>.+?){0,1}\\(?<object>.+?)(?<instance>\(.*?\)){0,1}\\(?<counter>.+)";

            Match counterInfo = Regex.Match(counterPath, counterPattern);

            _machine = Environment.MachineName;

            if (counterInfo.Groups["machine"]?.Value != null)
            {
                _machine = counterInfo.Groups["machine"].Value;
            }

            _counterHandle = handle;
            _counterName   = counterInfo.Groups["counter"].Value;
            _counterSet    = counterInfo.Groups["object"].Value;
            _instance      = Regex.Replace(counterInfo.Groups["instance"].Value, @"^\(|\)$", "");
        }
 public static extern PdhStatus PdhGetCounterInfo(
     PdhCounterHandle phCounter,
     bool bRetrieveExplainText,
     ref UInt32 pdwBufferSize,
     IntPtr lpBuffer);
 public static extern PdhStatus PdhGetCounterTimeBase(
     PdhCounterHandle phCounter,
     out UInt64 pTimeBase);
 public static extern PdhStatus PdhGetRawCounterValue(
     PdhCounterHandle phCounter,
     out uint lpdwType,
     out PDH_RAW_COUNTER pValue);
 public static extern PdhStatus PdhGetFormattedCounterArray(
     PdhCounterHandle phCounter,
     PdhFormat dwFormat,
     ref UInt32 dwBufferSize,
     out UInt32 dwBufferCount,
     IntPtr itemBuffer);
 public static extern PdhStatus PdhGetFormattedCounterValue(
     PdhCounterHandle phCounter,
     PdhFormat dwFormat,
     ref uint lpdwType,
     ref PDH_FMT_COUNTERVALUE pValue);
 public static extern PdhStatus PdhAddCounter(
     PdhQueryHandle hQuery,
     string szFullCounterPath,
     IntPtr dwUserData,
     out PdhCounterHandle phCounter);