コード例 #1
0
        internal static CpuInfo ParseOutput([CanBeNull] string content)
        {
            var logicalCores                  = SectionsHelper.ParseSections(content, ':');
            var processorModelNames           = new HashSet <string>();
            var processorsToPhysicalCoreCount = new Dictionary <string, int>();
            var logicalCoreCount              = 0;

            foreach (var logicalCore in logicalCores)
            {
                if (logicalCore.TryGetValue(ProcCpuInfoKeyNames.PhysicalId, out string physicalId) &&
                    logicalCore.TryGetValue(ProcCpuInfoKeyNames.CpuCores, out string cpuCoresValue) &&
                    int.TryParse(cpuCoresValue, out int cpuCoreCount) &&
                    cpuCoreCount > 0)
                {
                    processorsToPhysicalCoreCount[physicalId] = cpuCoreCount;
                }

                if (logicalCore.TryGetValue(ProcCpuInfoKeyNames.ModelName, out string modelName))
                {
                    processorModelNames.Add(modelName);
                    logicalCoreCount++;
                }
            }

            return(new CpuInfo(
                       processorModelNames.Count > 0 ? string.Join(", ", processorModelNames) : null,
                       processorsToPhysicalCoreCount.Count > 0 ? processorsToPhysicalCoreCount.Count : (int?)null,
                       processorsToPhysicalCoreCount.Count > 0 ? processorsToPhysicalCoreCount.Values.Sum() : (int?)null,
                       logicalCoreCount > 0 ? logicalCoreCount : (int?)null));
        }
コード例 #2
0
        internal static CpuInfo ParseOutput(string content)
        {
            var processors = SectionsHelper.ParseSections(content, '=');

            var processorModelNames = new HashSet <string>();
            int physicalCoreCount   = 0;
            int logicalCoreCount    = 0;
            int processorsCount     = 0;

            var currentClockSpeed = Frequency.Zero;
            var maxClockSpeed     = Frequency.Zero;
            var minClockSpeed     = Frequency.Zero;

            foreach (var processor in processors)
            {
                var numberOfCores = 0;
                if (processor.TryGetValue(WmicCpuInfoKeyNames.NumberOfCores, out string numberOfCoresValue) &&
                    int.TryParse(numberOfCoresValue, out numberOfCores) &&
                    numberOfCores > 0)
                {
                    physicalCoreCount += numberOfCores;
                }

                var numberOfLogical = 0;
                if (processor.TryGetValue(WmicCpuInfoKeyNames.NumberOfLogicalProcessors, out string numberOfLogicalValue) &&
                    int.TryParse(numberOfLogicalValue, out numberOfLogical) &&
                    numberOfLogical > 0)
                {
                    logicalCoreCount += numberOfLogical;
                }

                if (processor.TryGetValue(WmicCpuInfoKeyNames.Name, out string name))
                {
                    processorModelNames.Add(name);
                    processorsCount++;
                }

                var frequency = 0;
                if (processor.TryGetValue(WmicCpuInfoKeyNames.MaxClockSpeed, out string frequencyValue) &&
                    int.TryParse(frequencyValue, out frequency) &&
                    frequency > 0)
                {
                    maxClockSpeed += frequency;
                }
            }

            return(new CpuInfo(
                       processorModelNames.Count > 0 ? string.Join(", ", processorModelNames) : null,
                       processorsCount > 0 ? processorsCount : (int?)null,
                       physicalCoreCount > 0 ? physicalCoreCount : (int?)null,
                       logicalCoreCount > 0 ? logicalCoreCount : (int?)null,
                       currentClockSpeed > 0 && processorsCount > 0 ? Frequency.FromMHz(currentClockSpeed / processorsCount) : (Frequency?)null,
                       minClockSpeed > 0 && processorsCount > 0 ? Frequency.FromMHz(minClockSpeed / processorsCount) : (Frequency?)null,
                       maxClockSpeed > 0 && processorsCount > 0 ? Frequency.FromMHz(maxClockSpeed / processorsCount) : (Frequency?)null));
        }
