Example #1
0
        /// <summary>
        /// Determine if an [assemblyname]classname pair matches the current Exclusion or Inclusion filters
        /// </summary>
        /// <param name="processName">The name of the process</param>
        /// <param name="assemblyName">the name of the assembly under profile</param>
        /// <param name="className">the name of the class under profile</param>
        /// <returns>false - if pair matches the exclusion filter or matches no filters, true - if pair matches in the inclusion filter</returns>
        public bool InstrumentClass(string processName, string assemblyName, string className)
        {
            if (string.IsNullOrEmpty(processName) || string.IsNullOrEmpty(assemblyName) || string.IsNullOrEmpty(className))
            {
                return(false);
            }

            IList <AssemblyAndClassFilter> matchingExclusionFilters;

            if (ExcludeProcessOrAssembly(processName, assemblyName, out matchingExclusionFilters))
            {
                return(false);
            }

            if (matchingExclusionFilters
                .Where(exclusionFilter => exclusionFilter.ClassName != ".*")
                .Any(exclusionFilter => exclusionFilter.IsMatchingClassName(className)))
            {
                return(false);
            }

            var matchingInclusionFilters = InclusionFilters.GetMatchingFiltersForAssemblyName(assemblyName);

            return(matchingInclusionFilters.Any(inclusionFilter => inclusionFilter.IsMatchingClassName(className)));
        }
Example #2
0
        public bool InstrumentClass(string assemblyName, string className)
        {
            if (string.IsNullOrEmpty(assemblyName) || string.IsNullOrEmpty(className))
            {
                return(false);
            }

            var matchingExclusionFilters = ExclusionFilters.GetMatchingFiltersForAssemblyName(assemblyName);

            if (matchingExclusionFilters.Any(exclusionFilter => exclusionFilter.ClassName == ".*"))
            {
                return(false);
            }

            if (matchingExclusionFilters
                .Where(exclusionFilter => exclusionFilter.ClassName != ".*")
                .Any(exclusionFilter => exclusionFilter.IsMatchingClassName(className)))
            {
                return(false);
            }

            var matchingInclusionFilters = InclusionFilters.GetMatchingFiltersForAssemblyName(assemblyName);

            if (matchingInclusionFilters.Any(inclusionFilter => inclusionFilter.IsMatchingClassName(className)))
            {
                return(true);
            }

            return(false);
        }
Example #3
0
        public void AddFilter(string assemblyClassName)
        {
            string     assemblyName;
            string     className;
            FilterType filterType;

            GetAssemblyClassName(assemblyClassName, RegExFilters, out filterType, out assemblyName, out className);

            if (!RegExFilters)
            {
                assemblyName = assemblyName.ValidateAndEscape();
                className    = className.ValidateAndEscape();
            }

            var filter = new AssemblyAndClassFilter(assemblyName, className);

            if (filterType == FilterType.Inclusion)
            {
                InclusionFilters.Add(filter);
            }

            if (filterType == FilterType.Exclusion)
            {
                ExclusionFilters.Add(filter);
            }
        }
Example #4
0
        /// <summary>
        /// Add a filter
        /// </summary>
        /// <param name="processAssemblyClassFilter">Filter is of the format (+ or -)&lt;processFilter&gt;[assemblyFilter]classFilter, wildcards are allowed. <br/>
        /// i.e. -[mscorlib], -[System.*]*, +[App.*]*, +[*]*
        /// </param>
        public void AddFilter(string processAssemblyClassFilter)
        {
            string     assemblyFilter;
            string     classFilter;
            string     processFilter;
            FilterType filterType;

            GetAssemblyClassName(processAssemblyClassFilter, RegExFilters, out filterType, out assemblyFilter, out classFilter, out processFilter);

            try
            {
                if (!RegExFilters)
                {
                    processFilter  = ValidateAndEscape((string.IsNullOrEmpty(processFilter) ? "*" : processFilter), "<>|\"", "process"); // Path.GetInvalidPathChars except *?
                    assemblyFilter = ValidateAndEscape(assemblyFilter, @"\[]", "assembly");
                    classFilter    = ValidateAndEscape(classFilter, @"\[]", "class/type");
                }

                var filter = new AssemblyAndClassFilter(processFilter, assemblyFilter, classFilter);
                if (filterType == FilterType.Inclusion)
                {
                    InclusionFilters.Add(filter);
                }

                if (filterType == FilterType.Exclusion)
                {
                    ExclusionFilters.Add(filter);
                }
            }
            catch (Exception)
            {
                HandleInvalidFilterFormat(processAssemblyClassFilter);
            }
        }
