bool ListCommand::Run(const std::vector<std::string>& args) { static std::map<std::string, std::pair<int, std::string>> type_map = { {"hw", {PERF_TYPE_HARDWARE, "hardware events"}}, {"sw", {PERF_TYPE_SOFTWARE, "software events"}}, {"cache", {PERF_TYPE_HW_CACHE, "hw-cache events"}}, {"tracepoint", {PERF_TYPE_TRACEPOINT, "tracepoint events"}}, }; std::vector<std::string> names; if (args.empty()) { for (auto& item : type_map) { names.push_back(item.first); } } else { for (auto& arg : args) { if (type_map.find(arg) != type_map.end()) { names.push_back(arg); } else { LOG(ERROR) << "unknown event type category: " << arg << ", try using \"help list\""; return false; } } } auto& event_types = GetAllEventTypes(); for (auto& name : names) { auto it = type_map.find(name); PrintEventTypesOfType(it->second.first, it->second.second, event_types); } return true; }
const EventType* FindEventTypeByConfig(uint32_t type, uint64_t config) { for (auto& event_type : GetAllEventTypes()) { if (event_type.type == type && event_type.config == config) { return &event_type; } } return nullptr; }
const EventType* FindEventTypeByName(const std::string& name) { const EventType* result = nullptr; for (auto& event_type : GetAllEventTypes()) { if (event_type.name == name) { result = &event_type; break; } } if (result == nullptr) { LOG(ERROR) << "Unknown event_type '" << name << "', try `simpleperf list` to list all possible event type names"; return nullptr; } return result; }