Files
discord-decomp/_bundle/ActionLog.js
T
2026-11-01 12:12:55 +02:00

190 lines
4.7 KiB
JavaScript

// Metro module 651 (f652).
import { Logger } from "./log";
import { EventEmitter } from "./EventEmitter_652";
import { performance } from "./Module653";
let c574_4;
let c574_3 = new Logger("Flux");
class ActionLogger extends EventEmitter {
constructor(r1 = {}) {
let persist = r1.persist;
if (persist === void 0) {
persist = false;
}
super();
this.logs = [];
this.persist = persist;
}
log(a0, a1) {
let c12427_1 = a0;
const actionLog = new ActionLog(a0);
let c12427_0 = actionLog;
actionLog.startTime = performance.now();
try {
try {
a1((a0, a1) => {
let r23;
const r1 = {
name: a0,
time: -1
};
const r21 = performance.now();
try {
r23 = a1();
} catch (r36) {
r1.time = performance.now() - r21;
if (this.persist) {
c12427_0.traces.push(r1);
}
this.emit("trace", c12427_1.type, a0, r1.time);
throw r36;
}
r1.time = performance.now() - r21;
if (this.persist) {
c12427_0.traces.push(r1);
}
this.emit("trace", c12427_1.type, a0, r1.time);
return r23;
});
} catch (error) {
actionLog.error = error;
throw error;
}
} catch (r44) {
actionLog.totalTime = performance.now() - actionLog.startTime;
if (this.persist && actionLog.totalTime > 0) {
this.logs.push(actionLog);
}
if (this.logs.length > 1000) {
this.logs.shift();
}
this.emit("log", a0);
throw r44;
}
actionLog.totalTime = performance.now() - actionLog.startTime;
if (this.persist && actionLog.totalTime > 0) {
this.logs.push(actionLog);
}
if (this.logs.length > 1000) {
this.logs.shift();
}
this.emit("log", a0);
return actionLog;
}
getSlowestActions(a0) {
let c12428_1, c12428_2;
let length = arguments[1];
if (length === void 0) {
length = 20;
}
c12428_1 = void 0;
c12428_2 = void 0;
const r0 = [];
for (const log3 of this.logs) {
if (a0 != null && log3.name !== a0) {
continue;
}
for (const trace of log3.traces) {
r0.push([trace.name, log3.name, trace.time]);
}
}
r0.sort((a, b) => b[2] - a[2]);
if (r0.length > length) {
r0.length = length;
}
c12428_1 = 0;
c12428_2 = 0;
const r63 = r0.map((item) => {
const [r8, r11, r31] = item;
const r39 = `${r8}`;
const r42 = a0 == null ? r39 + `<${r11}>` : r39;
c12428_1 = Math.max(r42.length, c12428_1);
return [r42, r31];
}).map((item) => {
const [r27, r9] = item;
c12428_2 = c12428_2 + r9;
return `${r27.padEnd(c12428_1 + 1, " ")} - ${r9}ms`;
}).join("\n");
if (!(r0.length === 0 || r0[0][2] < 10 || c12428_2 < 20)) {
c574_3.log("Using Hermes:", !(global?.HermesInternal === void 0));
c574_3.log(`${a0 != null ? `
=== ${a0} ===` : ""}
${r63}
`);
c574_3.log(`Total Time: ${c12428_2}ms`);
}
return r0;
}
getLastActionMetrics(a0, length = 20) {
let c12429_0, c12429_1;
c12429_0 = void 0;
c12429_1 = void 0;
const r4 = {};
for (const log3 of this.logs) {
for (const trace of log3.traces) {
r4[trace.name] = [trace.name, log3.name, trace.time];
}
}
const r46 = Object.values(r4);
r46.sort((a, b) => b[2] - a[2]);
if (r46.length > length) {
r46.length = length;
}
c12429_0 = 0;
c12429_1 = 0;
const r60 = r46.map((item) => {
const [r26, , r30] = item;
c12429_0 = Math.max(r26.length, c12429_0);
return [r26, r30];
}).map((item) => {
const [r27, r9] = item;
c12429_1 = c12429_1 + r9;
return `${r27.padEnd(c12429_0 + 1, " ")} - ${r9}ms`;
}).join("\n");
if (!(r46.length === 0 || c12429_1 < 8)) {
c574_3.log(`
Using Hermes: ${!(global?.HermesInternal === void 0)}`, `
=== ${a0} ===
${r60}`, `
Total Time: ${c12429_1}ms
`);
}
return r46;
}
}
c574_4 = 0;
class ActionLog {
constructor(a0) {
const r6 = {
__proto__: new.target.prototype,
startTime: 0,
totalTime: 0,
traces: []
};
const id = +c574_4;
c574_4 = id + 1;
r6.id = id;
r6.action = a0;
r6.createdAt = new Date();
return r6;
}
get name() {
return this.action.type;
}
toJSON() {
if (this.createdAt == null) {
throw new Error("ActionLog.toJSON: You must complete your logging before calling toJSON");
}
return {
actionType: this.action.type,
created_at: this.createdAt,
totalTime: this.totalTime,
traces: this.traces
};
}
}
export { ActionLogger };
export { ActionLog };