• 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 #ifndef SRC_TRACE_PROCESSOR_IMPORTERS_ANDROID_BUGREPORT_ANDROID_BUGREPORT_PARSER_H_
18 #define SRC_TRACE_PROCESSOR_IMPORTERS_ANDROID_BUGREPORT_ANDROID_BUGREPORT_PARSER_H_
19 
20 #include <cstddef>
21 #include <vector>
22 
23 #include "perfetto/trace_processor/status.h"
24 #include "src/trace_processor/util/zip_reader.h"
25 
26 namespace perfetto {
27 namespace trace_processor {
28 
29 namespace util {
30 class ZipReader;
31 }
32 
33 struct AndroidLogEvent;
34 class TraceProcessorContext;
35 
36 // Trace importer for Android bugreport.zip archives.
37 class AndroidBugreportParser {
38  public:
39   static bool IsAndroidBugReport(
40       const std::vector<util::ZipFile>& zip_file_entries);
41   static util::Status Parse(TraceProcessorContext* context,
42                             std::vector<util::ZipFile> zip_file_entries);
43 
44  private:
45   AndroidBugreportParser(TraceProcessorContext* context,
46                          std::vector<util::ZipFile> zip_file_entries);
47   ~AndroidBugreportParser();
48   util::Status ParseImpl();
49 
50   bool DetectYearAndBrFilename();
51   void ParsePersistentLogcat();
52   void ParseDumpstateTxt();
53   void SortAndStoreLogcat();
54   void SortLogEvents();
55 
56   TraceProcessorContext* const context_;
57   std::vector<util::ZipFile> zip_file_entries_;
58   int br_year_ = 0;  // The year when the bugreport has been taken.
59   const util::ZipFile* dumpstate_file_ =
60       nullptr;  // The bugreport-xxx-2022-08-04....txt file
61   std::string build_fpr_;
62   std::vector<AndroidLogEvent> log_events_;
63   size_t log_events_last_sorted_idx_ = 0;
64 };
65 
66 }  // namespace trace_processor
67 }  // namespace perfetto
68 
69 #endif  // SRC_TRACE_PROCESSOR_IMPORTERS_ANDROID_BUGREPORT_ANDROID_BUGREPORT_PARSER_H_
70