provide constexpr constructor for Sampler

Constexpr constructor lets us use Sampler in TLS variable in cleaner
way.
This commit is contained in:
Aliaksey Kandratsenka 2018-08-05 17:42:04 -07:00
parent 1fb543cc70
commit 467502e70a
2 changed files with 7 additions and 5 deletions

View File

@ -105,6 +105,8 @@ class SamplerTest;
class PERFTOOLS_DLL_DECL Sampler {
public:
constexpr Sampler() {}
// Initialize this sampler.
void Init(uint64_t seed);
@ -144,13 +146,13 @@ class PERFTOOLS_DLL_DECL Sampler {
//
// Always non-negative with only very brief exceptions (see
// DecrementFast{,Finish}, so casting to size_t is ok.
ssize_t bytes_until_sample_;
uint64_t rnd_; // Cheap random number generator
bool initialized_;
private:
friend class SamplerTest;
bool RecordAllocationSlow(size_t k);
ssize_t bytes_until_sample_{};
uint64_t rnd_{}; // Cheap random number generator
bool initialized_{};
};
inline bool Sampler::RecordAllocation(size_t k) {

View File

@ -361,7 +361,7 @@ double StandardDeviationsErrorInSample(
}
TEST(Sampler, LargeAndSmallAllocs_CombinedTest) {
tcmalloc::Sampler sampler{0, 0, false};
tcmalloc::Sampler sampler;
sampler.Init(1);
int counter_big = 0;
int counter_small = 0;