3

Is there any way to check if an Android device is dual core? (Other than Runtime.availableProcessors() as it only reports the correct number occasionally.)

I need it as SoundPool doesn't work on dual cores (see http://code.google.com/p/android/issues/detail?id=17623)

Lukas Knuth
  • 25,449
  • 15
  • 83
  • 111
Ray Britton
  • 8,257
  • 3
  • 23
  • 32

3 Answers3

0

try some thing like this:

float ALOUD_MISTAKE = 20; // percent
int WORK_TIME = 1000; // milliseconds

public int work(){
   int workCounter = 0;
   long startTime = System. currentTime();
   long currentTime = System. currentTime();
   while(startTime < currentTime + WORK_TIME){
       currentTime = System. currentTime();
       workCounter++;
   }

   return workCounter;

}

start mainThread1;
check the work time and save it(keep it going)
now start new thread

new Thread(new Runnable(){
   void run(){
      while(true){
          work();
      }
   }
}).start();

let them run a bit and now check:

if(Math.abs(workTimeThread1 - savedWorkTimeThread1) / workTimeThread1 * 100 > ALOUD_MISTAKE)
{
    you got (number of new threads been started - 1) cores
}
Ray Britton
  • 8,257
  • 3
  • 23
  • 32
Ilya Gazman
  • 31,250
  • 24
  • 137
  • 216
0

check this answer here https://stackoverflow.com/a/4875506/737925

private String ReadCPUinfo()
 {
  ProcessBuilder cmd;
  String result="";

  try{
   String[] args = {"/system/bin/cat", "/proc/cpuinfo"};
   cmd = new ProcessBuilder(args);

   Process process = cmd.start();
   InputStream in = process.getInputStream();
   byte[] re = new byte[1024];
   while(in.read(re) != -1){
    System.out.println(new String(re));
    result = result + new String(re);
   }
   in.close();
  } catch(IOException ex){
   ex.printStackTrace();
  }
  return result;
 }
}`
Community
  • 1
  • 1
Mohammad Ersan
  • 12,304
  • 8
  • 54
  • 77
-1

I think that Runtime.availableProcessors() is the way to do it. The documentation says:

Returns the number of processors available to the virtual machine [...] at least 1.

I think that the result of this function returns the number of logical cores (not physical).

But this does not solve your problem: The Bug-report states that the bug occurs only on Samsung Galaxy S2 and I think that it will be fixed sometime in future.

thomas
  • 5,637
  • 2
  • 24
  • 35