- 浏览: 5777270 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (890)
- WindowsPhone (0)
- android (88)
- android快速迭代 (17)
- android基础 (34)
- android进阶 (172)
- android高级 (0)
- android拾遗 (85)
- android动画&效果 (68)
- Material Design (13)
- LUA (5)
- j2me (32)
- jQuery (39)
- spring (26)
- hibernate (20)
- struts (26)
- tomcat (9)
- javascript+css+html (62)
- jsp+servlet+javabean (14)
- java (37)
- velocity+FCKeditor (13)
- linux+批处理 (9)
- mysql (19)
- MyEclipse (9)
- ajax (7)
- wap (8)
- j2ee+apache (24)
- 其他 (13)
- phonegap (35)
最新评论
-
Memories_NC:
本地lua脚本终于执行成功了,虽然不是通过redis
java中调用lua脚本语言1 -
ZHOU452840622:
大神://处理返回的接收状态 这个好像没有监听到 遇 ...
android 发送短信的两种方式 -
PXY:
拦截部分地址,怎么写的for(int i=0;i<lis ...
判断是否登录的拦截器SessionFilter -
maotou1988:
Android控件之带清空按钮(功能)的AutoComplet ...
自定义AutoCompleteTextView -
yangmaolinpl:
希望有表例子更好。。。,不过也看明白了。
浅谈onInterceptTouchEvent、onTouchEvent与onTouch
原帖:
http://www.jianshu.com/p/f7add443cd32
Device Year Class 的主要功能是根据 CPU核数、时钟频率 以及 内存大小 对设备进行分级。
下表是 Facebook 公司提供的分级标准,其中 Year 栏表示分级结果。
以下类就是从Facebook 的开源项目Device Year Class中拿出来的
使用方法:
运行在Android设备上,启动本程序之后,在任何窗口可显示当前CPU工作频率等状态,显示当前电压电流电池容量等信息
https://github.com/will86/android-runninginfo
http://www.jianshu.com/p/f7add443cd32
Device Year Class 的主要功能是根据 CPU核数、时钟频率 以及 内存大小 对设备进行分级。
下表是 Facebook 公司提供的分级标准,其中 Year 栏表示分级结果。
以下类就是从Facebook 的开源项目Device Year Class中拿出来的
package com.yirui.youbao.util; import android.annotation.TargetApi; import android.app.ActivityManager; import android.content.Context; import android.os.Build; import java.io.*; /** * Helper class for accessing hardware specifications, including the number of CPU cores, CPU clock speed * and total available RAM. */ public class DeviceInfo { /** * The default return value of any method in this class when an * error occurs or when processing fails (Currently set to -1). Use this to check if * the information about the device in question was successfully obtained. */ public static final int DEVICEINFO_UNKNOWN = -1; /** * Reads the number of CPU cores from {@code /sys/devices/system/cpu/}. * * @return Number of CPU cores in the phone, or DEVICEINFO_UKNOWN = -1 in the event of an error. */ 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 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; } }; /** * Method for reading the clock speed of a CPU core on the device. Will read from either * {@code /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq} or {@code /proc/cpuinfo}. * * @return Clock speed of a core on the device, or -1 in the event of an error. */ 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; } /** * Calculates the total RAM of the device through Android API or /proc/meminfo. * * @param c - Context object for current running activity. * @return Total RAM that the device has, or DEVICEINFO_UNKNOWN = -1 in the event of an error. */ @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; } } /** * Helper method for reading values from system files, using a minimised buffer. * * @param textToMatch - Text in the system files to read for. * @param stream - FileInputStream of the system file being read from. * @return A numerical value following textToMatch in specified the system file. * -1 in the event of a failure. */ private static int parseFileForValue(String textToMatch, FileInputStream stream) { byte[] buffer = new byte[1024]; try { int length = stream.read(buffer); for (int i = 0; i < length; i++) { if (buffer[i] == '\n' || i == 0) { if (buffer[i] == '\n') i++; for (int j = i; j < length; j++) { int textIndex = j - i; //Text doesn't match query at some point. if (buffer[j] != textToMatch.charAt(textIndex)) { break; } //Text matches query here. if (textIndex == textToMatch.length() - 1) { return extractValue(buffer, j); } } } } } catch (IOException e) { //Ignore any exceptions and fall through to return unknown value. } catch (NumberFormatException e) { } return DEVICEINFO_UNKNOWN; } /** * Helper method used by {@link #parseFileForValue(String, FileInputStream) parseFileForValue}. Parses * the next available number after the match in the file being read and returns it as an integer. * @param index - The index in the buffer array to begin looking. * @return The next number on that line in the buffer, returned as an int. Returns * DEVICEINFO_UNKNOWN = -1 in the event that no more numbers exist on the same line. */ private static int extractValue(byte[] buffer, int index) { while (index < buffer.length && buffer[index] != '\n') { if (buffer[index] >= '0' && buffer[index] <= '9') { int start = index; index++; while (index < buffer.length && buffer[index] >= '0' && buffer[index] <= '9') { index++; } String str = new String(buffer, 0, start, index - start); return Integer.parseInt(str); } index++; } return DEVICEINFO_UNKNOWN; } }
package com.yirui.youbao.util; import java.util.ArrayList; import java.util.Collections; import android.content.Context; public class YearClass { // Year definitions public static final int CLASS_UNKNOWN = -1; public static final int CLASS_2008 = 2008; public static final int CLASS_2009 = 2009; public static final int CLASS_2010 = 2010; public static final int CLASS_2011 = 2011; public static final int CLASS_2012 = 2012; public static final int CLASS_2013 = 2013; public static final int CLASS_2014 = 2014; private static final long MB = 1024 * 1024; private static final int MHZ_IN_KHZ = 1000; private volatile static Integer mYearCategory; /** * Entry Point of YearClass. Extracts YearClass variable with memoizing. * Example usage: * <p> * <pre> * int yearClass = YearClass.get(context); * </pre> */ public static int get(Context c) { if (mYearCategory == null) { synchronized(YearClass.class) { if (mYearCategory == null) { mYearCategory = categorizeByYear(c); } } } return mYearCategory; } private static void conditionallyAdd(ArrayList<Integer> list, int value) { if (value != CLASS_UNKNOWN) { list.add(value); } } /** * Calculates the "best-in-class year" of the device. This represents the top-end or flagship * devices of that year, not the actual release year of the phone. For example, the Galaxy Duos * S was released in 2012, but its specs are very similar to the Galaxy S that was released in * 2010 as a then top-of-the-line phone, so it is a 2010 device. * * @return The year when this device would have been considered top-of-the-line. */ private static int categorizeByYear(Context c) { ArrayList<Integer> componentYears = new ArrayList<Integer>(); conditionallyAdd(componentYears, getNumCoresYear()); conditionallyAdd(componentYears, getClockSpeedYear()); conditionallyAdd(componentYears, getRamYear(c)); if (componentYears.isEmpty()) return CLASS_UNKNOWN; Collections.sort(componentYears); if ((componentYears.size() & 0x01) == 1) { // Odd number; pluck the median. return componentYears.get(componentYears.size() / 2); } else { // Even number. Average the two "center" values. int baseIndex = componentYears.size() / 2 - 1; // There's an implicit rounding down in here; 2011.5 becomes 2011. return componentYears.get(baseIndex) + (componentYears.get(baseIndex + 1) - componentYears.get(baseIndex)) / 2; } } /** * Calculates the year class by the number of processor cores the phone has. * Evaluations are based off the table below: * <table border="1"> * <thead> * <tr><th width="50%">Amount</th><th>Year</th></tr> * <thead> * <tbody> * <tr><td>>4 or More</td><td>2012</td></tr> * <tr><td>2 or 3</td><td>2011</td></tr> * <tr><td>1</td><td>2008</td></tr> * </tbody> * </table> * * @return the year in which top-of-the-line phones had the same number of processors as this phone. */ private static int getNumCoresYear() { int cores = DeviceInfo.getNumberOfCPUCores(); if (cores < 1) return CLASS_UNKNOWN; if (cores == 1) return CLASS_2008; if (cores <= 3) return CLASS_2011; return CLASS_2012; } /** * Calculates the year class by the clock speed of the cores in the phone. * Evaluations are based off the table below: * <table border="1"> * <thead> * <tr><th width="50%">Amount</th><th>Year</th></tr> * <thead> * <tbody> * <tr><td>>2GHz</td><td>2014</td></tr> * <tr><td><=2GHz</td><td>2013</td></tr> * <tr><td><=1.5GHz</td><td>2012</td></tr> * <tr><td><=1.2GHz</td><td>2011</td></tr> * <tr><td><=1GHz</td><td>2010</td></tr> * <tr><td><=600MHz</td><td>2009</td></tr> * <tr><td><=528MHz</td><td>2008</td></tr> * </tbody> * </table> * * @return the year in which top-of-the-line phones had the same clock speed. */ private static int getClockSpeedYear() { long clockSpeedKHz = DeviceInfo.getCPUMaxFreqKHz(); if (clockSpeedKHz == DeviceInfo.DEVICEINFO_UNKNOWN) return CLASS_UNKNOWN; // These cut-offs include 20MHz of "slop" because my "1.5GHz" Galaxy S3 reports // its clock speed as 1512000. So we add a little slop to keep things nominally correct. if (clockSpeedKHz <= 528 * MHZ_IN_KHZ) return CLASS_2008; if (clockSpeedKHz <= 620 * MHZ_IN_KHZ) return CLASS_2009; if (clockSpeedKHz <= 1020 * MHZ_IN_KHZ) return CLASS_2010; if (clockSpeedKHz <= 1220 * MHZ_IN_KHZ) return CLASS_2011; if (clockSpeedKHz <= 1520 * MHZ_IN_KHZ) return CLASS_2012; if (clockSpeedKHz <= 2020 * MHZ_IN_KHZ) return CLASS_2013; return CLASS_2014; } /** * Calculates the year class by the amount of RAM the phone has. * Evaluations are based off the table below: * <table border="1"> * <thead> * <tr><th width="50%">Amount</th><th>Year</th></tr> * <thead> * <tbody> * <tr><td>>2GB</td><td>2014</td></tr> * <tr><td><=2GB</td><td>2013</td></tr> * <tr><td><=1.5GB</td><td>2012</td></tr> * <tr><td><=1GB</td><td>2011</td></tr> * <tr><td><=512MB</td><td>2010</td></tr> * <tr><td><=256MB</td><td>2009</td></tr> * <tr><td><=128MB</td><td>2008</td></tr> * </tbody> * </table> * * @return the year in which top-of-the-line phones had the same amount of RAM as this phone. */ private static int getRamYear(Context c) { long totalRam = DeviceInfo.getTotalMemory(c); if (totalRam <= 0) return CLASS_UNKNOWN; if (totalRam <= 192 * MB) return CLASS_2008; if (totalRam <= 290 * MB) return CLASS_2009; if (totalRam <= 512 * MB) return CLASS_2010; if (totalRam <= 1024 * MB) return CLASS_2011; if (totalRam <= 1536 * MB) return CLASS_2012; if (totalRam <= 2048 * MB) return CLASS_2013; return CLASS_2014; } }
使用方法:
import android.app.Activity; import android.content.SharedPreferences; import android.os.AsyncTask; import android.os.Bundle; import android.widget.TextView; import com.facebook.device.yearclass.YearClass; public class MainActivity extends Activity { private static final String PREF_FILE = "YearClass"; private static final String PREF_NAME = "yearclass"; private TextView mYearClass; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); GetOrComputeYearClass findYearClass = new GetOrComputeYearClass(); findYearClass.execute(); mYearClass = (TextView) findViewById(R.id.year_class); } private class GetOrComputeYearClass extends AsyncTask<Void, Void, Integer> { @Override protected Integer doInBackground(Void... voids) { int yearClass = YearClass.CLASS_UNKNOWN; SharedPreferences prefs = getSharedPreferences(PREF_FILE, 0); if (prefs.contains(PREF_NAME)) { yearClass = prefs.getInt(PREF_NAME, YearClass.CLASS_UNKNOWN); } //Try again if device was previously unknown. if (yearClass == YearClass.CLASS_UNKNOWN) { yearClass = YearClass.get(getApplicationContext()); SharedPreferences.Editor editor = prefs.edit(); editor.putInt(PREF_NAME, yearClass); editor.apply(); } return yearClass; } @Override protected void onPostExecute(Integer yearClass) { //update UI mYearClass.setText(Integer.toString(yearClass)); } } }
运行在Android设备上,启动本程序之后,在任何窗口可显示当前CPU工作频率等状态,显示当前电压电流电池容量等信息
https://github.com/will86/android-runninginfo
发表评论
-
某些android手机获取不到IMEI问题
2018-08-21 14:17 7494某些山寨机可能拿不到IMEI 如果非要IMEI可以模拟一个 ... -
APK安装成功后点击"打开"再按Home键应用会重启的问题
2018-08-21 14:13 2711安装系统SD卡里面的apk或者原有的程序更新版本的时候, ... -
使用volley链接Https地址时报SSLHandshakeException
2018-08-21 14:06 2032在真实设备上出现以下错误 ︰ Volley error: ... -
PhotoView+Viewpager双指缩放的时候出现pointerIndex out of range问题
2017-07-10 14:30 4186PhotoView+Viewpager开发图集效果的时候,在某 ... -
Android6.0权限封装
2017-04-01 12:04 1527简介 Android6.0中对权限分为了一般权限和危险权限。 ... -
实现点击 WebView 中的图片,调用原生控件展示图片
2017-04-01 11:14 2745现在有很多时候,我们的 App 都进行了混合开发,而最简单,最 ... -
Android 方法引用数超过 65535 优雅解决
2017-03-31 09:37 1477随着应用不断迭代更新,业务线的扩展,应用越来越大(比如:集成了 ... -
android引用资源@与属性?备忘单
2017-03-30 10:09 1235几天前我偶然发现了我A ... -
ViewPager 与SwipeRefreshLayout,RecyclerView,ScrollView滑动冲突解决方法
2017-03-30 09:55 6514ViewPager 作为一个横向滚动的控件, 在 ViewGr ... -
Android中一些你可能没注意的小效果实现
2017-02-15 21:09 0http://www.see-source.com/blog/ ... -
Android热修复:Andfix和Hotfix,两种方案的比较与实现
2017-02-15 21:00 0http://www.see-source.com/blog/ ... -
Android 从网页中跳转到本地App
2017-01-11 09:27 1825我们在使用微信、QQ、京东等app的时候,会发现有时候通过他们 ... -
Activity的启动模式和onNewIntent
2016-12-28 09:10 1293一、启动模式介绍 启 ... -
android5.0使用Notification报RemoteServiceException的解决办法
2016-08-31 16:13 11462有时android5.0下使用Notification会报如下 ... -
RecyclerView 中的 item 如何居中问题
2016-05-18 09:52 12394一个很简单的Item布局,我只要让它由上而下排列,文字居中 ... -
sqlite3:not found 解决方法
2015-12-08 16:03 2500最最最重要,先root你的手机吧 sqlite3 为一个可 ... -
隐藏底部虚拟键NavigationBar实现全屏
2015-10-08 17:20 9799import android.app.Activity; ... -
服务端执行慢或网络延迟时,Volley多次发送请求的问题
2015-07-27 15:40 6939原文: Android Volley double post ... -
android点滴5
2015-04-10 17:32 2004一些小效果的实现 http://www.see-source. ... -
SwipeRefreshLayout和ListView的EmptyView共存冲突的问题
2015-01-20 11:47 18566SwipeRefreshLayout是android官方的下拉 ...
相关推荐
本文实例讲述了Android获取设备CPU核数、时钟频率以及内存大小的方法。分享给大家供大家参考,具体如下: 因项目需要,分析了一下 Facebook 的开源项目 – Device Year Class。 Device Year Class 的主要功能是根据 ...
获取主机信息,以“IP地址 主机名 CPU型号 主频 核数 物理内存总大小 磁盘名称 容量”格式输出csv。内附使用说明。
6、CPU核数 7、显卡型号 8、显卡显存 9、总内存 10、jdk版本 11、mysql 版本 12、redis 版本 13、python 版本 14、GCC 版本 15、CUDA 版本 后续有什么可以继续加。大家也可以留言,需要什么我会找时间加到里面,并...
3. 运行命令:./eat-cpu-memory.sh 第一个参数cpu核数 第二个参数内存大小(M) 第三个参数持续时间(秒数) & 提示: 命令尾部 不加 &,则表示在前端运行。 加了& 表示在后台运行。 日志: [root@bogon ~]# ./eat-...
1. CPU 核数、频率以及内存大小都可以通过设备树查询,目前都是硬编码 2. K210 串口中断处理利用 mstatus.mprv 可以做到更好 4. 如何处
配套博客参考:https://blog.csdn.net/passion_l/article/details/125068163?spm=1001.2014.3001.5502
本源码在CSDN IT1995的博客有代码详解,欢迎大家参考。谢谢!
高性能服务器CPU核数调整研究.pdf
linux下判断CPU的核数,有实际的例子。详解比较全面
Delphi检测获取CPU信息的程序源码,包括完整代码,实例编译后可运行,界面效果如演示截图所示。这个源码貌似比较早了,好像获取不到目前主流的CPU型号,里面的一些自定义变量需要重新定义下,大致的原理可参考下,用...
服务器偷来的源码。。加了ddos+cpu核数+开机时间..
# 总核数 = 物理CPU个数 X 每颗物理CPU的核数 # 总逻辑CPU数 = 物理CPU个数 X 每颗物理CPU的核数 X 超线程数 # 查看物理CPU个数 cat /proc/cpuinfo| grep “physical id”| sort| uniq| wc -l # 查看每个物理CPU...
机器的CPU逻辑核数检查jar包
Linux多核CPU控制启动核数.pdfLinux多核CPU控制启动核数.pdf
机器学习 深度学习 pytorch tensorflow 贝叶斯 神经网络 算法
下面介绍一下如何通过SQL语句获取处理器(CPU)、内存(Memory)、磁盘(Disk)以及操作系统相关信息。如有不足和遗漏,敬请补充。谢谢! 一:查看数据库服务器CPU的信息 —SQL 1:获取数据库服务器的CPU型号 EXEC xp_...
1.2 查看CPU核数 # cat /proc/cpuinfo | grep “cpu cores” | uniq cpu cores : 4 1.3 查看CPU型号 # cat /proc/cpuinfo | grep ‘model name’ |uniq model name : Intel(R) Xeon(R) CPU E5630 @ 2.53GHz 总结:该...
文章目录一、名词解释二、查看CPU信息参考文献未看完的参考文献 一、名词解释 CPU(Central Processing Unit): 中央处理单元, ...cpu核数: 每颗物理CPU可以有1个或者多个物理内核,通常每颗物理CPU