// Metro module 1124 (f1125). import { MAX_PROFILE_DURATION_MS } from "./Module1123"; import { debug } from "./Module817"; import { DEFAULT_BUNDLE_NAME } from "./Module1120"; let c932_2, parseHermesJSStackFrame; const mapSamples = function mapSamples(a0, r11 = c932_2) { const samples = []; const set = new Set(); const set2 = new Set(); const r38 = a0[0]; if (!r38) { debug.warn("[Profiling] No samples found in profile."); return { samples, hermesStacks: set2, jsThreads: set }; } const r47 = Number(r38.ts); for (const item of a0) { set.add(item.tid); set2.add(item.sf); const r64 = 1000 * (Number(item.ts) - r47); if (!(r64 >= r11)) { samples.push({ stack_id: item.sf, thread_id: item.tid, elapsed_since_start_ns: r64.toFixed(0) }); continue; } debug.warn(`[Profiling] Sample has elapsed time since start ${r64}ns greater than the max elapsed time ${r11}ns.`); break; } return { samples, hermesStacks: set2, jsThreads: set }; }; parseHermesJSStackFrame = function parseHermesJSStackFrame(a0) { if (a0.category !== "JavaScript") { return a0.name === "[root]" ? { function: a0.name, in_app: false } : { function: a0.name }; } if (a0.funcVirtAddr !== void 0 && a0.offset !== void 0) { return { function: a0.name, abs_path: DEFAULT_BUNDLE_NAME, lineno: 1, colno: Number(a0.funcVirtAddr) + Number(a0.offset) + 1 }; } const r7 = a0.name.indexOf("("); return { function: r7 !== -1 ? a0.name.substring(0, r7) || void 0 : a0.name, abs_path: DEFAULT_BUNDLE_NAME, lineno: a0.line !== void 0 ? Number(a0.line) : void 0, colno: a0.column !== void 0 ? Number(a0.column) : void 0 }; }; c932_2 = 1000000 * MAX_PROFILE_DURATION_MS; export function convertToSentryProfile(a0) { if (a0.samples.length === 0) { debug.warn("[Profiling] No samples found in profile."); return null; } const r36 = mapSamples(a0.samples); const { samples, hermesStacks, jsThreads } = r36; const r39 = (function mapFrames(a0) { const frames = []; const map = new Map(); for (const key in a0) { if (Object.prototype.hasOwnProperty.call(a0, key)) { const r24 = a0[key]; if (r24) { map.set(Number(key), frames.length); frames.push(parseHermesJSStackFrame(r24)); } } } return { frames, hermesStackFrameIdToSentryFrameIdMap: map }; })(a0.stackFrames); const frames = r39.frames; const r43 = (function mapStacks(a0, a1, a2) { let r48; const map = new Map(); const stacks = []; for (const item of a0) { map.set(item, stacks.length); const r35 = []; let r36 = item; if (item !== void 0) { do { const r39 = a2.get(r36); if (r39 !== void 0) { r35.push(r39); } const r46 = a1[r36]; r48 = r46 !== null ? r46 !== void 0 ? r46.parent : void 0 : void 0; r36 = r48; } while (r48 !== void 0); } stacks.push(r35); } return { stacks, hermesStackToSentryStackMap: map }; })(hermesStacks, a0.stackFrames, r39.hermesStackFrameIdToSentryFrameIdMap); const { stacks, hermesStackToSentryStackMap } = r43; for (const item of samples) { const stack_id = hermesStackToSentryStackMap.get(item.stack_id); if (stack_id === void 0) { debug.error(`[Profiling] Hermes Stack ID ${item.stack_id} not found when mapping to Sentry Stack ID.`); item.stack_id = -1; } else { item.stack_id = stack_id; } } const thread_metadata = {}; for (const item2 of jsThreads) { thread_metadata[item2] = { name: "JavaScriptThread", priority: 1 }; } return { samples, frames, stacks, thread_metadata, active_thread_id: Object.keys(thread_metadata)[0] || "0" }; } export { mapSamples }; export { parseHermesJSStackFrame };