@yuebai008/cli
Version:
Command line interface for rapid qg-minigame development
1 lines • 5.02 kB
JavaScript
import*as TraceEngine from"../../models/trace/trace.js";import*as TimelineModel from"../../models/timeline_model/timeline_model.js";import*as Common from"../../core/common/common.js";import*as ThemeSupport from"../../ui/legacy/theme_support/theme_support.js";import{ThreadAppender}from"./ThreadAppender.js";import{EntryType,InstantEventVisibleDurationMs}from"./TimelineFlameChartDataProvider.js";import{TimingsTrackAppender}from"./TimingsTrackAppender.js";import{InteractionsTrackAppender}from"./InteractionsTrackAppender.js";import{GPUTrackAppender}from"./GPUTrackAppender.js";import{LayoutShiftsTrackAppender}from"./LayoutShiftsTrackAppender.js";import{getEventLevel}from"./AppenderUtils.js";import{TimelineUIUtils}from"./TimelineUIUtils.js";import{AnimationsTrackAppender}from"./AnimationsTrackAppender.js";export const TrackNames=["Animations","Timings","Interactions","GPU","LayoutShifts","Thread"];export class CompatibilityTracksAppender{#e=new Map;#r=new Map;#t=new Map;#n=new Map;#a;#s;#i;#o;#p=new WeakMap;#c=[];#l=new Set([...TrackNames]);#h;#d;#T;#m;#u;#k;#v;#f=[];constructor(e,r,t,n,a){if(this.#a=e,this.#s=r,this.#i=t,this.#o=new Common.Color.Generator({min:30,max:55,count:void 0},{min:70,max:100,count:6},50,.7),this.#d=n,this.#h=a,this.#T=new TimingsTrackAppender(this,this.#a,this.#s,this.#o),this.#c.push(this.#T),this.#u=new InteractionsTrackAppender(this,this.#a,this.#s,this.#o),this.#c.push(this.#u),this.#m=new AnimationsTrackAppender(this,this.#s),this.#c.push(this.#m),this.#k=new GPUTrackAppender(this,this.#s),this.#c.push(this.#k),this.#v=new LayoutShiftsTrackAppender(this,this.#a,this.#s),this.#c.push(this.#v),this.#s.Renderer)for(const[e,r]of this.#s.Renderer.processes)for(const[t,n]of r.threads){if("CrRendererMain"!==n.name)continue;const r=new ThreadAppender(this,this.#s,this.#o,e,t);this.#f.push(r),this.#c.push(r)}ThemeSupport.ThemeSupport.instance().addEventListener(ThemeSupport.ThemeChangeEvent.eventName,(()=>{for(const e of this.#a.groups)e.style.color=ThemeSupport.ThemeSupport.instance().getComputedValue("--color-text-primary"),e.style.backgroundColor=ThemeSupport.ThemeSupport.instance().getComputedValue("--color-background")}))}getLegacyEvent(e){const r=this.#h.tracingModel()?.getProcessById(e.pid),t=r?.threadById(e.tid);return t?TraceEngine.Legacy.PayloadEvent.fromPayload(e,t):null}timingsTrackAppender(){return this.#T}animationsTrackAppender(){return this.#m}interactionsTrackAppender(){return this.#u}gpuTrackAppender(){return this.#k}layoutShiftsTrackAppender(){return this.#v}threadAppenders(){return this.#f}indexForEvent(e){return this.#p.get(e)}eventsInTrack(e){const r=this.#t.get(e);if(r)return r;let t=null,n=null;for(const[r,a]of this.#e)a.appenderName===e&&(null===t&&(t=r),n=r);if(null===t||null===n)throw new Error(`Could not find events for track: ${e}`);const a=this.#a.entryLevels,s=[];for(let e=0;e<a.length;e++)t<=a[e]&&a[e]<=n&&s.push(this.#i[e]);return s.sort(((e,r)=>e.ts-r.ts)),this.#t.set(e,s),s}canBuildTreesFromEvents(e){const r=[];for(const t of e){const e=t.ts,n=t.ts+(t.dur||0);let a=r.at(-1);if(void 0===a){r.push(t);continue}let s=a.ts+(a.dur||0);for(;r.length&&e>=s&&(r.pop(),a=r.at(-1),void 0!==a);)s=a.ts+(a.dur||0);if(r.length&&n>s)return!1;r.push(t)}return!0}eventsForTreeView(e){const r=this.#n.get(e);if(r)return r;let t=this.eventsInTrack(e);return this.canBuildTreesFromEvents(t)||(t=t.filter((e=>!TraceEngine.Types.TraceEvents.isAsyncPhase(e.ph)))),this.#n.set(e,t),t}registerTrackForGroup(e,r){this.#a.groups.push(e),this.#r.set(e,r)}groupEventsForTreeView(e){const r=this.#r.get(e);return r?this.eventsForTreeView(r.appenderName):null}registerTrackForLevel(e,r){this.#e.set(e,r)}appendEventAtLevel(e,r,t){this.#e.set(r,t);const n=this.#i.length;this.#i.push(e),this.#p.set(e,n),this.#d[r]=EntryType.TrackAppender,this.#a.entryLevels[n]=r,this.#a.entryStartTimes[n]=TraceEngine.Helpers.Timing.microSecondsToMilliseconds(e.ts);const a=e.dur||TraceEngine.Helpers.Timing.millisecondsToMicroseconds(InstantEventVisibleDurationMs);return this.#a.entryTotalTimes[n]=TraceEngine.Helpers.Timing.microSecondsToMilliseconds(a),n}appendEventsAtLevel(e,r,t){const n=[];for(let a=0;a<e.length;++a){const s=e[a],i=this.getLegacyEvent(s),o=new Set(TimelineUIUtils.visibleTypes());if(!(i&&o.has(TimelineModel.TimelineModelFilter.TimelineVisibleEventsFilter.eventType(i))))continue;const p=getEventLevel(s,n);this.appendEventAtLevel(s,r+p,t)}return this.#d.length=r+n.length,this.#d.fill(EntryType.TrackAppender,r),r+n.length}allVisibleTrackAppenders(){return this.#c.filter((e=>this.#l.has(e.appenderName)))}setVisibleTracks(e){this.#l=e||new Set([...TrackNames])}colorForEvent(e,r){const t=this.#e.get(r);if(!t)throw new Error("Track not found for level");return t.colorForEvent(e)}titleForEvent(e,r){const t=this.#e.get(r);if(!t)throw new Error("Track not found for level");return t.titleForEvent(e)}highlightedEntryInfo(e,r){const t=this.#e.get(r);if(!t)throw new Error("Track not found for level");return t.highlightedEntryInfo(e)}}