获取CPU内核个数

作者:追风剑情 发布于:2016-6-29 12:52 分类:Android

通过分析文件获取

1111.png

 

代码

        //获取CPU内核数
	public int getCPUCoreCount() {
	    class CpuFilter implements FileFilter {
	        @Override
	        public boolean accept(File pathname) {
	            if(Pattern.matches("cpu[0-9]", pathname.getName())) {
	                return true;
	            }
	            return false;
	        }      
	    }

	    try {
	        File dir = new File("/sys/devices/system/cpu/");
	        File[] files = dir.listFiles(new CpuFilter());
	        return files.length;
	    } catch(Exception e) {
	        Log.d(TAG, "CPU Count: Failed.");
	        e.printStackTrace();
	        return 1;
	    }
	}


 

标签: Android

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号