Home | History | Annotate | Download | only in simpleperf
      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[];
     51     } symbol_table;
     52   };
     53 
     54 meta_info feature section:
     55   meta_info infos[];
     56 
     57   struct meta_info {
     58     char key[];
     59     char value[];
     60   };
     61   keys in meta_info feature section include:
     62     simpleperf_version,
     63 
     64 */
     65 
     66 namespace PerfFileFormat {
     67 
     68 enum {
     69   FEAT_RESERVED = 0,
     70   FEAT_FIRST_FEATURE = 1,
     71   FEAT_TRACING_DATA = 1,
     72   FEAT_BUILD_ID,
     73   FEAT_HOSTNAME,
     74   FEAT_OSRELEASE,
     75   FEAT_VERSION,
     76   FEAT_ARCH,
     77   FEAT_NRCPUS,
     78   FEAT_CPUDESC,
     79   FEAT_CPUID,
     80   FEAT_TOTAL_MEM,
     81   FEAT_CMDLINE,
     82   FEAT_EVENT_DESC,
     83   FEAT_CPU_TOPOLOGY,
     84   FEAT_NUMA_TOPOLOGY,
     85   FEAT_BRANCH_STACK,
     86   FEAT_PMU_MAPPINGS,
     87   FEAT_GROUP_DESC,
     88   FEAT_LAST_FEATURE,
     89 
     90   FEAT_SIMPLEPERF_START = 128,
     91   FEAT_FILE = FEAT_SIMPLEPERF_START,
     92   FEAT_META_INFO,
     93   FEAT_MAX_NUM = 256,
     94 };
     95 
     96 std::string GetFeatureName(int feature_id);
     97 int GetFeatureId(const std::string& feature_name);
     98 
     99 struct SectionDesc {
    100   uint64_t offset;
    101   uint64_t size;
    102 };
    103 
    104 constexpr char PERF_MAGIC[] = "PERFILE2";
    105 
    106 struct FileHeader {
    107   char magic[8];
    108   uint64_t header_size;
    109   uint64_t attr_size;
    110   SectionDesc attrs;
    111   SectionDesc data;
    112   SectionDesc event_types;
    113   unsigned char features[FEAT_MAX_NUM / 8];
    114 };
    115 
    116 struct FileAttr {
    117   perf_event_attr attr;
    118   SectionDesc ids;
    119 };
    120 
    121 }  // namespace PerfFileFormat
    122 
    123 #endif  // SIMPLE_PERF_RECORD_FILE_FORMAT_H_
    124