是否可以在java(或C#)中创建一个可以检查用户CPU功率有多大的程序?如果是这样,可以查找哪些类/ API?我似乎无法通过谷歌搜索找到任何东西。
答案 0 :(得分:3)
使用:
System.getenv("PROCESSOR_IDENTIFIER");
System.getenv("PROCESSOR_ARCHITECTURE");
System.getenv("NUMBER_OF_PROCESSORS");
注意:System.getenv返回一个依赖于操作系统的映射,如果它们未在当前操作系统中定义,则可能会在上述键上返回null。
您还可以考虑使用Runtime
班级信息:
Runtime.getRuntime().availableProcessors();
如果您打算开发一个类似 JConsole 的工具,则应该浏览Java Management个包。那里有许多有用的课程可以满足你的要求。
答案 1 :(得分:1)
对于c#;
var query = new ObjectQuery("select * from Win32_Processor");
var mc = new ManagementObjectSearcher(query);
var props = mc.Get().Cast<ManagementObject>()
.SelectMany(m => m.Properties.Cast<PropertyData>())
.ToDictionary(p => p.Name, p => p.Value);
foreach (var prop in props.Where(kv => kv.Value != null))
{
Console.WriteLine("{0} = {1}", prop.Key, prop.Value);
}
它将打印出类似这样的内容
AddressWidth = 64
Architecture = 9
Availability = 3
Caption = Intel64 Family 6 Model 58 Stepping 9
CpuStatus = 1
CreationClassName = Win32_Processor
CurrentClockSpeed = 3201
CurrentVoltage = 41
DataWidth = 64
Description = Intel64 Family 6 Model 58 Stepping 9
DeviceID = CPU0
ExtClock = 100
Family = 205
L2CacheSize = 1024
L3CacheSize = 6144
L3CacheSpeed = 0
Level = 6
LoadPercentage = 1
Manufacturer = GenuineIntel
MaxClockSpeed = 3201
Name = Intel(R) Core(TM) i5-3470 CPU @ 3.20GHz
NumberOfCores = 4
NumberOfLogicalProcessors = 4
PowerManagementSupported = False
ProcessorType = 3
Role = CPU
SocketDesignation = CPU 1
SystemCreationClassName = Win32_ComputerSystem