android 得到cpu当前运行频率
来源:互联网 发布:ipad怎么登陆淘宝卖家 编辑:程序博客网 时间:2024/05/24 06:24
有时候,我们希望得到cpu的频率,以决定是否需要对cpu的频率进行调整。在google上搜索了一下后,得到了我想要的答案。修改并运行了一下,是可以得到cpu的频率的。它的原理实质是从文件中读取频率的。
原本这段代码是读取最大频率的,只需要把 “/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq“改成
“/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq”就可以得到当前频率了。
//package org.anddev.andengine.util;import java.io.IOException;import java.io.InputStream;import java.lang.reflect.Method;import java.util.Scanner;import java.util.regex.MatchResult;import android.content.Context;import android.content.pm.PackageInfo;import android.content.pm.PackageManager;import android.content.pm.PackageManager.NameNotFoundException;import android.os.Build;/** * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. * * @author Nicolas Gramlich * @since 15:50:31 - 14.07.2010 */class SystemUtils { private static final String BOGOMIPS_PATTERN = "BogoMIPS[\\s]*:[\\s]*(\\d+\\.\\d+)[\\s]*\n"; private static final String MEMTOTAL_PATTERN = "MemTotal[\\s]*:[\\s]*(\\d+)[\\s]*kB\n"; private static final String MEMFREE_PATTERN = "MemFree[\\s]*:[\\s]*(\\d+)[\\s]*kB\n"; /** * @return in kiloHertz. * @throws SystemUtilsException */ public static int getCPUFrequencyMax() throws Exception { return SystemUtils. readSystemFileAsInt("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq"); } private static int readSystemFileAsInt(final String pSystemFile) throws Exception { InputStream in = null; try { final Process process = new ProcessBuilder(new String[] { "/system/bin/cat", pSystemFile }).start(); in = process.getInputStream(); final String content = readFully(in); return Integer.parseInt(content); } catch (final Exception e) { throw new Exception(e); } } public static final String readFully(final InputStream pInputStream) throws IOException { final StringBuilder sb = new StringBuilder(); final Scanner sc = new Scanner(pInputStream); while(sc.hasNextLine()) { sb.append(sc.nextLine()); } return sb.toString(); } private static MatchResult matchSystemFile(final String pSystemFile, final String pPattern, final int pHorizon) throws Exception { InputStream in = null; try { final Process process = new ProcessBuilder(new String[] { "/system/bin/cat", pSystemFile }).start(); in = process.getInputStream(); final Scanner scanner = new Scanner(in); final boolean matchFound = scanner.findWithinHorizon(pPattern, pHorizon) != null; if(matchFound) { return scanner.match(); } else { throw new Exception(); } } catch (final IOException e) { throw new Exception(e); } }}
- android 得到cpu当前运行频率
- 获得CPU当前运行频率
- CPU当前的频率
- 测试CPU品牌和当前工作频率
- Android/linux修改cpu频率
- android 的cpu 频率 CPU核心数
- 如何在kernel中得到cpu的电压和频率
- VC得到当前电脑的CPU信息
- CPU频率
- CPU 频率
- android 如何获取CPU频率(HZ)
- 获取Android设备的CPU频率
- Android中cpu频率查看和更改
- Android中CPU频率查看和修改
- 实时获取Android手机CPU频率
- Android如何实时监控CPU频率
- Android中CPU频率查看和修改
- Android获取CPU频率和温度
- 向DataGridView控件添加数据
- 新浪旧事-在MyEclipse中添加dtd支持
- 增加外链的最好途径介绍
- MediaControllr使用简介
- 新浪旧事-MyEclipse7.5下手动安装freemarker插件
- android 得到cpu当前运行频率
- u盘安装ubuntu11.10
- 提高tomcat的JVM内存
- 反卷积效果演示
- Service初步
- Binary Lexicographic Sequence_简单DP
- http://acm.nyist.net/JudgeOnline/problem.php?pid=3
- 新浪旧事-设置action为welcomefile
- 新浪旧事-MyEclipse8.5安装svn