• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (c) 2021 Huawei Device Co., Ltd.
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5//
6//     http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
14import { CHART_OFFSET_LEFT, MAX_COUNT, QueryEnum, TraficEnum } from '../utils/QueryEnum';
15import { threadPool } from '../../SqlLite';
16import { TraceRow } from '../../../component/trace/base/TraceRow';
17import { JankStruct } from '../../ui-worker/ProcedureWorkerJank';
18
19export function processExpectedDataSender(pid: number, row: TraceRow<JankStruct>): Promise<JankStruct[]> {
20  let trafic: number = TraficEnum.Memory;
21  let width = row.clientWidth - CHART_OFFSET_LEFT;
22  if (trafic === TraficEnum.SharedArrayBuffer && !row.sharedArrayBuffers) {
23    row.sharedArrayBuffers = {
24      name: new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * MAX_COUNT),
25      pid: new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * MAX_COUNT),
26      type: new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * MAX_COUNT),
27      id: new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * MAX_COUNT),
28      ts: new SharedArrayBuffer(Float64Array.BYTES_PER_ELEMENT * MAX_COUNT),
29      dur: new SharedArrayBuffer(Float64Array.BYTES_PER_ELEMENT * MAX_COUNT),
30      depth: new SharedArrayBuffer(Uint16Array.BYTES_PER_ELEMENT * MAX_COUNT),
31    };
32  }
33  return new Promise((resolve, reject) => {
34    threadPool.submitProto(
35      QueryEnum.processExpectedData,
36      {
37        pid: pid,
38        startNS: TraceRow.range?.startNS || 0,
39        endNS: TraceRow.range?.endNS || 0,
40        recordStartNS: window.recordStartNS,
41        recordEndNS: window.recordEndNS,
42        t: Date.now(),
43        width: width,
44        sharedArrayBuffers: row.sharedArrayBuffers,
45        trafic: trafic,
46      },
47      (res: any, len: number, transfer: boolean): void => {
48        resolve(arrayBufferHandler(transfer ? res : row.sharedArrayBuffers, len));
49      }
50    );
51  });
52}
53
54function arrayBufferHandler(buffers: any, len: number): JankStruct[] {
55  let outArr: JankStruct[] = [];
56  let name = new Int32Array(buffers.name);
57  let pid = new Int32Array(buffers.pid);
58  let type = new Int32Array(buffers.type);
59  let id = new Int32Array(buffers.id);
60  let ts = new Float64Array(buffers.ts);
61  let dur = new Float64Array(buffers.dur);
62  let depth = new Uint16Array(buffers.depth);
63  for (let i = 0; i < len; i++) {
64    outArr.push({
65      name: name[i],
66      pid: pid[i],
67      type: type[i],
68      id: id[i],
69      ts: ts[i],
70      dur: dur[i],
71      depth: depth[i],
72    } as unknown as JankStruct);
73  }
74  return outArr;
75}
76