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>2019-01-07 22:36:35 +0300
committerjasnell <jasnell@gmail.com>2019-02-08 20:20:18 +0300
commitbcdd228f90b3e9e428b584814e7d52627616456a (patch)
treeeed1b405a1fd7e2f78bbf10e82d65c57d2c29105 /src/histogram-inl.h
parent679c23f2ae1e62443f8d90e653824007ce174139 (diff)
perf_hooks: implement histogram based api
Add a sampling-based event loop delay monitor. ```js const { monitorEventLoopDelay } = require('perf_hooks'); const h = monitorEventLoopDelay(); h.enable(); h.disable(); console.log(h.percentiles); console.log(h.min); console.log(h.max); console.log(h.mean); console.log(h.stddev); console.log(h.percentile(50)); ``` PR-URL: https://github.com/nodejs/node/pull/25378 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'src/histogram-inl.h')
-rw-r--r--src/histogram-inl.h63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/histogram-inl.h b/src/histogram-inl.h
new file mode 100644
index 00000000000..3135041f738
--- /dev/null
+++ b/src/histogram-inl.h
@@ -0,0 +1,63 @@
+#ifndef SRC_HISTOGRAM_INL_H_
+#define SRC_HISTOGRAM_INL_H_
+
+#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
+
+#include "histogram.h"
+#include "node_internals.h"
+
+namespace node {
+
+inline Histogram::Histogram(int64_t lowest, int64_t highest, int figures) {
+ CHECK_EQ(0, hdr_init(lowest, highest, figures, &histogram_));
+}
+
+inline Histogram::~Histogram() {
+ hdr_close(histogram_);
+}
+
+inline void Histogram::Reset() {
+ hdr_reset(histogram_);
+}
+
+inline bool Histogram::Record(int64_t value) {
+ return hdr_record_value(histogram_, value);
+}
+
+inline int64_t Histogram::Min() {
+ return hdr_min(histogram_);
+}
+
+inline int64_t Histogram::Max() {
+ return hdr_max(histogram_);
+}
+
+inline double Histogram::Mean() {
+ return hdr_mean(histogram_);
+}
+
+inline double Histogram::Stddev() {
+ return hdr_stddev(histogram_);
+}
+
+inline double Histogram::Percentile(double percentile) {
+ CHECK_GT(percentile, 0);
+ CHECK_LE(percentile, 100);
+ return hdr_value_at_percentile(histogram_, percentile);
+}
+
+inline void Histogram::Percentiles(std::function<void(double, double)> fn) {
+ hdr_iter iter;
+ hdr_iter_percentile_init(&iter, histogram_, 1);
+ while (hdr_iter_next(&iter)) {
+ double key = iter.specifics.percentiles.percentile;
+ double value = iter.value;
+ fn(key, value);
+ }
+}
+
+} // namespace node
+
+#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
+
+#endif // SRC_HISTOGRAM_INL_H_