• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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)22     public void CheckTraceFileFormat(File file, int expectedVersion) throws Exception {
23         InitializeParser(file);
24 
25         validateTraceHeader(expectedVersion);
26         boolean hasEntries = true;
27         boolean seenStopTracingMethod = false;
28         while (hasEntries) {
29             int headerType = GetEntryHeader();
30             switch (headerType) {
31                 case 1:
32                     ProcessMethodInfoEntry();
33                     break;
34                 case 2:
35                     ProcessThreadInfoEntry();
36                     break;
37                 case 3:
38                     // TODO(mythria): Add test to also check format of trace summary.
39                     hasEntries = false;
40                     break;
41                 default:
42                     int threadId = headerType;
43                     String eventString = ProcessEventEntry(threadId);
44                     if (ShouldIgnoreThread(threadId)) {
45                         break;
46                     }
47                     // Ignore events after method tracing was stopped. The code that is executed
48                     // later could be non-deterministic.
49                     if (!seenStopTracingMethod) {
50                         UpdateThreadEvents(threadId, eventString);
51                     }
52                     if (eventString.contains("Main$VMDebug $noinline$stopMethodTracing")) {
53                         seenStopTracingMethod = true;
54                     }
55             }
56         }
57         closeFile();
58 
59         // Printout the events.
60         for (String str : threadEventsMap.values()) {
61             System.out.println(str);
62         }
63     }
64 }
65