1 /* 2 * Copyright (C) 2018 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_JSON_TRACE_PARSER_H_ 18 #define SRC_TRACE_PROCESSOR_JSON_TRACE_PARSER_H_ 19 20 #include <stdint.h> 21 22 #include <memory> 23 #include <tuple> 24 #include <unordered_map> 25 26 #include "src/trace_processor/trace_parser.h" 27 #include "src/trace_processor/trace_sorter.h" 28 #include "src/trace_processor/trace_storage.h" 29 30 namespace Json { 31 class Value; 32 } 33 34 namespace perfetto { 35 namespace trace_processor { 36 37 class TraceProcessorContext; 38 39 base::Optional<int64_t> CoerceToInt64(const Json::Value& value); 40 base::Optional<uint32_t> CoerceToUint32(const Json::Value& value); 41 42 // Parses legacy chrome JSON traces. The support for now is extremely rough 43 // and supports only explicit TRACE_EVENT_BEGIN/END events. 44 class JsonTraceParser : public TraceParser { 45 public: 46 explicit JsonTraceParser(TraceProcessorContext*); 47 ~JsonTraceParser() override; 48 49 // TraceParser implementation. 50 void ParseTracePacket(int64_t timestamp, 51 TraceSorter::TimestampedTracePiece) override; 52 void ParseFtracePacket(uint32_t, 53 int64_t, 54 TraceSorter::TimestampedTracePiece) override; 55 56 private: 57 TraceProcessorContext* const context_; 58 }; 59 60 } // namespace trace_processor 61 } // namespace perfetto 62 63 #endif // SRC_TRACE_PROCESSOR_JSON_TRACE_PARSER_H_ 64