• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import { CpuRender, EmptyRender } from './ProcedureWorkerCPU.js';
17import { RequestMessage } from './ProcedureWorkerCommon.js';
18import { FreqRender } from './ProcedureWorkerFreq.js';
19import { ProcessRender } from './ProcedureWorkerProcess.js';
20import { MemRender } from './ProcedureWorkerMem.js';
21import { ThreadRender } from './ProcedureWorkerThread.js';
22import { FuncRender } from './ProcedureWorkerFunc.js';
23import { FpsRender } from './ProcedureWorkerFPS.js';
24import { HeapRender, NativeMemoryRender } from './ProcedureWorkerHeap.js';
25import { CpuAbilityRender } from './ProcedureWorkerCpuAbility.js';
26import { MemoryAbilityRender } from './ProcedureWorkerMemoryAbility.js';
27import { DiskIoAbilityRender } from './ProcedureWorkerDiskIoAbility.js';
28import { NetworkAbilityRender } from './ProcedureWorkerNetworkAbility.js';
29import { HiperfCpuRender } from './ProcedureWorkerHiPerfCPU.js';
30import { HiperfProcessRender } from './ProcedureWorkerHiPerfProcess.js';
31import { HiperfThreadRender } from './ProcedureWorkerHiPerfThread.js';
32import { HiperfEventRender } from './ProcedureWorkerHiPerfEvent.js';
33import { HiperfReportRender } from './ProcedureWorkerHiPerfReport.js';
34import { VirtualMemoryRender } from './ProcedureWorkerVirtualMemory.js';
35import { FileSystemRender } from './ProcedureWorkerFileSystem.js';
36import { info } from '../../../log/Log.js';
37import { SdkSliceRender } from './ProduceWorkerSdkSlice.js';
38import { SdkCounterRender } from './ProduceWorkerSdkCounter.js';
39import { CpuStateRender } from './ProcedureWorkerCpuState.js';
40import { EnergyAnomalyRender } from './ProcedureWorkerEnergyAnomaly.js';
41import { EnergySystemRender } from './ProcedureWorkerEnergySystem.js';
42import { EnergyPowerRender } from './ProcedureWorkerEnergyPower.js';
43import { EnergyStateRender } from './ProcedureWorkerEnergyState.js';
44import { CpuFreqLimitRender } from './ProcedureWorkerCpuFreqLimits.js';
45import { ClockRender } from './ProcedureWorkerClock.js';
46import { IrqRender } from './ProcedureWorkerIrq.js';
47import { JankRender } from './ProcedureWorkerJank.js';
48import { HeapTimelineRender } from './ProcedureWorkerHeapTimeline.js';
49import { HeapSnapshotRender } from './ProcedureWorkerHeapSnapshot.js';
50import { translateJsonString } from '../logic-worker/ProcedureLogicWorkerCommon.js';
51import { AppStartupRender } from './ProcedureWorkerAppStartup.js';
52import { SoRender } from './ProcedureWorkerSoInit.js';
53import { FrameDynamicRender } from './ProcedureWorkerFrameDynamic.js';
54import { FrameAnimationRender } from './ProcedureWorkerFrameAnimation.js';
55import { FrameSpacingRender } from './ProcedureWorkerFrameSpacing.js';
56import { JsCpuProfilerRender } from './ProcedureWorkerCpuProfiler.js';
57import { SnapshotRender } from './ProcedureWorkerSnapshot.js';
58
59let dataList: any = {};
60let dataList2: any = {};
61let dataFilter: any = {};
62let canvasList: any = {};
63let contextList: any = {};
64export let renders: any = {
65  'cpu-data': new CpuRender(),
66  'cpu-state': new CpuStateRender(),
67  'cpu-limit-freq': new CpuFreqLimitRender(),
68  fps: new FpsRender(),
69  freq: new FreqRender(),
70  empty: new EmptyRender(),
71  'virtual-memory-folder': new EmptyRender(),
72  'virtual-memory-cell': new VirtualMemoryRender(),
73  'file-system-group': new EmptyRender(),
74  'file-system-cell': new FileSystemRender(),
75  process: new ProcessRender(),
76  'app-start-up': new AppStartupRender(),
77  'app-so-init': new SoRender(),
78  heap: new HeapRender(),
79  'heap-timeline': new HeapTimelineRender(),
80  'heap-snapshot': new HeapSnapshotRender(),
81  mem: new MemRender(),
82  thread: new ThreadRender(),
83  func: new FuncRender(),
84  native: new NativeMemoryRender(),
85  'HiPerf-Group': new EmptyRender(),
86  monitorGroup: new EmptyRender(),
87  'HiPerf-Cpu': new HiperfCpuRender(),
88  'HiPerf-Process': new HiperfProcessRender(),
89  'HiPerf-Thread': new HiperfThreadRender(),
90  'HiPerf-Report-Event': new HiperfEventRender(),
91  'HiPerf-Report-Fold': new HiperfReportRender(),
92  monitorCpu: new CpuAbilityRender(),
93  monitorMemory: new MemoryAbilityRender(),
94  monitorDiskIo: new DiskIoAbilityRender(),
95  monitorNetwork: new NetworkAbilityRender(),
96  'sdk-slice': new SdkSliceRender(),
97  'sdk-counter': new SdkCounterRender(),
98  energyAnomaly: new EnergyAnomalyRender(),
99  energySystem: new EnergySystemRender(),
100  energyPower: new EnergyPowerRender(),
101  energyState: new EnergyStateRender(),
102  clock: new ClockRender(),
103  irq: new IrqRender(),
104  jank: new JankRender(),
105  frameDynamicCurve: new FrameDynamicRender(),
106  frameAnimation: new FrameAnimationRender(),
107  frameSpacing: new FrameSpacingRender(),
108  'js-cpu-profiler': new JsCpuProfilerRender(),
109  snapshot: new SnapshotRender(),
110};
111
112function match(type: string, req: RequestMessage) {
113  Reflect.ownKeys(renders).filter((it) => {
114    if (type.startsWith(it as string)) {
115      if (dataList[type]) {
116        req.lazyRefresh = dataList[type].length > 20000;
117      }
118      renders[it].render(req, dataList[type], dataFilter[type], dataList2);
119    }
120  });
121}
122
123let dec = new TextDecoder();
124let convertJSON = (arr: any) => {
125  if (arr instanceof ArrayBuffer) {
126    let jsonArr = [];
127    let str = dec.decode(new Uint8Array(arr));
128    str = str.substring(str.indexOf('\n') + 1);
129    if (!str) {
130    } else {
131      let parsed = JSON.parse(translateJsonString(str));
132      let columns = parsed.columns;
133      let values = parsed.values;
134      for (let i = 0; i < values.length; i++) {
135        let obj: any = {};
136        for (let j = 0; j < columns.length; j++) {
137          obj[columns[j]] = values[i][j];
138        }
139        jsonArr.push(obj);
140      }
141    }
142    return jsonArr;
143  } else {
144    return arr;
145  }
146};
147self.onmessage = function (e: any) {
148  if ((e.data.type as string).startsWith('clear')) {
149    dataList = {};
150    dataList2 = {};
151    dataFilter = {};
152    canvasList = {};
153    contextList = {};
154    // @ts-ignore
155    self.postMessage({
156      id: e.data.id,
157      type: e.data.type,
158      results: null,
159    });
160    return;
161  }
162  if (e.data.params.list) {
163    dataList[e.data.type] = convertJSON(e.data.params.list);
164    if (e.data.params.offscreen) {
165      canvasList[e.data.type] = e.data.params.offscreen;
166      contextList[e.data.type] = e.data.params.offscreen!.getContext('2d');
167      contextList[e.data.type].scale(e.data.params.dpr, e.data.params.dpr);
168    }
169  }
170  if (!dataFilter[e.data.type]) {
171    dataFilter[e.data.type] = [];
172  }
173  let req = new RequestMessage();
174  req.canvas = canvasList[e.data.type];
175  req.context = contextList[e.data.type];
176  req.type = e.data.type as string;
177  req.params = e.data.params;
178  req.online = e.data.params.online;
179  req.buf = e.data.params.buf;
180  req.isRangeSelect = e.data.params.isRangeSelect;
181  req.isHover = e.data.params.isHover;
182  req.xs = e.data.params.xs;
183  req.frame = e.data.params.frame;
184  req.flagMoveInfo = e.data.params.flagMoveInfo;
185  req.flagSelectedInfo = e.data.params.flagSelectedInfo;
186  req.hoverX = e.data.params.hoverX;
187  req.hoverY = e.data.params.hoverY;
188  req.startNS = e.data.params.startNS;
189  req.endNS = e.data.params.endNS;
190  req.totalNS = e.data.params.totalNS;
191  req.slicesTime = e.data.params.slicesTime;
192  req.range = e.data.params.range;
193  req.scale = e.data.params.scale;
194  req.canvasWidth = e.data.params.canvasWidth;
195  req.canvasHeight = e.data.params.canvasHeight;
196  req.useCache = e.data.params.useCache;
197  req.lineColor = e.data.params.lineColor;
198  req.chartColor = e.data.params.chartColor;
199  req.wakeupBean = e.data.params.wakeupBean;
200  req.intervalPerf = e.data.params.intervalPerf;
201  req.id = e.data.id;
202  if (!req.frame) {
203    info(req.frame);
204    return;
205  }
206  if (req.canvas) {
207    if (req.canvas.width !== req.canvasWidth || req.canvas.height !== req.canvasHeight) {
208      req.canvas.width = req.canvasWidth;
209      req.canvas.height = req.canvasHeight;
210      req.context.scale(e.data.params.dpr, e.data.params.dpr);
211    }
212  }
213  match(req.type, req);
214};
215self.onmessageerror = function (e: any) {};
216