• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <string>
21 
22 #include "perf_event.h"
23 
24 /*
25 The file structure of perf.data:
26     file_header
27     id_section
28     attr section
29     data section
30     feature section
31 
32 The feature section has the following structure:
33     a section descriptor array, each element contains the section information of one add_feature.
34     data section of feature 1
35     data section of feature 2
36     ....
37 
38 file feature section:
39   file_struct files[];
40 
41   struct file_struct {
42     uint32_t size;  // size of rest fields in file_struct
43     char file_path[];
44     uint32_t file_type;
45     uint64_t min_vaddr;
46     uint32_t symbol_count;
47     struct {
48       uint64_t start_vaddr;
49       uint32_t len;
50       char symbol_name[len+1];
51     } symbol_table[symbol_count];
52 
53     uint32_t dex_file_offset_count;  // Only when file_type = DSO_DEX_FILE
54     uint64_t dex_file_offsets[dex_file_offset_count];  // Only when file_type = DSO_DEX_FILE
55     uint64_t file_offset_of_min_vaddr;  // Only when file_type = DSO_ELF_FILE
56     uint64_t memory_offset_of_min_vaddr;  // Only when file_type = DSO_KERNEL_MODULE
57   };
58 
59 meta_info feature section:
60   meta_info infos[];
61 
62   struct meta_info {
63     char key[];
64     char value[];
65   };
66   keys in meta_info feature section include:
67     simpleperf_version,
68 
69 debug_unwind feature section:
70   message DebugUnwindFeature from record_file.proto
71 
72 debug_unwind_file feature section:
73   data for file 1
74   data for file 2
75   ...
76 
77   The file list is stored in debug_unwind feature section.
78 
79 file2 feature section (used to replace file feature section):
80   uint32_t file_msg1_size;
81   FileFeature file_msg1;  // FileFeature from record_file.proto
82   uint32_t file_msg2_size;
83   FileFeature file_msg2;
84   ...
85 
86 etm_branch_list feature section:
87   ETMBranchList etm_branch_list;  // from etm_branch_list.proto
88 */
89 
90 namespace simpleperf {
91 namespace PerfFileFormat {
92 
93 enum {
94   FEAT_RESERVED = 0,
95   FEAT_FIRST_FEATURE = 1,
96   FEAT_TRACING_DATA = 1,
97   FEAT_BUILD_ID,
98   FEAT_HOSTNAME,
99   FEAT_OSRELEASE,
100   FEAT_VERSION,
101   FEAT_ARCH,
102   FEAT_NRCPUS,
103   FEAT_CPUDESC,
104   FEAT_CPUID,
105   FEAT_TOTAL_MEM,
106   FEAT_CMDLINE,
107   FEAT_EVENT_DESC,
108   FEAT_CPU_TOPOLOGY,
109   FEAT_NUMA_TOPOLOGY,
110   FEAT_BRANCH_STACK,
111   FEAT_PMU_MAPPINGS,
112   FEAT_GROUP_DESC,
113   FEAT_AUXTRACE,
114   FEAT_LAST_FEATURE,
115 
116   FEAT_SIMPLEPERF_START = 128,
117   FEAT_FILE = FEAT_SIMPLEPERF_START,
118   FEAT_META_INFO,
119   FEAT_DEBUG_UNWIND,
120   FEAT_DEBUG_UNWIND_FILE,
121   FEAT_FILE2,
122   FEAT_ETM_BRANCH_LIST,
123   FEAT_MAX_NUM = 256,
124 };
125 
126 std::string GetFeatureName(int feature_id);
127 int GetFeatureId(const std::string& feature_name);
128 
129 struct SectionDesc {
130   uint64_t offset;
131   uint64_t size;
132 };
133 
134 constexpr char PERF_MAGIC[] = "PERFILE2";
135 
136 struct FileHeader {
137   char magic[8];
138   uint64_t header_size;
139   uint64_t attr_size;
140   SectionDesc attrs;
141   SectionDesc data;
142   SectionDesc event_types;
143   unsigned char features[FEAT_MAX_NUM / 8];
144 };
145 
146 struct FileAttr {
147   perf_event_attr attr;
148   SectionDesc ids;
149 };
150 
151 }  // namespace PerfFileFormat
152 }  // namespace simpleperf
153 
154 #endif  // SIMPLE_PERF_RECORD_FILE_FORMAT_H_
155