• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "src/trace_processor/importers/proto/proto_trace_parser.h"
28 
29 namespace perfetto {
30 namespace trace_processor {
31 
32 class TraceProcessorContext;
33 
34 class FuchsiaTraceParser : public TraceParser {
35  public:
36   explicit FuchsiaTraceParser(TraceProcessorContext*);
37   ~FuchsiaTraceParser() override;
38 
39   // TraceParser implementation
40   void ParseFuchsiaRecord(int64_t timestamp, FuchsiaRecord fr) override;
41   void ParseTrackEvent(int64_t, TrackEventData) override;
42   void ParseTracePacket(int64_t ts, TracePacketData data) override;
43 
44   struct Arg {
45     StringId name;
46     fuchsia_trace_utils::ArgValue value;
47   };
48 
49   // Utility to parse record arguments. Exposed here to provide consistent
50   // parsing between trace parsing and tokenization.
51   //
52   // Returns an empty optional on error, otherwise a vector containing zero or
53   // more arguments.
54   static std::optional<std::vector<Arg>> ParseArgs(
55       fuchsia_trace_utils::RecordCursor& cursor,
56       uint32_t n_args,
57       std::function<StringId(base::StringView string)> intern_string,
58       std::function<StringId(uint32_t index)> get_string);
59 
60  private:
61   TraceProcessorContext* const context_;
62   std::unique_ptr<ProtoTraceParser> proto_parser_;
63 };
64 
65 }  // namespace trace_processor
66 }  // namespace perfetto
67 
68 #endif  // SRC_TRACE_PROCESSOR_IMPORTERS_FUCHSIA_FUCHSIA_TRACE_PARSER_H_
69