1 /* 2 * Copyright (C) 2024 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_CHUNKED_LINE_READER_H_ 18 #define SRC_TRACE_PROCESSOR_IMPORTERS_ANDROID_BUGREPORT_CHUNKED_LINE_READER_H_ 19 20 #include "perfetto/base/status.h" 21 #include "perfetto/ext/base/status_or.h" 22 #include "perfetto/ext/base/string_view.h" 23 #include "perfetto/trace_processor/trace_blob_view.h" 24 #include "src/trace_processor/importers/common/chunked_trace_reader.h" 25 26 namespace perfetto ::trace_processor { 27 28 // Adapter on top of `ChunkedTraceReader` that performs line by line parsing. 29 class ChunkedLineReader : public ChunkedTraceReader { 30 public: 31 base::Status Parse(TraceBlobView) final; 32 base::Status NotifyEndOfFile() final; 33 34 // Called for each line in the input. Each line is terminated by a '\n' 35 // character. The new line character will be included the `line`. 36 virtual base::Status ParseLine(base::StringView line) = 0; 37 38 // Similar to `NotifyEndOfFile` but this also provides any leftovers. That 39 // would heppen if the last line in a stream is not terminated by the newline 40 // character. 41 virtual void EndOfStream(base::StringView leftovers) = 0; 42 43 private: 44 base::StatusOr<TraceBlobView> SpliceLoop(TraceBlobView data); 45 base::Status OnLine(const TraceBlobView& data); 46 47 // Buffers any leftovers from a previous call to `Parse`; 48 TraceBlobView buffer_; 49 }; 50 51 } // namespace perfetto::trace_processor 52 #endif // SRC_TRACE_PROCESSOR_IMPORTERS_ANDROID_BUGREPORT_CHUNKED_LINE_READER_H_ 53