• 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, TraficEnum } from './utils/QueryEnum';
15import { threadPool } from '../SqlLite';
16import { TraceRow } from '../../component/trace/base/TraceRow';
17import { JanksStruct } from '../../bean/JanksStruct';
18
19export function frameJanksSender(queryEnum: number, row: TraceRow<JanksStruct>): Promise<JanksStruct[]> {
20  let transferJankDataType: number = TraficEnum.Memory;
21  let width = row.clientWidth - CHART_OFFSET_LEFT;
22  if (transferJankDataType === TraficEnum.SharedArrayBuffer && !row.sharedArrayBuffers) {
23    row.sharedArrayBuffers = {
24      id: new SharedArrayBuffer(Uint16Array.BYTES_PER_ELEMENT * MAX_COUNT),
25      ipid: new SharedArrayBuffer(Uint16Array.BYTES_PER_ELEMENT * MAX_COUNT),
26      name: new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * MAX_COUNT),
27      app_dur: new SharedArrayBuffer(Float64Array.BYTES_PER_ELEMENT * MAX_COUNT),
28      dur: new SharedArrayBuffer(Float64Array.BYTES_PER_ELEMENT * MAX_COUNT),
29      ts: new SharedArrayBuffer(Float64Array.BYTES_PER_ELEMENT * MAX_COUNT),
30      jank_tag: new SharedArrayBuffer(Uint16Array.BYTES_PER_ELEMENT * MAX_COUNT),
31      pid: new SharedArrayBuffer(Uint32Array.BYTES_PER_ELEMENT * MAX_COUNT),
32      tid: new SharedArrayBuffer(Uint32Array.BYTES_PER_ELEMENT * MAX_COUNT),
33      rs_ts: new SharedArrayBuffer(Float64Array.BYTES_PER_ELEMENT * MAX_COUNT),
34      rs_vsync: new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * MAX_COUNT),
35      rs_dur: new SharedArrayBuffer(Float64Array.BYTES_PER_ELEMENT * MAX_COUNT),
36      rs_ipid: new SharedArrayBuffer(Uint16Array.BYTES_PER_ELEMENT * MAX_COUNT),
37      rs_pid: new SharedArrayBuffer(Uint32Array.BYTES_PER_ELEMENT * MAX_COUNT),
38      rs_name: new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * MAX_COUNT),
39      depth: new SharedArrayBuffer(Uint16Array.BYTES_PER_ELEMENT * MAX_COUNT),
40    };
41  }
42  return new Promise((resolve): void => {
43    threadPool.submitProto(
44      queryEnum,
45      {
46        queryEnum: queryEnum,
47        startNS: TraceRow.range?.startNS || 0,
48        endNS: TraceRow.range?.endNS || 0,
49        recordStartNS: window.recordStartNS,
50        recordEndNS: window.recordEndNS,
51        width: width,
52        t: new Date().getTime(),
53        trafic: transferJankDataType,
54        sharedArrayBuffers: row.sharedArrayBuffers,
55      },
56      (res: unknown, len: number, transfer: boolean): void => {
57        // @ts-ignore
58        resolve(arrayBufferHandler(transfer ? res : row.sharedArrayBuffers, len));
59      }
60    );
61  });
62}
63
64function arrayBufferHandler(res: unknown, len: number): unknown[] {
65  let outArr = [];
66  // @ts-ignore
67  let id = new Uint16Array(res.id);
68  // @ts-ignore
69  let ipId = new Uint16Array(res.ipid);
70  // @ts-ignore
71  let nameId = new Int32Array(res.name);
72  // @ts-ignore
73  let app_dur = new Float64Array(res.app_dur);
74  // @ts-ignore
75  let dur = new Float64Array(res.dur);
76  // @ts-ignore
77  let ts = new Float64Array(res.ts);
78  // @ts-ignore
79  let jank_tag = new Uint16Array(res.jank_tag);
80  // @ts-ignore
81  let pid = new Uint32Array(res.pid);
82  // @ts-ignore
83  let tid = new Uint32Array(res.tid);
84  // @ts-ignore
85  let rsTs = new Float64Array(res.rs_ts);
86  // @ts-ignore
87  let rs_vsync = new Int32Array(res.rs_vsync);
88  // @ts-ignore
89  let rs_dur = new Float64Array(res.rs_dur);
90  // @ts-ignore
91  let rs_ipId = new Uint16Array(res.rs_ipid);
92  // @ts-ignore
93  let rs_pid = new Uint32Array(res.rs_pid);
94  // @ts-ignore
95  let rs_name = new Int32Array(res.rs_name);
96  // @ts-ignore
97  let depth = new Uint16Array(res.depth);
98  for (let index = 0; index < len; index++) {
99    outArr.push({
100      id: id[index],
101      ipid: ipId[index],
102      name: nameId[index],
103      app_dur: app_dur[index],
104      dur: dur[index],
105      ts: ts[index],
106      jank_tag: jank_tag[index],
107      pid: pid[index],
108      tid: tid[index],
109      rs_ts: rsTs[index],
110      rs_vsync: rs_vsync[index],
111      rs_dur: rs_dur[index],
112      rs_ipid: rs_ipId[index],
113      rs_pid: rs_pid[index],
114      rs_name: rs_name[index],
115      depth: depth[index],
116    });
117  }
118  return outArr;
119}
120