예제 #1
0
        public long AddRelogCountersPreservingPaths(PerformanceCounterSampleSet sampleSet)
        {
            long num = 0;

            foreach (PerformanceCounterSample sample in sampleSet.CounterSamples)
            {
                PDH_COUNTER_PATH_ELEMENTS pCounterPathElements = new PDH_COUNTER_PATH_ELEMENTS();
                num = this.ParsePath(sample.Path, ref pCounterPathElements);
                if (num == 0)
                {
                    IntPtr ptr;
                    num = PdhAddRelogCounter(this.m_hQuery, sample.Path, (long)sample.CounterType, sample.DefaultScale, sample.TimeBase, out ptr);
                    if (num == 0)
                    {
                        CounterHandleNInstance instance = new CounterHandleNInstance {
                            hCounter = ptr
                        };
                        if (pCounterPathElements.InstanceName != null)
                        {
                            instance.InstanceName = pCounterPathElements.InstanceName.ToLower(CultureInfo.InvariantCulture);
                        }
                        if (!this.m_ReloggerPathToHandleAndInstanceMap.ContainsKey(sample.Path.ToLower(CultureInfo.InvariantCulture)))
                        {
                            this.m_ReloggerPathToHandleAndInstanceMap.Add(sample.Path.ToLower(CultureInfo.InvariantCulture), instance);
                        }
                    }
                }
            }
            if (this.m_ReloggerPathToHandleAndInstanceMap.Keys.Count <= 0)
            {
                return(num);
            }
            return(0);
        }
예제 #2
0
        public long AddCounters(ref StringCollection validPaths, bool bFlushOldCounters)
        {
            if (bFlushOldCounters)
            {
                this.m_ConsumerPathToHandleAndInstanceMap.Clear();
            }
            bool flag = false;
            long num  = 0;

            foreach (string str in validPaths)
            {
                IntPtr ptr;
                num = PdhAddCounter(this.m_hQuery, str, IntPtr.Zero, out ptr);
                if (num == 0)
                {
                    CounterHandleNInstance instance = new CounterHandleNInstance {
                        hCounter     = ptr,
                        InstanceName = null
                    };
                    PDH_COUNTER_PATH_ELEMENTS pCounterPathElements = new PDH_COUNTER_PATH_ELEMENTS();
                    num = this.ParsePath(str, ref pCounterPathElements);
                    if ((num == 0) && (pCounterPathElements.InstanceName != null))
                    {
                        instance.InstanceName = pCounterPathElements.InstanceName.ToLower(CultureInfo.InvariantCulture);
                    }
                    if (!this.m_ConsumerPathToHandleAndInstanceMap.ContainsKey(str.ToLower(CultureInfo.InvariantCulture)))
                    {
                        this.m_ConsumerPathToHandleAndInstanceMap.Add(str.ToLower(CultureInfo.InvariantCulture), instance);
                    }
                    flag = true;
                }
            }
            if (!flag)
            {
                return(num);
            }
            return(0);
        }
예제 #3
0
파일: PdhHelper.cs 프로젝트: nickchal/pash
 public long AddCounters(ref StringCollection validPaths, bool bFlushOldCounters)
 {
     if (bFlushOldCounters)
     {
         this.m_ConsumerPathToHandleAndInstanceMap.Clear();
     }
     bool flag = false;
     long num = 0;
     foreach (string str in validPaths)
     {
         IntPtr ptr;
         num = PdhAddCounter(this.m_hQuery, str, IntPtr.Zero, out ptr);
         if (num == 0)
         {
             CounterHandleNInstance instance = new CounterHandleNInstance {
                 hCounter = ptr,
                 InstanceName = null
             };
             PDH_COUNTER_PATH_ELEMENTS pCounterPathElements = new PDH_COUNTER_PATH_ELEMENTS();
             num = this.ParsePath(str, ref pCounterPathElements);
             if ((num == 0) && (pCounterPathElements.InstanceName != null))
             {
                 instance.InstanceName = pCounterPathElements.InstanceName.ToLower(CultureInfo.InvariantCulture);
             }
             if (!this.m_ConsumerPathToHandleAndInstanceMap.ContainsKey(str.ToLower(CultureInfo.InvariantCulture)))
             {
                 this.m_ConsumerPathToHandleAndInstanceMap.Add(str.ToLower(CultureInfo.InvariantCulture), instance);
             }
             flag = true;
         }
     }
     if (!flag)
     {
         return num;
     }
     return 0;
 }
