我正在尝试为我的项目自动化一项任务,我必须解析一个日志文件并搜索特定的 pid。如果该 pid 遇到超过 50 次,那么我必须打印我的消息。
我的代码:
#!/usr/bin/perl -w
use strict;
open(my $fh,"<","UIlogs.txt") or die "can not open the file $!";
my @lines = <$fh>;
close($fh);
my $count=0;
for(my $i=0; $i<=$#lines;$i++)
{
if($lines[$i] =~ m/Input event injection from pid (\d+) failed/gi)
{
#print"UI freez\n";
print"$1\n";
}
}
日志:
07-10 16:36:43.632 784 784 W InputManager: Input event injection from pid 2019 failed.
07-10 16:36:43.632 784 795 W InputManager: Input event injection from pid 2019 failed.
07-10 16:36:45.114 2041 2041 D AndroidRuntime:
07-10 16:36:45.114 2041 2041 D AndroidRuntime: >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
07-10 16:36:45.114 2041 2041 D AndroidRuntime: CheckJNI is OFF
07-10 16:36:45.124 2041 2041 D dalvikvm: Trying to load lib libjavacore.so 0x0
07-10 16:36:45.124 2041 2041 D dalvikvm: Added shared lib libjavacore.so 0x0
07-10 16:36:45.134 2041 2041 D dalvikvm: Trying to load lib libnativehelper.so 0x0
07-10 16:36:45.134 2041 2041 D dalvikvm: Added shared lib libnativehelper.so 0x0
07-10 16:36:45.244 2041 2041 D AndroidRuntime: Calling main entry com.android.commands.input.Input
07-10 16:36:45.244 2041 2041 I Input : injectKeyEvent: KeyEvent { action=ACTION_DOWN, keyCode=KEYCODE_DPAD_CENTER, scanCode=0, metaState=0, flags=0x0, repeatCount=0, eventTime=166218, downTime=166218, deviceId=-1, source=0x101 }
07-10 16:36:45.254 784 886 I InputDispatcher: Dropped event because input dispatch is disabled.
07-10 16:36:45.254 2041 2041 I Input : injectKeyEvent: KeyEvent { action=ACTION_UP, keyCode=KEYCODE_DPAD_CENTER, scanCode=0, metaState=0, flags=0x0, repeatCount=0, eventTime=166218, downTime=166218, deviceId=-1, source=0x101 }
07-10 16:36:45.254 784 886 I InputDispatcher: Dropped event because input dispatch is disabled.
07-10 16:36:45.254 2041 2041 D AndroidRuntime: Shutting down VM
07-10 16:36:45.254 2041 2050 D dalvikvm: GC_CONCURRENT freed 94K, 17% free 479K/576K, paused 0ms+0ms, total 3ms
07-10 16:36:45.254 784 1016 W InputManager: Input event injection from pid 2041 failed.
07-10 16:36:45.254 784 1083 W InputManager: Input event injection from pid 2041 failed.
07-10 16:36:52.932 2061 2061 D AndroidRuntime:
07-10 16:36:52.932 2061 2061 D AndroidRuntime: >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
07-10 16:36:52.932 2061 2061 D AndroidRuntime: CheckJNI is OFF
07-10 16:36:52.942 2061 2061 D dalvikvm: Trying to load lib libjavacore.so 0x0
07-10 16:36:52.942 2061 2061 D dalvikvm: Added shared lib libjavacore.so 0x0
07-10 16:36:52.952 2061 2061 D dalvikvm: Trying to load lib libnativehelper.so 0x0
07-10 16:36:52.952 2061 2061 D dalvikvm: Added shared lib libnativehelper.so 0x0
07-10 16:36:53.082 2061 2061 D AndroidRuntime: Calling main entry com.android.commands.monkey.Monkey
07-10 16:36:53.092 2061 2061 D dalvikvm: Note: class Landroid/app/ActivityManagerNative; has 163 unimplemented (abstract) methods
07-10 16:36:53.112 784 1076 I ActivityManager: START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.android.contacts/.activities.PeopleActivity} from pid 2061
07-10 16:36:53.122 784 1076 I ActivityManager: Start proc com.android.contacts for activity com.android.contacts/.activities.PeopleActivity: pid=2077 uid=10000 gids={50000, 3003, 1015, 1028}
07-10 16:36:53.212 2077 2077 I ContactsIntentResolver: Called with action: android.intent.action.MAIN
07-10 16:36:53.232 2077 2092 I AccountTypeManager: Loaded meta-data for 1 account types, 0 accounts in 19ms(wall) 5ms(cpu)
07-10 16:36:53.272 2077 2077 I ContactPhotoManager: Cache adj: 1.0
07-10 16:36:53.463 2077 2077 D libEGL : loaded /vendor/lib/egl/libEGL_adreno.so
07-10 16:36:53.463 2077 2077 D libEGL : loaded /vendor/lib/egl/libGLESv1_CM_adreno.so
07-10 16:36:53.463 2077 2077 D libEGL : loaded /vendor/lib/egl/libGLESv2_adreno.so
07-10 16:36:53.473 2077 2077 I Adreno-EGL: <qeglDrvAPI_eglInitialize:316>: EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_JB_2.6.04.02.02.109.046_msm8960_JB_2.6_CL3925444_release_AU (CL3925444)
07-10 16:36:53.473 2077 2077 I Adreno-EGL: OpenGL ES Shader Compiler Version: 17.01.08
07-10 16:36:53.473 2077 2077 I Adreno-EGL: Build Date: 07/09/13 Tue
07-10 16:36:53.473 2077 2077 I Adreno-EGL: Local Branch: mybranch1230998
07-10 16:36:53.473 2077 2077 I Adreno-EGL: Remote Branch: quic/jb_3.1
07-10 16:36:53.473 2077 2077 I Adreno-EGL: Local Patches: NONE
07-10 16:36:53.473 2077 2077 I Adreno-EGL: Reconstruct Branch: AU_LINUX_ANDROID_JB_2.6.04.02.02.109.046 + e363aa2 + 76767df + NOTHING
07-10 16:36:53.523 2077 2077 D OpenGLRenderer: Enabling debug mode 0
07-10 16:36:53.623 784 886 I InputDispatcher: Dropped event because input dispatch is disabled.
07-10 16:36:53.623 784 857 I ActivityManager: Displayed com.android.contacts/.activities.PeopleActivity: +511ms
07-10 16:36:53.623 784 1016 W InputManager: Input event injection from pid 2061 failed.
07-10 16:36:53.633 784 886 I InputDispatcher: Dropped event because input dispatch is disabled.
07-10 16:36:53.633 784 1103 W InputManager: Input event injection from pid 2061 failed.
07-10 16:36:54.133 784 886 I InputDispatcher: Dropped event because input dispatch is disabled.
07-10 16:36:54.133 784 886 I InputDispatcher: Dropped event because input dispatch is disabled.
07-10 16:36:54.133 784 1083 W InputManager: Input event injection from pid 2061 failed.
07-10 16:36:54.133 784 1016 W InputManager: Input event injection from pid 2061 failed.
07-10 16:36:54.634 784 886 I InputDispatcher: Dropped event because input dispatch is disabled.
07-10 16:36:54.634 784 886 I InputDispatcher: Dropped event because input dispatch is disabled.
07-10 16:36:54.634 784 796 W InputManager: Input event injection from pid 2061 failed.
07-10 16:36:54.634 784 795 W InputManager: Input event injection from pid 2061 failed.
07-10 16:36:55.144 784 886 I InputDispatcher: Dropped event because input dispatch is disabled.
07-10 16:36:55.144 784 886 I InputDispatcher: Dropped event because input dispatch is disabled.
07-10 16:36:55.144 784 1103 W InputManager: Input event injection from pid 2061 failed.
07-10 16:36:55.144 784 1191 W InputManager: Input event injection from pid 2061 failed.
07-10 16:36:55.645 784 886 I InputDispatcher: Dropped event because input dispatch is disabled.
07-10 16:36:55.645 784 886 I InputDispatcher: Dropped event because input dispatch is disabled.
07-10 16:36:55.645 784 1016 W InputManager: Input event injection from pid 2061 failed.
07-10 16:36:55.655 784 1083 W InputManager: Input event injection from pid 2061 failed.
07-10 16:36:56.156 784 886 I InputDispatcher: Dropped event because input dispatch is disabled.
07-10 16:36:56.156 784 886 I InputDispatcher: Dropped event because input dispatch is disabled.
07-10 16:36:56.156 784 784 W InputManager: Input event injection from pid 2061 failed.
07-10 16:36:56.156 784 795 W InputManager: Input event injection from pid 2061 failed.
07-10 16:36:56.666 784 886 I InputDispatcher: Dropped event because input dispatch is disabled.
07-10 16:36:56.666 784 886 I InputDispatcher: Dropped event because input dispatch is disabled.
07-10 16:36:56.666 784 796 W InputManager: Input event injection from pid 2061 failed.
07-10 16:36:56.666 784 1076 W InputManager: Input event injection from pid 2061 failed.
07-10 16:36:57.167 784 886 I InputDispatcher: Dropped event because input dispatch is disabled.
07-10 16:36:57.167 784 886 I InputDispatcher: Dropped event because input dispatch is disabled.
07-10 16:36:57.167 784 1190 W InputManager: Input event injection from pid 2061 failed.
07-10 16:36:57.167 784 1191 W InputManager: Input event injection from pid 2061 failed.
07-10 16:36:57.677 784 886 I InputDispatcher: Dropped event because input dispatch is disabled.
07-10 16:36:57.677 784 1103 W InputManager: Input event injection from pid 2061 failed.
07-10 16:36:57.677 784 886 I InputDispatcher: Dropped event because input dispatch is disabled.
07-10 16:36:57.677 784 1083 W InputManager: Input event injection from pid 2061 failed.
07-10 16:36:58.188 784 886 I InputDispatcher: Dropped event because input dispatch is disabled.
07-10 16:36:58.188 784 1016 W InputManager: Input event injection from pid 2061 failed.
07-10 16:36:58.188 784 886 I InputDispatcher: Dropped event because input dispatch is disabled.
07-10 16:36:58.188 784 795 W InputManager: Input event injection from pid 2061 failed.
07-10 16:36:58.698 784 886 I InputDispatcher: Dropped event because input dispatch is disabled.
07-10 16:36:58.698 784 784 W InputManager: Input event injection from pid 2061 failed.
07-10 16:36:58.698 784 886 I InputDispatcher: Dropped event because input dispatch is disabled.
07-10 16:36:58.698 784 796 W InputManager: Input event injection from pid 2061 failed.
07-10 16:36:59.039 784 910 W QCNEJ : |CORE| UNKOWN Unsolicited Event 6
07-10 16:36:59.209 784 886 I InputDispatcher: Dropped event because input dispatch is disabled.
07-10 16:36:59.209 784 886 I InputDispatcher: Dropped event because input dispatch is disabled.
07-10 16:36:59.209 784 1190 W InputManager: Input event injection from pid 2061 failed.
07-10 16:36:59.209 784 1103 W InputManager: Input event injection from pid 2061 failed.
07-10 16:36:59.719 784 886 I InputDispatcher: Dropped event because input dispatch is disabled.
07-10 16:36:59.719 784 886 I InputDispatcher: Dropped event because input dispatch is disabled.
07-10 16:36:59.719 784 1083 W InputManager: Input event injection from pid 2061 failed.
07-10 16:36:59.719 784 795 W InputManager: Input event injection from pid 2061 failed.
07-10 16:37:00.230 784 886 I InputDispatcher: Dropped event because input dispatch is disabled.
07-10 16:37:00.230 784 886 I InputDispatcher: Dropped event because input dispatch is disabled.
07-10 16:37:00.230 784 1191 W InputManager: Input event injection from pid 2061 failed.
07-10 16:37:00.230 784 1076 W InputManager: Input event injection from pid 2061 failed.
07-10 16:37:00.740 784 886 I InputDispatcher: Dropped event because input dispatch is disabled.
07-10 16:37:00.740 784 1103 W InputManager: Input event injection from pid 2061 failed.
07-10 16:37:00.740 784 886 I InputDispatcher: Dropped event because input dispatch is disabled.
07-10 16:37:00.740 784 1190 W InputManager: Input event injection from pid 2061 failed.
07-10 16:37:01.251 784 886 I InputDispatcher: Dropped event because input dispatch is disabled.
07-10 16:37:01.251 784 886 I InputDispatcher: Dropped event because input dispatch is disabled.
07-10 16:37:01.251 784 1016 W InputManager: Input event injection from pid 2061 failed.
07-10 16:37:01.251 784 784 W InputManager: Input event injection from pid 2061 failed.
07-10 16:37:01.762 784 886 I InputDispatcher: Dropped event because input dispatch is disabled.
07-10 16:37:01.762 784 886 I InputDispatcher: Dropped event because input dispatch is disabled.
07-10 16:37:01.762 784 796 W InputManager: Input event injection from pid 2061 failed.
07-10 16:37:01.762 784 1076 W InputManager: Input event injection from pid 2061 failed.
07-10 16:37:02.272 784 886 I InputDispatcher: Dropped event because input dispatch is disabled.
07-10 16:37:02.272 784 886 I InputDispatcher: Dropped event because input dispatch is disabled.
07-10 16:37:02.272 784 1191 W InputManager: Input event injection from pid 2061 failed.
07-10 16:37:02.272 784 1103 W InputManager: Input event injection from pid 2061 failed.
07-10 16:37:02.773 784 886 I InputDispatcher: Dropped event because input dispatch is disabled.
07-10 16:37:02.773 784 886 I InputDispatcher: Dropped event because input dispatch is disabled.
07-10 16:37:02.773 784 1190 W InputManager: Input event injection from pid 2061 failed.
07-10 16:37:02.783 784 795 W InputManager: Input event injection from pid 2061 failed.
使用我的代码,我无法处理其他 pid,即如何仅计算日志中存在超过 50 次的 pid。如果发生 UI 冻结,则只有一个 pid 会超过此计数。