124 lines
5.3 KiB
JavaScript
124 lines
5.3 KiB
JavaScript
// Metro module 1099 (f1100).
|
|
import { UIProfiler } from "./UIProfiler";
|
|
import { hasLegacyProfiling, isAutomatedPageLoadSpan, shouldProfileSpanLegacy, getActiveProfilesCount, findProfiledTransactionsFromEnvelope, addProfilesToEnvelope, takeProfileFromGlobalCache, createProfilingEvent, attachProfiledThreadToEvent } from "./createProfilePayload";
|
|
import { DEBUG_BUILD } from "./Module1072";
|
|
import { defineIntegration, debug, getActiveSpan, getRootSpan, hasSpansEnabled } from "./Module817";
|
|
import { WINDOW } from "./ignoreNextOnError";
|
|
import { startProfileForSpan } from "./Module1102";
|
|
Object.defineProperty(exports, Symbol.toStringTag, {
|
|
value: "Module"
|
|
});
|
|
export const browserProfilingIntegration = defineIntegration(() => ({
|
|
name: "BrowserProfiling",
|
|
setup: (a0) => {
|
|
const options = a0.getOptions();
|
|
const uIProfiler = new UIProfiler();
|
|
let c24204_0 = uIProfiler;
|
|
if (!(hasLegacyProfiling(options) || options.profileLifecycle)) {
|
|
options.profileLifecycle = "manual";
|
|
}
|
|
L34: {
|
|
if (hasLegacyProfiling(options) && !options.profilesSampleRate) {
|
|
if (!DEBUG_BUILD) {
|
|
break L34;
|
|
}
|
|
debug.log("[Profiling] Profiling disabled, no profiling options found.");
|
|
} else {
|
|
const activeSpan = getActiveSpan();
|
|
const r43 = activeSpan && getRootSpan(activeSpan);
|
|
if (hasLegacyProfiling(options) && options.profileSessionSampleRate !== void 0 && DEBUG_BUILD) {
|
|
debug.warn("[Profiling] Both legacy profiling (`profilesSampleRate`) and UI profiling settings are defined. `profileSessionSampleRate` has no effect when legacy profiling is enabled.");
|
|
}
|
|
if (hasLegacyProfiling(options)) {
|
|
if (r43 && isAutomatedPageLoadSpan(r43) && shouldProfileSpanLegacy(r43)) {
|
|
startProfileForSpan(r43);
|
|
}
|
|
a0.on("spanStart", (a0) => {
|
|
if (a0 === getRootSpan(a0) && shouldProfileSpanLegacy(a0)) {
|
|
startProfileForSpan(a0);
|
|
}
|
|
});
|
|
a0.on("beforeEnvelope", (a0) => {
|
|
let r38;
|
|
if (getActiveProfilesCount()) {
|
|
const r48 = findProfiledTransactionsFromEnvelope(a0);
|
|
if (r48.length) {
|
|
const r50 = [];
|
|
let r7 = r48[Symbol.iterator]();
|
|
const next = r7.next;
|
|
const r10 = "[Profiling] Could not retrieve profile for span: ";
|
|
const r52 = "[Profiling] cannot find profile for a span without a profile context";
|
|
while (true) {
|
|
const r53 = r7 === void 0 ? void 0 : (r38 = next.call(r7)).done ? r7 = void 0 : r38.value;
|
|
if (r7 === void 0) {
|
|
addProfilesToEnvelope(a0, r50);
|
|
break;
|
|
}
|
|
try {
|
|
const contexts = r53?.contexts;
|
|
const r61 = contexts == null ? void 0 : contexts.profile?.profile_id;
|
|
const r67 = contexts == null ? void 0 : contexts.profile?.start_timestamp;
|
|
if (typeof r61 === "string") {
|
|
if (r61) {
|
|
if (contexts?.profile) {
|
|
delete contexts["profile"];
|
|
}
|
|
const r111 = takeProfileFromGlobalCache(r61);
|
|
if (r111) {
|
|
const profilingEvent = createProfilingEvent(r61, r67, r111, r53);
|
|
if (profilingEvent) {
|
|
r50.push(profilingEvent);
|
|
}
|
|
} else if (DEBUG_BUILD) {
|
|
debug.log(HermesInternal.concat.call(r10, r61));
|
|
}
|
|
} else if (DEBUG_BUILD) {
|
|
debug.log(r52);
|
|
}
|
|
} else if (DEBUG_BUILD) {
|
|
debug.log(r52);
|
|
}
|
|
} catch (r134) {
|
|
if (r7 !== void 0 && typeof r7.return === "function") {
|
|
try {
|
|
r7.return();
|
|
} catch {}
|
|
}
|
|
throw r134;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
} else {
|
|
const profileLifecycle = options.profileLifecycle;
|
|
a0.on("startUIProfiler", () => c24204_0.start());
|
|
a0.on("stopUIProfiler", () => c24204_0.stop());
|
|
if (profileLifecycle === "manual") {
|
|
uIProfiler.initialize(a0);
|
|
} else if (profileLifecycle === "trace") {
|
|
if (!hasSpansEnabled(options)) {
|
|
if (DEBUG_BUILD) {
|
|
debug.warn("[Profiling] `profileLifecycle` is 'trace' but tracing is disabled. Set a `tracesSampleRate` or `tracesSampler` to enable span tracing.");
|
|
}
|
|
return void 0;
|
|
}
|
|
uIProfiler.initialize(a0);
|
|
if (r43) {
|
|
uIProfiler.notifyRootSpanActive(r43);
|
|
}
|
|
WINDOW.setTimeout(() => {
|
|
const activeSpan = getActiveSpan();
|
|
const r8 = activeSpan && getRootSpan(activeSpan);
|
|
if (r8) {
|
|
c24204_0.notifyRootSpanActive(r8);
|
|
}
|
|
}, 0);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
processEvent: (a0) => attachProfiledThreadToEvent(a0)
|
|
}));
|