public static MetricUnit InferUnit()

in Amazon.KinesisTap.Windows/PerformanceCounterSource.cs [124:195]


        public static MetricUnit InferUnit(string category, string counterName)
        {
            bool isPercent = _percentKeywords.Any(kw =>
                counterName.IndexOf(kw, StringComparison.InvariantCultureIgnoreCase) > -1);
            if (isPercent) return MetricUnit.Percent;

            bool isRate = counterName.IndexOf("/sec", StringComparison.InvariantCultureIgnoreCase) > -1
                || counterName.IndexOf("/ sec", StringComparison.InvariantCultureIgnoreCase) > -1
                || counterName.EndsWith("Rate", StringComparison.InvariantCultureIgnoreCase)
                || counterName.StartsWith("Rate of");

            string sizeKeyword = _sizeKeyWords.FirstOrDefault(kw =>
                counterName.IndexOf(kw, StringComparison.InvariantCultureIgnoreCase) > -1);
            bool isSize = !string.IsNullOrEmpty(sizeKeyword);

            if (isRate)
            {
                if (isSize)
                {
                    switch (char.ToLower(sizeKeyword[0]))
                    {
                        case 'm':
                            return MetricUnit.MegabytesSecond;
                        case 'k':
                            return MetricUnit.KilobytesSecond;
                        default:
                            return MetricUnit.BytesSecond;
                    }
                }
                else
                {
                    return MetricUnit.CountSecond;
                }
            }
            else //not rate
            {
                if (isSize)
                {
                    switch (char.ToLower(sizeKeyword[0]))
                    {
                        case 'm':
                            return MetricUnit.Megabytes;
                        case 'k':
                            return MetricUnit.Kilobytes;
                        default:
                            return MetricUnit.Bytes;
                    }
                }

                string timeKeyword = _timeKeyWords.FirstOrDefault(kw =>
                    counterName.IndexOf(kw, StringComparison.InvariantCultureIgnoreCase) > -1);
                if (!string.IsNullOrEmpty(timeKeyword))
                {
                    if (char.ToLower(timeKeyword[0]) == 's')
                    {
                        return MetricUnit.Seconds;
                    }
                    else if (timeKeyword.Equals("100 ns"))
                    {
                        return MetricUnit.HundredNanoseconds;
                    }
                    else
                    {
                        return MetricUnit.Milliseconds;
                    }
                }
                else
                {
                    return MetricUnit.Count;
                }
            }
        }