@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.
Files changed (2) hide show
  1. package/lib/esm/index.js +169 -164
  2. 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
- performance = globalThis.performance;
4
+ performance = globalThis.performance;
4
5
  } else {
5
- let _startTime;
6
- let _now;
7
- try {
8
- const GLib = globalThis.imports.gi.GLib;
9
- _startTime = GLib.get_monotonic_time();
10
- _now = () => (GLib.get_monotonic_time() - _startTime) / 1e3;
11
- } catch {
12
- const _start = Date.now();
13
- _startTime = 0;
14
- _now = () => Date.now() - _start;
15
- }
16
- const _entries = [];
17
- const _timeOrigin = Date.now() - _now();
18
- performance = {
19
- timeOrigin: _timeOrigin,
20
- now: _now,
21
- mark(name) {
22
- const entry = { name, entryType: "mark", startTime: _now(), duration: 0 };
23
- _entries.push(entry);
24
- return entry;
25
- },
26
- measure(name, startMark, endMark) {
27
- let startTime = 0;
28
- let endTime = _now();
29
- if (startMark) {
30
- const s = _entries.find((e) => e.entryType === "mark" && e.name === startMark);
31
- if (s) startTime = s.startTime;
32
- }
33
- if (endMark) {
34
- const e = _entries.find((e2) => e2.entryType === "mark" && e2.name === endMark);
35
- if (e) endTime = e.startTime;
36
- }
37
- const entry = { name, entryType: "measure", startTime, duration: endTime - startTime };
38
- _entries.push(entry);
39
- return entry;
40
- },
41
- getEntries() {
42
- return [..._entries];
43
- },
44
- getEntriesByName(name) {
45
- return _entries.filter((e) => e.name === name);
46
- },
47
- getEntriesByType(type) {
48
- return _entries.filter((e) => e.entryType === type);
49
- },
50
- clearMarks(name) {
51
- for (let i = _entries.length - 1; i >= 0; i--) {
52
- if (_entries[i].entryType === "mark" && (!name || _entries[i].name === name)) {
53
- _entries.splice(i, 1);
54
- }
55
- }
56
- },
57
- clearMeasures(name) {
58
- for (let i = _entries.length - 1; i >= 0; i--) {
59
- if (_entries[i].entryType === "measure" && (!name || _entries[i].name === name)) {
60
- _entries.splice(i, 1);
61
- }
62
- }
63
- },
64
- clearResourceTimings() {
65
- },
66
- setResourceTimingBufferSize() {
67
- },
68
- toJSON() {
69
- return { timeOrigin: _timeOrigin };
70
- }
71
- };
72
- }
73
- class PerformanceObserverStub {
74
- _callback;
75
- constructor(callback) {
76
- this._callback = callback;
77
- }
78
- observe(_options) {
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 PerformanceMark2 extends PerformanceEntryStub {
110
- };
111
- const PerformanceMeasure = globalThis.PerformanceMeasure || class PerformanceMeasure2 extends PerformanceEntryStub {
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
- return { idle: 0, active: 0, utilization: 0 };
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
- const wrapped = function(...args) {
118
- const start = performance.now();
119
- const result = fn.apply(this, args);
120
- const duration = performance.now() - start;
121
- void duration;
122
- return result;
123
- };
124
- Object.defineProperty(wrapped, "name", { value: fn.name });
125
- return wrapped;
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
- const percentiles = /* @__PURE__ */ new Map();
129
- return {
130
- enable() {
131
- },
132
- disable() {
133
- },
134
- reset() {
135
- },
136
- percentile(_p) {
137
- return 0;
138
- },
139
- get min() {
140
- return 0;
141
- },
142
- get max() {
143
- return 0;
144
- },
145
- get mean() {
146
- return 0;
147
- },
148
- get stddev() {
149
- return 0;
150
- },
151
- get percentiles() {
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 index_default = {
157
- performance,
158
- PerformanceObserver,
159
- PerformanceEntry,
160
- PerformanceObserverEntryList,
161
- PerformanceMark,
162
- PerformanceMeasure,
163
- eventLoopUtilization,
164
- timerify,
165
- monitorEventLoopDelay
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.12",
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.12",
34
- "@gjsify/unit": "^0.3.12",
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
  }