Skip to content

Commit

Permalink
Fixed: cpu name of arm and refine fps
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewleo committed Dec 30, 2015
1 parent a24e18d commit def4df8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 29 deletions.
19 changes: 7 additions & 12 deletions src/com/netease/qa/emmagee/utils/CpuInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,19 +141,14 @@ public String getCpuName() {
try {
RandomAccessFile cpuStat = new RandomAccessFile(CPU_INFO_PATH, "r");
// check cpu type
if (Build.CPU_ABI.equalsIgnoreCase(CPU_X86)) {
String line;
while (null != (line = cpuStat.readLine())) {
String[] values = line.split(":");
if (values[0].contains(INTEL_CPU_NAME)) {
cpuStat.close();
return values[1];
}
String line;
while (null != (line = cpuStat.readLine())) {
String[] values = line.split(":");
if (values[0].contains(INTEL_CPU_NAME) || values[0].contains("Processor")) {
cpuStat.close();
Log.d(LOG_TAG, "CPU name="+values[1]);
return values[1];
}
} else {
String[] cpu = cpuStat.readLine().split(":"); // cpu信息的前一段是含有processor字符串,此处替换为不显示
cpuStat.close();
return cpu[1];
}
} catch (IOException e) {
Log.e(LOG_TAG, "IOException: " + e.getMessage());
Expand Down
41 changes: 24 additions & 17 deletions src/com/netease/qa/emmagee/utils/FpsInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,27 @@ public class FpsInfo {
private static DataOutputStream os = null;
private static long startTime = 0L;
private static int lastFrameNum = 0;
private static boolean ok = true;

/**
* get frame per second
*
* @return frame per second
*/
public static float fps() {
long nowTime = System.nanoTime();
float f = (float) (nowTime - startTime) / 1000000.0F;
startTime = nowTime;
int nowFrameNum = getFrameNum();
final float fps = Math.round((nowFrameNum - lastFrameNum) * 1000 / f);
lastFrameNum = nowFrameNum;
return fps;
if (ok) {
long nowTime = System.nanoTime();
float f = (float) (nowTime - startTime) / 1000000.0F;
startTime = nowTime;
int nowFrameNum = getFrameNum();
final float fps = Math.round((nowFrameNum - lastFrameNum) * 1000
/ f);
lastFrameNum = nowFrameNum;
return fps;
} else {
return -1;
}

}

/**
Expand All @@ -43,19 +51,18 @@ public static final int getFrameNum() {
os.writeBytes("service call SurfaceFlinger 1013" + "\n");
os.flush();
String str1 = ir.readLine();
if (str1 == null) {
return -1;
if (str1 != null) {
int start = str1.indexOf("(");
int end = str1.indexOf(" ");
if ((start != -1) & (end > start)) {
String str2 = str1.substring(start + 1, end);
return Integer.parseInt((String) str2, 16);
}
}
int start = str1.indexOf("(");
int end = str1.indexOf(" ");
if ((start != -1) & (end > start)) {
String str2 = str1.substring(start + 1, end);
return Integer.parseInt((String) str2, 16);
}
return -1;
} catch (IOException e) {
e.printStackTrace();
return -1;
}
ok = false;
return -1;
}
}
2 changes: 2 additions & 0 deletions src/com/netease/qa/emmagee/utils/ProcessInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public int getPidByPackageName(Context context, String packageName) {
Log.i(LOG_TAG, "start getLaunchedPid");
ActivityManager am = (ActivityManager) context
.getSystemService(Context.ACTIVITY_SERVICE);
// Note: getRunningAppProcesses return itself in API 22
if (Build.VERSION.SDK_INT < ANDROID_M) {
List<RunningAppProcessInfo> run = am.getRunningAppProcesses();
for (RunningAppProcessInfo runningProcess : run) {
Expand Down Expand Up @@ -208,6 +209,7 @@ public Programe getProgrameByPackageName(Context context, String packageName) {
public static String getTopActivity(Context context) {
ActivityManager manager = (ActivityManager) context
.getSystemService(Context.ACTIVITY_SERVICE);
// Note: getRunningTasks is deprecated in API 21(Official)
List<RunningTaskInfo> runningTaskInfos = manager.getRunningTasks(1);
if (runningTaskInfos != null)
return (runningTaskInfos.get(0).topActivity).toString();
Expand Down

0 comments on commit def4df8

Please sign in to comment.