CPU相关信息

unit untCpuInfo;

interface

{ 获取 CPU 制造商 }
function GetCpuFactory: String;

{ 获取 CPU 家族系统 }
function GetCpuFamily: Cardinal;

{ 获取 CPU 型号 }
function GetCpuModel: Cardinal;

{ 获取 CPU 步进 }
function GetCpuStepping: Cardinal;

{ 获取 CPU 名称 }
function GetCpuName: String;

{ 获取 CPU 频率 }
function GetCpuFrequency: Cardinal;

{ 获取 CPU 指令集 }
function GetCpuInstructs: String;

{ 获取 CPU 个数 }
function GetCPUCount: String;

{ 获取 CPU 缓存信息 }
function GetCPUCacheInfo: String;

implementation

uses Windows, SysUtils, Math;

type
  TCPUParam = record
    bit: Integer;
    desc: array [0 .. 19] of AnsiChar;
    detail: array [0 .. 63] of AnsiChar;
  end;

{ 寄存器 }
  TRegisters = record
    EAX: DWORD;
    EBX: DWORD;
    ECX: DWORD;
    EDX: DWORD;
  end;

PROCESSOR_CACHE_TYPE            = (CacheUnified, CacheInstruction, CacheData, CacheTrace);
  TLOGICAL_PROCESSOR_RELATIONSHIP = (RelationProcessorCore, RelationNumaNode, RelationCache, RelationProcessorPackage, RelationGroup, RelationAll = $FFFFFF);

CACHE_DESCRIPTOR = record
    Level: Byte;
    Associativity: Byte;
    LineSize: WORD;
    Size: DWORD;
    iType: PROCESSOR_CACHE_TYPE;
  end;

TCACHE_DESCRIPTOR = CACHE_DESCRIPTOR;
  PCACHE_DESCRIPTOR = ^TCACHE_DESCRIPTOR;

SYSTEM_LOGICAL_PROCESSOR_INFORMATION = record
    ProcessorMask: NativeUInt;
    Relationship: TLOGICAL_PROCESSOR_RELATIONSHIP;
    Cache: TCACHE_DESCRIPTOR;
    Reserved: DWORD;
  end;

TSYSTEM_LOGICAL_PROCESSOR_INFORMATION = SYSTEM_LOGICAL_PROCESSOR_INFORMATION;
  PSYSTEM_LOGICAL_PROCESSOR_INFORMATION = ^TSYSTEM_LOGICAL_PROCESSOR_INFORMATION;

const
  IntelCPUParam_1: array [0 .. 29] of TCPUParam = (                          { }
    (bit: 0; desc: ‘FPU‘; detail: ‘Floating-point unit on-chip‘),            { }
    (bit: 1; desc: ‘VME‘; detail: ‘Virtual Mode Enhancements‘),              { }
    (bit: 2; desc: ‘DE‘; detail: ‘Debugging Extension‘),                     { }
    (bit: 3; desc: ‘PSE‘; detail: ‘Page Size Extension‘),                    { }
    (bit: 4; desc: ‘TSC‘; detail: ‘Time Stamp Counter‘),                     { }
    (bit: 5; desc: ‘MSR‘; detail: ‘Pentium Processor MSR‘),                  { }
    (bit: 6; desc: ‘PAE‘; detail: ‘Physical Address Extension‘),             { }
    (bit: 7; desc: ‘MCE‘; detail: ‘Machine Check Exception‘),                { }
    (bit: 8; desc: ‘CX8‘; detail: ‘CMPXCHG8B Instruction Supported‘),        { }
    (bit: 9; desc: ‘APIC‘; detail: ‘On-chip APIC Hardware Enabled‘),         { }
    (bit: 11; desc: ‘SEP‘; detail: ‘SYSENTER and SYSEXIT‘),                  { }
    (bit: 12; desc: ‘MTRR‘; detail: ‘Memory Type Range Registers‘),          { }
    (bit: 13; desc: ‘PGE‘; detail: ‘PTE Global Bit‘),                        { }
    (bit: 14; desc: ‘MCA‘; detail: ‘Machine Check Architecture‘),            { }
    (bit: 15; desc: ‘CMOV‘; detail: ‘Conditional Move/Compare Instruction‘), { }
    (bit: 16; desc: ‘PAT‘; detail: ‘Page Attribute Table‘),                  { }
    (bit: 17; desc: ‘PSE36‘; detail: ‘Page Size Extension 36-bit‘),          { }
    (bit: 18; desc: ‘PN‘; detail: ‘Processor Serial Number‘),                { }
    (bit: 19; desc: ‘CLFLUSH‘; detail: ‘CFLUSH instruction‘),                { }
    (bit: 21; desc: ‘DTS‘; detail: ‘Debug Store‘),                           { }
    (bit: 22; desc: ‘ACPI‘; detail: ‘Thermal Monitor and Clock Ctrl‘),       { }
    (bit: 23; desc: ‘MMX‘; detail: ‘MMX Technology‘),                        { }
    (bit: 24; desc: ‘FXSR‘; detail: ‘FXSAVE/FXRSTOR‘),                       { }
    (bit: 25; desc: ‘SSE‘; detail: ‘SSE Extensions‘),                        { }
    (bit: 26; desc: ‘SSE2‘; detail: ‘SSE2 Extensions‘),                      { }
    (bit: 27; desc: ‘SS‘; detail: ‘Self Snoop‘),                             { }
    (bit: 28; desc: ‘HT‘; detail: ‘Multi-threading‘),                        { }
    (bit: 29; desc: ‘TM‘; detail: ‘Therm. Monitor‘),                         { }
    (bit: 30; desc: ‘IA64‘; detail: ‘IA-64 Processor‘),                      { }
    (bit: 31; desc: ‘PBE‘; detail: ‘Pend. Brk. EN.‘)                         { }
    );

