1 /* 2 * Copyright (C) 2015 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 SIMPLE_PERF_RECORD_FILE_FORMAT_H_ 18 #define SIMPLE_PERF_RECORD_FILE_FORMAT_H_ 19 20 #include "perf_event.h" 21 22 /* 23 The file structure of perf.data: 24 file_header 25 id_section 26 attr section 27 data section 28 feature section 29 30 The feature section has the following structure: 31 a section descriptor array, each element contains the section information of one add_feature. 32 data section of feature 1 33 data section of feature 2 34 .... 35 36 file feature section: 37 file_struct files[]; 38 39 struct file_struct { 40 uint32_t size; // size of rest fields in file_struct 41 char file_path[]; 42 uint32_t file_type; 43 uint64_t min_vaddr; 44 uint32_t symbol_count; 45 struct { 46 uint64_t start_vaddr; 47 uint32_t len; 48 char symbol_name[]; 49 } symbol_table; 50 }; 51 52 meta_info feature section: 53 meta_info infos[]; 54 55 struct meta_info { 56 char key[]; 57 char value[]; 58 }; 59 keys in meta_info feature section include: 60 simpleperf_version, 61 62 */ 63 64 namespace PerfFileFormat { 65 66 enum { 67 FEAT_RESERVED = 0, 68 FEAT_FIRST_FEATURE = 1, 69 FEAT_TRACING_DATA = 1, 70 FEAT_BUILD_ID, 71 FEAT_HOSTNAME, 72 FEAT_OSRELEASE, 73 FEAT_VERSION, 74 FEAT_ARCH, 75 FEAT_NRCPUS, 76 FEAT_CPUDESC, 77 FEAT_CPUID, 78 FEAT_TOTAL_MEM, 79 FEAT_CMDLINE, 80 FEAT_EVENT_DESC, 81 FEAT_CPU_TOPOLOGY, 82 FEAT_NUMA_TOPOLOGY, 83 FEAT_BRANCH_STACK, 84 FEAT_PMU_MAPPINGS, 85 FEAT_GROUP_DESC, 86 FEAT_LAST_FEATURE, 87 88 FEAT_SIMPLEPERF_START = 128, 89 FEAT_FILE = FEAT_SIMPLEPERF_START, 90 FEAT_META_INFO, 91 FEAT_MAX_NUM = 256, 92 }; 93 94 struct SectionDesc { 95 uint64_t offset; 96 uint64_t size; 97 }; 98 99 constexpr char PERF_MAGIC[] = "PERFILE2"; 100 101 struct FileHeader { 102 char magic[8]; 103 uint64_t header_size; 104 uint64_t attr_size; 105 SectionDesc attrs; 106 SectionDesc data; 107 SectionDesc event_types; 108 unsigned char features[FEAT_MAX_NUM / 8]; 109 }; 110 111 struct FileAttr { 112 perf_event_attr attr; 113 SectionDesc ids; 114 }; 115 116 } // namespace PerfFileFormat 117 118 #endif // SIMPLE_PERF_RECORD_FILE_FORMAT_H_ 119