예제 #4
0
파일: PdhHelper.cs 프로젝트: nickchal/pash
 public long AddRelogCounters(PerformanceCounterSampleSet sampleSet)
 {
     long num = 0;
     Dictionary<string, List<PerformanceCounterSample>> dictionary = new Dictionary<string, List<PerformanceCounterSample>>();
     foreach (PerformanceCounterSample sample in sampleSet.CounterSamples)
     {
         PDH_COUNTER_PATH_ELEMENTS pCounterPathElements = new PDH_COUNTER_PATH_ELEMENTS();
         num = this.ParsePath(sample.Path, ref pCounterPathElements);
         if (num == 0)
         {
             List<PerformanceCounterSample> list;
             string str = pCounterPathElements.MachineName.ToLower(CultureInfo.InvariantCulture);
             string str2 = pCounterPathElements.ObjectName.ToLower(CultureInfo.InvariantCulture);
             string str3 = pCounterPathElements.CounterName.ToLower(CultureInfo.InvariantCulture);
             string key = @"\\" + str + @"\" + str2 + @"\" + str3;
             if (dictionary.TryGetValue(key, out list))
             {
                 dictionary[key].Add(sample);
             }
             else
             {
                 List<PerformanceCounterSample> list2 = new List<PerformanceCounterSample> {
                     sample
                 };
                 dictionary.Add(key, list2);
             }
         }
     }
     foreach (string str5 in dictionary.Keys)
     {
         IntPtr ptr;
         string path = dictionary[str5][0].Path;
         if (dictionary[str5].Count > 1)
         {
             num = this.MakeAllInstancePath(dictionary[str5][0].Path, out path);
             if (num != 0)
             {
                 continue;
             }
         }
         num = PdhAddRelogCounter(this.m_hQuery, path, (long) dictionary[str5][0].CounterType, dictionary[str5][0].DefaultScale, dictionary[str5][0].TimeBase, out ptr);
         if (num == 0)
         {
             foreach (PerformanceCounterSample sample2 in dictionary[str5])
             {
                 PDH_COUNTER_PATH_ELEMENTS pdh_counter_path_elements2 = new PDH_COUNTER_PATH_ELEMENTS();
                 num = this.ParsePath(sample2.Path, ref pdh_counter_path_elements2);
                 if (num == 0)
                 {
                     CounterHandleNInstance instance = new CounterHandleNInstance {
                         hCounter = ptr
                     };
                     if (pdh_counter_path_elements2.InstanceName != null)
                     {
                         instance.InstanceName = pdh_counter_path_elements2.InstanceName.ToLower(CultureInfo.InvariantCulture);
                     }
                     if (!this.m_ReloggerPathToHandleAndInstanceMap.ContainsKey(sample2.Path.ToLower(CultureInfo.InvariantCulture)))
                     {
                         this.m_ReloggerPathToHandleAndInstanceMap.Add(sample2.Path.ToLower(CultureInfo.InvariantCulture), instance);
                     }
                 }
             }
         }
     }
     if (this.m_ReloggerPathToHandleAndInstanceMap.Keys.Count <= 0)
     {
         return num;
     }
     return 0;
 }
