This is an automated email from the ASF dual-hosted git repository.
chenBright pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brpc.git
The following commit(s) were added to refs/heads/master by this push:
new b5dc6fc7 [bvar] Fix sampler interval after switch to cpuwide_time_ns
(#3278)
b5dc6fc7 is described below
commit b5dc6fc7816e9bf543f5e0dd8714080da235791f
Author: huangjun <[email protected]>
AuthorDate: Thu Apr 23 11:00:13 2026 +0800
[bvar] Fix sampler interval after switch to cpuwide_time_ns (#3278)
Commit 12fb539a ("Use monotonic time instead of wall time", #3268)
switched the three time-source calls in SamplerCollector::run() from
gettimeofday_us() to cpuwide_time_ns(), but the surrounding code still
treats the timestamps as microseconds:
- abstime += 1000000L now represents 1 ms (not 1 s), causing the
sampler to spin at ~1 kHz instead of 1 Hz;
- usleep(abstime - now) receives a nanosecond delta, which usleep()
interprets as microseconds.
Use cpuwide_time_us() instead, which preserves the monotonic behavior
from #3268 while keeping the existing microsecond-based arithmetic
correct.
Fixes #3277.
Co-authored-by: huangjun <[email protected]>
---
src/bvar/detail/sampler.cpp | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/bvar/detail/sampler.cpp b/src/bvar/detail/sampler.cpp
index f3462558..4632938b 100644
--- a/src/bvar/detail/sampler.cpp
+++ b/src/bvar/detail/sampler.cpp
@@ -155,7 +155,7 @@ void SamplerCollector::run() {
butil::LinkNode<Sampler> root;
int consecutive_nosleep = 0;
while (!_stop) {
- int64_t abstime = butil::cpuwide_time_ns();
+ int64_t abstime = butil::cpuwide_time_us();
Sampler* s = this->reset();
if (s) {
s->InsertBeforeAsList(&root);
@@ -176,13 +176,13 @@ void SamplerCollector::run() {
p = saved_next;
}
bool slept = false;
- int64_t now = butil::cpuwide_time_ns();
+ int64_t now = butil::cpuwide_time_us();
_cumulated_time_us += now - abstime;
abstime += 1000000L;
while (abstime > now) {
::usleep(abstime - now);
slept = true;
- now = butil::cpuwide_time_ns();
+ now = butil::cpuwide_time_us();
}
if (slept) {
consecutive_nosleep = 0;
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]