1 /* 2 * Copyright (C) 2022 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 17 import java.io.File; 18 import java.io.IOException; 19 20 public class StreamTraceParser extends BaseTraceParser { 21 CheckTraceFileFormat(File file, int expectedVersion, String threadName)22 public void CheckTraceFileFormat(File file, 23 int expectedVersion, String threadName) throws Exception { 24 InitializeParser(file); 25 26 validateTraceHeader(expectedVersion); 27 boolean hasEntries = true; 28 boolean seenStopTracingMethod = false; 29 while (hasEntries) { 30 int threadId = GetThreadID(); 31 if (threadId != 0) { 32 String eventString = ProcessEventEntry(threadId); 33 // This is an event from one of the ignored methods. Don't record this entry. 34 if (eventString == null) { 35 continue; 36 } 37 if (!ShouldCheckThread(threadId, threadName)) { 38 continue; 39 } 40 // Ignore events after method tracing was stopped. The code that is executed 41 // later could be non-deterministic. 42 if (!seenStopTracingMethod) { 43 UpdateThreadEvents(threadId, eventString); 44 } 45 if (eventString.contains("Main$VMDebug $noinline$stopMethodTracing")) { 46 seenStopTracingMethod = true; 47 } 48 } else { 49 int headerType = GetEntryHeader(); 50 switch (headerType) { 51 case 1: 52 ProcessMethodInfoEntry(); 53 break; 54 case 2: 55 ProcessThreadInfoEntry(); 56 break; 57 case 3: 58 // TODO(mythria): Add test to also check format of trace summary. 59 hasEntries = false; 60 break; 61 default: 62 System.out.println("Unexpected header in the trace " + headerType); 63 } 64 } 65 } 66 closeFile(); 67 68 // Printout the events. 69 for (String str : threadEventsMap.values()) { 70 System.out.println(str); 71 } 72 } 73 } 74