Reformatting code + static initializers

This commit is contained in:
Andrey Skobtsov 2020-03-06 19:31:31 +03:00
parent 50c603a74c
commit 0f1dff21b2
2 changed files with 12 additions and 18 deletions

View File

@ -47,7 +47,7 @@ namespace DB {
// This reports the CPU clock, a high-resolution per-CPU timer. // This reports the CPU clock, a high-resolution per-CPU timer.
// a bit broken according to this: https://stackoverflow.com/a/56967896 // a bit broken according to this: https://stackoverflow.com/a/56967896
// makeInfo(perf_type_id::PERF_TYPE_SOFTWARE, perf_sw_ids::PERF_COUNT_SW_CPU_CLOCK, ProfileEvents::PERF_COUNT_SW_CPU_CLOCK), // softwareEvent(PERF_COUNT_SW_CPU_CLOCK, ProfileEvents::PERF_COUNT_SW_CPU_CLOCK),
softwareEvent(PERF_COUNT_SW_TASK_CLOCK, ProfileEvents::PERF_COUNT_SW_TASK_CLOCK), softwareEvent(PERF_COUNT_SW_TASK_CLOCK, ProfileEvents::PERF_COUNT_SW_TASK_CLOCK),
softwareEvent(PERF_COUNT_SW_PAGE_FAULTS, ProfileEvents::PERF_COUNT_SW_PAGE_FAULTS), softwareEvent(PERF_COUNT_SW_PAGE_FAULTS, ProfileEvents::PERF_COUNT_SW_PAGE_FAULTS),
softwareEvent(PERF_COUNT_SW_CONTEXT_SWITCHES, ProfileEvents::PERF_COUNT_SW_CONTEXT_SWITCHES), softwareEvent(PERF_COUNT_SW_CONTEXT_SWITCHES, ProfileEvents::PERF_COUNT_SW_CONTEXT_SWITCHES),
@ -59,7 +59,7 @@ namespace DB {
// This is a placeholder event that counts nothing. Informational sample record types such as mmap or // This is a placeholder event that counts nothing. Informational sample record types such as mmap or
// comm must be associated with an active event. This dummy event allows gathering such records // comm must be associated with an active event. This dummy event allows gathering such records
// without requiring a counting event. // without requiring a counting event.
// softwareEventInfo(perf_sw_ids::PERF_COUNT_SW_DUMMY, ProfileEvents::PERF_COUNT_SW_DUMMY) // softwareEventInfo(PERF_COUNT_SW_DUMMY, ProfileEvents::PERF_COUNT_SW_DUMMY)
}; };
static_assert(std::size(PerfEventsCounters::perf_raw_events_info) == PerfEventsCounters::NUMBER_OF_RAW_EVENTS); static_assert(std::size(PerfEventsCounters::perf_raw_events_info) == PerfEventsCounters::NUMBER_OF_RAW_EVENTS);
@ -91,16 +91,14 @@ namespace DB {
static bool getPerfEventParanoid(int & result) { static bool getPerfEventParanoid(int & result) {
// the longest possible variant: "-1\0" // the longest possible variant: "-1\0"
constexpr int MAX_LENGTH = 3; constexpr int MAX_LENGTH = 3;
FILE *fp;
char str[MAX_LENGTH];
fp = fopen("/proc/sys/kernel/perf_event_paranoid", "r"); FILE * fp = fopen("/proc/sys/kernel/perf_event_paranoid", "r");
if (fp == nullptr) if (fp == nullptr)
return false; return false;
char str[MAX_LENGTH];
char * res = fgets(str, MAX_LENGTH, fp); char * res = fgets(str, MAX_LENGTH, fp);
fclose(fp); fclose(fp);
if (res == nullptr) if (res == nullptr)
return false; return false;
@ -133,8 +131,6 @@ namespace DB {
int perf_event_paranoid = 0; int perf_event_paranoid = 0;
bool is_pref_available = getPerfEventParanoid(perf_event_paranoid); bool is_pref_available = getPerfEventParanoid(perf_event_paranoid);
// printf("is_perf_available: %s, perf_event_paranoid: %d\n", is_pref_available ? "true" : "false", perf_event_paranoid);
if (!is_pref_available) if (!is_pref_available)
return; return;
@ -149,9 +145,7 @@ namespace DB {
if (fd == -1 && log_unsupported_event) if (fd == -1 && log_unsupported_event)
{ {
LOG_WARNING( LOG_WARNING(getLogger(), "Perf event is unsupported: event_type=" << event_info.event_type
getLogger(),
"Perf event is unsupported: event_type=" << event_info.event_type
<< ", event_config=" << event_info.event_config); << ", event_config=" << event_info.event_config);
} }
} }
@ -190,9 +184,9 @@ namespace DB {
if (ioctl(fd, PERF_EVENT_IOC_DISABLE, 0)) if (ioctl(fd, PERF_EVENT_IOC_DISABLE, 0))
LOG_WARNING(getLogger(), "Can't disable perf event with file descriptor: " << fd); LOG_WARNING(getLogger(), "Can't disable perf event with file descriptor: " << fd);
if (close(fd)) if (close(fd))
LOG_WARNING(getLogger(), "Can't close perf event file descriptor: " << fd << "; error: " << errno << " - " << strerror(errno)); LOG_WARNING(getLogger(),"Can't close perf event file descriptor: " << fd
<< "; error: " << errno << " - " << strerror(errno));
fd = -1; fd = -1;
} }

View File

@ -174,9 +174,9 @@ struct PerfEventsCounters
static const PerfEventInfo perf_raw_events_info[]; static const PerfEventInfo perf_raw_events_info[];
int events_descriptors[NUMBER_OF_RAW_EVENTS]; int events_descriptors[NUMBER_OF_RAW_EVENTS]{};
// temp array just to not create it each time event processing finishes // temp array just to not create it each time event processing finishes
long long raw_event_values[NUMBER_OF_RAW_EVENTS]; long long raw_event_values[NUMBER_OF_RAW_EVENTS]{};
bool perf_events_recording = false; bool perf_events_recording = false;
#endif #endif