1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.loganalysis.parser; 17 18 import com.android.loganalysis.item.MemoryHealthItem; 19 20 import junit.framework.TestCase; 21 22 import java.util.Arrays; 23 import java.util.List; 24 import java.util.Map; 25 26 /** 27 * Tests for memory health parser. 28 */ 29 public class MemHealthParserTest extends TestCase { 30 public void testOneForegroundProc() { 31 List<String> lines = Arrays.asList("Foreground", 32 "com.google.android.gm", 33 "Average Native Heap: 10910", 34 "Average Dalvik Heap: 8011", 35 "Average PSS: 90454", 36 "Peak Native Heap: 11136", 37 "Peak Dalvik Heap: 9812", 38 "Peak PSS: 95161", 39 "Average Summary Java Heap: 8223", 40 "Average Summary Native Heap: 3852", 41 "Average Summary Code: 1804", 42 "Average Summary Stack: 246", 43 "Average Summary Graphics: 0", 44 "Average Summary Other: 855", 45 "Average Summary System: 9151", 46 "Average Summary Overall Pss: 24135", 47 "Count 528" 48 ); 49 50 MemoryHealthItem item = new MemoryHealthParser().parse(lines); 51 Map<String, Map<String, Long>> processes = item.getForeground(); 52 assertNotNull(processes); 53 assertNotNull(processes.get("com.google.android.gm")); 54 Map<String, Long> process = processes.get("com.google.android.gm"); 55 assertEquals(10910, process.get("native_avg").longValue()); 56 assertEquals(8011, process.get("dalvik_avg").longValue()); 57 assertEquals(90454, process.get("pss_avg").longValue()); 58 assertEquals(11136, process.get("native_peak").longValue()); 59 assertEquals(9812, process.get("dalvik_peak").longValue()); 60 assertEquals(95161, process.get("pss_peak").longValue()); 61 assertEquals(8223, process.get("summary_java_heap_avg").longValue()); 62 assertEquals(3852, process.get("summary_native_heap_avg").longValue()); 63 assertEquals(1804, process.get("summary_code_avg").longValue()); 64 assertEquals(246, process.get("summary_stack_avg").longValue()); 65 assertEquals(0, process.get("summary_graphics_avg").longValue()); 66 assertEquals(855, process.get("summary_other_avg").longValue()); 67 assertEquals(9151, process.get("summary_system_avg").longValue()); 68 assertEquals(24135, process.get("summary_overall_pss_avg").longValue()); 69 } 70 71 public void testTwoForegroundProc() { 72 List<String> lines = Arrays.asList("Foreground", 73 "com.google.android.gm", 74 "Average Native Heap: 10910", 75 "Average Dalvik Heap: 8011", 76 "Average PSS: 90454", 77 "Peak Native Heap: 11136", 78 "Peak Dalvik Heap: 9812", 79 "Peak PSS: 95161", 80 "Average Summary Java Heap: 8223", 81 "Average Summary Native Heap: 3852", 82 "Average Summary Code: 1804", 83 "Average Summary Stack: 246", 84 "Average Summary Graphics: 0", 85 "Average Summary Other: 855", 86 "Average Summary System: 9151", 87 "Average Summary Overall Pss: 24135", 88 "Count 528", 89 "com.google.android.music", 90 "Average Native Heap: 1", 91 "Average Dalvik Heap: 2", 92 "Average PSS: 3", 93 "Peak Native Heap: 4", 94 "Peak Dalvik Heap: 5", 95 "Peak PSS: 6", 96 "Average Summary Java Heap: 7", 97 "Average Summary Native Heap: 8", 98 "Average Summary Code: 9", 99 "Average Summary Stack: 10", 100 "Average Summary Graphics: 11", 101 "Average Summary Other: 12", 102 "Average Summary System: 13", 103 "Average Summary Overall Pss: 14", 104 "Count 7" 105 ); 106 107 MemoryHealthItem item = new MemoryHealthParser().parse(lines); 108 Map<String, Map<String, Long>> processes = item.getForeground(); 109 assertEquals(2, processes.size()); 110 Map<String, Long> process = processes.get("com.google.android.music"); 111 assertEquals(1, process.get("native_avg").longValue()); 112 assertEquals(2, process.get("dalvik_avg").longValue()); 113 assertEquals(3, process.get("pss_avg").longValue()); 114 assertEquals(4, process.get("native_peak").longValue()); 115 assertEquals(5, process.get("dalvik_peak").longValue()); 116 assertEquals(6, process.get("pss_peak").longValue()); 117 assertEquals(7, process.get("summary_java_heap_avg").longValue()); 118 assertEquals(8, process.get("summary_native_heap_avg").longValue()); 119 assertEquals(9, process.get("summary_code_avg").longValue()); 120 assertEquals(10, process.get("summary_stack_avg").longValue()); 121 assertEquals(11, process.get("summary_graphics_avg").longValue()); 122 assertEquals(12, process.get("summary_other_avg").longValue()); 123 assertEquals(13, process.get("summary_system_avg").longValue()); 124 assertEquals(14, process.get("summary_overall_pss_avg").longValue()); 125 } 126 127 public void testForegroundBackgroundProc() { 128 List<String> lines = Arrays.asList("Foreground", 129 "com.google.android.gm", 130 "Average Native Heap: 10910", 131 "Average Dalvik Heap: 8011", 132 "Average PSS: 90454", 133 "Peak Native Heap: 11136", 134 "Peak Dalvik Heap: 9812", 135 "Peak PSS: 95161", 136 "Average Summary Java Heap: 8223", 137 "Average Summary Native Heap: 3852", 138 "Average Summary Code: 1804", 139 "Average Summary Stack: 246", 140 "Average Summary Graphics: 0", 141 "Average Summary Other: 855", 142 "Average Summary System: 9151", 143 "Average Summary Overall Pss: 24135", 144 "Count 528", 145 "Background", 146 "com.google.android.music", 147 "Average Native Heap: 1", 148 "Average Dalvik Heap: 2", 149 "Average PSS: 3", 150 "Peak Native Heap: 4", 151 "Peak Dalvik Heap: 5", 152 "Peak PSS: 6", 153 "Average Summary Java Heap: 7", 154 "Average Summary Native Heap: 8", 155 "Average Summary Code: 9", 156 "Average Summary Stack: 10", 157 "Average Summary Graphics: 11", 158 "Average Summary Other: 12", 159 "Average Summary System: 13", 160 "Average Summary Overall Pss: 14", 161 "Count 7" 162 ); 163 164 MemoryHealthItem item = new MemoryHealthParser().parse(lines); 165 Map<String, Map<String, Long>> processes = item.getForeground(); 166 assertEquals(1, processes.size()); 167 assertEquals(1, item.getBackground().size()); 168 Map<String, Long> process = item.getBackground().get("com.google.android.music"); 169 assertEquals(1, process.get("native_avg").longValue()); 170 assertEquals(2, process.get("dalvik_avg").longValue()); 171 assertEquals(3, process.get("pss_avg").longValue()); 172 assertEquals(4, process.get("native_peak").longValue()); 173 assertEquals(5, process.get("dalvik_peak").longValue()); 174 assertEquals(6, process.get("pss_peak").longValue()); 175 assertEquals(7, process.get("summary_java_heap_avg").longValue()); 176 assertEquals(8, process.get("summary_native_heap_avg").longValue()); 177 assertEquals(9, process.get("summary_code_avg").longValue()); 178 assertEquals(10, process.get("summary_stack_avg").longValue()); 179 assertEquals(11, process.get("summary_graphics_avg").longValue()); 180 assertEquals(12, process.get("summary_other_avg").longValue()); 181 assertEquals(13, process.get("summary_system_avg").longValue()); 182 assertEquals(14, process.get("summary_overall_pss_avg").longValue()); 183 } 184 } 185