コード例 #3
0
        internal static CpuInfo ParseOutput([CanBeNull] string content)
        {
            var logicalCores                  = SectionsHelper.ParseSections(content, ':');
            var processorModelNames           = new HashSet <string>();
            var processorsToPhysicalCoreCount = new Dictionary <string, int>();

            int logicalCoreCount = 0;
            var nominalFrequency = Frequency.Zero;
            var minFrequency     = Frequency.Zero;
            var maxFrequency     = Frequency.Zero;

            foreach (var logicalCore in logicalCores)
            {
                if (logicalCore.TryGetValue(ProcCpuInfoKeyNames.PhysicalId, out string physicalId) &&
                    logicalCore.TryGetValue(ProcCpuInfoKeyNames.CpuCores, out string cpuCoresValue) &&
                    int.TryParse(cpuCoresValue, out int cpuCoreCount) &&
                    cpuCoreCount > 0)
                {
                    processorsToPhysicalCoreCount[physicalId] = cpuCoreCount;
                }

                if (logicalCore.TryGetValue(ProcCpuInfoKeyNames.ModelName, out string modelName))
                {
                    processorModelNames.Add(modelName);
                    nominalFrequency = ParseFrequencyFromBrandString(modelName);
                    logicalCoreCount++;
                }

                if (logicalCore.TryGetValue(ProcCpuInfoKeyNames.MinFrequency, out string minCpuFreqValue) &&
                    Frequency.TryParseMHz(minCpuFreqValue, out var minCpuFreq))
                {
                    minFrequency = minCpuFreq;
                }

                if (logicalCore.TryGetValue(ProcCpuInfoKeyNames.MaxFrequency, out string maxCpuFreqValue) &&
                    Frequency.TryParseMHz(maxCpuFreqValue, out var maxCpuFreq))
                {
                    maxFrequency = maxCpuFreq;
                }
            }

            return(new CpuInfo(
                       processorModelNames.Count > 0 ? string.Join(", ", processorModelNames) : null,
                       processorsToPhysicalCoreCount.Count > 0 ? processorsToPhysicalCoreCount.Count : (int?)null,
                       processorsToPhysicalCoreCount.Count > 0 ? processorsToPhysicalCoreCount.Values.Sum() : (int?)null,
                       logicalCoreCount > 0 ? logicalCoreCount : (int?)null,
                       nominalFrequency > 0 ? nominalFrequency : (Frequency?)null,
                       minFrequency > 0 ? minFrequency : (Frequency?)null,
                       maxFrequency > 0 ? maxFrequency : (Frequency?)null));
        }
コード例 #4
0
        internal static CpuInfo ParseOutput([CanBeNull] string content)
        {
            var processors = SectionsHelper.ParseSections(content, '=');

            var processorModelNames = new HashSet <string>();
            int physicalCoreCount   = 0;
            int logicalCoreCount    = 0;
            int processorsCount     = 0;

            foreach (var processor in processors)
            {
                if (processor.TryGetValue(WmicCpuInfoKeyNames.NumberOfCores, out string numberOfCoresValue) &&
                    int.TryParse(numberOfCoresValue, out int numberOfCores) &&
                    numberOfCores > 0)
                {
                    physicalCoreCount += numberOfCores;
                }

                if (processor.TryGetValue(WmicCpuInfoKeyNames.NumberOfLogicalProcessors, out string numberOfLogicalValue) &&
                    int.TryParse(numberOfLogicalValue, out int numberOfLogical) &&
                    numberOfLogical > 0)
                {
                    logicalCoreCount += numberOfLogical;
                }

                if (processor.TryGetValue(WmicCpuInfoKeyNames.Name, out string name))
                {
                    processorModelNames.Add(name);
                    processorsCount++;
                }
            }

            return(new CpuInfo(
                       processorModelNames.Count > 0 ? string.Join(", ", processorModelNames) : null,
                       processorsCount > 0 ? processorsCount : (int?)null,
                       physicalCoreCount > 0 ? physicalCoreCount : (int?)null,
                       logicalCoreCount > 0 ? logicalCoreCount : (int?)null));
        }