diff options
author | James M Snell <jasnell@gmail.com> | 2021-12-12 03:59:48 +0300 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2021-12-19 20:56:36 +0300 |
commit | 23637e9a3b208892449268290143dad4391fee45 (patch) | |
tree | c8f83283bb0d357b7db22298e217cbe5e877a656 /src/histogram-inl.h | |
parent | 665b404e6512c6fdfe811e793d4f14bf8f8a7d36 (diff) |
perf_hooks: multiple fixes for Histogram
* The createHistogram(options) options weren't actually implemented
* Add a new count property that tracks the number of samples
* Adds BigInt options for relevant properties
* Adds add(other) method for RecordableHistogram
* Cleans up and expands tests
* Eliminates unnecessary ELDHistogram native class
* Improve/Simplify histogram transfer impl
Signed-off-by: James M Snell <jasnell@gmail.com>
perf_hooks: simplify Histogram constructor options
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/41153
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'src/histogram-inl.h')
-rw-r--r-- | src/histogram-inl.h | 49 |
1 files changed, 34 insertions, 15 deletions
diff --git a/src/histogram-inl.h b/src/histogram-inl.h index 18a1668512e..3b8712c8787 100644 --- a/src/histogram-inl.h +++ b/src/histogram-inl.h @@ -13,35 +13,49 @@ void Histogram::Reset() { Mutex::ScopedLock lock(mutex_); hdr_reset(histogram_.get()); exceeds_ = 0; + count_ = 0; prev_ = 0; } -int64_t Histogram::Min() { +double Histogram::Add(const Histogram& other) { + Mutex::ScopedLock lock(mutex_); + count_ += other.count_; + exceeds_ += other.exceeds_; + if (other.prev_ > prev_) + prev_ = other.prev_; + return static_cast<double>(hdr_add(histogram_.get(), other.histogram_.get())); +} + +size_t Histogram::Count() const { + Mutex::ScopedLock lock(mutex_); + return count_; +} + +int64_t Histogram::Min() const { Mutex::ScopedLock lock(mutex_); return hdr_min(histogram_.get()); } -int64_t Histogram::Max() { +int64_t Histogram::Max() const { Mutex::ScopedLock lock(mutex_); return hdr_max(histogram_.get()); } -double Histogram::Mean() { +double Histogram::Mean() const { Mutex::ScopedLock lock(mutex_); return hdr_mean(histogram_.get()); } -double Histogram::Stddev() { +double Histogram::Stddev() const { Mutex::ScopedLock lock(mutex_); return hdr_stddev(histogram_.get()); } -double Histogram::Percentile(double percentile) { +int64_t Histogram::Percentile(double percentile) const { Mutex::ScopedLock lock(mutex_); CHECK_GT(percentile, 0); CHECK_LE(percentile, 100); - return static_cast<double>( - hdr_value_at_percentile(histogram_.get(), percentile)); + return hdr_value_at_percentile(histogram_.get(), percentile); } template <typename Iterator> @@ -51,26 +65,31 @@ void Histogram::Percentiles(Iterator&& fn) { hdr_iter_percentile_init(&iter, histogram_.get(), 1); while (hdr_iter_next(&iter)) { double key = iter.specifics.percentiles.percentile; - double value = static_cast<double>(iter.value); - fn(key, value); + fn(key, iter.value); } } bool Histogram::Record(int64_t value) { Mutex::ScopedLock lock(mutex_); - return hdr_record_value(histogram_.get(), value); + bool recorded = hdr_record_value(histogram_.get(), value); + if (!recorded) + exceeds_++; + else + count_++; + return recorded; } uint64_t Histogram::RecordDelta() { Mutex::ScopedLock lock(mutex_); uint64_t time = uv_hrtime(); - uint64_t delta = 0; + int64_t delta = 0; if (prev_ > 0) { + CHECK_GE(time, prev_); delta = time - prev_; - if (delta > 0) { - if (!hdr_record_value(histogram_.get(), delta) && exceeds_ < 0xFFFFFFFF) - exceeds_++; - } + if (hdr_record_value(histogram_.get(), delta)) + count_++; + else + exceeds_++; } prev_ = time; return delta; |