IntelCPUParam_2: array [0 .. 24] of TCPUParam = (                       { }
    (bit: 0; desc: ‘PNI‘; detail: ‘SSE3 Extensions ‘),                    { }
    (bit: 1; desc: ‘PCLMULQDQ‘; detail: ‘Carryless Multiplication‘),      { }
    (bit: 2; desc: ‘DTES64‘; detail: ‘64-bit Debug Store‘),               { }
    (bit: 3; desc: ‘MONITOR‘; detail: ‘MONITOR/MWAIT‘),                   { }
    (bit: 4; desc: ‘DS_CPL‘; detail: ‘CPL Qualified Debug Store‘),        { }
    (bit: 5; desc: ‘VMX‘; detail: ‘Virtual Machine Extensions‘),          { }
    (bit: 6; desc: ‘SMX‘; detail: ‘Safer Mode Extensions‘),               { }
    (bit: 7; desc: ‘EST‘; detail: ‘Enhanced Intel SpeedStep Technology‘), { }
    (bit: 8; desc: ‘TM2‘; detail: ‘Thermal Monitor 2‘),                   { }
    (bit: 9; desc: ‘SSSE3‘; detail: ‘Supplemental SSE3‘),                 { }
    (bit: 10; desc: ‘CID‘; detail: ‘L1 Context ID‘),                      { }
    (bit: 12; desc: ‘FMA‘; detail: ‘Fused Multiply Add‘),                 { }
    (bit: 13; desc: ‘CX16‘; detail: ‘CMPXCHG16B Available‘),              { }
    (bit: 14; desc: ‘XTPR‘; detail: ‘xTPR Disable‘),                      { }
    (bit: 15; desc: ‘PDCM‘; detail: ‘Perf/Debug Capability MSR‘),         { }
    (bit: 18; desc: ‘DCA‘; detail: ‘Direct Cache Access‘),                { }
    (bit: 19; desc: ‘SSE4_1‘; detail: ‘SSE4.1 Extensions‘),               { }
    (bit: 20; desc: ‘SSE4_2‘; detail: ‘SSE4.2 Extensions‘),               { }
    (bit: 21; desc: ‘X2APIC‘; detail: ‘x2APIC Feature‘),                  { }
    (bit: 22; desc: ‘MOVBE‘; detail: ‘MOVBE Instruction‘),                { }
    (bit: 23; desc: ‘POPCNT‘; detail: ‘Pop Count Instruction‘),           { }
    (bit: 25; desc: ‘AES‘; detail: ‘AES Instruction‘),                    { }
    (bit: 26; desc: ‘XSAVE‘; detail: ‘XSAVE/XRSTOR Extensions‘),          { }
    (bit: 27; desc: ‘OSXSAVE‘; detail: ‘XSAVE/XRSTOR Enabled in the OS‘), { }
    (bit: 28; desc: ‘AVX‘; detail: ‘Advanced Vector Extension‘)           { }
    );

