private string GetAllInstancesLayout(string categoryName)
        {
            StringBuilder stringBuilder = new StringBuilder();

            try
            {
                using (PerformanceCounterMemoryMappedFile performanceCounterMemoryMappedFile = new PerformanceCounterMemoryMappedFile(categoryName, true))
                {
                    CategoryEntry categoryEntry = performanceCounterMemoryMappedFile.FindCategory(categoryName);
                    if (categoryEntry != null)
                    {
                        for (InstanceEntry instanceEntry = categoryEntry.FirstInstance; instanceEntry != null; instanceEntry = instanceEntry.Next)
                        {
                            CounterEntry firstCounter = instanceEntry.FirstCounter;
                            if (firstCounter != null)
                            {
                                LifetimeEntry lifetime = firstCounter.Lifetime;
                                if (lifetime != null && lifetime.Type == 1)
                                {
                                    stringBuilder.AppendLine(string.Format("A process is holding onto a transport performance counter. processId : {0}, counter : {1}, currentInstance : {2}, categoryName: {3} ", new object[]
                                    {
                                        lifetime.ProcessId,
                                        firstCounter,
                                        instanceEntry,
                                        categoryName
                                    }));
                                }
                            }
                        }
                    }
                }
            }
            catch (Win32Exception ex)
            {
                stringBuilder.AppendLine(string.Concat(new object[]
                {
                    "Win32Exception for category ",
                    categoryName,
                    " : ",
                    ex
                }));
            }
            catch (FileMappingNotFoundException ex2)
            {
                stringBuilder.AppendLine(string.Concat(new object[]
                {
                    "FileMappingNotFoundException for category ",
                    categoryName,
                    " : ",
                    ex2
                }));
            }
            catch (Exception arg)
            {
                stringBuilder.AppendLine("Exception : " + arg);
            }
            return(stringBuilder.ToString());
        }
Example #2
0
        public CategoryEntry FindCategory(string categoryName)
        {
            CategoryEntry next = this.FirstCategory;

            while (next != null && string.Compare(next.Name, categoryName, StringComparison.OrdinalIgnoreCase) != 0)
            {
                next = next.Next;
            }
            return(next);
        }
Example #3
0
        private unsafe void InitializeNextCategory(IntPtr handle)
        {
            CategoryEntry categoryEntry = this;

            while (categoryEntry.internalCategoryEntry->NextCategoryOffset != 0)
            {
                CategoryEntry categoryEntry2 = new CategoryEntry(CategoryEntry.GetInternalCategoryEntry(handle, categoryEntry.internalCategoryEntry->NextCategoryOffset), handle);
                categoryEntry.nextCategoryEntry = categoryEntry2;
                categoryEntry = categoryEntry2;
            }
        }
Example #4
0
        public void RemoveCategory(string categoryName, Action <CounterEntry, LifetimeEntry, InstanceEntry> logRemoveInstanceEvent)
        {
            CategoryEntry categoryEntry = this.FindCategory(categoryName);

            if (categoryEntry != null)
            {
                for (InstanceEntry instanceEntry = categoryEntry.FirstInstance; instanceEntry != null; instanceEntry = instanceEntry.Next)
                {
                    CounterEntry firstCounter = instanceEntry.FirstCounter;
                    if (firstCounter != null)
                    {
                        LifetimeEntry lifetime = firstCounter.Lifetime;
                        if (lifetime != null && lifetime.Type == 1)
                        {
                            instanceEntry.RefCount = 0;
                            logRemoveInstanceEvent(firstCounter, lifetime, instanceEntry);
                        }
                    }
                }
            }
        }
Example #5
0
 public CategoryEntry(IntPtr handle, int offset) : this(CategoryEntry.GetInternalCategoryEntry(handle, offset), handle)
 {
     this.offset = offset;
     this.InitializeNextCategory(handle);
 }