- 浏览: 5825944 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (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 7637某些山寨机可能拿不到IMEI 如果非要IMEI可以模拟一个 ... -
APK安装成功后点击"打开"再按Home键应用会重启的问题
2018-08-21 14:13 2774安装系统SD卡里面的apk或者原有的程序更新版本的时候, ... -
使用volley链接Https地址时报SSLHandshakeException
2018-08-21 14:06 2142在真实设备上出现以下错误 ︰ Volley error: ... -
PhotoView+Viewpager双指缩放的时候出现pointerIndex out of range问题
2017-07-10 14:30 4248PhotoView+Viewpager开发图集效果的时候,在某 ... -
Android6.0权限封装
2017-04-01 12:04 1575简介 Android6.0中对权限分为了一般权限和危险权限。 ... -
实现点击 WebView 中的图片,调用原生控件展示图片
2017-04-01 11:14 2814现在有很多时候,我们的 App 都进行了混合开发,而最简单,最 ... -
Android 方法引用数超过 65535 优雅解决
2017-03-31 09:37 1551随着应用不断迭代更新,业务线的扩展,应用越来越大(比如:集成了 ... -
android引用资源@与属性?备忘单
2017-03-30 10:09 1291几天前我偶然发现了我A ... -
ViewPager 与SwipeRefreshLayout,RecyclerView,ScrollView滑动冲突解决方法
2017-03-30 09:55 6571ViewPager 作为一个横向滚动的控件, 在 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 1885我们在使用微信、QQ、京东等app的时候,会发现有时候通过他们 ... -
Activity的启动模式和onNewIntent
2016-12-28 09:10 1338一、启动模式介绍 启 ... -
android5.0使用Notification报RemoteServiceException的解决办法
2016-08-31 16:13 11553有时android5.0下使用Notification会报如下 ... -
RecyclerView 中的 item 如何居中问题
2016-05-18 09:52 12558一个很简单的Item布局,我只要让它由上而下排列,文字居中 ... -
sqlite3:not found 解决方法
2015-12-08 16:03 2558最最最重要,先root你的手机吧 sqlite3 为一个可 ... -
隐藏底部虚拟键NavigationBar实现全屏
2015-10-08 17:20 9858import android.app.Activity; ... -
服务端执行慢或网络延迟时,Volley多次发送请求的问题
2015-07-27 15:40 7004原文: Android Volley double post ... -
android点滴5
2015-04-10 17:32 2053一些小效果的实现 http://www.see-source. ... -
SwipeRefreshLayout和ListView的EmptyView共存冲突的问题
2015-01-20 11:47 18652SwipeRefreshLayout是android官方的下拉 ...
相关推荐
本文实例讲述了Android获取设备CPU核数、时钟频率以及内存大小的方法。分享给大家供大家参考,具体如下: 因项目需要,分析了一下 Facebook 的开源项目 – Device Year Class。 Device Year Class 的主要功能是根据 ...
本篇文章将详细讲解如何编写一个shell脚本来批量获取主机的IP地址、主机名、CPU型号、主频、核数、物理内存总大小以及磁盘名称和容量,并将其输出为CSV格式。 首先,我们需要了解在Linux中获取这些信息的命令: 1....
在MTK Android设备上,对CPU和GPU进行管理和优化是至关重要的,这涉及到系统的性能、功耗以及稳定性。以下是一些常用命令的详细说明: **查看CPU频率:** 要查看CPU当前的工作频率,可以使用`cat`命令读取`/sys/...
在Android MTK设备上,通过ADB手动设置CPU核数和频率可以帮助优化性能,解决因Thermal过高导致的性能下降问题。然而,这些操作需要对Android系统有一定的了解,并且应谨慎进行,因为不恰当的操作可能会对设备稳定性...
通过大量测试发现主应用软件的许可管理机制是获取的正处于运行状态的CPU核数,这成为问题的突破点。 (2)分析问题与具体解决思路:主应用软件许可监控进程依赖处于运行状态下的CPU核总数;而CPU核运行状态信息又...
6、CPU核数 7、显卡型号 8、显卡显存 9、总内存 10、jdk版本 11、mysql 版本 12、redis 版本 13、python 版本 14、GCC 版本 15、CUDA 版本 后续有什么可以继续加。大家也可以留言,需要什么我会找时间加到里面,并...
Linux系统中查看CPU型号、内存大小、硬盘空间命令 Linux操作系统提供了多种命令来查看CPU型号、内存大小、硬盘空间等信息。本文将详细介绍这些命令的使用方法和示例输出。 一、查看CPU信息 1.1 查看CPU个数 命令...
Siger(可能是“System Information Gatherer”的缩写)是一个可能的库,用于帮助开发者轻松地获取包括CPU、内存、网络和I/O在内的各种系统信息。下面将详细介绍如何使用Java和Siger库来实现这一目标。 首先,我们...
3. 运行命令:./eat-cpu-memory.sh 第一个参数cpu核数 第二个参数内存大小(M) 第三个参数持续时间(秒数) & 提示: 命令尾部 不加 &,则表示在前端运行。 加了& 表示在后台运行。 日志: [root@bogon ~]# ./eat-...
8. **主频**:CPU 的时钟频率,单位为 GHz,代表 CPU 运算速度,主频越高,理论上处理速度越快。 获取这些信息的方法通常依赖于操作系统提供的工具或 API。在 Windows 上,可以通过 WMI(Windows Management ...
本主题聚焦于如何利用Qt获取计算机的CPU信息,这是一个常见的需求,特别是在系统监控、性能分析或者资源管理软件的开发中。下面我们将深入探讨如何在Qt中实现这一功能,并考虑在Linux和Windows平台上的差异。 在...
如果需要更详细的硬件信息,例如CPU信息,可以借助`SystemProperties`类或`cat /proc/cpuinfo`命令(在Adb Shell中执行),这将展示CPU的核数、频率等。 在Android应用程序中,这些信息通常通过Activity或者Service...
下面介绍一下如何通过SQL语句获取处理器(CPU)、内存(Memory)、磁盘(Disk)以及操作系统相关信息。如有不足和遗漏,敬请补充。谢谢! 一:查看数据库服务器CPU的信息 —SQL 1:获取数据库服务器的CPU型号 EXEC xp_...
在Windows API中,`GetSystemInfo`函数是一个重要的系统调用,它能够提供关于操作系统和硬件的详细信息,包括处理器的数量、内存大小等。通过调用这个函数,程序可以获取到当前计算机的硬件配置,从而实现动态适应...
本文将详细介绍如何在Linux环境下准确地获取物理CPU个数、每个物理CPU的核心数以及逻辑CPU的总数,并提供实际命令示例。 #### 一、物理CPU个数 **定义:** 物理CPU是指计算机系统中的实际处理器数量,不包括通过超...
【标题】"gh0st源码-(ddos和cpu核数与开机时间)"涉及的是一个恶意软件的源代码,该软件具有分布式拒绝服务攻击(DDoS)功能,并能获取目标系统的CPU核心数量和开机时间。这里我们将深入探讨gh0st恶意软件、DDoS攻击...
ANSYS 多 CPU 并行计算...ANSYS 多 CPU 并行计算设置需要考虑结果文件的大小、物理内存和虚拟内存的设置、内存不足的问题、系统内存限制等问题。通过采取相应的措施,我们可以提高模拟速度和效率,并避免问题的出现。
每个Container的内存大小应设置为最小容器大小和剩余内存除以Container总数的较大值。 公式: - 容器数 = min(2 * CPU核数, 1.8 * 磁盘数, 剩余内存 / 最小Container大小) - RAM-per-container = max(最小...