• 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 "perf_event.h"
21 
22 // The file structure of perf.data:
23 //    file_header
24 //    id_section
25 //    attr section
26 //    data section
27 //    feature section
28 //
29 //  The feature section has the following structure:
30 //    a section descriptor array, each element contains the section information of one add_feature.
31 //    data section of feature 1
32 //    data section of feature 2
33 //    ....
34 
35 namespace PerfFileFormat {
36 
37 enum {
38   FEAT_RESERVED = 0,
39   FEAT_FIRST_FEATURE = 1,
40   FEAT_TRACING_DATA = 1,
41   FEAT_BUILD_ID,
42   FEAT_HOSTNAME,
43   FEAT_OSRELEASE,
44   FEAT_VERSION,
45   FEAT_ARCH,
46   FEAT_NRCPUS,
47   FEAT_CPUDESC,
48   FEAT_CPUID,
49   FEAT_TOTAL_MEM,
50   FEAT_CMDLINE,
51   FEAT_EVENT_DESC,
52   FEAT_CPU_TOPOLOGY,
53   FEAT_NUMA_TOPOLOGY,
54   FEAT_BRANCH_STACK,
55   FEAT_PMU_MAPPINGS,
56   FEAT_GROUP_DESC,
57   FEAT_LAST_FEATURE,
58   FEAT_MAX_NUM = 256,
59 };
60 
61 struct SectionDesc {
62   uint64_t offset;
63   uint64_t size;
64 };
65 
66 constexpr char PERF_MAGIC[] = "PERFILE2";
67 
68 struct FileHeader {
69   char magic[8];
70   uint64_t header_size;
71   uint64_t attr_size;
72   SectionDesc attrs;
73   SectionDesc data;
74   SectionDesc event_types;
75   unsigned char features[FEAT_MAX_NUM / 8];
76 };
77 
78 struct FileAttr {
79   perf_event_attr attr;
80   SectionDesc ids;
81 };
82 
83 }  // namespace PerfFileFormat
84 
85 #endif  // SIMPLE_PERF_RECORD_FILE_FORMAT_H_
86