1*288bf522SAndroid Build Coastguard Worker /* 2*288bf522SAndroid Build Coastguard Worker * Copyright (C) 2015 The Android Open Source Project 3*288bf522SAndroid Build Coastguard Worker * 4*288bf522SAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*288bf522SAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*288bf522SAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*288bf522SAndroid Build Coastguard Worker * 8*288bf522SAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*288bf522SAndroid Build Coastguard Worker * 10*288bf522SAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*288bf522SAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*288bf522SAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*288bf522SAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*288bf522SAndroid Build Coastguard Worker * limitations under the License. 15*288bf522SAndroid Build Coastguard Worker */ 16*288bf522SAndroid Build Coastguard Worker 17*288bf522SAndroid Build Coastguard Worker #ifndef SIMPLE_PERF_EVENT_ATTR_H_ 18*288bf522SAndroid Build Coastguard Worker #define SIMPLE_PERF_EVENT_ATTR_H_ 19*288bf522SAndroid Build Coastguard Worker 20*288bf522SAndroid Build Coastguard Worker #include <stddef.h> 21*288bf522SAndroid Build Coastguard Worker #include <string.h> 22*288bf522SAndroid Build Coastguard Worker 23*288bf522SAndroid Build Coastguard Worker #include <string> 24*288bf522SAndroid Build Coastguard Worker #include <vector> 25*288bf522SAndroid Build Coastguard Worker 26*288bf522SAndroid Build Coastguard Worker #include "perf_event.h" 27*288bf522SAndroid Build Coastguard Worker 28*288bf522SAndroid Build Coastguard Worker namespace simpleperf { 29*288bf522SAndroid Build Coastguard Worker 30*288bf522SAndroid Build Coastguard Worker struct EventType; 31*288bf522SAndroid Build Coastguard Worker 32*288bf522SAndroid Build Coastguard Worker struct EventAttrWithId { 33*288bf522SAndroid Build Coastguard Worker perf_event_attr attr; 34*288bf522SAndroid Build Coastguard Worker std::vector<uint64_t> ids; 35*288bf522SAndroid Build Coastguard Worker }; 36*288bf522SAndroid Build Coastguard Worker 37*288bf522SAndroid Build Coastguard Worker using EventAttrIds = std::vector<EventAttrWithId>; 38*288bf522SAndroid Build Coastguard Worker 39*288bf522SAndroid Build Coastguard Worker inline constexpr uint64_t INFINITE_SAMPLE_PERIOD = 1ULL << 62; 40*288bf522SAndroid Build Coastguard Worker 41*288bf522SAndroid Build Coastguard Worker perf_event_attr CreateDefaultPerfEventAttr(const EventType& event_type); 42*288bf522SAndroid Build Coastguard Worker void DumpPerfEventAttr(const perf_event_attr& attr, size_t indent = 0); 43*288bf522SAndroid Build Coastguard Worker bool GetCommonEventIdPositionsForAttrs(const EventAttrIds& attrs, 44*288bf522SAndroid Build Coastguard Worker size_t* event_id_pos_in_sample_records, 45*288bf522SAndroid Build Coastguard Worker size_t* event_id_reverse_pos_in_non_sample_records); 46*288bf522SAndroid Build Coastguard Worker bool IsTimestampSupported(const perf_event_attr& attr); 47*288bf522SAndroid Build Coastguard Worker bool IsCpuSupported(const perf_event_attr& attr); 48*288bf522SAndroid Build Coastguard Worker // Return event name with modifier if the event is found, otherwise return "unknown". 49*288bf522SAndroid Build Coastguard Worker // This function is slow for using linear search, so only used when reporting. 50*288bf522SAndroid Build Coastguard Worker std::string GetEventNameByAttr(const perf_event_attr& attr); 51*288bf522SAndroid Build Coastguard Worker void ReplaceRegAndStackWithCallChain(perf_event_attr& attr); 52*288bf522SAndroid Build Coastguard Worker 53*288bf522SAndroid Build Coastguard Worker inline bool operator==(const perf_event_attr& attr1, const perf_event_attr& attr2) { 54*288bf522SAndroid Build Coastguard Worker return memcmp(&attr1, &attr2, sizeof(perf_event_attr)) == 0; 55*288bf522SAndroid Build Coastguard Worker } 56*288bf522SAndroid Build Coastguard Worker 57*288bf522SAndroid Build Coastguard Worker inline bool operator!=(const perf_event_attr& attr1, const perf_event_attr& attr2) { 58*288bf522SAndroid Build Coastguard Worker return !(attr1 == attr2); 59*288bf522SAndroid Build Coastguard Worker } 60*288bf522SAndroid Build Coastguard Worker 61*288bf522SAndroid Build Coastguard Worker } // namespace simpleperf 62*288bf522SAndroid Build Coastguard Worker 63*288bf522SAndroid Build Coastguard Worker #endif // SIMPLE_PERF_EVENT_ATTR_H_ 64