abseil-cpp/absl/profiling/internal/periodic_sampler.cc
Go to the documentation of this file.
1 // Copyright 2019 The Abseil Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
16 
17 #include <atomic>
18 
20 
21 namespace absl {
23 namespace profiling_internal {
24 
26  return rng_.GetStride(period);
27 }
28 
30  int current_period = period();
31 
32  // Deal with period case 0 (always off) and 1 (always on)
33  if (ABSL_PREDICT_FALSE(current_period < 2)) {
34  stride_ = 0;
35  return current_period == 1;
36  }
37 
38  // Check if this is the first call to Sample()
39  if (ABSL_PREDICT_FALSE(stride_ == 1)) {
40  stride_ = static_cast<uint64_t>(-GetExponentialBiased(current_period));
41  if (static_cast<int64_t>(stride_) < -1) {
42  ++stride_;
43  return false;
44  }
45  }
46 
47  stride_ = static_cast<uint64_t>(-GetExponentialBiased(current_period));
48  return true;
49 }
50 
51 } // namespace profiling_internal
53 } // namespace absl
ABSL_PREDICT_FALSE
#define ABSL_PREDICT_FALSE(x)
Definition: abseil-cpp/absl/base/optimization.h:180
ABSL_NAMESPACE_END
#define ABSL_NAMESPACE_END
Definition: third_party/abseil-cpp/absl/base/config.h:171
ABSL_NAMESPACE_BEGIN
#define ABSL_NAMESPACE_BEGIN
Definition: third_party/abseil-cpp/absl/base/config.h:170
int64_t
signed __int64 int64_t
Definition: stdint-msvc2008.h:89
uint64_t
unsigned __int64 uint64_t
Definition: stdint-msvc2008.h:90
periodic_sampler.h
absl::profiling_internal::PeriodicSamplerBase::period
virtual int period() const noexcept=0
absl::profiling_internal::PeriodicSamplerBase::GetExponentialBiased
virtual int64_t GetExponentialBiased(int period) noexcept
Definition: abseil-cpp/absl/profiling/internal/periodic_sampler.cc:25
rng_
std::mt19937 rng_
Definition: rls.cc:607
absl::profiling_internal::PeriodicSamplerBase::SubtleConfirmSample
bool SubtleConfirmSample() noexcept
Definition: abseil-cpp/absl/profiling/internal/periodic_sampler.cc:29
absl::profiling_internal::PeriodicSamplerBase::stride_
uint64_t stride_
Definition: abseil-cpp/absl/profiling/internal/periodic_sampler.h:151
absl
Definition: abseil-cpp/absl/algorithm/algorithm.h:31
exponential_biased.h


grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:42