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
6 changes: 3 additions & 3 deletions example/auto_concurrency_limiter/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,13 @@ struct TestCaseContext {
, stage_index(0)
, test_case(tc)
, next_stage_sec(test_case.qps_stage_list(0).duration_sec() +
butil::gettimeofday_s()) {
butil::cpuwide_time_s()) {
DisplayStage(test_case.qps_stage_list(stage_index));
Update();
}

bool Update() {
if (butil::gettimeofday_s() >= next_stage_sec) {
if (butil::cpuwide_time_s() >= next_stage_sec) {
++stage_index;
if (stage_index < test_case.qps_stage_list_size()) {
next_stage_sec += test_case.qps_stage_list(stage_index).duration_sec();
Expand All @@ -144,7 +144,7 @@ struct TestCaseContext {
} else if (qps_stage.type() == test::SMOOTH) {
qps = lower_bound + (upper_bound - lower_bound) /
double(qps_stage.duration_sec()) * (qps_stage.duration_sec() - next_stage_sec
+ butil::gettimeofday_s());
+ butil::cpuwide_time_s());
}
interval_us.store(1.0 / qps * 1000000, butil::memory_order_relaxed);
return true;
Expand Down
6 changes: 3 additions & 3 deletions example/auto_concurrency_limiter/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class EchoServiceImpl : public test::EchoService {
void SetTestCase(const test::TestCase& test_case) {
_test_case = test_case;
_next_stage_start = _test_case.latency_stage_list(0).duration_sec() +
butil::gettimeofday_s();
butil::cpuwide_time_s();
_stage_index = 0;
_running_case = false;
DisplayStage(_test_case.latency_stage_list(_stage_index));
Expand Down Expand Up @@ -137,7 +137,7 @@ class EchoServiceImpl : public test::EchoService {

void ComputeLatency() {
if (_stage_index < _test_case.latency_stage_list_size() &&
butil::gettimeofday_s() > _next_stage_start) {
butil::cpuwide_time_s() > _next_stage_start) {
++_stage_index;
if (_stage_index < _test_case.latency_stage_list_size()) {
_next_stage_start += _test_case.latency_stage_list(_stage_index).duration_sec();
Expand Down Expand Up @@ -167,7 +167,7 @@ class EchoServiceImpl : public test::EchoService {
int latency = lower_bound + (upper_bound - lower_bound) /
double(latency_stage.duration_sec()) *
(latency_stage.duration_sec() - _next_stage_start +
butil::gettimeofday_s());
butil::cpuwide_time_s());
_latency.store(latency, butil::memory_order_relaxed);
} else {
LOG(FATAL) << "Wrong Type:" << latency_stage.type();
Expand Down
4 changes: 2 additions & 2 deletions example/dynamic_partition_echo_c++/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ class EchoServiceImpl : public example::EchoService {
}
}
if (FLAGS_spin) {
int64_t end_time = butil::gettimeofday_us() + (int64_t)delay;
while (butil::gettimeofday_us() < end_time) {}
int64_t end_time = butil::cpuwide_time_us() + (int64_t)delay;
while (butil::cpuwide_time_us() < end_time) {}
} else {
bthread_usleep((int64_t)delay);
}
Expand Down
4 changes: 2 additions & 2 deletions example/multi_threaded_echo_fns_c++/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ class EchoServiceImpl : public example::EchoService {
}
}
if (FLAGS_spin) {
int64_t end_time = butil::gettimeofday_us() + (int64_t)delay;
while (butil::gettimeofday_us() < end_time) {}
int64_t end_time = butil::cpuwide_time_us() + (int64_t)delay;
while (butil::cpuwide_time_us() < end_time) {}
} else {
bthread_usleep((int64_t)delay);
}
Expand Down
4 changes: 2 additions & 2 deletions example/partition_echo_c++/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ class EchoServiceImpl : public example::EchoService {
}
}
if (FLAGS_spin) {
int64_t end_time = butil::gettimeofday_us() + (int64_t)delay;
while (butil::gettimeofday_us() < end_time) {}
int64_t end_time = butil::cpuwide_time_us() + (int64_t)delay;
while (butil::cpuwide_time_us() < end_time) {}
} else {
bthread_usleep((int64_t)delay);
}
Expand Down
8 changes: 4 additions & 4 deletions example/rdma_performance/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class PerformanceTest {
}
--closure->test->_iterations;
uint64_t last = g_last_time.load(butil::memory_order_relaxed);
uint64_t now = butil::gettimeofday_us();
uint64_t now = butil::cpuwide_time_us();
if (now > last && now - last > 100000) {
if (g_last_time.exchange(now, butil::memory_order_relaxed) == last) {
g_client_cpu_recorder <<
Expand All @@ -192,7 +192,7 @@ class PerformanceTest {

static void* RunTest(void* arg) {
PerformanceTest* test = (PerformanceTest*)arg;
test->_start_time = butil::gettimeofday_us();
test->_start_time = butil::cpuwide_time_us();
test->_iterations = FLAGS_test_iterations;

for (int i = 0; i < FLAGS_queue_depth; ++i) {
Expand Down Expand Up @@ -235,7 +235,7 @@ void Test(int thread_num, int attachment_size) {
}
tests.push_back(t);
}
uint64_t start_time = butil::gettimeofday_us();
uint64_t start_time = butil::cpuwide_time_us();
bthread_t tid[thread_num];
if (FLAGS_expected_qps > 0) {
bthread_t tid;
Expand All @@ -250,7 +250,7 @@ void Test(int thread_num, int attachment_size) {
bthread_usleep(10000);
}
}
uint64_t end_time = butil::gettimeofday_us();
uint64_t end_time = butil::cpuwide_time_us();
double throughput = g_total_bytes / 1.048576 / (end_time - start_time);
if (FLAGS_test_iterations == 0) {
std::cout << "Avg-Latency: " << g_latency_recorder.latency(10)
Expand Down
4 changes: 2 additions & 2 deletions example/selective_echo_c++/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ class EchoServiceImpl : public example::EchoService {
}
}
if (FLAGS_spin) {
int64_t end_time = butil::gettimeofday_us() + (int64_t)delay;
while (butil::gettimeofday_us() < end_time) {}
int64_t end_time = butil::cpuwide_time_us() + (int64_t)delay;
while (butil::cpuwide_time_us() < end_time) {}
} else {
bthread_usleep((int64_t)delay);
}
Expand Down
4 changes: 2 additions & 2 deletions src/brpc/cluster_recover_policy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ bool DefaultClusterRecoverPolicy::StopRecoverIfNecessary() {
if (!_recovering) {
return false;
}
int64_t now_ms = butil::gettimeofday_ms();
int64_t now_ms = butil::cpuwide_time_ms();
std::unique_lock<butil::Mutex> mu(_mutex);
if (_last_usable_change_time_ms != 0 && _last_usable != 0 &&
(now_ms - _last_usable_change_time_ms > _hold_seconds * 1000)) {
Expand Down Expand Up @@ -92,7 +92,7 @@ bool DefaultClusterRecoverPolicy::DoReject(const std::vector<ServerId>& server_l
if (!_recovering) {
return false;
}
int64_t now_ms = butil::gettimeofday_ms();
int64_t now_ms = butil::cpuwide_time_ms();
uint64_t usable = GetUsableServerCount(now_ms, server_list);
if (_last_usable != usable) {
std::unique_lock<butil::Mutex> mu(_mutex);
Expand Down
4 changes: 2 additions & 2 deletions src/brpc/details/health_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void* HealthCheckManager::AppCheck(void* arg) {
done->cntl.Reset();
done->cntl.http_request().uri() = done->hc_option.health_check_path;
ControllerPrivateAccessor(&done->cntl).set_health_check_call();
done->last_check_time_ms = butil::gettimeofday_ms();
done->last_check_time_ms = butil::cpuwide_time_ms();
done->channel.CallMethod(NULL, &done->cntl, NULL, NULL, done);
return NULL;
}
Expand All @@ -126,7 +126,7 @@ void OnAppHealthCheckDone::Run() {
<< ", " << cntl.ErrorText();

int64_t sleep_time_ms =
last_check_time_ms + interval_s * 1000 - butil::gettimeofday_ms();
last_check_time_ms + interval_s * 1000 - butil::cpuwide_time_ms();
if (sleep_time_ms > 0) {
// TODO(zhujiashun): we need to handle the case when timer fails
// and bthread_usleep returns immediately. In most situations,
Expand Down
6 changes: 3 additions & 3 deletions src/brpc/global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,13 @@ static void* GlobalUpdate(void*) {
}

std::vector<SocketId> conns;
const int64_t start_time_us = butil::gettimeofday_us();
const int64_t start_time_us = butil::cpuwide_time_us();
const int WARN_NOSLEEP_THRESHOLD = 2;
int64_t last_time_us = start_time_us;
int consecutive_nosleep = 0;
int64_t last_return_free_memory_time = start_time_us;
while (1) {
const int64_t sleep_us = 1000000L + last_time_us - butil::gettimeofday_us();
const int64_t sleep_us = 1000000L + last_time_us - butil::cpuwide_time_us();
if (sleep_us > 0) {
if (bthread_usleep(sleep_us) < 0) {
PLOG_IF(FATAL, errno != ESTOP) << "Fail to sleep";
Expand All @@ -257,7 +257,7 @@ static void* GlobalUpdate(void*) {
LOG(WARNING) << __FUNCTION__ << " is too busy!";
}
}
last_time_us = butil::gettimeofday_us();
last_time_us = butil::cpuwide_time_us();

TrackMe();

Expand Down
4 changes: 2 additions & 2 deletions src/brpc/policy/auto_concurrency_limiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ DEFINE_double(auto_cl_error_rate_punish_threshold, 0,

AutoConcurrencyLimiter::AutoConcurrencyLimiter()
: _max_concurrency(FLAGS_auto_cl_initial_max_concurrency)
, _remeasure_start_us(NextResetTime(butil::gettimeofday_us()))
, _remeasure_start_us(NextResetTime(butil::cpuwide_time_us()))
, _reset_latency_us(0)
, _min_latency_us(-1)
, _ema_max_qps(-1)
Expand All @@ -111,7 +111,7 @@ void AutoConcurrencyLimiter::OnResponded(int error_code, int64_t latency_us) {
return;
}

const int64_t now_time_us = butil::gettimeofday_us();
const int64_t now_time_us = butil::cpuwide_time_us();
int64_t last_sampling_time_us =
_last_sampling_time_us.load(butil::memory_order_relaxed);

Expand Down
6 changes: 3 additions & 3 deletions src/brpc/policy/locality_aware_load_balancer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#include <limits> // numeric_limits
#include <gflags/gflags.h>
#include "butil/time.h" // gettimeofday_us
#include "butil/time.h" // cpuwide_time_us
#include "butil/fast_rand.h"
#include "brpc/log.h"
#include "brpc/socket.h"
Expand Down Expand Up @@ -376,7 +376,7 @@ void LocalityAwareLoadBalancer::Feedback(const CallInfo& info) {

int64_t LocalityAwareLoadBalancer::Weight::Update(
const CallInfo& ci, size_t index) {
const int64_t end_time_us = butil::gettimeofday_us();
const int64_t end_time_us = butil::cpuwide_time_us();
const int64_t latency = end_time_us - ci.begin_time_us;
BAIDU_SCOPED_LOCK(_mutex);
if (Disabled()) {
Expand Down Expand Up @@ -524,7 +524,7 @@ void LocalityAwareLoadBalancer::Describe(
if (_db_servers.Read(&s) != 0) {
os << "fail to read _db_servers";
} else {
const int64_t now = butil::gettimeofday_us();
const int64_t now = butil::cpuwide_time_us();
const size_t n = s->weight_tree.size();
os << '[';
for (size_t i = 0; i < n; ++i) {
Expand Down
2 changes: 1 addition & 1 deletion src/brpc/policy/timeout_concurrency_limiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void TimeoutConcurrencyLimiter::OnResponded(int error_code,
return;
}

const int64_t now_time_us = butil::gettimeofday_us();
const int64_t now_time_us = butil::cpuwide_time_us();
int64_t last_sampling_time_us =
_last_sampling_time_us.load(butil::memory_order_relaxed);

Expand Down
6 changes: 3 additions & 3 deletions src/brpc/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,10 @@ void* Server::UpdateDerivedVars(void* arg) {
}
#endif

int64_t last_time = butil::gettimeofday_us();
int64_t last_time = butil::cpuwide_time_us();
int consecutive_nosleep = 0;
while (1) {
const int64_t sleep_us = 1000000L + last_time - butil::gettimeofday_us();
const int64_t sleep_us = 1000000L + last_time - butil::cpuwide_time_us();
if (sleep_us < 1000L) {
if (++consecutive_nosleep >= 2) {
consecutive_nosleep = 0;
Expand All @@ -388,7 +388,7 @@ void* Server::UpdateDerivedVars(void* arg) {
return NULL;
}
}
last_time = butil::gettimeofday_us();
last_time = butil::cpuwide_time_us();

// Update stats of accepted sockets.
if (server->_am) {
Expand Down
4 changes: 2 additions & 2 deletions src/brpc/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ int Socket::ResetFileDescriptor(int fd) {
// MUST store `_fd' before adding itself into epoll device to avoid
// race conditions with the callback function inside epoll
_fd.store(fd, butil::memory_order_release);
_reset_fd_real_us = butil::gettimeofday_us();
_reset_fd_real_us = butil::cpuwide_time_us();
if (!ValidFileDescriptor(fd)) {
return 0;
}
Expand Down Expand Up @@ -2316,7 +2316,7 @@ void Socket::DebugSocket(std::ostream& os, SocketId id) {
<< "\nnevent=" << ptr->_nevent.load(butil::memory_order_relaxed)
<< "\nfd=" << fd
<< "\ntos=" << ptr->_tos
<< "\nreset_fd_to_now=" << butil::gettimeofday_us() - ptr->_reset_fd_real_us << "us"
<< "\nreset_fd_to_now=" << butil::cpuwide_time_us() - ptr->_reset_fd_real_us << "us"
<< "\nremote_side=" << ptr->_remote_side
<< "\nlocal_side=" << ptr->_local_side
<< "\non_et_events=" << (void*)ptr->_on_edge_triggered_events
Expand Down
2 changes: 1 addition & 1 deletion src/brpc/trackme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ void TrackMe() {
if (FLAGS_trackme_server.empty()) {
return;
}
int64_t now = butil::gettimeofday_us();
int64_t now = butil::cpuwide_time_us();
std::unique_lock<pthread_mutex_t> mu(s_trackme_mutex);
if (s_trackme_last_time == 0) {
// Delay the first ping randomly within s_trackme_interval. This
Expand Down
6 changes: 3 additions & 3 deletions src/bvar/collector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,8 @@ void Collector::update_speed_limit(CollectorSpeedLimit* sl,
size_t new_sampling_range = 0;
const size_t old_sampling_range = sl->sampling_range;
if (!sl->ever_grabbed) {
if (sl->first_sample_real_us) {
interval_us = butil::gettimeofday_us() - sl->first_sample_real_us;
if (sl->first_sample_us) {
interval_us = butil::cpuwide_time_us() - sl->first_sample_us;
if (interval_us < 0) {
interval_us = 0;
}
Expand Down Expand Up @@ -350,7 +350,7 @@ size_t is_collectable_before_first_time_grabbed(CollectorSpeedLimit* sl) {
int before_add = sl->count_before_grabbed.fetch_add(
1, butil::memory_order_relaxed);
if (before_add == 0) {
sl->first_sample_real_us = butil::gettimeofday_us();
sl->first_sample_us = butil::cpuwide_time_us();
} else if (before_add >= FLAGS_bvar_collector_expected_per_second) {
butil::get_leaky_singleton<Collector>()->wakeup_grab_thread();
}
Expand Down
2 changes: 1 addition & 1 deletion src/bvar/collector.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct CollectorSpeedLimit {
size_t sampling_range;
bool ever_grabbed;
butil::static_atomic<int> count_before_grabbed;
int64_t first_sample_real_us;
int64_t first_sample_us;
};

static const size_t COLLECTOR_SAMPLING_BASE = 16384;
Expand Down
6 changes: 3 additions & 3 deletions src/bvar/default_variables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class CachedReader {
template <typename ReadFn>
static const T& get_value(const ReadFn& fn) {
CachedReader* p = butil::get_leaky_singleton<CachedReader>();
const int64_t now = butil::gettimeofday_us();
const int64_t now = butil::cpuwide_time_us();
if (now > p->_mtime_us + CACHED_INTERVAL_US) {
pthread_mutex_lock(&p->_mutex);
if (now > p->_mtime_us + CACHED_INTERVAL_US) {
Expand Down Expand Up @@ -625,10 +625,10 @@ static void get_kernel_version(std::ostream& os, void*) {

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

static int64_t g_starting_time = butil::gettimeofday_us();
static int64_t g_starting_time = butil::cpuwide_time_us();

static timeval get_uptime(void*) {
int64_t uptime_us = butil::gettimeofday_us() - g_starting_time;
int64_t uptime_us = butil::cpuwide_time_us() - g_starting_time;
timeval tm;
tm.tv_sec = uptime_us / 1000000L;
tm.tv_usec = uptime_us - tm.tv_sec * 1000000L;
Expand Down
6 changes: 3 additions & 3 deletions src/bvar/detail/sampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ void SamplerCollector::run() {
butil::LinkNode<Sampler> root;
int consecutive_nosleep = 0;
while (!_stop) {
int64_t abstime = butil::gettimeofday_us();
int64_t abstime = butil::cpuwide_time_ns();
Sampler* s = this->reset();
if (s) {
s->InsertBeforeAsList(&root);
Expand All @@ -176,13 +176,13 @@ void SamplerCollector::run() {
p = saved_next;
}
bool slept = false;
int64_t now = butil::gettimeofday_us();
int64_t now = butil::cpuwide_time_ns();
_cumulated_time_us += now - abstime;
abstime += 1000000L;
while (abstime > now) {
::usleep(abstime - now);
slept = true;
now = butil::gettimeofday_us();
now = butil::cpuwide_time_ns();
}
if (slept) {
consecutive_nosleep = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/bvar/detail/sampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "butil/logging.h" // LOG()
#include "butil/containers/bounded_queue.h"// BoundedQueue
#include "butil/type_traits.h" // is_same
#include "butil/time.h" // gettimeofday_us
#include "butil/time.h" // cpuwide_time_us
#include "butil/class_name.h"

namespace bvar {
Expand Down Expand Up @@ -136,7 +136,7 @@ class ReducerSampler : public Sampler {
// get_value() of _reducer can still be called.
latest.data = _reducer->get_value();
}
latest.time_us = butil::gettimeofday_us();
latest.time_us = butil::cpuwide_time_us();
_q.elim_push(latest);
}

Expand Down
2 changes: 1 addition & 1 deletion test/brpc_auto_concurrency_limiter_unittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void AddSamplesAndTriggerWindow(brpc::policy::AutoConcurrencyLimiter& limiter,
int succ_count, int64_t succ_latency,
int fail_count, int64_t fail_latency) {
ASSERT_GT(succ_count, 0) << "Need at least 1 success to trigger window";
int64_t now = butil::gettimeofday_us();
int64_t now = butil::cpuwide_time_us();

// Add successful samples (reserve one for the trigger)
for (int i = 0; i < succ_count - 1; ++i) {
Expand Down
Loading
Loading