예제 #5
0
파일: PdhHelper.cs 프로젝트: nickchal/pash
 public long AddRelogCountersPreservingPaths(PerformanceCounterSampleSet sampleSet)
 {
     long num = 0;
     foreach (PerformanceCounterSample sample in sampleSet.CounterSamples)
     {
         PDH_COUNTER_PATH_ELEMENTS pCounterPathElements = new PDH_COUNTER_PATH_ELEMENTS();
         num = this.ParsePath(sample.Path, ref pCounterPathElements);
         if (num == 0)
         {
             IntPtr ptr;
             num = PdhAddRelogCounter(this.m_hQuery, sample.Path, (long) sample.CounterType, sample.DefaultScale, sample.TimeBase, out ptr);
             if (num == 0)
             {
                 CounterHandleNInstance instance = new CounterHandleNInstance {
                     hCounter = ptr
                 };
                 if (pCounterPathElements.InstanceName != null)
                 {
                     instance.InstanceName = pCounterPathElements.InstanceName.ToLower(CultureInfo.InvariantCulture);
                 }
                 if (!this.m_ReloggerPathToHandleAndInstanceMap.ContainsKey(sample.Path.ToLower(CultureInfo.InvariantCulture)))
                 {
                     this.m_ReloggerPathToHandleAndInstanceMap.Add(sample.Path.ToLower(CultureInfo.InvariantCulture), instance);
                 }
             }
         }
     }
     if (this.m_ReloggerPathToHandleAndInstanceMap.Keys.Count <= 0)
     {
         return num;
     }
     return 0;
 }
예제 #6
0
파일: PdhHelper.cs 프로젝트: 40a/PowerShell
        //
        // AddRelogCountersPreservingPaths preserves all paths and adds as relog counters to m_hQuery.
        // The counter handles and full paths are added to m_ReloggerPathToHandleAndInstanceMap
        //
        public uint AddRelogCountersPreservingPaths(PerformanceCounterSampleSet sampleSet)
        {
            Debug.Assert(_hQuery != null && !_hQuery.IsInvalid);

            uint res = 0;

            // 
            // Go through all the samples one, constructing prefixInstanceMap and adding new counters as needed
            //            
            foreach (PerformanceCounterSample sample in sampleSet.CounterSamples)
            {
                PDH_COUNTER_PATH_ELEMENTS pathElts = new PDH_COUNTER_PATH_ELEMENTS();
                res = ParsePath(sample.Path, ref pathElts);
                if (res != 0)
                {
                    // Skipping for now, but should be a non-terminating error
                    continue;
                }

                IntPtr counterHandle;
                res = PdhAddRelogCounter(_hQuery,
                                         sample.Path,
                                         (uint)sample.CounterType,
                                         sample.DefaultScale,
                                         sample.TimeBase,
                                         out counterHandle);
                if (res != 0)
                {
                    // Skipping for now, but should be a non-terminating error
                    continue;
                }

                CounterHandleNInstance chi = new CounterHandleNInstance();

                chi.hCounter = counterHandle;
                if (pathElts.InstanceName != null)
                {
                    chi.InstanceName = pathElts.InstanceName.ToLower(CultureInfo.InvariantCulture);
                }

                if (!_reloggerPathToHandleAndInstanceMap.ContainsKey(sample.Path.ToLower(CultureInfo.InvariantCulture)))
                {
                    _reloggerPathToHandleAndInstanceMap.Add(sample.Path.ToLower(CultureInfo.InvariantCulture), chi);
                }
            }

            return (_reloggerPathToHandleAndInstanceMap.Keys.Count > 0) ? 0 : res;
        }
