求教,显示cpu频率,闪存cpk样本容量及频率命令是什么

为什么我在BIOS里已经把内存频率设置过了,但是开机后CPU-Z里面确是这么显示的,还有我的cpu_百度知道怎么查看CPU的运行频率?_百度知道计算机专转本预测题及答案_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
计算机专转本预测题及答案
上传于||文档简介
&&江​苏
阅读已结束,如果下载本文需要使用1下载券
想免费下载本文?
定制HR最喜欢的简历
下载文档到电脑,查找使用更方便
还剩27页未读,继续阅读
定制HR最喜欢的简历
你可能喜欢如何获取 Android 设备的CPU核数、时钟频率以及内存大小 - 简书
下载简书移动应用
写了5811字,被152人关注,获得了119个喜欢
如何获取 Android 设备的CPU核数、时钟频率以及内存大小
因项目需要,分析了一下 Facebook 的开源项目 - 。
Device Year Class 的主要功能是根据 CPU核数、时钟频率 以及 内存大小 对设备进行分级。代码很简单,只包含两个类:
DeviceInfo -& 获取设备参数,
YearClass -& 根据参数进行分级。
下表是 Facebook 公司提供的,其中 Year 栏表示分级结果。
关于输出年份的计算方法可以参考,本文只把一些比较常用的功能抽取出来做一个简要介绍。
获取 CPU 核数
我们都知道,Linux 中的设备都是以文件的形式存在,CPU 也不例外,因此 CPU 的文件个数就等价与核数。
Android 的 CPU 设备文件位于 /sys/devices/system/cpu/ 目录,文件名的的格式为 cpu\d+。
root@generic_x86_64:/sys/devices/system/cpu # lscpu0cpufreqcpuidlekernel_maxmodaliasofflineonlinepossiblepowerpresentuevent
统计一下文件个数便可以获得 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 dual-core
// chipset and G that can let an app in the background run without impacting
// the foreground application. But for our purposes, it makes them single core.
cores = new File("/sys/devices/system/cpu/").listFiles(CPU_FILTER).
} catch (SecurityException e) {
cores = DEVICEINFO_UNKNOWN;
} catch (NullPointerException e) {
cores = DEVICEINFO_UNKNOWN;
private static final FileFilter CPU_FILTER = new FileFilter() {
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') {
获取时钟频率
获取时钟频率需要读取系统文件 - /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq 或者 /proc/cpuinfo。
我的 Android 模拟器中并没有 cpuinfo_max_freq 文件,因此只能读取 /proc/cpuinfo。
/proc/cpuinfo 包含了很多 cpu 数据。
: 0vendor_id
: GenuineIntelcpu family
: 70model name
: Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHzstepping
: 1cpu MHz
: 0.000cache size
: 1024 KBfdiv_bug
: nohlt_bug
: nof00f_bug
: nocoma_bug
: yesfpu_exception
: yescpuid level
代码如下:
public static int getCPUMaxFreqKHz() {
int maxFreq = DEVICEINFO_UNKNOWN;
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);
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 = freqB
} catch (NumberFormatException e) {
//Fall through and use /proc/cpuinfo.
} finally {
stream.close();
if (maxFreq == DEVICEINFO_UNKNOWN) {
FileInputStream stream = new FileInputStream("/proc/cpuinfo");
int freqBound = parseFileForValue("cpu MHz", stream);
freqBound *= 1000; //MHz -& kHz
if (freqBound & maxFreq) maxFreq = freqB
} finally {
stream.close();
} catch (IOException e) {
maxFreq = DEVICEINFO_UNKNOWN; //Fall through and return unknown.
return maxF
获取内存大小
如果 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.totalM
return DEVICEINFO_UNKNOWN;
long totalMem = DEVICEINFO_UNKNOWN;
FileInputStream stream = new FileInputStream("/proc/meminfo");
totalMem = parseFileForValue("MemTotal", stream);
totalMem *= 1024;
} finally {
stream.close();
} catch (IOException e) {
return totalM
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
被以下专题收入,发现更多相似内容:
欢迎与我交流Android 开发和互联网项环内容。
欢迎关注我的微信公众号:AndroidMate
· 4897人關注
干货技术文。
· 3457人关注
Android,Java
· 1908人关注
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
选择支付方式:

我要回帖

更多关于 闪存型号容量 的文章

 

随机推荐