AMDCPUParam_1: array [0 .. 9] of TCPUParam = (                          { }
    (bit: 11; desc: ‘SYSCALL‘; detail: ‘SYSCALL and SYSRET‘),             { }
    (bit: 19; desc: ‘MP‘; detail: ‘MP Capable‘),                          { }
    (bit: 20; desc: ‘NX‘; detail: ‘No-Execute Page Protection‘),          { }
    (bit: 22; desc: ‘MMXEXT‘; detail: ‘MMX Technology (AMD Extensions)‘), { }
    (bit: 25; desc: ‘FXSR_OPT‘; detail: ‘Fast FXSAVE/FXRSTOR‘),           { }
    (bit: 26; desc: ‘PDPE1GB‘; detail: ‘PDP Entry for 1GiB Page‘),        { }
    (bit: 27; desc: ‘RDTSCP‘; detail: ‘RDTSCP Instruction‘),              { }
    (bit: 29; desc: ‘LM‘; detail: ‘Long Mode Capable‘),                   { }
    (bit: 30; desc: ‘3DNOWEXT‘; detail: ‘3DNow! Extensions‘),             { }
    (bit: 31; desc: ‘3DNOW‘; detail: ‘3DNow!‘)                            { }
    );

AMDCPUParam_2: array [0 .. 13] of TCPUParam = (                            { }
    (bit: 0; desc: ‘LAHF_LM‘; detail: ‘LAHF/SAHF Supported in 64-bit Mode‘), { }
    (bit: 1; desc: ‘CMP_LEGACY‘; detail: ‘Chip Multi-Core‘),                 { }
    (bit: 2; desc: ‘SVM‘; detail: ‘Secure Virtual Machine‘),                 { }
    (bit: 3; desc: ‘EXTAPIC‘; detail: ‘Extended APIC Space‘),                { }
    (bit: 4; desc: ‘CR8_LEGACY‘; detail: ‘CR8 Available in Legacy Mode‘),    { }
    (bit: 5; desc: ‘ABM‘; detail: ‘Advanced Bit Manipulation‘),              { }
    (bit: 6; desc: ‘SSE4A‘; detail: ‘SSE4A Extensions‘),                     { }
    (bit: 7; desc: ‘MISALIGNSSE‘; detail: ‘Misaligned SSE Mode‘),            { }
    (bit: 8; desc: ‘3DNOWPREFETCH‘; detail: ‘3DNow! Prefetch/PrefetchW‘),    { }
    (bit: 9; desc: ‘OSVW‘; detail: ‘OS Visible Workaround‘),                 { }
    (bit: 10; desc: ‘IBS‘; detail: ‘Instruction Based Sampling‘),            { }
    (bit: 11; desc: ‘SSE5‘; detail: ‘SSE5 Extensions‘),                      { }
    (bit: 12; desc: ‘SKINIT‘; detail: ‘SKINIT, STGI, and DEV Support‘),      { }
    (bit: 13; desc: ‘WDT‘; detail: ‘Watchdog Timer Support‘)                 { }
    );

function GetLogicalProcessorInformation(Buffer: PSYSTEM_LOGICAL_PROCESSOR_INFORMATION; var ReturnLength: DWORD): BOOL; stdcall; external ‘kernel32.dll‘;

procedure GetCPUID(Param: Cardinal; var Registers: TRegisters);
asm
  PUSH    EBX                         { save affected registers }
  PUSH    EDI
  MOV     EDI, Registers
  XOR     EBX, EBX                    { clear EBX register }
  XOR     ECX, ECX                    { clear ECX register }
  XOR     EDX, EDX                    { clear EDX register }
  DB $0F, $A2                         { CPUID opcode }
  MOV     TRegisters(EDI).&EAX, EAX   { save EAX register }
  MOV     TRegisters(EDI).&EBX, EBX   { save EBX register }
  MOV     TRegisters(EDI).&ECX, ECX   { save ECX register }
  MOV     TRegisters(EDI).&EDX, EDX   { save EDX register }
  POP     EDI                         { restore registers }
  POP     EBX
