MCPcopy Create free account
hub / github.com/nodejs/node / instrument

Function instrument

deps/v8/tools/wasm/wasm-import-profiler.js:10–38  ·  view source on GitHub ↗
(imports, profile)

Source from the content-addressed store, hash-verified

8 let instanceCounter = 0;
9
10 function instrument(imports, profile) {
11 let orig_imports = imports;
12 return new Proxy(imports, {
13 get: (obj, module_name) => {
14 let orig_module = orig_imports[module_name];
15 return new Proxy(orig_module, {
16 get: (obj, item_name) => {
17 let orig_func = orig_module[item_name];
18 let item = orig_func;
19 if (typeof orig_func == "function") {
20 var full_name = module_name + "." + item_name;
21 print("instrumented " + full_name);
22 profile[full_name] = {name: full_name, count: 0, total: 0};
23 item = function profiled_func(...args) {
24 var before = performance.now();
25 var result = orig_func(...args);
26 var delta = performance.now() - before;
27 var data = profile[full_name];
28 data.count++;
29 data.total += delta;
30 return result;
31 }
32 }
33 return item;
34 }
35 })
36 }
37 });
38 }
39
40 function dumpProfile(profile) {
41 let array = [];

Callers 1

Calls 2

nowMethod · 0.80
printFunction · 0.50

Tested by

no test coverage detected