Beispiel #1
0
        private void DoDispose()
        {
            foreach (var key in _counters.Keys.ToList())
            {
                if (_counters[key] != null)
                {
                    _counters[key].Dispose();
                    _counters.Remove(key);
                }
            }

            if (_query != null)
            {
                _query.Dispose();
                _query = null;
            }
        }
Beispiel #2
0
        private void DoAddCounters(IEnumerable <IPerfCounter> counters)
        {
            uint result;

            if (_query == null)
            {
                PdhQueryHandle query;

                result = Pdh.PdhOpenQueryW(null, IntPtr.Zero, out query);
                if (result != 0)
                {
                    throw new Win32Exception((int)result);
                }

                _query = query;
            }

            List <IPerfCounter> missingCounters = new List <IPerfCounter>();

            foreach (var counter in counters)
            {
                PdhCounterHandle hCounter;

                result = Pdh.PdhAddEnglishCounterW(_query, counter.Path, IntPtr.Zero, out hCounter);
                if (result == Pdh.PDH_CSTATUS_NO_OBJECT ||
                    result == Pdh.PDH_CSTATUS_NO_COUNTER)
                {
                    missingCounters.Add(counter);
                    continue;
                }
                if (result != 0)
                {
                    throw new Win32Exception((int)result);
                }

                _counters[counter] = hCounter;
            }

            if (missingCounters.Count > 0)
            {
                throw new MissingCountersException(missingCounters);
            }
        }
Beispiel #3
0
 public static extern UInt32 PdhCollectQueryData(
     PdhQueryHandle phQuery);
Beispiel #4
0
 public static extern UInt32 PdhAddEnglishCounterW(
     PdhQueryHandle hQuery,
     string szFullCounterPath,
     IntPtr dwUserData,
     out PdhCounterHandle phCounter);
Beispiel #5
0
 public static extern UInt32 PdhOpenQueryH(
     PdhLogHandle hDataSource,
     IntPtr dwUserData,
     out PdhQueryHandle phQuery);
Beispiel #6
0
 public static extern UInt32 PdhOpenQueryW(
     string szDataSource,
     IntPtr dwUserData,
     out PdhQueryHandle phQuery);