@matterbridge/utils 3.10.14-dev-20261010-607ee18 → 3.10.14-dev-20261013-e87a0c8
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/dist/runtimeBun.d.ts +1 -0
- package/dist/runtimeBun.js +5 -0
- package/dist/tracker.d.ts +4 -2
- package/dist/tracker.js +37 -16
- package/package.json +1 -1
package/dist/runtimeBun.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export declare function which(command: string): string | null;
|
|
|
12
12
|
export declare function gc(force?: boolean): void;
|
|
13
13
|
export declare function setGcLevel(level?: 0 | 1 | 2): 0 | 1 | 2 | undefined;
|
|
14
14
|
export declare function memoryFootprint(): number;
|
|
15
|
+
export declare function constrainedMemory(): number;
|
|
15
16
|
export interface BunRuntimeInfo {
|
|
16
17
|
isBun: boolean;
|
|
17
18
|
version?: string;
|
package/dist/runtimeBun.js
CHANGED
|
@@ -97,6 +97,11 @@ export function memoryFootprint() {
|
|
|
97
97
|
}
|
|
98
98
|
return process.memoryUsage().rss;
|
|
99
99
|
}
|
|
100
|
+
export function constrainedMemory() {
|
|
101
|
+
const totalMemory = os.totalmem();
|
|
102
|
+
const constrained = process.constrainedMemory();
|
|
103
|
+
return typeof constrained === 'number' && Number.isFinite(constrained) && constrained > 0 && constrained < totalMemory ? constrained : totalMemory;
|
|
104
|
+
}
|
|
100
105
|
export function getBunRuntimeInfo() {
|
|
101
106
|
const bun = getBun();
|
|
102
107
|
return {
|
package/dist/tracker.d.ts
CHANGED
|
@@ -5,6 +5,8 @@ export type TrackerSnapshot = {
|
|
|
5
5
|
peakFreeMemory: number;
|
|
6
6
|
totalMemory: number;
|
|
7
7
|
peakTotalMemory: number;
|
|
8
|
+
constrainedMemory: number;
|
|
9
|
+
peakConstrainedMemory: number;
|
|
8
10
|
osCpu: number;
|
|
9
11
|
peakOsCpu: number;
|
|
10
12
|
processCpu: number;
|
|
@@ -23,8 +25,8 @@ export type TrackerSnapshot = {
|
|
|
23
25
|
interface TrackerEvents {
|
|
24
26
|
start: [];
|
|
25
27
|
stop: [];
|
|
26
|
-
uptime: [
|
|
27
|
-
cpu: [
|
|
28
|
+
uptime: [systemUptime: number, processUptime: number];
|
|
29
|
+
cpu: [osCpu: number, processCpu: number];
|
|
28
30
|
memory: [free: number, total: number, rss: number, heapUsed: number, heapTotal: number, external: number, arrayBuffers: number];
|
|
29
31
|
snapshot: [snapshot: TrackerSnapshot];
|
|
30
32
|
reset_peaks: [];
|
package/dist/tracker.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import EventEmitter from 'node:events';
|
|
2
2
|
import os from 'node:os';
|
|
3
3
|
import { AnsiLogger, BRIGHT, CYAN, db, RED, RESET, YELLOW } from 'node-ansi-logger';
|
|
4
|
-
import {
|
|
4
|
+
import { hasAnyParameter, hasParameter } from './commandLine.js';
|
|
5
|
+
import { formatBytes, formatPercent, formatTimeStamp, formatUptime } from './format.js';
|
|
5
6
|
import { logModuleLoaded } from './loader.js';
|
|
6
|
-
import { isBun, gc, memoryFootprint, setGcLevel } from './runtimeBun.js';
|
|
7
|
+
import { isBun, gc, constrainedMemory, memoryFootprint, setGcLevel } from './runtimeBun.js';
|
|
7
8
|
logModuleLoaded('Tracker');
|
|
8
9
|
export class Tracker extends EventEmitter {
|
|
9
10
|
name;
|
|
@@ -20,6 +21,8 @@ export class Tracker extends EventEmitter {
|
|
|
20
21
|
peakFreeMemory: 0,
|
|
21
22
|
totalMemory: 0,
|
|
22
23
|
peakTotalMemory: 0,
|
|
24
|
+
constrainedMemory: 0,
|
|
25
|
+
peakConstrainedMemory: 0,
|
|
23
26
|
osCpu: 0,
|
|
24
27
|
peakOsCpu: 0,
|
|
25
28
|
processCpu: 0,
|
|
@@ -45,24 +48,38 @@ export class Tracker extends EventEmitter {
|
|
|
45
48
|
this.verbose = verbose;
|
|
46
49
|
this.tracker = tracker;
|
|
47
50
|
this.forceGc = forceGc;
|
|
48
|
-
if (
|
|
51
|
+
if (hasAnyParameter('debug', 'verbose')) {
|
|
49
52
|
this.debug = true;
|
|
50
53
|
}
|
|
51
|
-
if (
|
|
54
|
+
if (hasParameter('verbose')) {
|
|
52
55
|
this.verbose = true;
|
|
53
56
|
}
|
|
54
|
-
if (
|
|
57
|
+
if (hasParameter('tracker')) {
|
|
55
58
|
this.tracker = true;
|
|
56
59
|
}
|
|
57
|
-
if (
|
|
60
|
+
if (hasParameter('force-gc')) {
|
|
58
61
|
this.forceGc = true;
|
|
59
62
|
}
|
|
60
|
-
|
|
63
|
+
if (this.verbose)
|
|
64
|
+
this.debug = true;
|
|
65
|
+
this.log = new AnsiLogger({ logName: name, logTimestampFormat: 4, logLevel: this.debug ? "debug" : "info" });
|
|
61
66
|
this.log.logNameColor = YELLOW;
|
|
62
67
|
if (this.verbose) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
68
|
+
const cpuGroups = new Map();
|
|
69
|
+
for (const cpu of os.cpus()) {
|
|
70
|
+
const key = `${cpu.model} @ ${cpu.speed} MHz`;
|
|
71
|
+
cpuGroups.set(key, (cpuGroups.get(key) ?? 0) + 1);
|
|
72
|
+
}
|
|
73
|
+
const cpus = Array.from(cpuGroups, ([key, count]) => `${CYAN}${count} × ${key}${db}`).join(', ') || `${CYAN}unknown${db}`;
|
|
74
|
+
this.log.debug(`os.cpus(): ${cpus} (availableParallelism ${CYAN}${os.availableParallelism()}${db})`);
|
|
75
|
+
const cpuUsage = process.cpuUsage();
|
|
76
|
+
this.log.debug(`process.cpuUsage(): user ${CYAN}${(cpuUsage.user / 1_000_000).toFixed(2)} s${db}, system ${CYAN}${(cpuUsage.system / 1_000_000).toFixed(2)} s${db}`);
|
|
77
|
+
const memoryUsage = process.memoryUsage();
|
|
78
|
+
this.log.debug(`process.memoryUsage(): rss ${CYAN}${formatBytes(memoryUsage.rss)}${db}, heapTotal ${CYAN}${formatBytes(memoryUsage.heapTotal)}${db}, heapUsed ${CYAN}${formatBytes(memoryUsage.heapUsed)}${db}, ` +
|
|
79
|
+
`external ${CYAN}${formatBytes(memoryUsage.external)}${db}, arrayBuffers ${CYAN}${formatBytes(memoryUsage.arrayBuffers)}${db}`);
|
|
80
|
+
this.log.debug(`constrainedMemory(): ${CYAN}${formatBytes(constrainedMemory())}${db}`);
|
|
81
|
+
this.log.debug(`os.uptime(): ${CYAN}${formatUptime(Math.floor(os.uptime()))}${db}`);
|
|
82
|
+
this.log.debug(`process.uptime(): ${CYAN}${formatUptime(Math.floor(process.uptime()))}${db}`);
|
|
66
83
|
}
|
|
67
84
|
this.on('start', () => {
|
|
68
85
|
this.start();
|
|
@@ -123,6 +140,8 @@ export class Tracker extends EventEmitter {
|
|
|
123
140
|
entry.peakFreeMemory = Math.max(prevEntry.peakFreeMemory, entry.freeMemory);
|
|
124
141
|
entry.totalMemory = os.totalmem();
|
|
125
142
|
entry.peakTotalMemory = Math.max(prevEntry.peakTotalMemory, entry.totalMemory);
|
|
143
|
+
entry.constrainedMemory = constrainedMemory();
|
|
144
|
+
entry.peakConstrainedMemory = Math.max(prevEntry.peakConstrainedMemory, entry.constrainedMemory);
|
|
126
145
|
const mem = process.memoryUsage();
|
|
127
146
|
entry.rss = memoryFootprint();
|
|
128
147
|
entry.peakRss = Math.max(prevEntry.peakRss, entry.rss);
|
|
@@ -136,8 +155,9 @@ export class Tracker extends EventEmitter {
|
|
|
136
155
|
entry.peakArrayBuffers = Math.max(prevEntry.peakArrayBuffers, mem.arrayBuffers);
|
|
137
156
|
this.emit('memory', entry.freeMemory, entry.totalMemory, entry.rss, entry.heapUsed, entry.heapTotal, entry.external, entry.arrayBuffers);
|
|
138
157
|
this.emit('snapshot', entry);
|
|
139
|
-
if (this.
|
|
140
|
-
this.log.
|
|
158
|
+
if (this.tracker) {
|
|
159
|
+
this.log.info(db +
|
|
160
|
+
`Time: ${formatTimeStamp(entry.timestamp)} ` +
|
|
141
161
|
`os ${CYAN}${BRIGHT}${formatPercent(entry.osCpu)}${RESET}${db} (${entry.peakOsCpu > prevEntry.peakOsCpu ? RED : ''}${formatPercent(entry.peakOsCpu)}${db}) ` +
|
|
142
162
|
`process ${CYAN}${BRIGHT}${formatPercent(entry.processCpu)}${RESET}${db} (${entry.peakProcessCpu > prevEntry.peakProcessCpu ? RED : ''}${formatPercent(entry.peakProcessCpu)}${db}) ` +
|
|
143
163
|
`rss: ${CYAN}${BRIGHT}${formatBytes(entry.rss)}${RESET}${db} (${entry.peakRss > prevEntry.peakRss ? RED : ''}${formatBytes(entry.peakRss)}${db}) ` +
|
|
@@ -203,15 +223,16 @@ export class Tracker extends EventEmitter {
|
|
|
203
223
|
clearInterval(this.trackerInterval);
|
|
204
224
|
this.trackerInterval = undefined;
|
|
205
225
|
}
|
|
206
|
-
if (this.
|
|
207
|
-
this.log.
|
|
208
|
-
this.log.
|
|
226
|
+
if (this.tracker) {
|
|
227
|
+
this.log.info(db + `Tracker history for ${YELLOW}${BRIGHT}${this.name}:${RESET}`);
|
|
228
|
+
this.log.info(db + 'Timestamp Host cpu Process cpu Rss Heap Used Heap Total External ArrayBuffers');
|
|
209
229
|
for (let i = 0; i < Tracker.historySize; i++) {
|
|
210
230
|
const index = (Tracker.historyIndex + i) % Tracker.historySize;
|
|
211
231
|
const entry = Tracker.history[index];
|
|
212
232
|
if (entry.timestamp === 0)
|
|
213
233
|
continue;
|
|
214
|
-
this.log.
|
|
234
|
+
this.log.info(db +
|
|
235
|
+
`${formatTimeStamp(entry.timestamp)} ` +
|
|
215
236
|
`${CYAN}${BRIGHT}${formatPercent(entry.osCpu).padStart(8)}${RESET} (${formatPercent(entry.peakOsCpu).padStart(8)}) ` +
|
|
216
237
|
`${CYAN}${BRIGHT}${formatPercent(entry.processCpu).padStart(8)}${RESET} (${formatPercent(entry.peakProcessCpu).padStart(8)}) ` +
|
|
217
238
|
`${CYAN}${BRIGHT}${formatBytes(entry.rss).padStart(9)}${RESET} (${formatBytes(entry.peakRss).padStart(9)}) ` +
|
package/package.json
CHANGED