Ⅰ 如何獲取 android 設備的CPU核數,時鍾頻率以及內存大小
獲取 CPU 核數 Linux 中的設備都是以文件的形式存在,CPU 也不例外,因此 CPU 的文件個數就等價與核數。 Android 的 CPU 設備文件位於/sys/devices/system/cpu/目錄,文件名的的格式為cpu\d+。 root@generic_x86_64:/sys/devices/system/cpu # ls cpu0 cpufreq cpuidle kernel_max modalias offline online possible power present uevent 統計一下文件個數便可以獲得 CPU 核數。 public static int getNumberOfCPUCores() { if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) { // Gingerbread doesn't support giving a single application access to both cores, but a // handful of devices (Atrix 4G and Droid X2 for example) were released with a al-core // chipset and Gingerbread; that can let an app in the background run without impacting // the foreground application. But for our purposes, it makes them single core. return 1; } int cores; try { cores = new File("/sys/devices/system/cpu/").listFiles(CPU_FILTER).length; } catch (SecurityException e) { cores = DEVICEINFO_UNKNOWN; } catch (NullPointerException e) { cores = DEVICEINFO_UNKNOWN; } return cores; } private static final FileFilter CPU_FILTER = new FileFilter() { @Override public boolean accept(File pathname) { String path = pathname.getName(); //regex is slow, so checking char by char. if (path.startsWith("cpu")) { for (int i = 3; i < path.length(); i++) { if (path.charAt(i) < '0' path.charAt(i) > '9') { return false; } } return true; } return false; } }; 獲取時鍾頻率 獲取時鍾頻率需要讀取系統文件 -/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq或者/proc/cpuinfo。 Android 模擬器中並沒有cpuinfo_max_freq文件,因此只能讀取/proc/cpuinfo。 /proc/cpuinfo包含了很多 cpu 數據。 processor : 0 vendor_id : GenuineIntel cpu family : 6 model : 70 model name : Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz stepping : 1 cpu MHz : 0.000 cache size : 1024 KB fdiv_bug : no hlt_bug : no f00f_bug : no coma_bug : no fpu : yes fpu_exception : yes cpuid level : 4 wp : yes 代碼如下: public static int getCPUMaxFreqKHz() { int maxFreq = DEVICEINFO_UNKNOWN; try { for (int i = 0; i < getNumberOfCPUCores(); i++) { String filename = "/sys/devices/system/cpu/cpu" + i + "/cpufreq/cpuinfo_max_freq"; File cpuInfoMaxFreqFile = new File(filename); if (cpuInfoMaxFreqFile.exists()) { byte[] buffer = new byte[128]; FileInputStream stream = new FileInputStream(cpuInfoMaxFreqFile); try { stream.read(buffer); int endIndex = 0; //Trim the first number out of the byte buffer. while (buffer[endIndex] >= '0' && buffer[endIndex] <= '9' && endIndex < buffer.length) endIndex++; String str = new String(buffer, 0, endIndex); Integer freqBound = Integer.parseInt(str); if (freqBound > maxFreq) maxFreq = freqBound; } catch (NumberFormatException e) { //Fall through and use /proc/cpuinfo. } finally { stream.close(); } } } if (maxFreq == DEVICEINFO_UNKNOWN) { FileInputStream stream = new FileInputStream("/proc/cpuinfo"); try { int freqBound = parseFileForValue("cpu MHz", stream); freqBound *= 1000; //MHz -> kHz if (freqBound > maxFreq) maxFreq = freqBound; } finally { stream.close(); } } } catch (IOException e) { maxFreq = DEVICEINFO_UNKNOWN; //Fall through and return unknown. } return maxFreq; } 獲取內存大小 如果 SDK 版本大於等於JELLY_BEAN,可以通過ActivityManager來獲取內從大小。 ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo(); ActivityManager am = (ActivityManager) c.getSystemService(Context.ACTIVITY_SERVICE); am.getMemoryInfo(memInfo); 如果版本低於JELLY_BEAN,則只能讀取系統文件了。 FileInputStream stream = new FileInputStream("/proc/meminfo"); totalMem = parseFileForValue("MemTotal", stream); 完整代碼如下: @TargetApi(Build.VERSION_CODES.JELLY_BEAN) public static long getTotalMemory(Context c) { // memInfo.totalMem not supported in pre-Jelly Bean APIs. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo(); ActivityManager am = (ActivityManager) c.getSystemService(Context.ACTIVITY_SERVICE); am.getMemoryInfo(memInfo); if (memInfo != null) { return memInfo.totalMem; } else { return DEVICEINFO_UNKNOWN; } } else { long totalMem = DEVICEINFO_UNKNOWN; try { FileInputStream stream = new FileInputStream("/proc/meminfo"); try { totalMem = parseFileForValue("MemTotal", stream); totalMem *= 1024; } finally { stream.close(); } } catch (IOException e) { } return totalMem; } }
Ⅱ android可以獲取cpuid嗎
可以,直接下載個安兔兔,再看設備信息即可看到
Ⅲ 如何獲取 Android 設備的CPU核數,時鍾頻率以及內存大小
Device Year Class 的主要功能是根據 CPU核數、時鍾頻率 以及 內存大小 對設備進行分級。代碼很簡單,只包含兩個類:
DeviceInfo-> 獲取設備參數,
YearClass-> 根據參數進行分級。
下表是 Facebook 公司提供的分級標准,其中Year欄表示分級結果。
Year
Cores
Clock
RAM
2008 1 528MHz 192MB
2009 n/a 600MHz 290MB
2010 n/a 1.0GHz 512MB
2011 2 1.2GHz 1GB
2012 4 1.5GHz 1.5GB
2013 n/a 2.0GHz 2GB
2014 n/a >2GHz >2GB
關於輸出年份的計算方法可以參考源碼,本文只把一些比較常用的功能抽取出來做一個簡要介紹。
獲取 CPU 核數
我們都知道,Linux 中的設備都是以文件的形式存在,CPU 也不例外,因此 CPU 的文件個數就等價與核數。
Android 的 CPU 設備文件位於/sys/devices/system/cpu/目錄,文件名的的格式為cpu\d+。
root@generic_x86_64:/sys/devices/system/cpu # ls <b>cpu0</b> cpufreq
cpuidle
kernel_max
modalias
offline
online
possible
power
present
uevent
統計一下文件個數便可以獲得 CPU 核數。
public static int getNumberOfCPUCores() {
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
// Gingerbread doesn't support giving a single application access to both cores, but a
// handful of devices (Atrix 4G and Droid X2 for example) were released with a al-core
// chipset and Gingerbread; that can let an app in the background run without impacting
// the foreground application. But for our purposes, it makes them single core.
return 1;
}
int cores;
try {
cores = new File("/sys/devices/system/cpu/").listFiles(CPU_FILTER).length;
} catch (SecurityException e) {
cores = DEVICEINFO_UNKNOWN;
} catch (NullPointerException e) {
cores = DEVICEINFO_UNKNOWN;
}
return cores;
}
private static final FileFilter CPU_FILTER = new FileFilter() {
@Override
public boolean accept(File pathname) {
String path = pathname.getName();
//regex is slow, so checking char by char.
if (path.startsWith("cpu")) {
for (int i = 3; i < path.length(); i++) {
if (path.charAt(i) < '0' || path.charAt(i) > '9') {
return false;
}
}
return true;
}
return false;
}
};
獲取時鍾頻率
獲取時鍾頻率需要讀取系統文件 -/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq或者/proc/cpuinfo。
我的 Android 模擬器中並沒有cpuinfo_max_freq文件,因此只能讀取/proc/cpuinfo。
/proc/cpuinfo包含了很多 cpu 數據。
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 70
model name : Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
stepping : 1
cpu MHz : 0.000
cache size : 1024 KB
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 4
wp : yes
代碼如下:
public static int getCPUMaxFreqKHz() {
int maxFreq = DEVICEINFO_UNKNOWN;
try {
for (int i = 0; i < getNumberOfCPUCores(); i++) {
String filename =
"/sys/devices/system/cpu/cpu" + i + "/cpufreq/cpuinfo_max_freq";
File cpuInfoMaxFreqFile = new File(filename);
if (cpuInfoMaxFreqFile.exists()) {
byte[] buffer = new byte[128];
FileInputStream stream = new FileInputStream(cpuInfoMaxFreqFile);
try {
stream.read(buffer);
int endIndex = 0;
//Trim the first number out of the byte buffer.
while (buffer[endIndex] >= '0' && buffer[endIndex] <= '9'
&& endIndex < buffer.length) endIndex++;
String str = new String(buffer, 0, endIndex);
Integer freqBound = Integer.parseInt(str);
if (freqBound > maxFreq) maxFreq = freqBound;
} catch (NumberFormatException e) {
//Fall through and use /proc/cpuinfo.
} finally {
stream.close();
}
}
}
if (maxFreq == DEVICEINFO_UNKNOWN) {
FileInputStream stream = new FileInputStream("/proc/cpuinfo");
try {
int freqBound = parseFileForValue("cpu MHz", stream);
freqBound *= 1000; //MHz -> kHz
if (freqBound > maxFreq) maxFreq = freqBound;
} finally {
stream.close();
}
}
} catch (IOException e) {
maxFreq = DEVICEINFO_UNKNOWN; //Fall through and return unknown.
}
return maxFreq;
}
獲取內存大小
如果 SDK 版本大於等於JELLY_BEAN,可以通過ActivityManager來獲取內從大小。
ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo();
ActivityManager am = (ActivityManager) c.getSystemService(Context.ACTIVITY_SERVICE);
am.getMemoryInfo(memInfo);
如果版本低於JELLY_BEAN,則只能讀取系統文件了。
FileInputStream stream = new FileInputStream("/proc/meminfo");
totalMem = parseFileForValue("MemTotal", stream);
Ⅳ 如何獲取 Android 設備的CPU核數,時鍾頻率以及內存大小
獲取 CPU 核數
Linux 中的設備都是以文件的形式存在,CPU 也不例外,因此 CPU 的文件個數就等價與核數。
Android 的 CPU 設備文件位於/sys/devices/system/cpu/目錄,文件名的的格式為cpu\d+。
root@generic_x86_64:/sys/devices/system/cpu # ls cpu0 cpufreq
cpuidle
kernel_max
modalias
offline
online
possible
power
present
uevent
統計一下文件個數便可以獲得 CPU 核數。
public static int getNumberOfCPUCores() {
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
// Gingerbread doesn't support giving a single application access to both cores, but a
// handful of devices (Atrix 4G and Droid X2 for example) were released with a al-core
// chipset and Gingerbread; that can let an app in the background run without impacting
// the foreground application. But for our purposes, it makes them single core.
return 1;
}
int cores;
try {
cores = new File("/sys/devices/system/cpu/").listFiles(CPU_FILTER).length;
} catch (SecurityException e) {
cores = DEVICEINFO_UNKNOWN;
} catch (NullPointerException e) {
cores = DEVICEINFO_UNKNOWN;
}
return cores;
}
private static final FileFilter CPU_FILTER = new FileFilter() {
@Override
public boolean accept(File pathname) {
String path = pathname.getName();
//regex is slow, so checking char by char.
if (path.startsWith("cpu")) {
for (int i = 3; i < path.length(); i++) {
if (path.charAt(i) < '0' || path.charAt(i) > '9') {
return false;
}
}
return true;
}
return false;
}
};
獲取時鍾頻率
獲取時鍾頻率需要讀取系統文件 -/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq或者/proc/cpuinfo。
Android 模擬器中並沒有cpuinfo_max_freq文件,因此只能讀取/proc/cpuinfo。
/proc/cpuinfo包含了很多 cpu 數據。
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 70
model name : Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
stepping : 1
cpu MHz : 0.000
cache size : 1024 KB
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 4
wp : yes
代碼如下:
public static int getCPUMaxFreqKHz() {
int maxFreq = DEVICEINFO_UNKNOWN;
try {
for (int i = 0; i < getNumberOfCPUCores(); i++) {
String filename =
"/sys/devices/system/cpu/cpu" + i + "/cpufreq/cpuinfo_max_freq";
File cpuInfoMaxFreqFile = new File(filename);
if (cpuInfoMaxFreqFile.exists()) {
byte[] buffer = new byte[128];
FileInputStream stream = new FileInputStream(cpuInfoMaxFreqFile);
try {
stream.read(buffer);
int endIndex = 0;
//Trim the first number out of the byte buffer.
while (buffer[endIndex] >= '0' && buffer[endIndex] <= '9'
&& endIndex < buffer.length) endIndex++;
String str = new String(buffer, 0, endIndex);
Integer freqBound = Integer.parseInt(str);
if (freqBound > maxFreq) maxFreq = freqBound;
} catch (NumberFormatException e) {
//Fall through and use /proc/cpuinfo.
} finally {
stream.close();
}
}
}
if (maxFreq == DEVICEINFO_UNKNOWN) {
FileInputStream stream = new FileInputStream("/proc/cpuinfo");
try {
int freqBound = parseFileForValue("cpu MHz", stream);
freqBound *= 1000; //MHz -> kHz
if (freqBound > maxFreq) maxFreq = freqBound;
} finally {
stream.close();
}
}
} catch (IOException e) {
maxFreq = DEVICEINFO_UNKNOWN; //Fall through and return unknown.
}
return maxFreq;
}
獲取內存大小
如果 SDK 版本大於等於JELLY_BEAN,可以通過ActivityManager來獲取內從大小。
ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo();
ActivityManager am = (ActivityManager) c.getSystemService(Context.ACTIVITY_SERVICE);
am.getMemoryInfo(memInfo);
如果版本低於JELLY_BEAN,則只能讀取系統文件了。
FileInputStream stream = new FileInputStream("/proc/meminfo");
totalMem = parseFileForValue("MemTotal", stream);
完整代碼如下:
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public static long getTotalMemory(Context c) {
// memInfo.totalMem not supported in pre-Jelly Bean APIs.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo();
ActivityManager am = (ActivityManager) c.getSystemService(Context.ACTIVITY_SERVICE);
am.getMemoryInfo(memInfo);
if (memInfo != null) {
return memInfo.totalMem;
} else {
return DEVICEINFO_UNKNOWN;
}
} else {
long totalMem = DEVICEINFO_UNKNOWN;
try {
FileInputStream stream = new FileInputStream("/proc/meminfo");
try {
totalMem = parseFileForValue("MemTotal", stream);
totalMem *= 1024;
} finally {
stream.close();
}
} catch (IOException e) {
}
return totalMem;
}
}
Ⅳ 死亡扳機2怎麼刷金幣
板機2僵屍太厲害了 賺錢難~不過有張圖很好刷錢 現在技術升到4級了殺僵屍得2塊,砍手砍頭獎勵7塊呢!僵屍還隨機掉錢40塊, 非洲室外地圖有個運4箱子的很好拿刀刷錢,主要是交3個箱子,第四個不交找個地方拿刀砍怪,可能游戲問題第四箱子拿到手不交任務就不刷小boss了,全小僵屍,拿刀特好刷錢,我刷的簡單級別,2刀一隻怪,掉落和困難一樣,可以掛機刷,不過要小心拿棍子的僵屍,距離比刀遠,第一時間殺。我一般帶20紅瓶,刷一萬就閃~怕死機
Ⅵ 如何獲取 Android 設備的CPU核數,時鍾頻率以及內存大小
獲取 CPU 核數
Linux 中的設備都是以文件的形式存在,CPU 也不例外,因此 CPU 的文件個數就等價與核數。
Android 的 CPU 設備文件位於/sys/devices/system/cpu/目錄,文件名的的格式為cpu\d+。
root@generic_x86_64:/sys/devices/system/cpu # ls cpu0 cpufreq
cpuidle
kernel_max
modalias
offline
online
possible
power
present
uevent
統計一下文件個數便可以獲得 CPU 核數。
public static int getNumberOfCPUCores() {
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
// Gingerbread doesn't support giving a single application access to both cores, but a
// handful of devices (Atrix 4G and Droid X2 for example) were released with a al-core
// chipset and Gingerbread; that can let an app in the background run without impacting
// the foreground application. But for our purposes, it makes them single core.
return 1;
}
int cores;
try {
cores = new File(「/sys/devices/system/cpu/」)。listFiles(CPU_FILTER)。length;
} catch (SecurityException e) {
cores = DEVICEINFO_UNKNOWN;
} catch (NullPointerException e) {
cores = DEVICEINFO_UNKNOWN;
}
return cores;
}
private static final FileFilter CPU_FILTER = new FileFilter() {
@Override
public boolean accept(File pathname) {
String path = pathname.getName();
//regex is slow, so checking char by char.
if (path.startsWith(「cpu」)) {
for (int i = 3; i < path.length(); i++) {
if (path.charAt(i) < '0' path.charAt(i) > '9『) {
return false;
}
}
return true;
}
return false;
}
};
獲取時鍾頻率
獲取時鍾頻率需要讀取系統文件 -/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq或者/proc/cpuinfo。
Android 模擬器中並沒有cpuinfo_max_freq文件,因此只能讀取/proc/cpuinfo。
/proc/cpuinfo包含了很多 cpu 數據。
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 70
model name : Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
stepping : 1
cpu MHz : 0.000
cache size : 1024 KB
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 4
wp : yes
代碼如下:
public static int getCPUMaxFreqKHz() {
int maxFreq = DEVICEINFO_UNKNOWN;
try {
for (int i = 0; i < getNumberOfCPUCores(); i++) {
String filename =
「/sys/devices/system/cpu/cpu」 + i + 「/cpufreq/cpuinfo_max_freq」;
File cpuInfoMaxFreqFile = new File(filename);
if (cpuInfoMaxFreqFile.exists()) {
byte[] buffer = new byte[128];
FileInputStream stream = new FileInputStream(cpuInfoMaxFreqFile);
try {
stream.read(buffer);
int endIndex = 0;
//Trim the first number out of the byte buffer.
while (buffer[endIndex] >= '0' && buffer[endIndex] <= '9'
&& endIndex < buffer.length) endIndex++;
String str = new String(buffer, 0, endIndex);
Integer freqBound = Integer.parseInt(str);
if (freqBound > maxFreq) maxFreq = freqBound;
} catch (NumberFormatException e) {
//Fall through and use /proc/cpuinfo.
} finally {
stream.close();
}
}
}
if (maxFreq == DEVICEINFO_UNKNOWN) {
FileInputStream stream = new FileInputStream(「/proc/cpuinfo」);
try {
int freqBound = parseFileForValue(「cpu MHz」, stream);
freqBound *= 1000; //MHz -> kHz
if (freqBound > maxFreq) maxFreq = freqBound;
} finally {
stream.close();
}
}
} catch (IOException e) {
maxFreq = DEVICEINFO_UNKNOWN; //Fall through and return unknown.
}
return maxFreq;
}
獲取內存大小
如果 SDK 版本大於等於JELLY_BEAN,可以通過ActivityManager來獲取內從大小。
ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo();
ActivityManager am = (ActivityManager) c.getSystemService(Context.ACTIVITY_SERVICE);
am.getMemoryInfo(memInfo);
如果版本低於JELLY_BEAN,則只能讀取系統文件了。
FileInputStream stream = new FileInputStream(「/proc/meminfo」);
totalMem = parseFileForValue(「MemTotal」, stream);
完整代碼如下:
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public static long getTotalMemory(Context c) {
// memInfo.totalMem not supported in pre-Jelly Bean APIs.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo();
ActivityManager am = (ActivityManager) c.getSystemService(Context.ACTIVITY_SERVICE);
am.getMemoryInfo(memInfo);
if (memInfo != null) {
return memInfo.totalMem;
} else {
return DEVICEINFO_UNKNOWN;
}
} else {
long totalMem = DEVICEINFO_UNKNOWN;
try {
FileInputStream stream = new FileInputStream(「/proc/meminfo」);
try {
totalMem = parseFileForValue(「MemTotal」, stream);
totalMem *= 1024;
} finally {
stream.close();
}
} catch (IOException e) {
}
return totalMem;
}
}
Ⅶ 華為筆記本bobwah9是I5幾代
「Intel推出了代號為Coffeelake的酷睿8代了,聽說性能漲了一大截!我是不是該升級了呢?」每當被問到這個問題,我就會反問朋友的電腦配置,令我驚訝的是很多人都不知道怎麼看自己的CPU是什麼型號,更對自己型號意味著第幾代酷睿沒有概念。那麼如何得到這些信息呢?
CPU型號那裡找?
很簡單,用Win + E打開Windows Explorer,右鍵點擊「這台電腦」,在彈出的菜單裡面選擇「屬性」。
在隨後的「系統屬性」窗口中我們就可以看到CPU的信息了:
CPU信息意味著什麼?
那麼這個Core(TM) i5-5300U是什麼意思呢?Core就是酷睿,i5就是酷睿i3、i5、i7和i9中的i5,當然不屬於極品i9,但也算對得起社會了。到底是i5的第幾代呢?秘密就在後面的5300U上。Intel官網有詳細的介紹:Intel® Processor Numbers: Laptop, Desktop, and Mobile Device
這里簡單介紹一下
第一個字母是幾就是幾代,5300U就是酷睿第五代,U則代表超低功耗:
代號Coffeelake的最新第8代酷睿的編號意思也差不多:
對更老的型號、奔騰、賽揚和志強系列等感興趣的同學可以自行查看原文。
酷睿n代和代碼的關系
有同學會問酷睿n代和晶元架構代碼(codename)的關系,怎麼知道某一代叫什麼名字,這樣出去吹牛也可以裝扮一下內行。Intel習慣於以美國地名命做codename,這和AMD玄妙的命名方式不同,也沒有Android那麼萌。CPU晶元架構的命名很有規律,那就是如果Core架構變化不大,則codename的地點類型不變,例如Well井系列:Haswell, Broardwell就是一個例子,前面是Bridge橋系列,下來就是悠長的Lake湖系列,Skylake, Kabylake和Coffelake。這也是Intel有名的Tick, Tock節奏帶來的命名規則。
那麼第一代是什麼呢?i3、i5和i7第一代起源於傳奇的Nehalem架構,在他的繼任者Westmere出現後,這種tick-tock的戰略還不穩定,命名規則也沒有確定下來,導致他們都是酷睿一代。
CPU型號信息哪裡來的?
作為一個BIOS和UEFI專欄,大家也許猜到了,這個信息是BIOS提供的。BIOS通過SMBIOS表告訴了OS這個信息,OS才能在系統信息裡面顯示出來。那麼BIOS又是從哪裡得到這個信息呢,是根據CPU型號自己組合出來的嗎?
答案是否定的。這個信息叫做Processor Brand String,BIOS是通過CPUID指令得到的,我們在EAX其中依次填入0x8000002,0x8000003和0x8000004,分別執行三次CPUID命令,即可以在返回值裡面讀出准確的CPU brand name。這個過程在IA32的"聖經"三卷裡面有詳細的記載:
Ⅷ 最終幻想大師如何刷初始首抽
【快速首刷】FINAL FANTASY GRANDMASTERS
【不需root】
【刪除檔案】
/sdcard/Android/data/com.square_enix.android_googleplay.ffgm/files/cpuid.bin
【流程推薦】: 進行到職業任務時將各職業任務第一關完成共2000石可四抽,最近有維修獎勵可在一抽。
【首抽推薦】: 看板武器都十分推薦、s防具也推
【首抽難度】:★★★★✩
【備注】: 推薦僅供參考,等待勇者們的攻略。
IOS首刷教學攻略:首先IOS設備需要JB,Document資料夾內的cpuid.bin刪除。
Ⅸ 如何獲取 Android 設備的CPU核數,時鍾頻率以及內存大小
Device Year Class 的主要功能是根據 CPU核數、時鍾頻率 以及 內存大小 對設備進行分級。代碼很簡單,只包含兩個類: DeviceInfo-> 獲取設備參數, YearClass-> 根據參數進行分級。 下表是 Facebook 公司提供的分級標准,其中Year欄表示分級結果。 Year Cores Clock RAM 2008 1 528MHz 192MB 2009 n/a 600MHz 290MB 2010 n/a 1.0GHz 512MB 2011 2 1.2GHz 1GB 2012 4 1.5GHz 1.5GB 2013 n/a 2.0GHz 2GB 2014 n/a >2GHz >2GB 關於輸出年份的計算方法可以參考源碼,本文只把一些比較常用的功能抽取出來做一個簡要介紹。 獲取 CPU 核數 我們都知道,Linux 中的設備都是以文件的形式存在,CPU 也不例外,因此 CPU 的文件個數就等價與核數。 Android 的 CPU 設備文件位於/sys/devices/system/cpu/目錄,文件名的的格式為cpu\d+。 ? 1 2 3 4 5 6 7 8 9 10 root@generic_x86_64:/sys/devices/system/cpu # ls <b>cpu0</b> cpufreq cpuidle kernel_max modalias offline online possible power present uevent 統計一下文件個數便可以獲得 CPU 核數。 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 public static int getNumberOfCPUCores() { if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) { // Gingerbread doesn't support giving a single application access to both cores, but a // handful of devices (Atrix 4G and Droid X2 for example) were released with a al-core // chipset and Gingerbread; that can let an app in the background run without impacting // the foreground application. But for our purposes, it makes them single core. return 1; } int cores; try { cores = new File("/sys/devices/system/cpu/").listFiles(CPU_FILTER).length; } catch (SecurityException e) { cores = DEVICEINFO_UNKNOWN; } catch (NullPointerException e) { cores = DEVICEINFO_UNKNOWN; } return cores; } private static final FileFilter CPU_FILTER = new FileFilter() { @Override public boolean accept(File pathname) { String path = pathname.getName(); //regex is slow, so checking char by char. if (path.startsWith("cpu")) { for (int i = 3; i < path.length(); i++) { if (path.charAt(i) < '0' path.charAt(i) > '9') { return false; } } return true; } return false; } }; 回到頂部 獲取時鍾頻率 獲取時鍾頻率需要讀取系統文件 -/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq或者/proc/cpuinfo。 我的 Android 模擬器中並沒有cpuinfo_max_freq文件,因此只能讀取/proc/cpuinfo。 /proc/cpuinfo包含了很多 cpu 數據。 ? processor : 0 vendor_id : GenuineIntel cpu family : 6 model : 70 model name : Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz stepping : 1 cpu MHz : 0.000 cache size : 1024 KB fdiv_bug : no hlt_bug : no f00f_bug : no coma_bug : no fpu : yes fpu_exception : yes cpuid level : 4 wp : yes 代碼如下: public static int getCPUMaxFreqKHz() { int maxFreq = DEVICEINFO_UNKNOWN; try { for (int i = 0; i < getNumberOfCPUCores(); i++) { String filename = "/sys/devices/system/cpu/cpu" + i + "/cpufreq/cpuinfo_max_freq"; File cpuInfoMaxFreqFile = new File(filename); if (cpuInfoMaxFreqFile.exists()) { byte[] buffer = new byte[128]; FileInputStream stream = new FileInputStream(cpuInfoMaxFreqFile); try { stream.read(buffer); int endIndex = 0; //Trim the first number out of the byte buffer. while (buffer[endIndex] >= '0' && buffer[endIndex] <= '9' && endIndex < buffer.length) endIndex++; String str = new String(buffer, 0, endIndex); Integer freqBound = Integer.parseInt(str); if (freqBound > maxFreq) maxFreq = freqBound; } catch (NumberFormatException e) { //Fall through and use /proc/cpuinfo. } finally { stream.close(); } } } if (maxFreq == DEVICEINFO_UNKNOWN) { FileInputStream stream = new FileInputStream("/proc/cpuinfo"); try { int freqBound = parseFileForValue("cpu MHz", stream); freqBound *= 1000; //MHz -> kHz if (freqBound > maxFreq) maxFreq = freqBound; } finally { stream.close(); } } } catch (IOException e) { maxFreq = DEVICEINFO_UNKNOWN; //Fall through and return unknown. } return maxFreq; } 回到頂部 獲取內存大小 如果 SDK 版本大於等於JELLY_BEAN,可以通過ActivityManager來獲取內從大小。 ? ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo(); ActivityManager am = (ActivityManager) c.getSystemService(Context.ACTIVITY_SERVICE); am.getMemoryInfo(memInfo); 如果版本低於JELLY_BEAN,則只能讀取系統文件了。 ? FileInputStream stream = new FileInputStream("/proc/meminfo"); totalMem = parseFileForValue("MemTotal", stream); 完整代碼如下: @TargetApi(Build.VERSION_CODES.JELLY_BEAN) public static long getTotalMemory(Context c) { // memInfo.totalMem not supported in pre-Jelly Bean APIs. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo(); ActivityManager am = (ActivityManager) c.getSystemService(Context.ACTIVITY_SERVICE); am.getMemoryInfo(memInfo); if (memInfo != null) { return memInfo.totalMem; } else { return DEVICEINFO_UNKNOWN; } } else { long totalMem = DEVICEINFO_UNKNOWN; try { FileInputStream stream = new FileInputStream("/proc/meminfo"); try { totalMem = parseFileForValue("MemTotal", stream); totalMem *= 1024; } finally { stream.close(); } } catch (IOException e) { } return totalMem; } }