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 "src/trace_processor/importers/common/chunked_trace_reader.h" 21 #include "src/trace_processor/storage/trace_storage.h" 22 23 namespace perfetto { 24 namespace trace_processor { 25 26 namespace util { 27 class ZipReader; 28 } 29 30 struct AndroidLogEvent; 31 class TraceProcessorContext; 32 33 // Trace importer for Android bugreport.zip archives. 34 class AndroidBugreportParser : public ChunkedTraceReader { 35 public: 36 explicit AndroidBugreportParser(TraceProcessorContext*); 37 ~AndroidBugreportParser() override; 38 39 // ChunkedTraceReader implementation. 40 util::Status Parse(TraceBlobView) override; 41 void NotifyEndOfFile() override; 42 43 private: 44 bool DetectYearAndBrFilename(); 45 void ParsePersistentLogcat(); 46 void ParseDumpstateTxt(); 47 void SortAndStoreLogcat(); 48 void SortLogEvents(); 49 50 TraceProcessorContext* const context_; 51 int br_year_ = 0; // The year when the bugreport has been taken. 52 std::string dumpstate_fname_; // The name of bugreport-xxx-2022-08-04....txt 53 std::string build_fpr_; 54 bool first_chunk_seen_ = false; 55 std::unique_ptr<util::ZipReader> zip_reader_; 56 std::vector<AndroidLogEvent> log_events_; 57 size_t log_events_last_sorted_idx_ = 0; 58 }; 59 60 } // namespace trace_processor 61 } // namespace perfetto 62 63 #endif // SRC_TRACE_PROCESSOR_IMPORTERS_ANDROID_BUGREPORT_ANDROID_BUGREPORT_PARSER_H_ 64