forked from NetEase/Emmagee
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
andrewleo
committed
Jul 31, 2015
1 parent
2d2a44f
commit 669de8a
Showing
5 changed files
with
70 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.netease.qa.emmagee.utils; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.DataOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
|
||
public class FpsInfo { | ||
|
||
private static Process process; | ||
private static BufferedReader ir; | ||
private static DataOutputStream os = null; | ||
private static long startTime = 0L; | ||
private static int lastFrameNum = 0; | ||
|
||
/** | ||
* 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; | ||
} | ||
|
||
/** | ||
* get frame value | ||
* | ||
* @return frame value | ||
*/ | ||
public static final int getFrameNum() { | ||
try { | ||
if (process == null) { | ||
process = Runtime.getRuntime().exec("su"); | ||
os = new DataOutputStream(process.getOutputStream()); | ||
ir = new BufferedReader(new InputStreamReader( | ||
process.getInputStream())); | ||
} | ||
os.writeBytes("service call SurfaceFlinger 1013" + "\n"); | ||
os.flush(); | ||
String str1 = ir.readLine(); | ||
if (str1 == null) { | ||
return -1; | ||
} | ||
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; | ||
} | ||
} | ||
} |