i looking determine(or count) number of cores in embedded processor of android device.
i tried using /proc/cpuinfo
, not returning number of cores of device !
i don't found code anywhere on internet. here know how can determine this, please answer. in advance
update:
the answers on question how can detect dual-core cpu on android device code? doesn't run in devices. tested them dual core & quad core processors, returned 2 & 4 respectively, fine !
but, on octa core processor in samsung note 3 returned 4. (perhaps in note 3 there 2 sets of quad core processors running individually )
i looking solve problem.
update
the app cpu-z returning correct core count in device samsung note 3 here seems there exists possible solution...
you may use combination of above answer one. way perform faster on devices running api 17+ method faster filtering out files.
private int getnumberofcores() { if(build.version.sdk_int >= 17) { return runtime.getruntime().availableprocessors() } else { // use saurabh64's answer return getnumcoresoldphones(); } } /** * gets number of cores available in device, across processors. * requires: ability peruse filesystem @ "/sys/devices/system/cpu" * @return number of cores, or 1 if failed result */ private int getnumcoresoldphones() { //private class display cpu devices in directory listing class cpufilter implements filefilter { @override public boolean accept(file pathname) { //check if filename "cpu", followed single digit number if(pattern.matches("cpu[0-9]+", pathname.getname())) { return true; } return false; } } try { //get directory containing cpu info file dir = new file("/sys/devices/system/cpu/"); //filter list devices care file[] files = dir.listfiles(new cpufilter()); //return number of cores (virtual cpu devices) return files.length; } catch(exception e) { //default return 1 core return 1; } }
public int availableprocessors ()
added in api level 1 returns number of processor cores available vm, @ least 1. traditionally returned number online, many mobile devices able take unused cores offline save power, releases newer android 4.2 (jelly bean) return maximum number of cores made available if there no power or heat constraints.
also there information number of cores inside file located in /sys/devices/system/cpu/present
reports number of available cpus in following format:
- 0 -> single cpu/core
- 0-1 -> 2 cpus/cores
- 0-3 -> 4 cpus/cores
- 0-7 -> 8 cpus/cores
etc.
also please check inside /sys/devices/system/cpu/possible
on note 3
both files have r--r--r--
or 444
file permissions set on them, should able read them without rooted device in code.
edit: posting code out
private void printnumberofcores() { printfile("/sys/devices/system/cpu/present"); printfile("/sys/devices/system/cpu/possible"); } private void printfile(string path) { inputstream inputstream = null; try { inputstream = new fileinputstream(path); if (inputstream != null) { bufferedreader bufferedreader = new bufferedreader(new inputstreamreader(inputstream)); string line; { line = bufferedreader.readline(); log.d(path, line); } while (line != null); } } catch (exception e) { } { if (inputstream != null) { try { inputstream.close(); } catch (ioexception e) { } } } }
with result
d//sys/devices/system/cpu/present﹕ 0-3 d//sys/devices/system/cpu/possible﹕ 0-3
the test run on oneplus 1 running blisspop rom android v5.1.1 , prints should. please try on samsung
Comments
Post a Comment