• 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 { SmapsRender } from './ProcedureWorkerSmaps.js';
45import { CpuFreqLimitRender } from './ProcedureWorkerCpuFreqLimits.js';
46import { ClockRender } from './ProcedureWorkerClock.js';
47import { IrqRender } from './ProcedureWorkerIrq.js';
48import { JankRender } from './ProcedureWorkerJank.js';
49import { HeapTimelineRender } from './ProcedureWorkerHeapTimeline.js';
50import { HeapSnapshotRender } from './ProcedureWorkerHeapSnapshot.js';
51import { translateJsonString } from '../logic-worker/ProcedureLogicWorkerCommon.js';
52import { AppStartupRender } from './ProcedureWorkerAppStartup.js';
53import { SoRender } from './ProcedureWorkerSoInit.js';
54
55let dataList: any = {};
56let dataList2: any = {};
57let dataFilter: any = {};
58let canvasList: any = {};
59let contextList: any = {};
60export let renders: any = {
61  'cpu-data': new CpuRender(),
62  'cpu-state': new CpuStateRender(),
63  'cpu-limit-freq': new CpuFreqLimitRender(),
64  fps: new FpsRender(),
65  freq: new FreqRender(),
66  empty: new EmptyRender(),
67  'virtual-memory-folder': new EmptyRender(),
68  'virtual-memory-cell': new VirtualMemoryRender(),
69  'file-system-group': new EmptyRender(),
70  'file-system-cell': new FileSystemRender(),
71  process: new ProcessRender(),
72  'app-start-up': new AppStartupRender(),
73  'app-so-init': new SoRender(),
74  heap: new HeapRender(),
75  heapTimeline: new HeapTimelineRender(),
76  heapSnapshot: new HeapSnapshotRender(),
77  mem: new MemRender(),
78  thread: new ThreadRender(),
79  func: new FuncRender(),
80  native: new NativeMemoryRender(),
81  'HiPerf-Group': new EmptyRender(),
82  monitorGroup: new EmptyRender(),
83  'HiPerf-Cpu': new HiperfCpuRender(),
84  'HiPerf-Process': new HiperfProcessRender(),
85  'HiPerf-Thread': new HiperfThreadRender(),
86  'HiPerf-Report-Event': new HiperfEventRender(),
87  'HiPerf-Report-Fold': new HiperfReportRender(),
88  monitorCpu: new CpuAbilityRender(),
89  monitorMemory: new MemoryAbilityRender(),
90  monitorDiskIo: new DiskIoAbilityRender(),
91  monitorNetwork: new NetworkAbilityRender(),
92  'sdk-slice': new SdkSliceRender(),
93  'sdk-counter': new SdkCounterRender(),
94  energyAnomaly: new EnergyAnomalyRender(),
95  energySystem: new EnergySystemRender(),
96  energyPower: new EnergyPowerRender(),
97  energyState: new EnergyStateRender(),
98  smaps: new SmapsRender(),
99  clock: new ClockRender(),
100  irq: new IrqRender(),
101  jank: new JankRender(),
102};
103
104function match(type: string, req: RequestMessage) {
105  Reflect.ownKeys(renders).filter((it) => {
106    if (type.startsWith(it as string)) {
107      if (dataList[type]) {
108        req.lazyRefresh = dataList[type].length > 20000;
109      }
110      renders[it].render(req, dataList[type], dataFilter[type], dataList2);
111    }
112  });
113}
114
115let dec = new TextDecoder();
116let convertJSON = (arr: any) => {
117  if (arr instanceof ArrayBuffer) {
118    let jsonArr = [];
119    let str = dec.decode(new Uint8Array(arr));
120    str = str.substring(str.indexOf('\n') + 1);
121    if (!str) {
122    } else {
123      let parsed = JSON.parse(translateJsonString(str));
124      let columns = parsed.columns;
125      let values = parsed.values;
126      for (let i = 0; i < values.length; i++) {
127        let obj: any = {};
128        for (let j = 0; j < columns.length; j++) {
129          obj[columns[j]] = values[i][j];
130        }
131        jsonArr.push(obj);
132      }
133    }
134    return jsonArr;
135  } else {
136    return arr;
137  }
138};
139self.onmessage = function (e: any) {
140  if ((e.data.type as string).startsWith('clear')) {
141    dataList = {};
142    dataList2 = {};
143    dataFilter = {};
144    canvasList = {};
145    contextList = {};
146    // @ts-ignore
147    self.postMessage({
148      id: e.data.id,
149      type: e.data.type,
150      results: null,
151    });
152    return;
153  }
154  if (e.data.params.list) {
155    dataList[e.data.type] = convertJSON(e.data.params.list);
156    if (e.data.params.offscreen) {
157      canvasList[e.data.type] = e.data.params.offscreen;
158      contextList[e.data.type] = e.data.params.offscreen!.getContext('2d');
159      contextList[e.data.type].scale(e.data.params.dpr, e.data.params.dpr);
160    }
161  }
162  if (!dataFilter[e.data.type]) {
163    dataFilter[e.data.type] = [];
164  }
165  let req = new RequestMessage();
166  req.canvas = canvasList[e.data.type];
167  req.context = contextList[e.data.type];
168  req.type = e.data.type as string;
169  req.params = e.data.params;
170  req.online = e.data.params.online;
171  req.buf = e.data.params.buf;
172  req.isRangeSelect = e.data.params.isRangeSelect;
173  req.isHover = e.data.params.isHover;
174  req.xs = e.data.params.xs;
175  req.frame = e.data.params.frame;
176  req.flagMoveInfo = e.data.params.flagMoveInfo;
177  req.flagSelectedInfo = e.data.params.flagSelectedInfo;
178  req.hoverX = e.data.params.hoverX;
179  req.hoverY = e.data.params.hoverY;
180  req.startNS = e.data.params.startNS;
181  req.endNS = e.data.params.endNS;
182  req.totalNS = e.data.params.totalNS;
183  req.slicesTime = e.data.params.slicesTime;
184  req.range = e.data.params.range;
185  req.scale = e.data.params.scale;
186  req.canvasWidth = e.data.params.canvasWidth;
187  req.canvasHeight = e.data.params.canvasHeight;
188  req.useCache = e.data.params.useCache;
189  req.lineColor = e.data.params.lineColor;
190  req.chartColor = e.data.params.chartColor;
191  req.wakeupBean = e.data.params.wakeupBean;
192  req.intervalPerf = e.data.params.intervalPerf;
193  req.id = e.data.id;
194  if (!req.frame) {
195    info(req.frame);
196    return;
197  }
198  if (req.canvas) {
199    if (req.canvas.width !== req.canvasWidth || req.canvas.height !== req.canvasHeight) {
200      req.canvas.width = req.canvasWidth;
201      req.canvas.height = req.canvasHeight;
202      req.context.scale(e.data.params.dpr, e.data.params.dpr);
203    }
204  }
205  match(req.type, req);
206};
207self.onmessageerror = function (e: any) {};
208