Example #5
0
        /// <summary>
        /// Should we instrument this asssembly
        /// </summary>
        /// <param name="processName"></param>
        /// <returns></returns>
        public bool InstrumentProcess(string processName)
        {
            if (string.IsNullOrEmpty(processName))
            {
                return(false);
            }

            if (!ExclusionFilters.Any() && !InclusionFilters.Any())
            {
                return(true);
            }

            if (IsProcessExcluded(processName))
            {
                return(false);
            }

            if (InclusionFilters.Any())
            {
                var matchingInclusionFilters = InclusionFilters.GetMatchingFiltersForProcessName(processName);
                return(matchingInclusionFilters.Any());
            }

            return(true); // not excluded and no inclusion filters
        }
Example #6
0
        /// <summary>
        /// Add a filter
        /// </summary>
        /// <param name="assemblyClassName">A filter is of the format (+ or -)[assemblyName]className, wildcards are allowed. <br/>
        /// i.e. -[mscorlib], -[System.*]*, +[App.*]*, +[*]*
        /// </param>
        public void AddFilter(string assemblyClassName)
        {
            string     assemblyName;
            string     className;
            string     processName;
            FilterType filterType;

            GetAssemblyClassName(assemblyClassName, RegExFilters, out filterType, out assemblyName, out className, out processName);

            if (!RegExFilters)
            {
                processName  = (string.IsNullOrEmpty(processName) ? "*" : processName).ValidateAndEscape("/?\"<>|}{");
                assemblyName = assemblyName.ValidateAndEscape();
                className    = className.ValidateAndEscape();
            }

            var filter = new AssemblyAndClassFilter(processName, assemblyName, className);

            if (filterType == FilterType.Inclusion)
            {
                InclusionFilters.Add(filter);
            }

            if (filterType == FilterType.Exclusion)
            {
                ExclusionFilters.Add(filter);
            }
        }
Example #7
0
        /// <summary>
        /// Decides whether an assembly should be included in the instrumentation
        /// </summary>
        /// <param name="processName">The name of the process being profiled</param>
        /// <param name="assemblyName">The name of the assembly under profile</param>
        /// <remarks>All assemblies matching either the inclusion or exclusion filter should be included
        /// as it is the class that is being filtered within these unless the class filter is *</remarks>
        public bool UseAssembly(string processName, string assemblyName)
        {
            if (ExcludeProcessOrAssembly(processName, assemblyName, out IList <AssemblyAndClassFilter> matchingExclusionFilters))
            {
                return(false);
            }

            if (matchingExclusionFilters.Any(exclusionFilter => exclusionFilter.ClassName != ".*"))
            {
                return(true);
            }

            var matchingInclusionFilters = InclusionFilters.GetMatchingFiltersForAssemblyName(assemblyName);

            return(matchingInclusionFilters.Any());
        }