end;

{ 获取 CPU 制造商 }
function GetCpuFactory: String;
var
  regs      : TRegisters;
  VendorName: array [0 .. 12] of AnsiChar;
begin
  GetCPUID(0, regs);
  { 1、制造商 }
  Move(regs.EBX, VendorName[0], 4);
  Move(regs.EDX, VendorName[4], 4);
  Move(regs.ECX, VendorName[8], 4);
  VendorName[12] := #0;
  Result         := string(AnsiString(VendorName));
end;

{ 获取 CPU 家族系统 }
function GetCpuFamily: Cardinal;
var
  regs: TRegisters;
begin
  GetCPUID(1, regs);
  Result := (regs.EAX shr 8) and $F;
  if (Result = $F) then
    Result := Result + (regs.EAX shr 20) and $FF;
end;

{ 获取 CPU 型号 }
function GetCpuModel: Cardinal;
var
  regs: TRegisters;
begin
  GetCPUID(1, regs);
  Result := (regs.EAX shr 4) and $F;
  if (GetCpuFamily = $F) or (GetCpuFamily = 6) then
    Result := Result + ((regs.EAX shr 16) and $F) shl 4;
end;

{ 获取 CPU 步进 }
function GetCpuStepping: Cardinal;
var
  regs: TRegisters;
begin
  GetCPUID(1, regs);
  Result := regs.EAX and $F;
end;

{ 获取 CPU 名称 }
function GetCpuName: String;
var
  regs          : TRegisters;
  processor_name: array [0 .. 48] of AnsiChar;
  III           : Integer;
  TTT           : Cardinal;
begin
  for III := 2 to 4 do
  begin
    TTT := 1 shl 31 + III;
    GetCPUID(TTT, regs);
    Move(regs.EAX, processor_name[(III - 2) * 16 + 00], 4);
    Move(regs.EBX, processor_name[(III - 2) * 16 + 04], 4);
    Move(regs.ECX, processor_name[(III - 2) * 16 + 08], 4);
    Move(regs.EDX, processor_name[(III - 2) * 16 + 12], 4);
  end;
  processor_name[48] := #0;
  Result             := string(AnsiString(processor_name));
end;

{ 获取 CPU 频率 }
function GetCpuFrequency: Cardinal;
var
 CurrTicks, TicksCount: TLargeInteger;
 iST, iET : Int64;
 OldProcessP : DWORD;
 OldThreadP : DWORD;
begin
 { 获取进程、线程级别 }
 OldProcessP := GetPriorityClass(GetCurrentProcess);
 OldThreadP := GetThreadPriority(GetCurrentThread);

{ 调整进程、线程级别到最高级别 }
 SetPriorityClass(GetCurrentProcess, REALTIME_PRIORITY_CLASS);
 SetThreadPriority(GetCurrentThread, THREAD_PRIORITY_TIME_CRITICAL);

QueryPerformanceFrequency(TicksCount);
 QueryPerformanceCounter(CurrTicks);
 LARGE_INTEGER(TicksCount).QuadPart := Round(LARGE_INTEGER(TicksCount).QuadPart / 16);
 LARGE_INTEGER(TicksCount).QuadPart := LARGE_INTEGER(TicksCount).QuadPart + LARGE_INTEGER(CurrTicks).QuadPart;

asm
 RDTSC
 MOV DWORD PTR iST + 0, EAX
 MOV DWORD PTR iST + 4, EDX
 end;

while (LARGE_INTEGER(CurrTicks).QuadPart < LARGE_INTEGER(TicksCount).QuadPart) do
 begin
 QueryPerformanceCounter(CurrTicks);
 end;

asm
 RDTSC
 MOV DWORD PTR iET + 0, EAX
 MOV DWORD PTR iET + 4, EDX
 end;

{ 恢复进程、线程级别原有级别 }
 SetThreadPriority(GetCurrentThread, OldThreadP);
 SetPriorityClass(GetCurrentProcess, OldProcessP);

