• 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 processActualDataSender(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      jank_tag: new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * MAX_COUNT),
25      dst_slice: new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * MAX_COUNT),
26      depth: new SharedArrayBuffer(Uint16Array.BYTES_PER_ELEMENT * MAX_COUNT),
27      name: new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * MAX_COUNT),
28      pid: new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * MAX_COUNT),
29      type: new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * MAX_COUNT),
30      id: new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * MAX_COUNT),
31      ts: new SharedArrayBuffer(Float64Array.BYTES_PER_ELEMENT * MAX_COUNT),
32      dur: new SharedArrayBuffer(Float64Array.BYTES_PER_ELEMENT * MAX_COUNT),
33    };
34  }
35  return new Promise((resolve, reject) => {
36    threadPool.submitProto(
37      QueryEnum.processActualData,
38      {
39        startNS: TraceRow.range?.startNS || 0,
40        endNS: TraceRow.range?.endNS || 0,
41        pid: pid,
42        recordStartNS: window.recordStartNS,
43        recordEndNS: window.recordEndNS,
44        width: width,
45        trafic: trafic,
46        sharedArrayBuffers: row.sharedArrayBuffers,
47        t: Date.now(),
48      },
49      (res: any, len: number, transfer: boolean): void => {
50        resolve(arrayBufferHandler(transfer ? res : row.sharedArrayBuffers, len));
51      }
52    );
53  });
54}
55
56function arrayBufferHandler(buffers: any, len: number): JankStruct[] {
57  let name = new Int32Array(buffers.name);
58  let id = new Int32Array(buffers.id);
59  let pid = new Int32Array(buffers.pid);
60  let type = new Int32Array(buffers.type);
61  let ts = new Float64Array(buffers.ts);
62  let dur = new Float64Array(buffers.dur);
63  let outArr: JankStruct[] = [];
64  let jank_tag = new Int32Array(buffers.jank_tag);
65  let dst_slice = new Int32Array(buffers.dst_slice);
66  let depth = new Uint16Array(buffers.depth);
67  for (let i = 0; i < len; i++) {
68    outArr.push({
69      name: name[i],
70      pid: pid[i],
71      type: type[i],
72      id: id[i],
73      ts: ts[i],
74      dur: dur[i],
75      jank_tag: jank_tag[i],
76      dst_slice: dst_slice[i],
77      depth: depth[i],
78    } as unknown as JankStruct);
79  }
80  return outArr;
81}
82