@gjsify/perf_hooks 0.3.12 → 0.3.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/esm/index.js +169 -164
- package/package.json +3 -3
package/lib/esm/index.js
CHANGED
|
@@ -1,178 +1,183 @@
|
|
|
1
|
+
//#region src/index.ts
|
|
1
2
|
let performance;
|
|
2
3
|
if (globalThis.performance) {
|
|
3
|
-
|
|
4
|
+
performance = globalThis.performance;
|
|
4
5
|
} else {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
disconnect() {
|
|
81
|
-
}
|
|
82
|
-
takeRecords() {
|
|
83
|
-
return [];
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
class PerformanceEntryStub {
|
|
87
|
-
name = "";
|
|
88
|
-
entryType = "";
|
|
89
|
-
startTime = 0;
|
|
90
|
-
duration = 0;
|
|
91
|
-
toJSON() {
|
|
92
|
-
return { name: this.name, entryType: this.entryType, startTime: this.startTime, duration: this.duration };
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
class PerformanceObserverEntryListStub {
|
|
96
|
-
getEntries() {
|
|
97
|
-
return [];
|
|
98
|
-
}
|
|
99
|
-
getEntriesByName(_name) {
|
|
100
|
-
return [];
|
|
101
|
-
}
|
|
102
|
-
getEntriesByType(_type) {
|
|
103
|
-
return [];
|
|
104
|
-
}
|
|
6
|
+
let _startTime;
|
|
7
|
+
let _now;
|
|
8
|
+
try {
|
|
9
|
+
const GLib = globalThis.imports.gi.GLib;
|
|
10
|
+
_startTime = GLib.get_monotonic_time();
|
|
11
|
+
_now = () => (GLib.get_monotonic_time() - _startTime) / 1e3;
|
|
12
|
+
} catch {
|
|
13
|
+
const _start = Date.now();
|
|
14
|
+
_startTime = 0;
|
|
15
|
+
_now = () => Date.now() - _start;
|
|
16
|
+
}
|
|
17
|
+
const _entries = [];
|
|
18
|
+
const _timeOrigin = Date.now() - _now();
|
|
19
|
+
performance = {
|
|
20
|
+
timeOrigin: _timeOrigin,
|
|
21
|
+
now: _now,
|
|
22
|
+
mark(name) {
|
|
23
|
+
const entry = {
|
|
24
|
+
name,
|
|
25
|
+
entryType: "mark",
|
|
26
|
+
startTime: _now(),
|
|
27
|
+
duration: 0
|
|
28
|
+
};
|
|
29
|
+
_entries.push(entry);
|
|
30
|
+
return entry;
|
|
31
|
+
},
|
|
32
|
+
measure(name, startMark, endMark) {
|
|
33
|
+
let startTime = 0;
|
|
34
|
+
let endTime = _now();
|
|
35
|
+
if (startMark) {
|
|
36
|
+
const s = _entries.find((e) => e.entryType === "mark" && e.name === startMark);
|
|
37
|
+
if (s) startTime = s.startTime;
|
|
38
|
+
}
|
|
39
|
+
if (endMark) {
|
|
40
|
+
const e = _entries.find((e) => e.entryType === "mark" && e.name === endMark);
|
|
41
|
+
if (e) endTime = e.startTime;
|
|
42
|
+
}
|
|
43
|
+
const entry = {
|
|
44
|
+
name,
|
|
45
|
+
entryType: "measure",
|
|
46
|
+
startTime,
|
|
47
|
+
duration: endTime - startTime
|
|
48
|
+
};
|
|
49
|
+
_entries.push(entry);
|
|
50
|
+
return entry;
|
|
51
|
+
},
|
|
52
|
+
getEntries() {
|
|
53
|
+
return [..._entries];
|
|
54
|
+
},
|
|
55
|
+
getEntriesByName(name) {
|
|
56
|
+
return _entries.filter((e) => e.name === name);
|
|
57
|
+
},
|
|
58
|
+
getEntriesByType(type) {
|
|
59
|
+
return _entries.filter((e) => e.entryType === type);
|
|
60
|
+
},
|
|
61
|
+
clearMarks(name) {
|
|
62
|
+
for (let i = _entries.length - 1; i >= 0; i--) {
|
|
63
|
+
if (_entries[i].entryType === "mark" && (!name || _entries[i].name === name)) {
|
|
64
|
+
_entries.splice(i, 1);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
clearMeasures(name) {
|
|
69
|
+
for (let i = _entries.length - 1; i >= 0; i--) {
|
|
70
|
+
if (_entries[i].entryType === "measure" && (!name || _entries[i].name === name)) {
|
|
71
|
+
_entries.splice(i, 1);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
clearResourceTimings() {},
|
|
76
|
+
setResourceTimingBufferSize() {},
|
|
77
|
+
toJSON() {
|
|
78
|
+
return { timeOrigin: _timeOrigin };
|
|
79
|
+
}
|
|
80
|
+
};
|
|
105
81
|
}
|
|
82
|
+
var PerformanceObserverStub = class {
|
|
83
|
+
_callback;
|
|
84
|
+
constructor(callback) {
|
|
85
|
+
this._callback = callback;
|
|
86
|
+
}
|
|
87
|
+
observe(_options) {}
|
|
88
|
+
disconnect() {}
|
|
89
|
+
takeRecords() {
|
|
90
|
+
return [];
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
var PerformanceEntryStub = class {
|
|
94
|
+
name = "";
|
|
95
|
+
entryType = "";
|
|
96
|
+
startTime = 0;
|
|
97
|
+
duration = 0;
|
|
98
|
+
toJSON() {
|
|
99
|
+
return {
|
|
100
|
+
name: this.name,
|
|
101
|
+
entryType: this.entryType,
|
|
102
|
+
startTime: this.startTime,
|
|
103
|
+
duration: this.duration
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
var PerformanceObserverEntryListStub = class {
|
|
108
|
+
getEntries() {
|
|
109
|
+
return [];
|
|
110
|
+
}
|
|
111
|
+
getEntriesByName(_name) {
|
|
112
|
+
return [];
|
|
113
|
+
}
|
|
114
|
+
getEntriesByType(_type) {
|
|
115
|
+
return [];
|
|
116
|
+
}
|
|
117
|
+
};
|
|
106
118
|
const PerformanceObserver = globalThis.PerformanceObserver || PerformanceObserverStub;
|
|
107
119
|
const PerformanceEntry = globalThis.PerformanceEntry || PerformanceEntryStub;
|
|
108
120
|
const PerformanceObserverEntryList = globalThis.PerformanceObserverEntryList || PerformanceObserverEntryListStub;
|
|
109
|
-
const PerformanceMark = globalThis.PerformanceMark || class
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
};
|
|
121
|
+
const PerformanceMark = globalThis.PerformanceMark || class PerformanceMark extends PerformanceEntryStub {};
|
|
122
|
+
const PerformanceMeasure = globalThis.PerformanceMeasure || class PerformanceMeasure extends PerformanceEntryStub {};
|
|
123
|
+
/** Stub: event loop utilization metrics (not available in GJS). */
|
|
113
124
|
function eventLoopUtilization(_utilization1, _utilization2) {
|
|
114
|
-
|
|
125
|
+
return {
|
|
126
|
+
idle: 0,
|
|
127
|
+
active: 0,
|
|
128
|
+
utilization: 0
|
|
129
|
+
};
|
|
115
130
|
}
|
|
131
|
+
/** Stub: wraps a function to measure its execution time. */
|
|
116
132
|
function timerify(fn) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
133
|
+
const wrapped = function(...args) {
|
|
134
|
+
const start = performance.now();
|
|
135
|
+
const result = fn.apply(this, args);
|
|
136
|
+
const duration = performance.now() - start;
|
|
137
|
+
void duration;
|
|
138
|
+
return result;
|
|
139
|
+
};
|
|
140
|
+
Object.defineProperty(wrapped, "name", { value: fn.name });
|
|
141
|
+
return wrapped;
|
|
126
142
|
}
|
|
143
|
+
/** Stub: monitor event loop delay. */
|
|
127
144
|
function monitorEventLoopDelay(_options) {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
return percentiles;
|
|
153
|
-
}
|
|
154
|
-
};
|
|
145
|
+
const percentiles = new Map();
|
|
146
|
+
return {
|
|
147
|
+
enable() {},
|
|
148
|
+
disable() {},
|
|
149
|
+
reset() {},
|
|
150
|
+
percentile(_p) {
|
|
151
|
+
return 0;
|
|
152
|
+
},
|
|
153
|
+
get min() {
|
|
154
|
+
return 0;
|
|
155
|
+
},
|
|
156
|
+
get max() {
|
|
157
|
+
return 0;
|
|
158
|
+
},
|
|
159
|
+
get mean() {
|
|
160
|
+
return 0;
|
|
161
|
+
},
|
|
162
|
+
get stddev() {
|
|
163
|
+
return 0;
|
|
164
|
+
},
|
|
165
|
+
get percentiles() {
|
|
166
|
+
return percentiles;
|
|
167
|
+
}
|
|
168
|
+
};
|
|
155
169
|
}
|
|
156
|
-
var
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
};
|
|
167
|
-
export {
|
|
168
|
-
PerformanceEntry,
|
|
169
|
-
PerformanceMark,
|
|
170
|
-
PerformanceMeasure,
|
|
171
|
-
PerformanceObserver,
|
|
172
|
-
PerformanceObserverEntryList,
|
|
173
|
-
index_default as default,
|
|
174
|
-
eventLoopUtilization,
|
|
175
|
-
monitorEventLoopDelay,
|
|
176
|
-
performance,
|
|
177
|
-
timerify
|
|
170
|
+
var src_default = {
|
|
171
|
+
performance,
|
|
172
|
+
PerformanceObserver,
|
|
173
|
+
PerformanceEntry,
|
|
174
|
+
PerformanceObserverEntryList,
|
|
175
|
+
PerformanceMark,
|
|
176
|
+
PerformanceMeasure,
|
|
177
|
+
eventLoopUtilization,
|
|
178
|
+
timerify,
|
|
179
|
+
monitorEventLoopDelay
|
|
178
180
|
};
|
|
181
|
+
|
|
182
|
+
//#endregion
|
|
183
|
+
export { PerformanceEntry, PerformanceMark, PerformanceMeasure, PerformanceObserver, PerformanceObserverEntryList, src_default as default, eventLoopUtilization, monitorEventLoopDelay, performance, timerify };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/perf_hooks",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.14",
|
|
4
4
|
"description": "Node.js perf_hooks module for Gjs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "lib/esm/index.js",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"perf_hooks"
|
|
31
31
|
],
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@gjsify/cli": "^0.3.
|
|
34
|
-
"@gjsify/unit": "^0.3.
|
|
33
|
+
"@gjsify/cli": "^0.3.14",
|
|
34
|
+
"@gjsify/unit": "^0.3.14",
|
|
35
35
|
"@types/node": "^25.6.0",
|
|
36
36
|
"typescript": "^6.0.3"
|
|
37
37
|
}
|