From 4348cc0f92b088ab3b58001e1b370b69b86577a2 Mon Sep 17 00:00:00 2001 From: gopinath Date: Thu, 27 Apr 2017 18:56:49 -0700 Subject: Apptransition parser change. Change to new logging format. Latency parser change will be taken care separately. Events log parser test changes. b/36490501 Tests : OK (252 tests) - Passed Change-Id: I6425ebd08c7f6120a056c268528d371cd7096b97 (cherry picked from commit 5e008d690d460b25e174d02932413be850798efb) --- .../loganalysis/parser/EventsLogParser.java | 49 +++------ .../loganalysis/parser/EventsLogParserTest.java | 109 ++++++--------------- 2 files changed, 43 insertions(+), 115 deletions(-) diff --git a/src/com/android/loganalysis/parser/EventsLogParser.java b/src/com/android/loganalysis/parser/EventsLogParser.java index a15abf8..6620cd6 100644 --- a/src/com/android/loganalysis/parser/EventsLogParser.java +++ b/src/com/android/loganalysis/parser/EventsLogParser.java @@ -35,24 +35,14 @@ public class EventsLogParser implements IParser { // 08-21 17:53:53.876 1053 2135 private static final String EVENTS_PREFIX = "^\\d{2}-\\d{2} \\d{2}:\\d{2}" + ":\\d{2}.\\d{3}\\s+\\d+\\s+\\d+ "; - // 08-21 17:53:53.876 1053 2135 I am_restart_activity: - // [0,188098346,127,com.google.android.gm/.ConversationListActivityGmail] - private static final Pattern ACTIVITY_RESTART = Pattern.compile( - String.format("%s%s", EVENTS_PREFIX, "I am_restart_activity: " - + "\\[\\d+\\,\\d+\\,\\d+\\,(?.*)\\]$")); - // 08-21 17:53:53.876 1053 2135 I am_resume_activity: - // [0,228277756,132,com.google.android.gm/.ConversationListActivityGmail] - private static final Pattern ACTIVITY_RESUME = Pattern.compile( - String.format("%s%s", EVENTS_PREFIX, "I am_resume_activity: " - + "\\[\\d+\\,\\d+\\,\\d+\\,(?.*)\\]$")); - // 08-21 17:53:53.876 1053 2135 I sysui_action: [321,74] - private static final Pattern STARTING_WINDOW_DELAY = Pattern.compile( - String.format("%s%s", EVENTS_PREFIX, "I sysui_action: \\[321," - + "(?.*)\\]$")); - // 08-21 17:53:53.876 1053 2135 I sysui_action: [319,99] + + // 01-01 01:38:44.863 1037 1111 I sysui_multi_action: + // [319,64,321,64,322,99,325,5951,757,761,758,9,759,4,806,com.google.android.gm,871, + // com.google.android.gm.welcome.WelcomeTourActivity,905,0] private static final Pattern TRANSITION_DELAY = Pattern.compile( - String.format("%s%s", EVENTS_PREFIX, "I sysui_action: \\[319," - + "(?.*)\\]$")); + String.format("%s%s", EVENTS_PREFIX, "I sysui_multi_action: \\[319,(.*),321,(.*)" + + ",322,(.*),806,(.*),871,(.*),905.*\\]$")); + // 08-21 17:53:53.876 1053 2135 I sysui_latency: [1,50] private static final Pattern ACTION_LATENCY = Pattern.compile( String.format("%s%s", EVENTS_PREFIX, "I sysui_latency: \\[(?.*)," @@ -75,30 +65,13 @@ public class EventsLogParser implements IParser { throws IOException { List transitionDelayItems = new ArrayList(); String line; - List componentNameStack = new ArrayList(); - boolean isRecentStartWindowDelay = false; while ((line = input.readLine()) != null) { Matcher match = null; - if ((match = matches(ACTIVITY_RESTART, line)) != null || - ((match = matches(ACTIVITY_RESUME, line)) != null)) { - componentNameStack.add(match.group("componentname")); - isRecentStartWindowDelay = false; - } else if (((match = matches(STARTING_WINDOW_DELAY, line)) != null) - && (componentNameStack.size() > 0)) { - TransitionDelayItem delayItem = new TransitionDelayItem(); - delayItem.setComponentName( - componentNameStack.remove(componentNameStack.size() - 1)); - delayItem.setStartingWindowDelay(Long.parseLong(match.group("startdelay"))); - delayItem.setTransitionDelay(-1); - transitionDelayItems.add(delayItem); - isRecentStartWindowDelay = true; - } else if (((match = matches(TRANSITION_DELAY, line)) != null) - && (componentNameStack.size() > 0) && !isRecentStartWindowDelay) { + if (((match = matches(TRANSITION_DELAY, line)) != null)) { TransitionDelayItem delayItem = new TransitionDelayItem(); - delayItem.setComponentName( - componentNameStack.remove(componentNameStack.size() - 1)); - delayItem.setTransitionDelay(Long.parseLong(match.group("transitdelay"))); - delayItem.setStartingWindowDelay(-1); + delayItem.setComponentName(match.group(4) + "/" + match.group(5)); + delayItem.setTransitionDelay(Long.parseLong(match.group(1))); + delayItem.setStartingWindowDelay(Long.parseLong(match.group(2))); transitionDelayItems.add(delayItem); } } diff --git a/tests/src/com/android/loganalysis/parser/EventsLogParserTest.java b/tests/src/com/android/loganalysis/parser/EventsLogParserTest.java index a3dc283..b568e57 100644 --- a/tests/src/com/android/loganalysis/parser/EventsLogParserTest.java +++ b/tests/src/com/android/loganalysis/parser/EventsLogParserTest.java @@ -73,45 +73,23 @@ public class EventsLogParserTest extends TestCase { /** * Test for Cold launch transition delay info */ - public void testColdLaunchTransitionDelay() throws IOException { + public void testValidTransitionDelay() throws IOException { List lines = Arrays - .asList("08-25 13:01:19.412 1152 9031 I am_restart_activity: [0,85290699,38,com.google.android.gm/.ConversationListActivityGmail]", - "08-25 13:01:19.437 1152 1226 I sysui_action: [321,85]", - "08-25 13:01:19.437 1152 1226 I sysui_action: [320,1]", - "08-25 13:01:19.437 1152 1226 I sysui_action: [319,85]"); + .asList("01-02 08:12:10.849 934 986 I sysui_multi_action: [319,42,321,59,322,208,325,84100,757,761,758,9,759,4,806,com.google.android.apps.maps,871,com.google.android.maps.MapsActivity,905,0]", + "01-02 08:12:16.895 1446 1446 I sysui_multi_action: [757,803,799,overview_trigger_nav_btn,802,1]", + "01-02 08:12:16.895 1446 1446 I sysui_multi_action: [757,803,799,overview_source_app,802,1]", + "01-02 08:12:16.895 1446 1446 I sysui_multi_action: [757,804,799,overview_source_app_index,801,8,802,1]"); List transitionItems = (new EventsLogParser()). parseTransitionDelayInfo(readInputBuffer(getTempFile(lines))); assertEquals("Transition Delay items list should have one item", 1, transitionItems.size()); assertEquals("Component name not parsed correctly", - "com.google.android.gm/.ConversationListActivityGmail", + "com.google.android.apps.maps/com.google.android.maps.MapsActivity", transitionItems.get(0).getComponentName()); - assertEquals("Cold launch info is not set correctly", 85, - transitionItems.get(0).getStartingWindowDelay()); - assertEquals("Hot launch info is set which is not expected", -1, + assertEquals("Transition delay is not parsed correctly", 42, transitionItems.get(0).getTransitionDelay()); - } - - /** - * Test for Hot launch transition delay - */ - public void testHotLaunchTransitionDelay() throws IOException { - List lines = Arrays - .asList("08-25 13:02:04.740 1152 2715 I am_resume_activity: [0,85290699,38,com.google.android.gm/.ConversationListActivityGmail]", - "08-25 13:02:04.754 1152 1180 I sysui_count: [window_time_0,23]", - "08-25 13:02:04.755 1152 1226 I sysui_action: [320,0]", - "08-25 13:02:04.755 1152 1226 I sysui_action: [319,37]"); - List transitionItems = (new EventsLogParser()). - parseTransitionDelayInfo(readInputBuffer(getTempFile(lines))); - assertEquals("Transition Delay items list shopuld have one item", 1, - transitionItems.size()); - assertEquals("Component name not parsed correctly", - "com.google.android.gm/.ConversationListActivityGmail", - transitionItems.get(0).getComponentName()); - assertEquals("Cold launch info is set which is not expected", -1, + assertEquals("Starting window delay is not parsed correctly", 59, transitionItems.get(0).getStartingWindowDelay()); - assertEquals("Hot launch info is not set correctly", 37, - transitionItems.get(0).getTransitionDelay()); } /** @@ -119,26 +97,19 @@ public class EventsLogParserTest extends TestCase { */ public void testTransitionDelayOrder() throws IOException { List lines = Arrays - .asList("08-25 13:01:19.412 1152 9031 I am_restart_activity: [0,85290699,38,com.google.android.gm/.ConversationListActivityGmail]", - "08-25 13:01:19.437 1152 1226 I sysui_action: [321,85]", - "08-25 13:01:19.437 1152 1226 I sysui_action: [320,1]", - "08-25 13:01:19.437 1152 1226 I sysui_action: [319,85]", - "08-25 12:56:15.850 1152 8968 I am_focused_stack: [0,0,1,appDied setFocusedActivity]", - "08-25 12:56:15.850 1152 8968 I wm_task_moved: [6,1,1]", - "08-25 12:56:15.852 1152 8968 I am_focused_activity: [0,com.google.android.apps.nexuslauncher/.NexusLauncherActivity,appDied]", - "08-25 12:56:15.852 1152 8968 I wm_task_removed: [27,removeTask]", - "08-25 12:56:15.852 1152 8968 I wm_stack_removed: 1", - "08-25 13:02:04.740 1152 2715 I am_resume_activity: [0,85290699,38,com.google.android.gm/.ConversationListActivityGmail]", - "08-25 13:02:04.754 1152 1180 I sysui_count: [window_time_0,23]", - "08-25 13:02:04.755 1152 1226 I sysui_action: [320,0]", - "08-25 13:02:04.755 1152 1226 I sysui_action: [319,37]"); + .asList("01-02 08:12:10.849 934 986 I sysui_multi_action: [319,42,321,59,322,208,325,84100,757,761,758,9,759,4,806,com.google.android.apps.maps,871,com.google.android.maps.MapsActivity,905,0]", + "01-02 08:12:16.895 1446 1446 I sysui_multi_action: [757,803,799,overview_trigger_nav_btn,802,1]", + "01-02 08:12:16.895 1446 1446 I sysui_multi_action: [757,803,799,overview_source_app,802,1]", + "01-02 08:12:16.895 1446 1446 I sysui_multi_action: [757,804,799,overview_source_app_index,801,8,802,1]", + "01-02 08:12:42.187 934 986 I sysui_multi_action: [319,61,321,46,322,159,325,84131,757,761,758,9,759,4,806,com.google.android.apps.maps,871,com.google.android.maps.MapsActivity,905,0]", + "01-02 08:12:42.450 1446 1446 I sysui_multi_action: [757,224,758,2]"); List transitionItems = (new EventsLogParser()). parseTransitionDelayInfo(readInputBuffer(getTempFile(lines))); assertEquals("Transition Delay items list should have two items", 2, transitionItems.size()); - assertEquals("Cold launch transition delay is not the first item", 85, - transitionItems.get(0).getStartingWindowDelay()); - assertEquals("Hot launch transition delay is not the second item", 37, + assertEquals("Transition delay for the first item is not set correct", 42, + transitionItems.get(0).getTransitionDelay()); + assertEquals("Transition delay for the second item is not set correct", 61, transitionItems.get(1).getTransitionDelay()); } @@ -147,27 +118,18 @@ public class EventsLogParserTest extends TestCase { */ public void testDifferentAppTransitionDelay() throws IOException { List lines = Arrays - .asList("08-25 13:01:19.412 1152 9031 I am_restart_activity: [0,85290699,38,com.google.android.gm/.ConversationListActivityGmail]", - "08-25 13:01:19.437 1152 1226 I sysui_action: [321,85]", - "08-25 13:01:19.437 1152 1226 I sysui_action: [320,1]", - "08-25 13:01:19.437 1152 1226 I sysui_action: [319,85]", - "08-25 12:56:15.850 1152 8968 I am_focused_stack: [0,0,1,appDied setFocusedActivity]", - "08-25 12:56:15.850 1152 8968 I wm_task_moved: [6,1,1]", - "08-25 12:56:15.852 1152 8968 I am_focused_activity: [0,com.google.android.apps.nexuslauncher/.NexusLauncherActivity,appDied]", - "08-25 12:56:15.852 1152 8968 I wm_task_removed: [27,removeTask]", - "08-25 12:56:15.852 1152 8968 I wm_stack_removed: 1", - "08-25 13:03:35.528 1152 2715 I am_restart_activity: [0,32358360,39,com.google.android.apps.maps/com.google.android.maps.MapsActivity]", - "08-25 13:03:35.540 1152 1179 I am_pss : [7727,10032,com.google.android.apps.nexuslauncher,50991104,45486080,0]", - "08-25 13:03:35.566 1152 1179 I am_pss : [9207,10045,com.google.android.googlequicksearchbox:search,111955968,102227968,0]", - "08-25 13:03:35.569 1152 1226 I sysui_action: [321,92]", - "08-25 13:03:35.569 1152 1226 I sysui_action: [320,1]", - "08-25 13:03:35.569 1152 1226 I sysui_action: [319,92]"); + .asList("01-02 08:11:58.691 934 986 I sysui_multi_action: [319,48,321,37,322,82,325,84088,757,761,758,9,759,4,806,com.google.android.calculator,871,com.android.calculator2.Calculator,905,0]", + "01-02 08:12:03.639 934 970 I sysui_multi_action: [757,803,799,window_time_0,802,5]", + "01-02 08:12:10.849 934 986 I sysui_multi_action: [319,42,321,59,322,208,325,84100,757,761,758,9,759,4,806,com.google.android.apps.maps,871,com.google.android.maps.MapsActivity,905,0]", + "01-02 08:12:16.895 1446 1446 I sysui_multi_action: [757,803,799,overview_trigger_nav_btn,802,1]", + "01-02 08:12:16.895 1446 1446 I sysui_multi_action: [757,803,799,overview_source_app,802,1]", + "01-02 08:12:16.895 1446 1446 I sysui_multi_action: [757,804,799,overview_source_app_index,801,8,802,1]"); List transitionItems = (new EventsLogParser()). parseTransitionDelayInfo(readInputBuffer(getTempFile(lines))); assertEquals("Transition Delay items list should have two items", 2, transitionItems.size()); - assertEquals("Gmail is not the first transition delay item", - "com.google.android.gm/.ConversationListActivityGmail", + assertEquals("Calculator is not the first transition delay item", + "com.google.android.calculator/com.android.calculator2.Calculator", transitionItems.get(0).getComponentName()); assertEquals("Maps is not the second transition delay item", "com.google.android.apps.maps/com.google.android.maps.MapsActivity", @@ -175,23 +137,16 @@ public class EventsLogParserTest extends TestCase { } /** - * Test for invalid transition delay items pattern + * Test for invalid transition delay items pattern having different code. */ public void testInvalidTransitionPattern() throws IOException { List lines = Arrays - .asList("08-25 13:01:19.412 1152 9031 I am_restart_activity: [com.google.android.gm/.ConversationListActivityGmail,0,85290699,38]", - "08-25 13:01:19.437 1152 1226 I sysui_action: [321,85]", - "08-25 13:01:19.437 1152 1226 I sysui_action: [320,1]", - "08-25 13:01:19.437 1152 1226 I sysui_action: [319,85]", - "08-25 12:56:15.850 1152 8968 I am_focused_stack: [0,0,1,appDied setFocusedActivity]", - "08-25 12:56:15.850 1152 8968 I wm_task_moved: [6,1,1]", - "08-25 12:56:15.852 1152 8968 I am_focused_activity: [0,com.google.android.apps.nexuslauncher/.NexusLauncherActivity,appDied]", - "08-25 12:56:15.852 1152 8968 I wm_task_removed: [27,removeTask]", - "08-25 12:56:15.852 1152 8968 I wm_stack_removed: 1", - "08-25 13:02:04.740 1152 2715 I am_res_activity: [0,85290699,38,com.google.android.gm/.ConversationListActivityGmail]", - "08-25 13:02:04.754 1152 1180 I sysui_count: [window_time_0,23]", - "08-25 13:02:04.755 1152 1226 I sysui_action: [320,0]", - "08-25 13:02:04.755 1152 1226 I sysui_action: [319,37]"); + .asList("01-02 08:11:58.691 934 986 I sysui_multi_action: [319,48,328,37,322,82,325,84088,757,761,758,9,759,4,806,com.google.android.calculator,871,com.android.calculator2.Calculator,905,0]", + "01-02 08:12:03.639 934 970 I sysui_multi_action: [757,803,799,window_time_0,802,5]", + "01-02 08:12:10.849 934 986 I sysui_multi_action: 319,42,321,59,322,208,325,84100,757,761,758,9,759,4,806,com.google.android.apps.maps,871,com.google.android.maps.MapsActivity,905,0]", + "01-02 08:12:16.895 1446 1446 I sysui_multi_action: [757,803,799,overview_trigger_nav_btn,802,1]", + "01-02 08:12:16.895 1446 1446 I sysui_multi_action: [757,803,799,overview_source_app,802,1]", + "01-02 08:12:16.895 1446 1446 I sysui_multi_action: [757,804,799,overview_source_app_index,801,8,802,1]"); List transitionItems = (new EventsLogParser()). parseTransitionDelayInfo(readInputBuffer(getTempFile(lines))); assertEquals("Transition Delay items list should be empty", 0, -- cgit v1.2.3