simpleperf: add type modifier when reporting events.

Before the change:
$simpleperf record -e cpu-cycles:u sleep 1
$simpleperf report
...
Event: cpu-cycles (type 0, config 0)
...

After the change:
$simpleperf report
...
Event: cpu-cycles:u (type 0, config 0)
...

Change-Id: I296c5476e03250e928ed0f579483d6866576d417
diff --git a/simpleperf/cmd_report.cpp b/simpleperf/cmd_report.cpp
index 90e0778..ef2a93d 100644
--- a/simpleperf/cmd_report.cpp
+++ b/simpleperf/cmd_report.cpp
@@ -512,11 +512,7 @@
     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_) {
diff --git a/simpleperf/event_attr.cpp b/simpleperf/event_attr.cpp
index 12ab1ad..10cef52 100644
--- a/simpleperf/event_attr.cpp
+++ b/simpleperf/event_attr.cpp
@@ -98,12 +98,7 @@
 }
 
 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);
@@ -226,3 +221,18 @@
 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";
+}
diff --git a/simpleperf/event_attr.h b/simpleperf/event_attr.h
index df97c2f..030f7c9 100644
--- a/simpleperf/event_attr.h
+++ b/simpleperf/event_attr.h
@@ -19,6 +19,7 @@
 
 #include <stddef.h>
 
+#include <string>
 #include <vector>
 
 #include "perf_event.h"
@@ -31,5 +32,7 @@
                                        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_
diff --git a/simpleperf/event_fd.cpp b/simpleperf/event_fd.cpp
index eb09191..705d6f3 100644
--- a/simpleperf/event_fd.cpp
+++ b/simpleperf/event_fd.cpp
@@ -31,6 +31,7 @@
 #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"
@@ -45,11 +46,7 @@
 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) {
diff --git a/simpleperf/event_type.cpp b/simpleperf/event_type.cpp
index 2eaafa2..83b900e 100644
--- a/simpleperf/event_type.cpp
+++ b/simpleperf/event_type.cpp
@@ -74,15 +74,6 @@
   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()) {
diff --git a/simpleperf/event_type.h b/simpleperf/event_type.h
index 4100125..12d83b3 100644
--- a/simpleperf/event_type.h
+++ b/simpleperf/event_type.h
@@ -41,7 +41,6 @@
 };
 
 const std::vector<EventType>& GetAllEventTypes();
-const EventType* FindEventTypeByConfig(uint32_t type, uint64_t config);
 const EventType* FindEventTypeByName(const std::string& name);
 
 struct EventTypeAndModifier {