{ 返回结果 MHz }
 Result := Round((iET - iST) / 62500);
end;

{ 获取 CPU 指令集 }
function GetCpuInstructs: String;
var
  regs1, regs2          : TRegisters;
  amd_flags1, amd_flags2: Integer;
  III                   : Integer;
begin
  GetCPUID(1, regs1);

for III := 29 downto 0 do
  begin
    if regs1.EDX and (1 shl IntelCPUParam_1[III].bit) = 1 shl IntelCPUParam_1[III].bit then
    begin
      Result := string(StrPas(IntelCPUParam_1[III].desc)) + ‘ ‘ + Result;
    end;
  end;

for III := 24 downto 0 do
  begin
    if regs1.ECX and (1 shl IntelCPUParam_2[III].bit) = 1 shl IntelCPUParam_2[III].bit then
    begin
      Result := Result + ‘ ‘ + string(StrPas(IntelCPUParam_2[III].desc));
    end;
  end;

GetCPUID($80000001, regs2);
  amd_flags1 := regs2.EDX;
  amd_flags2 := regs2.ECX;

for III := 10 downto 0 do
  begin
    if amd_flags1 and (1 shl AMDCPUParam_1[III].bit) = 1 shl AMDCPUParam_1[III].bit then
    begin
      Result := Result + ‘ ‘ + string(StrPas(AMDCPUParam_1[III].desc));
    end;
  end;

for III := 13 downto 0 do
  begin
    if amd_flags2 and (1 shl AMDCPUParam_2[III].bit) = 1 shl AMDCPUParam_2[III].bit then
    begin
      Result := Result + ‘ ‘ + string(StrPas(AMDCPUParam_2[III].desc));
    end;
  end;
end;

function CountSetBits(const bitMask: Cardinal): DWORD;
var
  LSHIFT     : DWORD;
  bitSetCount: DWORD;
  bitTest    : Uint64;
  I          : DWORD;
begin
  LSHIFT      := sizeof(Cardinal) * 8 - 1;
  bitSetCount := 0;
  bitTest     := 1 shl LSHIFT;

for I := 0 to LSHIFT - 1 do
  begin
    bitSetCount := Ifthen((bitMask and bitTest) = 0, 1, 0);
    bitTest     := bitTest div 2;
  end;

Result := bitSetCount;
end;

{ 获取 CPU 个数 }
function GetCPUCount: String;
var
  Buffer               : array of SYSTEM_LOGICAL_PROCESSOR_INFORMATION;
  ReturnLength         : DWORD;
  III, Count           : Integer;
  processorCoreCount   : Integer;
  numaNodeCount        : Integer;
  logicalProcessorCount: Integer;
  processorPackageCount: Integer;
  JJJ                  : Integer;
begin
  SetLength(Buffer, 1);
  ReturnLength := sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION);

{ 第一次调用获取缓冲区大小 }
  if not GetLogicalProcessorInformation(@Buffer[0], ReturnLength) then
  begin
    if GetLastError = ERROR_INSUFFICIENT_BUFFER then
    begin
      SetLength(Buffer, ReturnLength div sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION) + 1);
      { 第二次调用,返回结果 }
      if not GetLogicalProcessorInformation(@Buffer[0], ReturnLength) then
      begin
        Exit;
      end;
    end;
  end;

processorCoreCount    := 0;
  numaNodeCount         := 0;
  logicalProcessorCount := 0;
  processorPackageCount := 0;

Count   := ReturnLength div sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION);
  for III := 0 to Count - 1 do
  begin
    case Buffer[III].Relationship of
      RelationProcessorCore:
        Inc(processorCoreCount);
      RelationNumaNode:
        Inc(numaNodeCount);
      RelationProcessorPackage:
        Inc(processorPackageCount);
      RelationCache:
        begin
          JJJ := CountSetBits(Buffer[III].ProcessorMask);
          if JJJ = 1 then
          begin
            Inc(logicalProcessorCount);
          end;
        end;
    end;
  end;
  Result := Format(‘NumaNodes=%d PhysicalProcessorPackages=%d ProcessorCores=%d LogicalProcessors=%d‘, [numaNodeCount, processorPackageCount, processorCoreCount,
    logicalProcessorCount]);
