1 /* 2 ** 3 ** Copyright 2015, The Android Open Source Project 4 ** 5 ** Licensed under the Apache License, Version 2.0 (the "License"); 6 ** you may not use this file except in compliance with the License. 7 ** You may obtain a copy of the License at 8 ** 9 ** http://www.apache.org/licenses/LICENSE-2.0 10 ** 11 ** Unless required by applicable law or agreed to in writing, software 12 ** distributed under the License is distributed on an "AS IS" BASIS, 13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 ** See the License for the specific language governing permissions and 15 ** limitations under the License. 16 */ 17 18 #ifndef PERF_INTERNALS_H 19 #define PERF_INTERNALS_H 20 21 #include <linux/perf_event.h> 22 #include "kernel-headers/tools/perf/util/types.h" 23 #include "kernel-headers/tools/perf/util/include/linux/bitops.h" 24 #include "kernel-headers/tools/perf/util/include/linux/types.h" 25 #include "kernel-headers/tools/perf/util/build-id.h" 26 #include "kernel-headers/tools/perf/util/include/linux/kernel/kernel.h" 27 #include "kernel-headers/tools/perf/util/header.h" 28 #include "kernel-headers/tools/perf/util/event.h" 29 #include "kernel-headers/tools/perf/util/target.h" 30 #include "kernel-headers/tools/perf/perf.h" 31 32 // The first 64 bits of the perf header, used as a perf data file ID tag. 33 const uint64_t kPerfMagic = 0x32454c4946524550LL; // "PERFILE2" little-endian 34 35 #undef max 36 #undef min 37 38 // 39 // Wrapper class to manage creation/deletion of storage associated 40 // with perf_sample structs. 41 // 42 class PerfSampleCustodian { 43 public: PerfSampleCustodian(struct perf_sample & sample)44 explicit PerfSampleCustodian(struct perf_sample& sample) 45 : sample_(sample) { 46 sample.raw_data = NULL; 47 sample.callchain = NULL; 48 sample.branch_stack = NULL; 49 } ~PerfSampleCustodian()50 ~PerfSampleCustodian() { 51 if (sample_.callchain) 52 delete [] sample_.callchain; 53 if (sample_.branch_stack) 54 delete [] sample_.branch_stack; 55 if (sample_.branch_stack) 56 delete [] reinterpret_cast<char*>(sample_.raw_data); 57 } 58 private: 59 struct perf_sample& sample_; 60 }; 61 62 typedef perf_event event_t; 63 64 #endif 65