diff options
author | James M Snell <jasnell@gmail.com> | 2019-01-07 22:36:35 +0300 |
---|---|---|
committer | jasnell <jasnell@gmail.com> | 2019-02-08 20:20:18 +0300 |
commit | bcdd228f90b3e9e428b584814e7d52627616456a (patch) | |
tree | eed1b405a1fd7e2f78bbf10e82d65c57d2c29105 /src/histogram.h | |
parent | 679c23f2ae1e62443f8d90e653824007ce174139 (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.h')
-rw-r--r-- | src/histogram.h | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/histogram.h b/src/histogram.h new file mode 100644 index 00000000000..eb94af5da2a --- /dev/null +++ b/src/histogram.h @@ -0,0 +1,38 @@ +#ifndef SRC_HISTOGRAM_H_ +#define SRC_HISTOGRAM_H_ + +#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS + +#include "hdr_histogram.h" +#include <functional> +#include <map> + +namespace node { + +class Histogram { + public: + inline Histogram(int64_t lowest, int64_t highest, int figures = 3); + inline virtual ~Histogram(); + + inline bool Record(int64_t value); + inline void Reset(); + inline int64_t Min(); + inline int64_t Max(); + inline double Mean(); + inline double Stddev(); + inline double Percentile(double percentile); + inline void Percentiles(std::function<void(double, double)> fn); + + size_t GetMemorySize() const { + return hdr_get_memory_size(histogram_); + } + + private: + hdr_histogram* histogram_; +}; + +} // namespace node + +#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS + +#endif // SRC_HISTOGRAM_H_ |