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 "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 // file feature section:
     36 //  file_struct files[];
     37 //
     38 //  struct file_struct {
     39 //    uint32_t size;  // size of rest fields in file_struct
     40 //    char file_path[];
     41 //    uint32_t file_type;
     42 //    uint64_t min_vaddr;
     43 //    uint32_t symbol_count;
     44 //    struct {
     45 //      uint64_t start_vaddr;
     46 //      uint32_t len;
     47 //      char symbol_name[];
     48 //    } symbol_table;
     49 //  };
     50 
     51 namespace PerfFileFormat {
     52 
     53 enum {
     54   FEAT_RESERVED = 0,
     55   FEAT_FIRST_FEATURE = 1,
     56   FEAT_TRACING_DATA = 1,
     57   FEAT_BUILD_ID,
     58   FEAT_HOSTNAME,
     59   FEAT_OSRELEASE,
     60   FEAT_VERSION,
     61   FEAT_ARCH,
     62   FEAT_NRCPUS,
     63   FEAT_CPUDESC,
     64   FEAT_CPUID,
     65   FEAT_TOTAL_MEM,
     66   FEAT_CMDLINE,
     67   FEAT_EVENT_DESC,
     68   FEAT_CPU_TOPOLOGY,
     69   FEAT_NUMA_TOPOLOGY,
     70   FEAT_BRANCH_STACK,
     71   FEAT_PMU_MAPPINGS,
     72   FEAT_GROUP_DESC,
     73   FEAT_LAST_FEATURE,
     74 
     75   FEAT_SIMPLEPERF_START = 128,
     76   FEAT_FILE = FEAT_SIMPLEPERF_START,
     77   FEAT_MAX_NUM = 256,
     78 };
     79 
     80 struct SectionDesc {
     81   uint64_t offset;
     82   uint64_t size;
     83 };
     84 
     85 constexpr char PERF_MAGIC[] = "PERFILE2";
     86 
     87 struct FileHeader {
     88   char magic[8];
     89   uint64_t header_size;
     90   uint64_t attr_size;
     91   SectionDesc attrs;
     92   SectionDesc data;
     93   SectionDesc event_types;
     94   unsigned char features[FEAT_MAX_NUM / 8];
     95 };
     96 
     97 struct FileAttr {
     98   perf_event_attr attr;
     99   SectionDesc ids;
    100 };
    101 
    102 }  // namespace PerfFileFormat
    103 
    104 #endif  // SIMPLE_PERF_RECORD_FILE_FORMAT_H_
    105