1 /* 2 * Copyright (C) 2019 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_FUCHSIA_FUCHSIA_TRACE_PARSER_H_ 18 #define SRC_TRACE_PROCESSOR_IMPORTERS_FUCHSIA_FUCHSIA_TRACE_PARSER_H_ 19 20 #include <functional> 21 #include <optional> 22 #include <vector> 23 24 #include "src/trace_processor/importers/common/trace_parser.h" 25 #include "src/trace_processor/importers/fuchsia/fuchsia_record.h" 26 #include "src/trace_processor/importers/fuchsia/fuchsia_trace_utils.h" 27 28 namespace perfetto { 29 namespace trace_processor { 30 31 class TraceProcessorContext; 32 33 class FuchsiaTraceParser : public FuchsiaRecordParser { 34 public: 35 explicit FuchsiaTraceParser(TraceProcessorContext*); 36 ~FuchsiaTraceParser() override; 37 38 void ParseFuchsiaRecord(int64_t timestamp, FuchsiaRecord fr) override; 39 40 struct Arg { 41 StringId name; 42 fuchsia_trace_utils::ArgValue value; 43 }; 44 45 // Utility to parse record arguments. Exposed here to provide consistent 46 // parsing between trace parsing and tokenization. 47 // 48 // Returns an empty optional on error, otherwise a vector containing zero or 49 // more arguments. 50 static std::optional<std::vector<Arg>> ParseArgs( 51 fuchsia_trace_utils::RecordCursor& cursor, 52 uint32_t n_args, 53 std::function<StringId(base::StringView string)> intern_string, 54 std::function<StringId(uint32_t index)> get_string); 55 56 private: 57 TraceProcessorContext* const context_; 58 }; 59 60 } // namespace trace_processor 61 } // namespace perfetto 62 63 #endif // SRC_TRACE_PROCESSOR_IMPORTERS_FUCHSIA_FUCHSIA_TRACE_PARSER_H_ 64