Example #8
0
        /// <summary>
        /// Should we instrument this asssembly
        /// </summary>
        /// <param name="processPath"></param>
        /// <returns></returns>
        public bool InstrumentProcess(string processPath)
        {
            if (string.IsNullOrEmpty(processPath))
            {
                return(false);
            }
            if (!ExclusionFilters.Any() && !InclusionFilters.Any())
            {
                return(true);
            }

            var processName = Path.GetFileNameWithoutExtension(processPath); // can return null!

            if (ExclusionFilters.Any())
            {
                var matchingExclusionFilters = new List <AssemblyAndClassFilter>(ExclusionFilters.GetMatchingFiltersForProcessName(processPath));
                if (!string.IsNullOrWhiteSpace(processName) && processName != processPath)
                {
                    matchingExclusionFilters.AddRange(ExclusionFilters.GetMatchingFiltersForProcessName(processName));
                }
                if (matchingExclusionFilters.Any
                        (exclusionFilter =>
                        // class-filter is .* and assembly-filter is matching processName
                        // this does not match default exclude filters like {.*}[mscorlib].* or {.*}[system].*
                        // but does match {.*}[.*].* or {.*}[processNa*].* or {.*}[processName].* where assemblyName == processName
                        exclusionFilter.ClassName == ".*" && exclusionFilter.IsMatchingAssemblyName(processName)
                        )
                    )
                {
                    return(false);
                }
            }

            if (InclusionFilters.Any())
            {
                var matchingInclusionFilters = new List <AssemblyAndClassFilter>(InclusionFilters.GetMatchingFiltersForProcessName(processPath));
                if (!string.IsNullOrWhiteSpace(processName) && processName != processPath)
                {
                    matchingInclusionFilters.AddRange(InclusionFilters.GetMatchingFiltersForProcessName(processName));
                }
                return(matchingInclusionFilters.Any());
            }

            return(true); // not excluded and no inclusion filters
        }
Example #9
0
        public bool InstrumentProcess(string processName)
        {
            if (string.IsNullOrEmpty(processName))
            {
                return(false);
            }

            processName = Path.GetFileNameWithoutExtension(processName);
            var matchingExclusionFilters = ExclusionFilters.GetMatchingFiltersForProcessName(processName);

            if (matchingExclusionFilters.Any(exclusionFilter => exclusionFilter.AssemblyName == ".*" && exclusionFilter.ClassName == ".*"))
            {
                return(false);
            }

            var matchingInclusionFilters = InclusionFilters.GetMatchingFiltersForProcessName(processName);

            return(matchingInclusionFilters.Any(inclusionFilter => inclusionFilter.AssemblyName == ".*" || inclusionFilter.ClassName == ".*"));
        }
Example #10
0
        public bool UseAssembly(string assemblyName)
        {
            var matchingExclusionFilters = ExclusionFilters.GetMatchingFiltersForAssemblyName(assemblyName);

            if (matchingExclusionFilters.Any(exclusionFilter => exclusionFilter.ClassName == ".*"))
            {
                return(false);
            }

            if (matchingExclusionFilters.Any(exclusionFilter => exclusionFilter.ClassName != ".*"))
            {
                return(true);
            }

            var matchingInclusionFilters = InclusionFilters.GetMatchingFiltersForAssemblyName(assemblyName);

            if (matchingInclusionFilters.Any())
            {
                return(true);
            }

            return(false);
        }
Example #11
0
        /// <summary>
        /// Decides whether an assembly should be included in the instrumentation
        /// </summary>
        /// <param name="processName">The name of the process being profiled</param>
        /// <param name="assemblyName">the name of the assembly under profile</param>
        /// <remarks>All assemblies matching either the inclusion or exclusion filter should be included
        /// as it is the class that is being filtered within these unless the class filter is *</remarks>
        public bool UseAssembly(string processName, string assemblyName)
        {
            processName = Path.GetFileNameWithoutExtension(processName);
            var matchingExclusionFilters = ExclusionFilters.GetMatchingFiltersForAssemblyName(assemblyName);

            if (matchingExclusionFilters.Any(exclusionFilter => exclusionFilter.ClassName == ".*" && exclusionFilter.IsMatchingProcessName(processName)))
            {
                return(false);
            }

            if (matchingExclusionFilters.Any(exclusionFilter => exclusionFilter.ClassName != ".*"))
            {
                return(true);
            }

            var matchingInclusionFilters = InclusionFilters.GetMatchingFiltersForAssemblyName(assemblyName);

            if (matchingInclusionFilters.Any())
            {
                return(true);
            }

            return(false);
        }