"use strict";(self.wpRiseJsonp=self.wpRiseJsonp||[]).push([["profiler"],{30965:(ie,b,u)=>{u.r(b),u.d(b,{DEFAULT_RUM_PROFILER_CONFIGURATION:()=>y,createRumProfiler:()=>G});var w=u(93195),P=u(91045),A=u(90637),L=u(87791),f=u(62877),I=u(15320),U=u(54203);function V(t){let s=0;for(const i of t)i.stackId!==void 0&&s++;return s}const j=/\/(?![vV]\d{1,2}\/)([^/\d?]*\d+[^/?]*)/g;function F(t){return t?t.replace(j,"/?"):"/"}const E=(t,s)=>t||F(s);var x=u(72029);function B(t,s,i){const a={application:{id:s}};i&&(a.session={id:i});const{ids:d,names:m}=H(t.views);d.length&&(a.view={id:d,name:m});const p=t.longTasks.map(l=>l.id).filter(l=>l!==void 0);return p.length&&(a.long_task={id:p}),a}function H(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 J(t,s,i){return{event:z(t,s,i),"wall-time.json":t}}function z(t,s,i){const a=(0,x.m5)(s),d=B(t,s.applicationId,i),m=C(a);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 C(t){return t.concat(["language:javascript","runtime:chrome","family:chrome","host:browser"])}const y={sampleIntervalMs:10,collectIntervalMs:6e4,minProfileDurationMs:5e3,minNumberOfSamples:50};function G(t,s,i,a,d,m,p,l=y){const X=(0,U.wP)(t,s,m,6);let g;const S=[];let n={state:"stopped",stateReason:"initializing"};s.subscribe(9,()=>{D("session-expired").catch(w.Dx)}),s.subscribe(10,()=>{n.state==="stopped"&&n.stateReason==="session-expired"&&T()});function T(){if(n.state==="running")return;const e=p.findView();g=e?{startClocks:e.startClocks,viewId:e.id,viewName:E(e.name,document.location.pathname)}:void 0,S.push((0,P.q)(t,window,"visibilitychange",$).stop,(0,P.q)(t,window,"beforeunload",q).stop),v()}async function Z(){await D("stopped-by-user")}async function D(e){await Q(e),S.forEach(r=>r()),a.set({status:"stopped",error_reason:void 0})}function K(e){if(e.state==="running")return{cleanupTasks:e.cleanupTasks};const r=[],c=s.subscribe(2,o=>{const h={viewId:o.id,viewName:E(o.name,document.location.pathname),startClocks:o.startClocks};k(h),g=h});return r.push(c.unsubscribe),{cleanupTasks:r}}function v(){const e=(0,A.VZ)().Profiler;if(!e)throw a.set({status:"error",error_reason:"not-supported-by-browser"}),new Error("RUM Profiler is not supported in this browser.");O(n).catch(w.Dx);const{cleanupTasks:r}=K(n);let c;try{c=new e({sampleInterval:l.sampleIntervalMs,maxBufferSize:Math.round(l.collectIntervalMs*1.5/l.sampleIntervalMs)})}catch(o){o instanceof Error&&o.message.includes("disabled by Document Policy")?(L.Vy.warn("[DD_RUM] Profiler startup failed. Ensure your server includes the `Document-Policy: js-profiling` response header when serving HTML pages.",o),a.set({status:"error",error_reason:"missing-document-policy-header"})):a.set({status:"error",error_reason:"unexpected-exception"});return}a.set({status:"running",error_reason:void 0}),n={state:"running",startClocks:(0,f.M8)(),profiler:c,timeoutId:(0,I.wg)(v,l.collectIntervalMs),views:[],cleanupTasks:r,longTasks:[]},k(g),c.addEventListener("samplebufferfull",N)}async function O(e){if(e.state!=="running")return;(0,I.DJ)(e.timeoutId),e.profiler.removeEventListener("samplebufferfull",N);const{startClocks:r,views:c}=e;await e.profiler.stop().then(o=>{const h=(0,f.M8)(),M=d.findLongTasks(r.relative),se=(0,f.vk)(r.timeStamp,h.timeStamp)<l.minProfileDurationMs,ne=V(o.samples)<l.minNumberOfSamples;M.length===0&&(se||ne)||Y(Object.assign(o,{startClocks:r,endClocks:h,clocksOrigin:(0,f.Oc)(),longTasks:M,views:c,sampleInterval:l.sampleIntervalMs}))}).catch(w.Dx)}async function Q(e){n.state==="running"&&(await R(),n={state:"stopped",stateReason:e})}async function W(){n.state==="running"&&(await R(),n={state:"paused"})}async function R(){n.state==="running"&&(n.cleanupTasks.forEach(e=>e()),await O(n))}function k(e){n.state!=="running"||!e||n.views.push(e)}function Y(e){var r;const c=(r=i.findTrackedSession())===null||r===void 0?void 0:r.id,o=J(e,t,c);X.send(o)}function N(){v()}function $(){document.visibilityState==="hidden"&&n.state==="running"?W().catch(w.Dx):document.visibilityState==="visible"&&n.state==="paused"&&v()}function q(){v()}function _(){return n.state==="stopped"}function ee(){return n.state==="running"}function te(){return n.state==="paused"}return{start:T,stop:Z,isStopped:_,isRunning:ee,isPaused:te}}}}]);
