static std::unique_ptr<EventFd> OpenHardwareEventOnCpu0() {
  std::unique_ptr<EventTypeAndModifier> event_type_modifier = ParseEventType("cpu-cycles");
  if (event_type_modifier == nullptr) {
    return nullptr;
  }
  perf_event_attr attr = CreateDefaultPerfEventAttr(event_type_modifier->event_type);
  return EventFd::OpenEventFile(attr, getpid(), 0);
}
Пример #2
0
static void PrintEventTypesOfType(uint32_t type, const std::string& type_name,
                                  const std::vector<EventType>& event_types) {
  printf("List of %s:\n", type_name.c_str());
  for (auto& event_type : event_types) {
    if (event_type.type == type &&
        IsEventAttrSupportedByKernel(CreateDefaultPerfEventAttr(event_type))) {
      printf("  %s\n", event_type.name.c_str());
    }
  }
  printf("\n");
}
static void PrintEventTypesOfType(uint32_t type, const std::string& type_name,
                                  const std::vector<EventType>& event_types) {
  printf("List of %s:\n", type_name.c_str());
  for (auto& event_type : event_types) {
    if (event_type.type == type) {
      perf_event_attr attr = CreateDefaultPerfEventAttr(event_type);
      // Exclude kernel to list supported events even when
      // /proc/sys/kernel/perf_event_paranoid is 2.
      attr.exclude_kernel = 1;
      if (IsEventAttrSupportedByKernel(attr)) {
        printf("  %s\n", event_type.name.c_str());
      }
    }
  }
  printf("\n");
}