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 if (!ShouldCheckThread(threadId, threadName)) { 34 continue; 35 } 36 // Ignore events after method tracing was stopped. The code that is executed 37 // later could be non-deterministic. 38 if (!seenStopTracingMethod) { 39 UpdateThreadEvents(threadId, eventString); 40 } 41 if (eventString.contains("Main$VMDebug $noinline$stopMethodTracing")) { 42 seenStopTracingMethod = true; 43 } 44 } else { 45 int headerType = GetEntryHeader(); 46 switch (headerType) { 47 case 1: 48 ProcessMethodInfoEntry(); 49 break; 50 case 2: 51 ProcessThreadInfoEntry(); 52 break; 53 case 3: 54 // TODO(mythria): Add test to also check format of trace summary. 55 hasEntries = false; 56 break; 57 default: 58 System.out.println("Unexpected header in the trace " + headerType); 59 } 60 } 61 } 62 closeFile(); 63 64 // Printout the events. 65 for (String str : threadEventsMap.values()) { 66 System.out.println(str); 67 } 68 } 69 } 70