Now, I want to search some data for app startup time. I use adb shell can do it, like that:
adb logcat -s ActivityManager:I | grep Displayed
Here is the result:
I/ActivityManager( 949): Displayed com.gtr.sdkdemo/com.gtr.test.MainActivity: +303ms (total +1s546ms)
But when I use java.lang.Runtime to run "logcat -s ActivityManager:I | grep Displayed", I can't get anything.
Here is my code:
private void runShellForAppLaunchTime() {
Process logcatProcess = null;
try {
// adb logcat -s ActivityManager:I | grep Displayed
String cmd = "logcat -s ActivityManager:I | grep Displayed";
logcatProcess = Runtime.getRuntime().exec(cmd);
mReader = new DataInputStream(logcatProcess.getInputStream());
String line;
while ((line = mReader.readUTF()) != null) {
appLaunchTimeList.add(line);
}
} catch (IOException e){
// nothing to do
} catch (SecurityException |
IllegalArgumentException |
NullPointerException e) {
e.printStackTrace();
} finally {
if (mReader != null) {
try {
mReader.close();
} catch (IOException e) {
e.printStackTrace();
}
mReader = null;
}
if (logcatProcess != null) {
logcatProcess.destroy();
}
}
}
Then I run "logcat *:V ", It's same that I can't get any log which not belong to my own app. Is Google in security consideration? How can I get my own app startup time in code ? Any idea?