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_DUMPSTATE_READER_H_
18 #define SRC_TRACE_PROCESSOR_IMPORTERS_ANDROID_BUGREPORT_ANDROID_DUMPSTATE_READER_H_
19 
20 #include "src/trace_processor/importers/android_bugreport/android_battery_stats_reader.h"
21 #include "src/trace_processor/importers/android_bugreport/android_log_reader.h"
22 #include "src/trace_processor/importers/android_bugreport/chunked_line_reader.h"
23 #include "src/trace_processor/storage/trace_storage.h"
24 
25 namespace perfetto::trace_processor {
26 
27 class TraceProcessorContext;
28 
29 // Trace importer for Android dumpstate files.
30 class AndroidDumpstateReader : public ChunkedLineReader {
31  public:
32   // Create a reader that will only forward events that are not present in the
33   // given list.
34   AndroidDumpstateReader(
35       TraceProcessorContext* context,
36       int32_t year = 0,
37       std::vector<TimestampedAndroidLogEvent> logcat_events = {});
38   ~AndroidDumpstateReader() override;
39 
40   base::Status ParseLine(base::StringView line) override;
41   void EndOfStream(base::StringView leftovers) override;
42 
43  private:
44   enum class Section { kOther = 0, kDumpsys, kLog, kBatteryStats };
45   TraceProcessorContext* const context_;
46   AndroidBatteryStatsReader battery_stats_reader_;
47   DedupingAndroidLogReader log_reader_;
48   Section current_section_ = Section::kOther;
49   StringId current_section_id_ = StringId::Null();
50   StringId current_service_id_ = StringId::Null();
51 };
52 
53 }  // namespace perfetto::trace_processor
54 
55 #endif  // SRC_TRACE_PROCESSOR_IMPORTERS_ANDROID_BUGREPORT_ANDROID_DUMPSTATE_READER_H_
56