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