0

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?

hyperion
  • 1
  • 1

2 Answers2

0

Try these first

  1. Go to the device tab, click your device. and go back to the logcat tab
  2. You might have filter set.
  3. You are probably viewing the wrong package.

Then...

You can always simply pipe the logcat to grep:

$ adb logcat | grep 'known error substring'

If you are on Windows, then use find instead:

C:\> adb logcat | find 'known error substring'
PartTimeNerd
  • 305
  • 1
  • 2
  • 20
  • Thanks for you answer! I can get log by "adb logcat" as I said, just get nothing when run the shell in java code by use java.lang.Runtime. – hyperion Nov 02 '18 at 03:06
0

It just only works on rooted device if you want to get any log those not belong to your own app. That is to say, I can't get my app startup time by this way. Anybody give some idea for this purpose?

hyperion
  • 1
  • 1