EventAttrWithName attr;
attr.attr = *attr_with_id.attr;
attr.event_ids = attr_with_id.ids;
- const EventType* event_type =
- FindEventTypeByConfig(attr.attr.type, attr.attr.config);
- if (event_type != nullptr) {
- attr.name = event_type->name;
- }
+ attr.name = GetEventNameByAttr(attr.attr);
event_attrs_.push_back(attr);
}
if (use_branch_address_) {
}
void DumpPerfEventAttr(const perf_event_attr& attr, size_t indent) {
- std::string event_name = "unknown";
- const EventType* event_type = FindEventTypeByConfig(attr.type, attr.config);
- if (event_type != nullptr) {
- event_name = event_type->name;
- }
-
+ std::string event_name = GetEventNameByAttr(attr);
PrintIndented(indent, "event_attr: for event type %s\n", event_name.c_str());
PrintIndented(indent + 1, "type %u, size %u, config %llu\n", attr.type, attr.size, attr.config);
bool IsTimestampSupported(const perf_event_attr& attr) {
return attr.sample_id_all && (attr.sample_type & PERF_SAMPLE_TIME);
}
+
+std::string GetEventNameByAttr(const perf_event_attr& attr) {
+ for (const auto& event_type : GetAllEventTypes()) {
+ if (event_type.type == attr.type && event_type.config == attr.config) {
+ std::string name = event_type.name;
+ if (attr.exclude_user && !attr.exclude_kernel) {
+ name += ":k";
+ } else if (attr.exclude_kernel && !attr.exclude_user) {
+ name += ":u";
+ }
+ return name;
+ }
+ }
+ return "unknown";
+}
#include <stddef.h>
+#include <string>
#include <vector>
#include "perf_event.h"
size_t* event_id_pos_in_sample_records,
size_t* event_id_reverse_pos_in_non_sample_records);
bool IsTimestampSupported(const perf_event_attr& attr);
+// Return event name with modifier if the event is found, otherwise return "unknown".
+std::string GetEventNameByAttr(const perf_event_attr& attr);
#endif // SIMPLE_PERF_EVENT_ATTR_H_
#include <android-base/logging.h>
#include <android-base/stringprintf.h>
+#include "event_attr.h"
#include "event_type.h"
#include "perf_event.h"
#include "utils.h"
std::unique_ptr<EventFd> EventFd::OpenEventFile(const perf_event_attr& attr, pid_t tid, int cpu,
bool report_error) {
perf_event_attr perf_attr = attr;
- std::string event_name = "unknown event";
- const EventType* event_type = FindEventTypeByConfig(perf_attr.type, perf_attr.config);
- if (event_type != nullptr) {
- event_name = event_type->name;
- }
+ std::string event_name = GetEventNameByAttr(attr);
int perf_event_fd = perf_event_open(&perf_attr, tid, cpu, -1, 0);
if (perf_event_fd == -1) {
if (report_error) {
return event_type_array;
}
-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()) {
};
const std::vector<EventType>& GetAllEventTypes();
-const EventType* FindEventTypeByConfig(uint32_t type, uint64_t config);
const EventType* FindEventTypeByName(const std::string& name);
struct EventTypeAndModifier {