end;

{ 获取 CPU 缓存信息 }
function GetCPUCacheInfo: String;
var
  Buffer               : array of SYSTEM_LOGICAL_PROCESSOR_INFORMATION;
  ReturnLength         : DWORD;
  III, Count           : Integer;
  L1DataCache          : Integer;
  L1InstructionCache   : Integer;
  L2DataCache          : Integer;
  L3DataCache          : Integer;
  L1DataCacheStr       : String;
  L1InstructionCacheStr: String;
  L2DataCacheStr       : String;
  L3DataCacheStr       : String;
  L10                  : String;
  L11                  : String;
  L2, L3               : string;
  L1DataSize           : Integer;
  L1InstructionSize    : Integer;
  L2DataSize           : Integer;
  L3DataSize           : Integer;
begin
  SetLength(Buffer, 1);
  ReturnLength      := sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION);
  L1DataSize        := 0;
  L1InstructionSize := 0;
  L2DataSize        := 0;
  L3DataSize        := 0;

{ 第一次调用获取缓冲区大小 }
  if not GetLogicalProcessorInformation(@Buffer[0], ReturnLength) then
  begin
    if GetLastError = ERROR_INSUFFICIENT_BUFFER then
    begin
      SetLength(Buffer, ReturnLength div sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION) + 1);
      { 第二次调用,返回结果 }
      if not GetLogicalProcessorInformation(@Buffer[0], ReturnLength) then
      begin
        Exit;
      end;
    end;
  end;

L1DataCache        := 0;
  L1InstructionCache := 0;

L2DataCache := 0;
  L3DataCache := 0;

Count   := ReturnLength div sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION);
  for III := 0 to Count - 1 do
  begin
    { CPU一级缓存 }
    if Buffer[III].Cache.Level = 1 then
    begin
      { CPU一级数据缓存 }
      if Buffer[III].Cache.iType = CacheData then
      begin
        Inc(L1DataCache);
        L1DataSize     := Buffer[III].Cache.Size div 1024;
        L1DataCacheStr := Format(‘%d 路成组相连,%d 字节管道尺寸‘, [Buffer[III].Cache.Associativity, Buffer[III].Cache.LineSize]);
      end;

{ CPU一级指令缓存 }
      if Buffer[III].Cache.iType = CacheInstruction then
      begin
        Inc(L1InstructionCache);
        L1InstructionSize     := Buffer[III].Cache.Size div 1024;
        L1InstructionCacheStr := Format(‘%d 路成组相连,%d 字节管道尺寸‘, [Buffer[III].Cache.Associativity, Buffer[III].Cache.LineSize]);
      end;
    end;

{ CPU二级缓存 }
    if Buffer[III].Cache.Level = 2 then
    begin
      Inc(L2DataCache);
      L2DataSize     := Buffer[III].Cache.Size div 1024;
      L2DataCacheStr := Format(‘%d 路成组相连,%d 字节管道尺寸‘, [Buffer[III].Cache.Associativity, Buffer[III].Cache.LineSize]);
    end;

{ CPU三级缓存 }
    if Buffer[III].Cache.Level = 3 then
    begin
      Inc(L3DataCache);
      L3DataSize     := Buffer[III].Cache.Size div 1024;
      L3DataCacheStr := Format(‘%d 路成组相连,%d 字节管道尺寸‘, [Buffer[III].Cache.Associativity, Buffer[III].Cache.LineSize]);
    end;
  end;

L10 := Format(‘一级缓存数据缓存(参数:%s):%d×%dK‘, [L1DataCacheStr, L1DataCache, L1DataSize]);
  L11 := Format(‘一级缓存指令缓存(%s):%d×%dK‘, [L1InstructionCacheStr, L1InstructionCache, L1InstructionSize]);
  L2  := Format(‘二级缓存(%s):%d×%dK‘, [L2DataCacheStr, L2DataCache, L2DataSize]);
  L3  := Format(‘三级缓存(%s):%d×%dK‘, [L3DataCacheStr, L3DataCache, L3DataSize]);

Result := L10 + ‘    ‘ + L11 + ‘    ‘ + L2 + ‘    ‘ + L3;
end;

