summaryrefslogtreecommitdiff
path: root/src/node_perf.h
diff options
context:
space:
mode:
authorJames M Snell <jasnell@gmail.com>2019-01-07 11:36:35 -0800
committerjasnell <jasnell@gmail.com>2019-02-08 09:20:18 -0800
commitbcdd228f90b3e9e428b584814e7d52627616456a (patch)
treeeed1b405a1fd7e2f78bbf10e82d65c57d2c29105 /src/node_perf.h
parent679c23f2ae1e62443f8d90e653824007ce174139 (diff)
downloadandroid-node-v8-bcdd228f90b3e9e428b584814e7d52627616456a.tar.gz
android-node-v8-bcdd228f90b3e9e428b584814e7d52627616456a.tar.bz2
android-node-v8-bcdd228f90b3e9e428b584814e7d52627616456a.zip
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/node_perf.h')
-rw-r--r--src/node_perf.h36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/node_perf.h b/src/node_perf.h
index e3ef69c0fb..a8e43dc347 100644
--- a/src/node_perf.h
+++ b/src/node_perf.h
@@ -7,6 +7,7 @@
#include "node_perf_common.h"
#include "env.h"
#include "base_object-inl.h"
+#include "histogram-inl.h"
#include "v8.h"
#include "uv.h"
@@ -124,6 +125,41 @@ class GCPerformanceEntry : public PerformanceEntry {
PerformanceGCKind gckind_;
};
+class ELDHistogram : public BaseObject, public Histogram {
+ public:
+ ELDHistogram(Environment* env,
+ Local<Object> wrap,
+ int32_t resolution);
+
+ ~ELDHistogram() override;
+
+ bool RecordDelta();
+ bool Enable();
+ bool Disable();
+ void ResetState() {
+ Reset();
+ exceeds_ = 0;
+ prev_ = 0;
+ }
+ int64_t Exceeds() { return exceeds_; }
+
+ void MemoryInfo(MemoryTracker* tracker) const override {
+ tracker->TrackFieldWithSize("histogram", GetMemorySize());
+ }
+
+ SET_MEMORY_INFO_NAME(ELDHistogram)
+ SET_SELF_SIZE(ELDHistogram)
+
+ private:
+ void CloseTimer();
+
+ bool enabled_ = false;
+ int32_t resolution_ = 0;
+ int64_t exceeds_ = 0;
+ uint64_t prev_ = 0;
+ uv_timer_t* timer_;
+};
+
} // namespace performance
} // namespace node