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

91 lines
3.0 KiB
JavaScript

// Metro module 1102 (f1103).
import { addProfileToGlobalCache, isAutomatedPageLoadSpan, startJSSelfProfile, MAX_PROFILE_DURATION_MS } from "./createProfilePayload";
import { debug, spanToJSON, timestampInSeconds, uuid4, getCurrentScope } from "./Module817";
import { DEBUG_BUILD } from "./Module1072";
import { WINDOW } from "./ignoreNextOnError";
Object.defineProperty(exports, Symbol.toStringTag, {
value: "Module"
});
export function startProfileForSpan(a0) {
let c12800_1, c12800_2, c12800_3, c12800_4, c12800_5, _onProfileHandler2;
const onProfileHandler2 = function onProfileHandler() {
return _onProfileHandler2.apply(this, arguments);
};
_onProfileHandler2 = function _onProfileHandler() {
const r9 = async () => {
L13: {
if (!a0) {
break L13;
}
if (!c12800_1) {
break L13;
}
if (c12800_3) {
if (!DEBUG_BUILD) {
break L13;
}
debug.log("[Profiling] profile for:", spanToJSON(a0).description, "already exists, returning early");
break L13;
}
return c12800_1.stop().then((result) => {
if (c12800_4) {
WINDOW.clearTimeout(c12800_4);
c12800_4 = void 0;
}
if (DEBUG_BUILD) {
debug.log(`[Profiling] stopped profiling of span: ${spanToJSON(a0).description}`);
}
if (result) {
c12800_3 = result;
addProfileToGlobalCache(c12800_2, result);
} else if (DEBUG_BUILD) {
debug.log(`[Profiling] profiler returned null profile for: ${spanToJSON(a0).description}`, "this may indicate an overlapping span or a call to stopProfiling with a profile title that was never started");
}
}).catch((error) => {
if (DEBUG_BUILD) {
debug.log("[Profiling] error while stopping profiler:", error);
}
});
}
};
_onProfileHandler2 = r9;
return r9.apply(this, arguments);
};
const start_timestamp = isAutomatedPageLoadSpan(a0) ? 1000 * timestampInSeconds() : void 0;
const r25 = startJSSelfProfile();
c12800_1 = r25;
if (r25) {
if (DEBUG_BUILD) {
debug.log(`[Profiling] started profiling span: ${spanToJSON(a0).description}`);
}
const profile_id = uuid4();
c12800_2 = profile_id;
c12800_3 = null;
getCurrentScope().setContext("profile", {
profile_id,
start_timestamp
});
c12800_4 = WINDOW.setTimeout(() => {
if (DEBUG_BUILD) {
debug.log("[Profiling] max profile duration elapsed, stopping profiling for:", spanToJSON(a0).description);
}
onProfileHandler2();
}, MAX_PROFILE_DURATION_MS);
c12800_5 = a0.end.bind(a0);
a0.end = function profilingWrappedSpanEnd() {
let r7;
if (a0) {
onProfileHandler2().then(() => {
c12800_5();
}, () => {
c12800_5();
});
r7 = a0;
} else {
r7 = c12800_5();
}
return r7;
};
}
}