end.

来自为知笔记(Wiz)

附件列表

CPU相关信息

时间: 2024-10-10 21:44:01

CPU相关信息的相关文章

借助Sigar API获取CPU相关信息

Sigar(全称System Information Gatherer And Reporter,即系统信息收集报表器),它提供了一个开源的跨平台的收集计算机硬件和操作系统信息的API(该API底层接口用C语言编写),本文将演示如何借助Sigar API获取CPU相关信息: package com.ghj.packageoftest; import org.hyperic.sigar.Cpu; import org.hyperic.sigar.CpuInfo; import org.hyperi

cpu相关信息(进程、线程、核...)

cpu的相关信息. 1.cpu 1.1 物理cpu 实际Server中插槽上的CPU个数.物理cpu数量,可以数不重复的 physical id 有几个 1.1.1 查看物理CPU的个数 cat /proc/cpuinfo |grep "physical id"|sort |uniq|wc -l 1.2 逻辑cpu Linux用户对 /proc/cpuinfo 这个文件肯定不陌生. 它是用来存储cpu硬件信息的.信息内容分别列出了processor 0 – n 的规格.这里需要注意,如

Linux CPU相关信息查看

linux 下查看机器是cpu是几核的 几个cpu more /proc/cpuinfo |grep "physical id"|uniq|wc -l 每个cpu是几核(假设cpu配置相同) more /proc/cpuinfo |grep "physical id"|grep "0"|wc -l cat /proc/cpuinfo | grep processor 1. 查看物理CPU的个数#cat /proc/cpuinfo |grep &q

Linux下查看CPU相关信息

相关概念 物理CPU总核数 = 逻辑CPU总核数 = 物理CPU个数 * 每颗物理CPU的核数 (没有超线程时) 逻辑CPU总核数 = 物理CPU个数 * 每颗物理CPU的核数 * 超线程数 (有超线程时) 物理CPU:实际上服务器插入的CPU个数,在/proc/cpuinfo文件中有几个"physical id"就代表有几个物理CPU. 逻辑CPU:操作系统可以使用逻辑CPU来模拟出真实CPU的效果,在之前没有多核处理器的时候,一个CPU只有一个核,而现在有了多核技术,其效果就好像把

cpu相关信息查看

查看CPU型号:grep "model name" /proc/cpuinfo | uniqdmidecode -s processor-version | uniq 查看物理CPU个数grep "physical id" /proc/cpuinfo | sort -u | wc -lgrep "physical id" /proc/cpuinfo | uniq | wc -l 查看CPU核心数grep "core id" /

一个可以获取linux 系统硬件相关信息的类

<?php  class CServerInfo {     static public function getCpuData($speed = 0.5)     {         if (false === ($prevVal = @file("/proc/stat"))) return false;         $prevVal = implode($prevVal, PHP_EOL);         $prevArr = explode(' ', trim($pr

更改CPU厂商信息

更改第三方手机检测到的CPU厂商型号,在kernel\arch\arm\mach-msm下面对应的Board-*.c文件里更改,比如我们是8226的CPU,就要在Board-8226.c里将DT_MACHINE_START(MSM8226_DT, "Qualcomm MSM 8226 (Flattened Device Tree)")  这里的8226改成客户指定的型号,比如要改成8926,就要这么改: DT_MACHINE_START(MSM8226_DT, "Qualco

在linux中查询硬件相关信息

1.查询cpu的相关 a.查询CPU的统计信息 使用命令:lscpu 得到的结果如下: Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian CPU(s): 12 On-line CPU(s) list: 0-11 Thread(s) per core: 1 Core(s) per socket: 6 Socket(s): 2 NUMA node(s): 2 Vendor ID: Genuine

你不一定懂的cpu显示信息

在使用top命令的时候会看到这么一行: 里面的各个值分别是什么意思呢? 今天被问到这个问题,发现答的不是很清楚.果然啊,天天用最多的top命令都还没摸透...惭愧...于是就查了些资料: 官方解释 Cpu(s)表示的是cpu信息.各个值的意思是: us: user cpu time (or) % CPU time spent in user space sy: system cpu time (or) % CPU time spent in kernel space ni: user nice