Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames M Snell <jasnell@gmail.com>2021-01-30 20:26:15 +0300
committerJames M Snell <jasnell@gmail.com>2021-02-15 00:03:49 +0300
commit4a19cc8947b1bba2b2d27816ec3d0edf9b28e503 (patch)
tree8c75fbee068d6eda2682bd660198952ffb30bcf4 /src/histogram-inl.h
parentce4798b55515827f2a68d269d0f433e3ea9828bb (diff)
perf_hooks: introduce createHistogram
Adds a new `perf_hooks.createHistogram()` API for creating histogram instances that allow user recording. Makes Histogram instances cloneable via MessagePort. This allows, for instance, an event loop delay monitor to be running on the main thread while the histogram data can be monitored actively from a worker thread. Signed-off-by: James M Snell <jasnell@gmail.com> PR-URL: https://github.com/nodejs/node/pull/37155 Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'src/histogram-inl.h')
-rw-r--r--src/histogram-inl.h43
1 files changed, 24 insertions, 19 deletions
diff --git a/src/histogram-inl.h b/src/histogram-inl.h
index 58911dae8f2..18a1668512e 100644
--- a/src/histogram-inl.h
+++ b/src/histogram-inl.h
@@ -10,30 +10,34 @@
namespace node {
void Histogram::Reset() {
+ Mutex::ScopedLock lock(mutex_);
hdr_reset(histogram_.get());
-}
-
-bool Histogram::Record(int64_t value) {
- return hdr_record_value(histogram_.get(), value);
+ exceeds_ = 0;
+ prev_ = 0;
}
int64_t Histogram::Min() {
+ Mutex::ScopedLock lock(mutex_);
return hdr_min(histogram_.get());
}
int64_t Histogram::Max() {
+ Mutex::ScopedLock lock(mutex_);
return hdr_max(histogram_.get());
}
double Histogram::Mean() {
+ Mutex::ScopedLock lock(mutex_);
return hdr_mean(histogram_.get());
}
double Histogram::Stddev() {
+ Mutex::ScopedLock lock(mutex_);
return hdr_stddev(histogram_.get());
}
double Histogram::Percentile(double percentile) {
+ Mutex::ScopedLock lock(mutex_);
CHECK_GT(percentile, 0);
CHECK_LE(percentile, 100);
return static_cast<double>(
@@ -42,6 +46,7 @@ double Histogram::Percentile(double percentile) {
template <typename Iterator>
void Histogram::Percentiles(Iterator&& fn) {
+ Mutex::ScopedLock lock(mutex_);
hdr_iter iter;
hdr_iter_percentile_init(&iter, histogram_.get(), 1);
while (hdr_iter_next(&iter)) {
@@ -51,29 +56,29 @@ void Histogram::Percentiles(Iterator&& fn) {
}
}
-bool HistogramBase::RecordDelta() {
+bool Histogram::Record(int64_t value) {
+ Mutex::ScopedLock lock(mutex_);
+ return hdr_record_value(histogram_.get(), value);
+}
+
+uint64_t Histogram::RecordDelta() {
+ Mutex::ScopedLock lock(mutex_);
uint64_t time = uv_hrtime();
- bool ret = true;
+ uint64_t delta = 0;
if (prev_ > 0) {
- int64_t delta = time - prev_;
+ delta = time - prev_;
if (delta > 0) {
- ret = Record(delta);
- TraceDelta(delta);
- if (!ret) {
- if (exceeds_ < 0xFFFFFFFF)
- exceeds_++;
- TraceExceeds(delta);
- }
+ if (!hdr_record_value(histogram_.get(), delta) && exceeds_ < 0xFFFFFFFF)
+ exceeds_++;
}
}
prev_ = time;
- return ret;
+ return delta;
}
-void HistogramBase::ResetState() {
- Reset();
- exceeds_ = 0;
- prev_ = 0;
+size_t Histogram::GetMemorySize() const {
+ Mutex::ScopedLock lock(mutex_);
+ return hdr_get_memory_size(histogram_.get());
}
} // namespace node