예제 #7
0
파일: PdhHelper.cs 프로젝트: 40a/PowerShell
        //
        // AddRelogCounters combines instances and adds counters to m_hQuery.
        // The counter handles and full paths 
        //
        public uint AddRelogCounters(PerformanceCounterSampleSet sampleSet)
        {
            Debug.Assert(_hQuery != null && !_hQuery.IsInvalid);

            uint res = 0;

            Dictionary<string, List<PerformanceCounterSample>> prefixInstanceMap = new Dictionary<string, List<PerformanceCounterSample>>();

            // 
            // Go through all the samples one, constructing prefixInstanceMap and adding new counters as needed
            //            
            foreach (PerformanceCounterSample sample in sampleSet.CounterSamples)
            {
                PDH_COUNTER_PATH_ELEMENTS pathElts = new PDH_COUNTER_PATH_ELEMENTS();
                res = ParsePath(sample.Path, ref pathElts);
                if (res != 0)
                {
                    // Skipping for now, but should be a non-terminating error
                    continue;
                }

                string lowerCaseMachine = pathElts.MachineName.ToLower(CultureInfo.InvariantCulture);
                string lowerCaseObject = pathElts.ObjectName.ToLower(CultureInfo.InvariantCulture);
                string lowerCaseCounter = pathElts.CounterName.ToLower(CultureInfo.InvariantCulture);

                string lcPathMinusInstance = @"\\" + lowerCaseMachine + @"\" + lowerCaseObject + @"\" + lowerCaseCounter;

                List<PerformanceCounterSample> sampleList;
                if (prefixInstanceMap.TryGetValue(lcPathMinusInstance, out sampleList))
                {
                    prefixInstanceMap[lcPathMinusInstance].Add(sample);
                }
                else
                {
                    List<PerformanceCounterSample> newList = new List<PerformanceCounterSample>();
                    newList.Add(sample);
                    prefixInstanceMap.Add(lcPathMinusInstance, newList);
                }

                //Console.WriteLine ("Added path " + sample.Path + " to the 1ist map with prefix " + lcPathMinusInstance);                
            }

            // 
            // Add counters to the query, consolidating multi-instance with a wildcard path,
            // and construct m_ReloggerPathToHandleAndInstanceMap where each full path would be pointing to its counter handle 
            // and an instance name (might be empty for no-instance counter types).
            // You can have multiple full paths inside m_ReloggerPathToHandleAndInstanceMap pointing to the same handle.
            //

            foreach (string prefix in prefixInstanceMap.Keys)
            {
                IntPtr counterHandle;
                string unifiedPath = prefixInstanceMap[prefix][0].Path;

                if (prefixInstanceMap[prefix].Count > 1)
                {
                    res = MakeAllInstancePath(prefixInstanceMap[prefix][0].Path, out unifiedPath);
                    if (res != 0)
                    {
                        // Skipping for now, but should be a non-terminating error
                        continue;
                    }
                }

                res = PdhAddRelogCounter(_hQuery,
                                         unifiedPath,
                                         (UInt32)prefixInstanceMap[prefix][0].CounterType,
                                         prefixInstanceMap[prefix][0].DefaultScale,
                                         prefixInstanceMap[prefix][0].TimeBase,
                                         out counterHandle);
                if (res != 0)
                {
                    // Skipping for now, but should be a non-terminating error
                    // Console.WriteLine ("PdhAddCounter returned " + res + " for counter path " + unifiedPath);
                    continue;
                }

                //Console.WriteLine ("added  pdh query path:" + unifiedPath );

                //now, add all actual paths to m_ReloggerPathToHandleAndInstanceMap 
                foreach (PerformanceCounterSample sample in prefixInstanceMap[prefix])
                {
                    PDH_COUNTER_PATH_ELEMENTS pathElts = new PDH_COUNTER_PATH_ELEMENTS();
                    res = ParsePath(sample.Path, ref pathElts);
                    if (res != 0)
                    {
                        // Skipping for now, but should be a non-terminating error
                        continue;
                    }

                    CounterHandleNInstance chi = new CounterHandleNInstance();

                    chi.hCounter = counterHandle;

                    if (pathElts.InstanceName != null)
                    {
                        chi.InstanceName = pathElts.InstanceName.ToLower(CultureInfo.InvariantCulture);
                    }

                    if (!_reloggerPathToHandleAndInstanceMap.ContainsKey(sample.Path.ToLower(CultureInfo.InvariantCulture)))
                    {
                        _reloggerPathToHandleAndInstanceMap.Add(sample.Path.ToLower(CultureInfo.InvariantCulture), chi);
                        //Console.WriteLine ("added map path:" + sample.Path );
                    }
                }
            }

            //TODO: verify that all counters are in the map

            return (_reloggerPathToHandleAndInstanceMap.Keys.Count > 0) ? 0 : res;
        }
