"use strict";(globalThis.wpRiseJsonp=globalThis.wpRiseJsonp||[]).push([["profiler"],{6267(ue,D,l){l.d(D,{createRumProfiler:()=>W});var M=l(52411),w=l(47653),L=l(51821),R=l(30351),f=l(74269),y=l(48664),V=l(50059),g=l(100);function j(t){let s=0;for(const i of t)i.stackId!==void 0&&s++;return s}const U=/\/(?![vV]\d{1,2}\/)([^/\d?]*\d+[^/?]*)/g;function H(t){return t?t.replace(U,"/?"):"/"}const E=(t,s)=>t||H(s);var B=l(25309);function G(t,s,i){const{ids:r,names:d}=F(t.views),m=t.longTasks.map(p=>p.id).filter(p=>p!==void 0),a={application:{id:s}};return i&&(a.session={id:i}),r.length&&(a.view={id:r,name:d}),m.length&&(a.long_task={id:m}),a}function F(t){const s={ids:[],names:[]};for(const i of t)s.ids.push(i.viewId),i.viewName&&s.names.push(i.viewName);return s.names=Array.from(new Set(s.names)),s}function x(t,s,i){return{event:K(t,s,i),"wall-time.json":t}}function K(t,s,i){const r=(0,B.m5)(s),d=G(t,s.applicationId,i),m=J(r);return{...d,attachments:["wall-time.json"],start:new Date(t.startClocks.timeStamp).toISOString(),end:new Date(t.endClocks.timeStamp).toISOString(),family:"chrome",runtime:"chrome",format:"json",version:4,tags_profiler:m.join(","),_dd:{clock_drift:(0,f.TP)()}}}function J(t){return t.concat(["language:javascript","runtime:chrome","family:chrome","host:browser"])}var z=l(54828),X=l(8566);const Y=z.AQ;function Q(t){const s=(0,X.qj)({expireDelay:Y});return t.subscribe(12,({rawRumEvent:i,startClocks:r,duration:d})=>{i.type==="long_task"&&s.add({id:i.long_task.id,startClocks:r,duration:d,entryType:i.long_task.entry_type===g.K.LONG_TASK?g.do.LONG_TASK:g.do.LONG_ANIMATION_FRAME},r.relative).close((0,f.Gw)(r.relative,d))}),s}const Z={sampleIntervalMs:10,collectIntervalMs:6e4,minProfileDurationMs:5e3,minNumberOfSamples:50};function W(t,s,i,r,d,m,a=Z){const p=(0,g.wP)(t,s,d,6);let b;const I=[],$=(0,M.B)(Q)(s);let n={state:"stopped",stateReason:"initializing"};s.subscribe(9,()=>{S("session-expired")}),s.subscribe(10,()=>{n.state==="stopped"&&n.stateReason==="session-expired"&&P()});function P(){if(n.state==="running")return;const e=m.findView();b=e?{startClocks:e.startClocks,viewId:e.id,viewName:E(e.name,document.location.pathname)}:void 0,I.push((0,w.q)(t,window,"visibilitychange",se).stop,(0,w.q)(t,window,"beforeunload",ne).stop),v()}function C(){S("stopped-by-user")}function S(e){_(e),I.forEach(o=>o()),I.length=0,r.set({status:"stopped",error_reason:void 0})}function q(e){if(e.state==="running")return{cleanupTasks:e.cleanupTasks};const o=[],c=s.subscribe(2,u=>{const h={viewId:u.id,viewName:E(u.name,document.location.pathname),startClocks:u.startClocks};k(h),b=h});return o.push(c.unsubscribe),{cleanupTasks:o}}function v(){const e=(0,L.VZ)().Profiler;if(!e)throw r.set({status:"error",error_reason:"not-supported-by-browser"}),new Error("RUM Profiler is not supported in this browser.");n.state==="running"&&T(n);const{cleanupTasks:o}=q(n);let c;try{c=new e({sampleInterval:a.sampleIntervalMs,maxBufferSize:Math.round(a.collectIntervalMs*1.5/a.sampleIntervalMs)})}catch(u){u instanceof Error&&u.message.includes("disabled by Document Policy")?(R.Vy.warn("[DD_RUM] Profiler startup failed. Ensure your server includes the `Document-Policy: js-profiling` response header when serving HTML pages.",u),r.set({status:"error",error_reason:"missing-document-policy-header"})):r.set({status:"error",error_reason:"unexpected-exception"});return}r.set({status:"running",error_reason:void 0}),n={state:"running",startClocks:(0,f.M8)(),profiler:c,timeoutId:(0,y.wg)(v,a.collectIntervalMs),views:[],cleanupTasks:o,longTasks:[]},k(b),c.addEventListener("samplebufferfull",N)}function T(e){(0,y.DJ)(e.timeoutId),e.profiler.removeEventListener("samplebufferfull",N);const{startClocks:o,views:c}=e;e.profiler.stop().then(u=>{const h=(0,f.M8)(),O=(0,f.vk)(o.timeStamp,h.timeStamp),A=$.findAll(o.relative,O),ae=O<a.minProfileDurationMs,le=j(u.samples)<a.minNumberOfSamples;A.length===0&&(ae||le)||te(Object.assign(u,{startClocks:o,endClocks:h,clocksOrigin:(0,f.Oc)(),longTasks:A,views:c,sampleInterval:a.sampleIntervalMs}))}).catch(V.Dx)}function _(e){if(n.state!=="running"){(n.state==="paused"||n.state==="stopped"&&e==="stopped-by-user")&&(n={state:"stopped",stateReason:e});return}const o=n;n={state:"stopped",stateReason:e},o.cleanupTasks.forEach(c=>c()),T(o)}function ee(){if(n.state!=="running")return;const e=n;n={state:"paused"},e.cleanupTasks.forEach(o=>o()),T(e)}function k(e){n.state!=="running"||!e||n.views.push(e)}function te(e){var o;const c=(o=i.findTrackedSession())===null||o===void 0?void 0:o.id,u=x(e,t,c);p.send(u)}function N(){v()}function se(){document.visibilityState==="hidden"&&n.state==="running"?ee():document.visibilityState==="visible"&&n.state==="paused"&&v()}function ne(){v()}function oe(){return n.state==="stopped"}function ie(){return n.state==="running"}function re(){return n.state==="paused"}return{start:P,stop:C,isStopped:oe,isRunning:ie,isPaused:re}}}}]);
