summaryrefslogtreecommitdiff
path: root/src/node_perf.cc
diff options
context:
space:
mode:
authorvmarchaud <contact@vmarchaud.fr>2019-06-30 22:37:18 +0200
committerAnna Henningsen <anna@addaleax.net>2019-07-12 00:36:27 +0200
commit0ebf01dc53b474ffca78c7ace023bb10341b6664 (patch)
tree47aa24677e1903e7a2d5f694b19ea12f59ad7d43 /src/node_perf.cc
parentca0884a60b2fc828b6ca35e9b46e6979d9024146 (diff)
downloadandroid-node-v8-0ebf01dc53b474ffca78c7ace023bb10341b6664.tar.gz
android-node-v8-0ebf01dc53b474ffca78c7ace023bb10341b6664.tar.bz2
android-node-v8-0ebf01dc53b474ffca78c7ace023bb10341b6664.zip
perf_hooks: add HttpRequest statistics monitoring #28445
```js const { PerformanceObserver, performance } = require('perf_hooks'); const http = require('http'); const obs = new PerformanceObserver((items) => { const entry = items.getEntries()[0]; console.log(entry.name, entry.duration); }); obs.observe({ entryTypes: ['http'] }); const server = http.Server(function(req, res) { server.close(); res.writeHead(200); res.end('hello world\n'); }); server.listen(0, function() { const req = http.request({ port: this.address().port, path: '/', method: 'POST' }).end(); }); ``` PR-URL: https://github.com/nodejs/node/pull/28486 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'src/node_perf.cc')
-rw-r--r--src/node_perf.cc16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/node_perf.cc b/src/node_perf.cc
index f43c102136..45adcf332a 100644
--- a/src/node_perf.cc
+++ b/src/node_perf.cc
@@ -366,6 +366,21 @@ void Timerify(const FunctionCallbackInfo<Value>& args) {
args.GetReturnValue().Set(wrap);
}
+// Notify a custom PerformanceEntry to observers
+void Notify(const FunctionCallbackInfo<Value>& args) {
+ Environment* env = Environment::GetCurrent(args);
+ Utf8Value type(env->isolate(), args[0]);
+ Local<Value> entry = args[1];
+ PerformanceEntryType entry_type = ToPerformanceEntryTypeEnum(*type);
+ AliasedUint32Array& observers = env->performance_state()->observers;
+ if (entry_type != NODE_PERFORMANCE_ENTRY_TYPE_INVALID &&
+ observers[entry_type]) {
+ USE(env->performance_entry_callback()->
+ Call(env->context(), Undefined(env->isolate()), 1, &entry));
+ }
+}
+
+
// Event Loop Timing Histogram
namespace {
static void ELDHistogramMin(const FunctionCallbackInfo<Value>& args) {
@@ -562,6 +577,7 @@ void Initialize(Local<Object> target,
env->SetMethod(target, "timerify", Timerify);
env->SetMethod(
target, "setupGarbageCollectionTracking", SetupGarbageCollectionTracking);
+ env->SetMethod(target, "notify", Notify);
Local<Object> constants = Object::New(isolate);