1 /* 2 * Copyright (C) 2021 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_UTIL_DEBUG_ANNOTATION_PARSER_H_ 18 #define SRC_TRACE_PROCESSOR_UTIL_DEBUG_ANNOTATION_PARSER_H_ 19 20 #include <string> 21 22 #include "perfetto/base/status.h" 23 #include "perfetto/protozero/field.h" 24 #include "src/trace_processor/util/proto_to_args_parser.h" 25 26 #include "protos/perfetto/trace/track_event/debug_annotation.pbzero.h" 27 28 namespace perfetto::trace_processor::util { 29 30 // |DebugAnnotationParser| is responsible for parsing DebugAnnotation protos 31 // and turning it into key-value arg pairs. 32 // |DebugAnnotationParser| is a logical extension of |ProtoToArgsParser|: 33 // it uses |ProtoToArgsParser::Delegate| for writing the results and uses 34 // |ProtoToArgsParser| to parse arbitrary protos nested inside DebugAnnotation. 35 class DebugAnnotationParser { 36 public: 37 explicit DebugAnnotationParser(ProtoToArgsParser& proto_to_args_parser); 38 39 base::Status Parse(protozero::ConstBytes data, 40 ProtoToArgsParser::Delegate& delegate); 41 42 private: 43 struct ParseResult { 44 base::Status status; 45 // True if parsing of the annotation added at least one entry to the 46 // |delegate|. 47 bool added_entry; 48 }; 49 50 static base::Status ParseDebugAnnotationName( 51 protos::pbzero::DebugAnnotation::Decoder& annotation, 52 ProtoToArgsParser::Delegate& delegate, 53 std::string& result); 54 ParseResult ParseDebugAnnotationValue( 55 protos::pbzero::DebugAnnotation::Decoder& annotation, 56 ProtoToArgsParser::Delegate& delegate, 57 const ProtoToArgsParser::Key& context_name); 58 ParseResult ParseNestedValueArgs(protozero::ConstBytes nested_value, 59 const ProtoToArgsParser::Key& context_name, 60 ProtoToArgsParser::Delegate& delegate); 61 62 ProtoToArgsParser& proto_to_args_parser_; 63 }; 64 65 } // namespace perfetto::trace_processor::util 66 67 #endif // SRC_TRACE_PROCESSOR_UTIL_DEBUG_ANNOTATION_PARSER_H_ 68