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_EVENT_H_ 18 #define SIMPLE_PERF_EVENT_H_ 19 20 #include <stdint.h> 21 #include <strings.h> 22 #include <memory> 23 #include <set> 24 #include <string> 25 #include <vector> 26 27 // EventType represents one type of event, like cpu_cycle_event, cache_misses_event. 28 // The user knows one event type by its name, and the kernel knows one event type by its 29 // (type, config) pair. EventType connects the two representations, and tells the user if 30 // the event type is supported by the kernel. 31 32 struct EventType { EventTypeEventType33 EventType(const std::string& name, uint32_t type, uint64_t config, 34 const std::string& description, const std::string& limited_arch) 35 : name(name), type(type), config(config), description(description), 36 limited_arch(limited_arch) { 37 } 38 EventTypeEventType39 EventType() : type(0), config(0) { 40 } 41 42 bool operator<(const EventType& other) const { 43 return strcasecmp(name.c_str(), other.name.c_str()) < 0; 44 } 45 IsPmuEventEventType46 bool IsPmuEvent() const { 47 return name.find('/') != std::string::npos; 48 } 49 50 std::vector<int> GetPmuCpumask(); 51 52 std::string name; 53 uint32_t type; 54 uint64_t config; 55 std::string description; 56 std::string limited_arch; 57 }; 58 59 bool SetTracepointEventsFilePath(const std::string& filepath); 60 std::string GetTracepointEvents(); 61 62 // Used to temporarily change event types returned by GetAllEventTypes(). 63 class ScopedEventTypes { 64 public: 65 static std::string BuildString(const std::vector<const EventType*>& event_types); 66 67 ScopedEventTypes(const std::string& event_type_str); 68 ~ScopedEventTypes(); 69 70 private: 71 std::set<EventType> saved_event_types_; 72 uint32_t saved_etm_event_type_; 73 }; 74 75 const std::set<EventType>& GetAllEventTypes(); 76 const EventType* FindEventTypeByName(const std::string& name, bool report_error = true); 77 78 struct EventTypeAndModifier { 79 std::string name; 80 EventType event_type; 81 std::string modifier; 82 bool exclude_user; 83 bool exclude_kernel; 84 bool exclude_hv; 85 bool exclude_host; 86 bool exclude_guest; 87 int precise_ip : 2; 88 EventTypeAndModifierEventTypeAndModifier89 EventTypeAndModifier() 90 : exclude_user(false), 91 exclude_kernel(false), 92 exclude_hv(false), 93 exclude_host(false), 94 exclude_guest(false), 95 precise_ip(0) { 96 } 97 }; 98 99 std::unique_ptr<EventTypeAndModifier> ParseEventType(const std::string& event_type_str); 100 bool IsEtmEventType(uint32_t type); 101 102 #endif // SIMPLE_PERF_EVENT_H_ 103