mirror of
https://github.com/nodejs/node.git
synced 2026-11-09 15:11:11 -05:00
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>
39 lines
832 B
C++
39 lines
832 B
C++
#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_
|