2 * Copyright (C) 2008 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * One line from the loaded-classes file.
23 * The delimiter character we use, {@code :}, conflicts with some other
24 * names. In that case, manually replace the delimiter with something else.
26 private static final String[] REPLACE_CLASSES = {
27 "com.google.android.apps.maps:FriendService",
28 "com.google.android.apps.maps\\u003AFriendService",
29 "com.google.android.apps.maps:driveabout",
30 "com.google.android.apps.maps\\u003Adriveabout",
31 "com.google.android.apps.maps:GoogleLocationService",
32 "com.google.android.apps.maps\\u003AGoogleLocationService",
33 "com.google.android.apps.maps:LocationFriendService",
34 "com.google.android.apps.maps\\u003ALocationFriendService",
35 "com.google.android.apps.maps:MapsBackgroundService",
36 "com.google.android.apps.maps\\u003AMapsBackgroundService",
37 "com.google.android.apps.maps:NetworkLocationService",
38 "com.google.android.apps.maps\\u003ANetworkLocationService",
39 "com.android.chrome:sandboxed_process",
40 "com.android.chrome\\u003Asandboxed_process",
41 "com.android.fakeoemfeatures:background",
42 "com.android.fakeoemfeatures\\u003Abackground",
43 "com.android.fakeoemfeatures:core",
44 "com.android.fakeoemfeatures\\u003Acore",
45 "com.android.launcher:wallpaper_chooser",
46 "com.android.launcher\\u003Awallpaper_chooser",
47 "com.android.nfc:handover",
48 "com.android.nfc\\u003Ahandover",
49 "com.google.android.music:main",
50 "com.google.android.music\\u003Amain",
51 "com.google.android.music:ui",
52 "com.google.android.music\\u003Aui",
53 "com.google.android.setupwarlock:broker",
54 "com.google.android.setupwarlock\\u003Abroker",
55 "mobi.mgeek.TunnyBrowser:DolphinNotification",
56 "mobi.mgeek.TunnyBrowser\\u003ADolphinNotification",
57 "com.qo.android.sp.oem:Quickword",
58 "com.qo.android.sp.oem\\u003AQuickword",
66 /** Start of initialization. */
69 /** End of initialization. */
72 /** Start of initialization. */
75 /** End of initialization. */
79 /** Parent process ID. */
89 final String processName;
91 /** Class loader pointer. */
92 final int classLoader;
94 /** Type of record. */
97 /** Name of loaded class. */
98 final String className;
100 /** Record time (ns). */
103 /** Source file line# */
104 int sourceLineNumber;
107 * Parses a line from the loaded-classes file.
109 Record(String line, int lineNum) {
110 char typeChar = line.charAt(0);
112 case '>': type = Type.START_LOAD; break;
113 case '<': type = Type.END_LOAD; break;
114 case '+': type = Type.START_INIT; break;
115 case '-': type = Type.END_INIT; break;
116 default: throw new AssertionError("Bad line: " + line);
119 sourceLineNumber = lineNum;
121 for (int i = 0; i < REPLACE_CLASSES.length; i+= 2) {
122 line = line.replace(REPLACE_CLASSES[i], REPLACE_CLASSES[i+1]);
125 line = line.substring(1);
126 String[] parts = line.split(":");
128 ppid = Integer.parseInt(parts[0]);
129 pid = Integer.parseInt(parts[1]);
130 tid = Integer.parseInt(parts[2]);
132 processName = decode(parts[3]).intern();
134 classLoader = Integer.parseInt(parts[4]);
135 className = vmTypeToLanguage(decode(parts[5])).intern();
137 time = Long.parseLong(parts[6]);
141 * Decode any escaping that may have been written to the log line.
143 * Supports unicode-style escaping: \\uXXXX = character in hex
145 * @param rawField the field as it was written into the log
146 * @result the same field with any escaped characters replaced
148 String decode(String rawField) {
149 String result = rawField;
150 int offset = result.indexOf("\\u");
151 while (offset >= 0) {
152 String before = result.substring(0, offset);
153 String escaped = result.substring(offset+2, offset+6);
154 String after = result.substring(offset+6);
156 result = String.format("%s%c%s", before, Integer.parseInt(escaped, 16), after);
158 // find another but don't recurse
159 offset = result.indexOf("\\u", offset + 1);
165 * Converts a VM-style name to a language-style name.
167 String vmTypeToLanguage(String typeName) {
168 // if the typename is (null), just return it as-is. This is probably in dexopt and
169 // will be discarded anyway. NOTE: This corresponds to the case in dalvik/vm/oo/Class.c
170 // where dvmLinkClass() returns false and we clean up and exit.
171 if ("(null)".equals(typeName)) {
175 if (!typeName.startsWith("L") || !typeName.endsWith(";") ) {
176 throw new AssertionError("Bad name: " + typeName + " in line " + sourceLineNumber);
179 typeName = typeName.substring(1, typeName.length() - 1);
180 return typeName.replace("/", ".");