Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions src/bvar/collector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ BAIDU_CASSERT(!(COLLECTOR_SAMPLING_BASE & (COLLECTOR_SAMPLING_BASE - 1)),
// Combine two circular linked list into one.
struct CombineCollected {
void operator()(Collected* & s1, Collected* s2) const {
if (s2 == NULL) {
if (s2 == nullptr) {
return;
}
if (s1 == NULL) {
if (s1 == nullptr) {
s1 = s2;
return;
}
Expand Down Expand Up @@ -79,13 +79,13 @@ class Collector : public bvar::Reducer<Collected*, CombineCollected> {
static void* run_grab_thread(void* arg) {
butil::PlatformThread::SetNameSimple("bvar_collector_grabber");
static_cast<Collector*>(arg)->grab_thread();
return NULL;
return nullptr;
}

static void* run_dump_thread(void* arg) {
butil::PlatformThread::SetNameSimple("bvar_collector_dumper");
static_cast<Collector*>(arg)->dump_thread();
return NULL;
return nullptr;
}

static int64_t get_pending_count(void* arg) {
Expand Down Expand Up @@ -121,11 +121,11 @@ Collector::Collector()
, _ngrab(0)
, _ndrop(0)
, _ndump(0) {
pthread_mutex_init(&_dump_thread_mutex, NULL);
pthread_cond_init(&_dump_thread_cond, NULL);
pthread_mutex_init(&_sleep_mutex, NULL);
pthread_cond_init(&_sleep_cond, NULL);
int rc = pthread_create(&_grab_thread, NULL, run_grab_thread, this);
pthread_mutex_init(&_dump_thread_mutex, nullptr);
pthread_cond_init(&_dump_thread_cond, nullptr);
pthread_mutex_init(&_sleep_mutex, nullptr);
pthread_cond_init(&_sleep_cond, nullptr);
int rc = pthread_create(&_grab_thread, nullptr, run_grab_thread, this);
if (rc != 0) {
LOG(ERROR) << "Fail to create Collector, " << berror(rc);
} else {
Expand All @@ -136,7 +136,7 @@ Collector::Collector()
Collector::~Collector() {
if (_created) {
_stop = true;
pthread_join(_grab_thread, NULL);
pthread_join(_grab_thread, nullptr);
_created = false;
}
pthread_mutex_destroy(&_dump_thread_mutex);
Expand All @@ -150,7 +150,7 @@ static T deref_value(void* arg) {
return *(T*)arg;
}

// for limiting samples returning NULL in speed_limit()
// for limiting samples returning nullptr in speed_limit()
static CollectorSpeedLimit g_null_speed_limit = BVAR_COLLECTOR_SPEED_LIMIT_INITIALIZER;

void Collector::grab_thread() {
Expand All @@ -161,7 +161,7 @@ void Collector::grab_thread() {
// called inside the separate _dump_thread to prevent a slow callback
// (caused by busy disk generally) from blocking collecting code too long
// that pending requests may explode memory.
CHECK_EQ(0, pthread_create(&_dump_thread, NULL, run_dump_thread, this));
CHECK_EQ(0, pthread_create(&_dump_thread, nullptr, run_dump_thread, this));

// vars
bvar::PassiveStatus<int64_t> pending_sampled_data(
Expand Down Expand Up @@ -199,7 +199,7 @@ void Collector::grab_thread() {
if (head) {
butil::LinkNode<Collected> tmp_root;
head->InsertBeforeAsList(&tmp_root);
head = NULL;
head = nullptr;

// Group samples by preprocessors.
for (butil::LinkNode<Collected>* p = tmp_root.next(); p != &tmp_root;) {
Expand All @@ -218,13 +218,13 @@ void Collector::grab_thread() {
// don't call preprocessor when there's no samples.
continue;
}
if (it->first != NULL) {
if (it->first != nullptr) {
it->first->process(list);
}
for (size_t i = 0; i < list.size(); ++i) {
Collected* p = list[i];
CollectorSpeedLimit* speed_limit = p->speed_limit();
if (speed_limit == NULL) {
if (speed_limit == nullptr) {
++ngrab_map[&g_null_speed_limit];
} else {
// Add up the samples of certain type.
Expand Down Expand Up @@ -280,7 +280,7 @@ void Collector::grab_thread() {
_stop = true;
pthread_cond_signal(&_dump_thread_cond);
}
CHECK_EQ(0, pthread_join(_dump_thread, NULL));
CHECK_EQ(0, pthread_join(_dump_thread, nullptr));
}

void Collector::wakeup_grab_thread() {
Expand Down Expand Up @@ -379,7 +379,7 @@ void Collector::dump_thread() {
while (!_stop) {
++round;
// Get new samples set by grab_thread.
butil::LinkNode<Collected>* newhead = NULL;
butil::LinkNode<Collected>* newhead = nullptr;
{
BAIDU_SCOPED_LOCK(_dump_thread_mutex);
while (!_stop && _dump_root.next() == &_dump_root) {
Expand Down
8 changes: 4 additions & 4 deletions src/bvar/collector.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,20 @@ class Collected : public butil::LinkNode<Collected> {
virtual void destroy() = 0;

// Returns an object to control #samples collected per second.
// If NULL is returned, samples collected per second is limited by a
// global speed limit shared with other samples also returning NULL.
// If nullptr is returned, samples collected per second is limited by a
// global speed limit shared with other samples also returning nullptr.
// All instances of a subclass of Collected should return a same instance
// of CollectorSpeedLimit. The instance should remain valid during lifetime
// of program.
virtual CollectorSpeedLimit* speed_limit() = 0;

// If this method returns a non-NULL instance, it will be applied to
// If this method returns a non-nullptr instance, it will be applied to
// samples in batch before dumping. You can sort or shuffle the samples
// in the impl.
// All instances of a subclass of Collected should return a same instance
// of CollectorPreprocessor. The instance should remain valid during
// lifetime of program.
virtual CollectorPreprocessor* preprocessor() { return NULL; }
virtual CollectorPreprocessor* preprocessor() { return nullptr; }
};

// To know if an instance should be sampled.
Expand Down
52 changes: 26 additions & 26 deletions src/bvar/default_variables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ static bool read_proc_status(ProcStat &stat) {
// Read status from /proc/self/stat. Information from `man proc' is out of date,
// see http://man7.org/linux/man-pages/man5/proc.5.html
butil::ScopedFILE fp("/proc/self/stat", "r");
if (NULL == fp) {
if (nullptr == fp) {
static bool ever_printed_stat_err = false;
if (!ever_printed_stat_err) {
fprintf(stderr, "WARNING: Fail to open /proc/self/stat, errno=%d. "
Expand Down Expand Up @@ -136,7 +136,7 @@ template <typename T>
class CachedReader {
public:
CachedReader() : _mtime_us(0), _cached{} {
CHECK_EQ(0, pthread_mutex_init(&_mutex, NULL));
CHECK_EQ(0, pthread_mutex_init(&_mutex, nullptr));
}
~CachedReader() {
pthread_mutex_destroy(&_mutex);
Expand Down Expand Up @@ -192,13 +192,13 @@ class ProcStatReader {
#define BVAR_DEFINE_PROC_STAT_FIELD(field) \
PassiveStatus<BVAR_MEMBER_TYPE(&ProcStat::field)> g_##field( \
ProcStatReader::get_field<BVAR_MEMBER_TYPE(&ProcStat::field), \
offsetof(ProcStat, field)>, NULL);
offsetof(ProcStat, field)>, nullptr);

#define BVAR_DEFINE_PROC_STAT_FIELD2(field, name) \
PassiveStatus<BVAR_MEMBER_TYPE(&ProcStat::field)> g_##field( \
name, \
ProcStatReader::get_field<BVAR_MEMBER_TYPE(&ProcStat::field), \
offsetof(ProcStat, field)>, NULL);
offsetof(ProcStat, field)>, nullptr);

// ==================================================

Expand All @@ -217,7 +217,7 @@ static bool read_proc_memory(ProcMemory &m) {
errno = 0;
#if defined(OS_LINUX)
butil::ScopedFILE fp("/proc/self/statm", "r");
if (NULL == fp) {
if (nullptr == fp) {
PLOG_ONCE(WARNING) << "Fail to open /proc/self/statm";
return false;
}
Expand Down Expand Up @@ -271,7 +271,7 @@ class ProcMemoryReader {
PassiveStatus<BVAR_MEMBER_TYPE(&ProcMemory::field)> g_##field( \
name, \
ProcMemoryReader::get_field<BVAR_MEMBER_TYPE(&ProcMemory::field), \
offsetof(ProcMemory, field)>, NULL);
offsetof(ProcMemory, field)>, nullptr);

// ==================================================

Expand All @@ -284,7 +284,7 @@ struct LoadAverage {
static bool read_load_average(LoadAverage &m) {
#if defined(OS_LINUX)
butil::ScopedFILE fp("/proc/loadavg", "r");
if (NULL == fp) {
if (nullptr == fp) {
PLOG_ONCE(WARNING) << "Fail to open /proc/loadavg";
return false;
}
Expand Down Expand Up @@ -331,7 +331,7 @@ class LoadAverageReader {
PassiveStatus<BVAR_MEMBER_TYPE(&LoadAverage::field)> g_##field( \
name, \
LoadAverageReader::get_field<BVAR_MEMBER_TYPE(&LoadAverage::field), \
offsetof(LoadAverage, field)>, NULL);
offsetof(LoadAverage, field)>, nullptr);

// ==================================================

Expand Down Expand Up @@ -437,7 +437,7 @@ struct ProcIO {
static bool read_proc_io(ProcIO* s) {
#if defined(OS_LINUX)
butil::ScopedFILE fp("/proc/self/io", "r");
if (NULL == fp) {
if (nullptr == fp) {
static bool ever_printed_io_err = false;
if (!ever_printed_io_err) {
fprintf(stderr, "WARNING: Fail to open /proc/self/io, errno=%d. "
Expand Down Expand Up @@ -488,7 +488,7 @@ class ProcIOReader {
#define BVAR_DEFINE_PROC_IO_FIELD(field) \
PassiveStatus<BVAR_MEMBER_TYPE(&ProcIO::field)> g_##field( \
ProcIOReader::get_field<BVAR_MEMBER_TYPE(&ProcIO::field), \
offsetof(ProcIO, field)>, NULL);
offsetof(ProcIO, field)>, nullptr);

// ==================================================
// Refs:
Expand Down Expand Up @@ -550,7 +550,7 @@ struct DiskStat {
static bool read_disk_stat(DiskStat* s) {
#if defined(OS_LINUX)
butil::ScopedFILE fp("/proc/diskstats", "r");
if (NULL == fp) {
if (nullptr == fp) {
PLOG_ONCE(WARNING) << "Fail to open /proc/diskstats";
return false;
}
Expand Down Expand Up @@ -598,7 +598,7 @@ class DiskStatReader {
#define BVAR_DEFINE_DISK_STAT_FIELD(field) \
PassiveStatus<BVAR_MEMBER_TYPE(&DiskStat::field)> g_##field( \
DiskStatReader::get_field<BVAR_MEMBER_TYPE(&DiskStat::field), \
offsetof(DiskStat, field)>, NULL);
offsetof(DiskStat, field)>, nullptr);

// =====================================

Expand Down Expand Up @@ -663,13 +663,13 @@ class RUsageReader {
#define BVAR_DEFINE_RUSAGE_FIELD(field) \
PassiveStatus<BVAR_MEMBER_TYPE(&rusage::field)> g_##field( \
RUsageReader::get_field<BVAR_MEMBER_TYPE(&rusage::field), \
offsetof(rusage, field)>, NULL); \
offsetof(rusage, field)>, nullptr); \

#define BVAR_DEFINE_RUSAGE_FIELD2(field, name) \
PassiveStatus<BVAR_MEMBER_TYPE(&rusage::field)> g_##field( \
name, \
RUsageReader::get_field<BVAR_MEMBER_TYPE(&rusage::field), \
offsetof(rusage, field)>, NULL); \
offsetof(rusage, field)>, nullptr); \

// ======================================

Expand All @@ -688,7 +688,7 @@ static void get_username(std::ostream& os, void*) {
}

PassiveStatus<std::string> g_username(
"process_username", get_username, NULL);
"process_username", get_username, nullptr);

BVAR_DEFINE_PROC_STAT_FIELD(minflt);
PerSecond<PassiveStatus<unsigned long> > g_minflt_second(
Expand All @@ -699,7 +699,7 @@ BVAR_DEFINE_PROC_STAT_FIELD2(priority, "process_priority");
BVAR_DEFINE_PROC_STAT_FIELD2(nice, "process_nice");

BVAR_DEFINE_PROC_STAT_FIELD2(num_threads, "process_thread_count");
PassiveStatus<int> g_fd_num("process_fd_count", print_fd_count, NULL);
PassiveStatus<int> g_fd_num("process_fd_count", print_fd_count, nullptr);

BVAR_DEFINE_PROC_MEMORY_FIELD(size, "process_memory_virtual");
BVAR_DEFINE_PROC_MEMORY_FIELD(resident, "process_memory_resident");
Expand Down Expand Up @@ -734,12 +734,12 @@ PerSecond<PassiveStatus<size_t> > g_disk_write_second(

BVAR_DEFINE_RUSAGE_FIELD(ru_utime);
BVAR_DEFINE_RUSAGE_FIELD(ru_stime);
PassiveStatus<timeval> g_uptime("process_uptime", get_uptime, NULL);
PassiveStatus<timeval> g_uptime("process_uptime", get_uptime, nullptr);

static int get_core_num(void*) {
return sysconf(_SC_NPROCESSORS_ONLN);
}
PassiveStatus<int> g_core_num("system_core_count", get_core_num, NULL);
PassiveStatus<int> g_core_num("system_core_count", get_core_num, nullptr);

struct TimePercent {
int64_t time_us;
Expand Down Expand Up @@ -769,7 +769,7 @@ static TimePercent get_cputime_percent(void*) {
butil::timeval_to_microseconds(g_uptime.get_value()) };
return tp;
}
PassiveStatus<TimePercent> g_cputime_percent(get_cputime_percent, NULL);
PassiveStatus<TimePercent> g_cputime_percent(get_cputime_percent, nullptr);
Window<PassiveStatus<TimePercent>, SERIES_IN_SECOND> g_cputime_percent_second(
"process_cpu_usage", &g_cputime_percent, FLAGS_bvar_dump_interval);

Expand All @@ -778,7 +778,7 @@ static TimePercent get_stime_percent(void*) {
butil::timeval_to_microseconds(g_uptime.get_value()) };
return tp;
}
PassiveStatus<TimePercent> g_stime_percent(get_stime_percent, NULL);
PassiveStatus<TimePercent> g_stime_percent(get_stime_percent, nullptr);
Window<PassiveStatus<TimePercent>, SERIES_IN_SECOND> g_stime_percent_second(
"process_cpu_usage_system", &g_stime_percent, FLAGS_bvar_dump_interval);

Expand All @@ -787,7 +787,7 @@ static TimePercent get_utime_percent(void*) {
butil::timeval_to_microseconds(g_uptime.get_value()) };
return tp;
}
PassiveStatus<TimePercent> g_utime_percent(get_utime_percent, NULL);
PassiveStatus<TimePercent> g_utime_percent(get_utime_percent, nullptr);
Window<PassiveStatus<TimePercent>, SERIES_IN_SECOND> g_utime_percent_second(
"process_cpu_usage_user", &g_utime_percent, FLAGS_bvar_dump_interval);

Expand All @@ -811,11 +811,11 @@ PerSecond<PassiveStatus<long> > cs_vol_second(
PerSecond<PassiveStatus<long> > cs_invol_second(
"process_context_switches_involuntary_second", &g_ru_nivcsw);

PassiveStatus<std::string> g_cmdline("process_cmdline", get_cmdline, NULL);
PassiveStatus<std::string> g_cmdline("process_cmdline", get_cmdline, nullptr);
PassiveStatus<std::string> g_kernel_version(
"kernel_version", get_kernel_version, NULL);
"kernel_version", get_kernel_version, nullptr);

static std::string* s_gcc_version = NULL;
static std::string* s_gcc_version = nullptr;
pthread_once_t g_gen_gcc_version_once = PTHREAD_ONCE_INIT;

void gen_gcc_version() {
Expand Down Expand Up @@ -866,15 +866,15 @@ void get_gcc_version(std::ostream& os, void*) {
}

// =============================================
PassiveStatus<std::string> g_gcc_version("gcc_version", get_gcc_version, NULL);
PassiveStatus<std::string> g_gcc_version("gcc_version", get_gcc_version, nullptr);

void get_work_dir(std::ostream& os, void*) {
butil::FilePath path;
const bool rc = butil::GetCurrentDirectory(&path);
LOG_IF(WARNING, !rc) << "Fail to GetCurrentDirectory";
os << path.value();
}
PassiveStatus<std::string> g_work_dir("process_work_dir", get_work_dir, NULL);
PassiveStatus<std::string> g_work_dir("process_work_dir", get_work_dir, nullptr);

#undef BVAR_MEMBER_TYPE
#undef BVAR_DEFINE_PROC_STAT_FIELD
Expand Down
Loading
Loading