1 /* 2 * Copyright (C) 2024 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_MMAP_RECORD_H_ 18 #define SRC_TRACE_PROCESSOR_IMPORTERS_PERF_MMAP_RECORD_H_ 19 20 #include <cstdint> 21 #include <optional> 22 #include <string> 23 #include "perfetto/base/status.h" 24 #include "protos/perfetto/trace/profiling/profile_packet.pbzero.h" 25 #include "src/trace_processor/util/build_id.h" 26 27 namespace perfetto::trace_processor::perf_importer { 28 29 struct Record; 30 31 struct CommonMmapRecordFields { 32 uint32_t pid; 33 uint32_t tid; 34 uint64_t addr; 35 uint64_t len; 36 uint64_t pgoff; 37 }; 38 39 struct MmapRecord : public CommonMmapRecordFields { 40 std::string filename; 41 protos::pbzero::Profiling::CpuMode cpu_mode; 42 43 base::Status Parse(const Record& record); 44 }; 45 46 struct BaseMmap2Record : public CommonMmapRecordFields { 47 struct BuildIdFields { 48 static constexpr size_t kMaxBuildIdSize = 20; 49 uint8_t build_id_size; 50 uint8_t reserved_1; 51 uint16_t reserved_2; 52 char build_id_buf[kMaxBuildIdSize]; 53 }; 54 struct InodeFields { 55 uint32_t maj; 56 uint32_t min; 57 int64_t ino; 58 uint64_t ino_generation; 59 }; 60 static_assert(sizeof(BuildIdFields) == sizeof(InodeFields)); 61 62 union { 63 BuildIdFields build_id; 64 InodeFields inode; 65 }; 66 uint32_t prot; 67 uint32_t flags; 68 }; 69 70 struct Mmap2Record : public BaseMmap2Record { 71 std::string filename; 72 protos::pbzero::Profiling::CpuMode cpu_mode; 73 bool has_build_id; 74 75 base::Status Parse(const Record& record); 76 std::optional<BuildId> GetBuildId() const; 77 }; 78 79 } // namespace perfetto::trace_processor::perf_importer 80 81 #endif // SRC_TRACE_PROCESSOR_IMPORTERS_PERF_MMAP_RECORD_H_ 82