예제 #8
0
파일: PdhHelper.cs 프로젝트: 40a/PowerShell
        public uint AddCounters(ref StringCollection validPaths, bool bFlushOldCounters)
        {
            Debug.Assert(_hQuery != null && !_hQuery.IsInvalid);

            if (bFlushOldCounters)
            {
                _consumerPathToHandleAndInstanceMap.Clear();
            }

            bool bAtLeastOneAdded = false;
            uint res = 0;

            foreach (string counterPath in validPaths)
            {
                IntPtr counterHandle;
                res = PdhAddCounter(_hQuery, counterPath, IntPtr.Zero, out counterHandle);
                if (res == 0)
                {
                    CounterHandleNInstance chi = new CounterHandleNInstance();
                    chi.hCounter = counterHandle;
                    chi.InstanceName = null;

                    PDH_COUNTER_PATH_ELEMENTS pathElts = new PDH_COUNTER_PATH_ELEMENTS();
                    res = ParsePath(counterPath, ref pathElts);
                    if (res == 0 && pathElts.InstanceName != null)
                    {
                        chi.InstanceName = pathElts.InstanceName.ToLower(CultureInfo.InvariantCulture);
                    }

                    if (!_consumerPathToHandleAndInstanceMap.ContainsKey(counterPath.ToLower(CultureInfo.InvariantCulture)))
                    {
                        _consumerPathToHandleAndInstanceMap.Add(counterPath.ToLower(CultureInfo.InvariantCulture), chi);
                    }

                    bAtLeastOneAdded = true;
                }
            }

            return bAtLeastOneAdded ? 0 : res;
        }
예제 #9
0
        public long AddRelogCounters(PerformanceCounterSampleSet sampleSet)
        {
            long num = 0;
            Dictionary <string, List <PerformanceCounterSample> > dictionary = new Dictionary <string, List <PerformanceCounterSample> >();

            foreach (PerformanceCounterSample sample in sampleSet.CounterSamples)
            {
                PDH_COUNTER_PATH_ELEMENTS pCounterPathElements = new PDH_COUNTER_PATH_ELEMENTS();
                num = this.ParsePath(sample.Path, ref pCounterPathElements);
                if (num == 0)
                {
                    List <PerformanceCounterSample> list;
                    string str  = pCounterPathElements.MachineName.ToLower(CultureInfo.InvariantCulture);
                    string str2 = pCounterPathElements.ObjectName.ToLower(CultureInfo.InvariantCulture);
                    string str3 = pCounterPathElements.CounterName.ToLower(CultureInfo.InvariantCulture);
                    string key  = @"\\" + str + @"\" + str2 + @"\" + str3;
                    if (dictionary.TryGetValue(key, out list))
                    {
                        dictionary[key].Add(sample);
                    }
                    else
                    {
                        List <PerformanceCounterSample> list2 = new List <PerformanceCounterSample> {
                            sample
                        };
                        dictionary.Add(key, list2);
                    }
                }
            }
            foreach (string str5 in dictionary.Keys)
            {
                IntPtr ptr;
                string path = dictionary[str5][0].Path;
                if (dictionary[str5].Count > 1)
                {
                    num = this.MakeAllInstancePath(dictionary[str5][0].Path, out path);
                    if (num != 0)
                    {
                        continue;
                    }
                }
                num = PdhAddRelogCounter(this.m_hQuery, path, (long)dictionary[str5][0].CounterType, dictionary[str5][0].DefaultScale, dictionary[str5][0].TimeBase, out ptr);
                if (num == 0)
                {
                    foreach (PerformanceCounterSample sample2 in dictionary[str5])
                    {
                        PDH_COUNTER_PATH_ELEMENTS pdh_counter_path_elements2 = new PDH_COUNTER_PATH_ELEMENTS();
                        num = this.ParsePath(sample2.Path, ref pdh_counter_path_elements2);
                        if (num == 0)
                        {
                            CounterHandleNInstance instance = new CounterHandleNInstance {
                                hCounter = ptr
                            };
                            if (pdh_counter_path_elements2.InstanceName != null)
                            {
                                instance.InstanceName = pdh_counter_path_elements2.InstanceName.ToLower(CultureInfo.InvariantCulture);
                            }
                            if (!this.m_ReloggerPathToHandleAndInstanceMap.ContainsKey(sample2.Path.ToLower(CultureInfo.InvariantCulture)))
                            {
                                this.m_ReloggerPathToHandleAndInstanceMap.Add(sample2.Path.ToLower(CultureInfo.InvariantCulture), instance);
                            }
                        }
                    }
                }
            }
            if (this.m_ReloggerPathToHandleAndInstanceMap.Keys.Count <= 0)
            {
                return(num);
            }
            return(0);
        }