1 /* 2 * Copyright (C) 2023 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_PERF_RECORD_PARSER_H_ 18 #define SRC_TRACE_PROCESSOR_IMPORTERS_PERF_RECORD_PARSER_H_ 19 20 #include <stdint.h> 21 #include <cstdint> 22 #include <vector> 23 24 #include "perfetto/base/status.h" 25 #include "src/trace_processor/importers/common/trace_parser.h" 26 #include "src/trace_processor/importers/perf/mmap_record.h" 27 #include "src/trace_processor/importers/perf/record.h" 28 #include "src/trace_processor/importers/perf/sample.h" 29 #include "src/trace_processor/storage/trace_storage.h" 30 31 namespace perfetto { 32 namespace trace_processor { 33 34 class TraceProcessorContext; 35 36 namespace perf_importer { 37 38 class PerfDataTracker; 39 class Reader; 40 41 // Parses samples from perf.data files. 42 class RecordParser : public PerfRecordParser { 43 public: 44 explicit RecordParser(TraceProcessorContext*); 45 ~RecordParser() override; 46 47 void ParsePerfRecord(int64_t timestamp, Record record) override; 48 49 private: 50 base::Status ParseRecord(int64_t timestamp, Record record); 51 base::Status ParseSample(int64_t ts, Record record); 52 base::Status ParseComm(Record record); 53 base::Status ParseMmap(Record record); 54 base::Status ParseMmap2(Record record); 55 56 base::Status InternSample(Sample sample); 57 58 base::Status UpdateCounters(const Sample& sample); 59 base::Status UpdateCountersInReadGroups(const Sample& sample); 60 61 std::optional<CallsiteId> InternCallchain( 62 UniquePid upid, 63 const std::vector<Sample::Frame>& callchain); 64 65 UniquePid GetUpid(const CommonMmapRecordFields& fields) const; 66 67 TraceProcessorContext* context_ = nullptr; 68 }; 69 70 } // namespace perf_importer 71 } // namespace trace_processor 72 } // namespace perfetto 73 74 #endif // SRC_TRACE_PROCESSOR_IMPORTERS_PERF_RECORD_PARSER_H_ 75