Holds information about performance counter types.
예제 #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PerfCategory" /> class.
 /// </summary>
 /// <param name="assembly">The assembly.</param>
 /// <param name="performanceType">Type of the performance.</param>
 /// <param name="categoryName">Name of the category.</param>
 private PerfCategory(
     [NotNull] string assembly,
     [NotNull] PerformanceType performanceType,
     [NotNull] string categoryName)
 {
     _assemblies = new List <string> {
         assembly
     };
     PerformanceType = performanceType;
     CategoryName    = categoryName;
 }
예제 #2
0
        /// <summary>
        /// Adds or updates a performance counter categories information.
        /// </summary>
        /// <param name="categoryName">Name of the category.</param>
        /// <param name="typeReference">The type reference.</param>
        /// <param name="assembly">The assembly.</param>
        /// <param name="categoryHelp">The category help.</param>
        public static void Set(
            [NotNull] string categoryName,
            [NotNull] TypeReference typeReference,
            [NotNull] string assembly,
            string categoryHelp)
        {
            if (categoryName == null)
            {
                throw new ArgumentNullException("categoryName");
            }
            if (typeReference == null)
            {
                throw new ArgumentNullException("typeReference");
            }
            if (assembly == null)
            {
                throw new ArgumentNullException("assembly");
            }
            try
            {
                PerformanceType performanceType = PerformanceType.Get(typeReference);
                PerfCategory    category        = _categories.GetOrAdd(
                    categoryName,
                    // ReSharper disable once AssignNullToNotNullAttribute
                    n => new PerfCategory(assembly, performanceType, n));
                Debug.Assert(category != null);

                // Type cannot change.
                if (category.PerformanceType != performanceType)
                {
                    Logger.Add(
                        Level.Error,
                        "The '{0}' performance counter category was declared more than once with different types ('{1}' and '{2}') in assembly '{3}'.",
                        categoryName,
                        category.PerformanceType,
                        performanceType,
                        assembly);
                    return;
                }

                // Only update category help if not already set.
                if (!string.IsNullOrWhiteSpace(categoryHelp) &&
                    string.IsNullOrWhiteSpace(category.CategoryHelp))
                {
                    category.CategoryHelp = categoryHelp;
                }

                // Add assembly if not seen before
                if (!category._assemblies.Contains(assembly))
                {
                    category._assemblies.Add(assembly);
                }
            }
            catch (Exception e)
            {
                Logger.Add(
                    Level.Error,
                    "Failed to set performance category information for category '{0}' in assembly '{1}'. {2}",
                    categoryName,
                    assembly,
                    e.Message);
            }
        }
예제 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PerfCategory" /> class.
 /// </summary>
 /// <param name="assembly">The assembly.</param>
 /// <param name="performanceType">Type of the performance.</param>
 /// <param name="categoryName">Name of the category.</param>
 private PerfCategory(
     [NotNull] string assembly,
     [NotNull] PerformanceType performanceType,
     [NotNull] string categoryName)
 {
     _assemblies = new List<string> { assembly };
     PerformanceType = performanceType;
     CategoryName = categoryName;
 }