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(Uint16Array.BYTES_PER_ELEMENT * MAX_COUNT), 32 rs_ts: new SharedArrayBuffer(Float64Array.BYTES_PER_ELEMENT * MAX_COUNT), 33 rs_vsync: new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * MAX_COUNT), 34 rs_dur: new SharedArrayBuffer(Float64Array.BYTES_PER_ELEMENT * MAX_COUNT), 35 rs_ipid: new SharedArrayBuffer(Uint16Array.BYTES_PER_ELEMENT * MAX_COUNT), 36 rs_pid: new SharedArrayBuffer(Uint16Array.BYTES_PER_ELEMENT * MAX_COUNT), 37 rs_name: new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * MAX_COUNT), 38 depth: new SharedArrayBuffer(Uint16Array.BYTES_PER_ELEMENT * MAX_COUNT), 39 }; 40 } 41 return new Promise((resolve): void => { 42 threadPool.submitProto( 43 queryEnum, 44 { 45 queryEnum: queryEnum, 46 startNS: TraceRow.range?.startNS || 0, 47 endNS: TraceRow.range?.endNS || 0, 48 recordStartNS: window.recordStartNS, 49 recordEndNS: window.recordEndNS, 50 width: width, 51 t: new Date().getTime(), 52 trafic: transferJankDataType, 53 sharedArrayBuffers: row.sharedArrayBuffers, 54 }, 55 (res: unknown, len: number, transfer: boolean): void => { 56 // @ts-ignore 57 resolve(arrayBufferHandler(transfer ? res : row.sharedArrayBuffers, len)); 58 } 59 ); 60 }); 61} 62 63function arrayBufferHandler(res: unknown, len: number): unknown[] { 64 let outArr = []; 65 // @ts-ignore 66 let id = new Uint16Array(res.id); 67 // @ts-ignore 68 let ipId = new Uint16Array(res.ipid); 69 // @ts-ignore 70 let nameId = new Int32Array(res.name); 71 // @ts-ignore 72 let app_dur = new Float64Array(res.app_dur); 73 // @ts-ignore 74 let dur = new Float64Array(res.dur); 75 // @ts-ignore 76 let ts = new Float64Array(res.ts); 77 // @ts-ignore 78 let jank_tag = new Uint16Array(res.jank_tag); 79 // @ts-ignore 80 let pid = new Uint16Array(res.pid); 81 // @ts-ignore 82 let rsTs = new Float64Array(res.rs_ts); 83 // @ts-ignore 84 let rs_vsync = new Int32Array(res.rs_vsync); 85 // @ts-ignore 86 let rs_dur = new Float64Array(res.rs_dur); 87 // @ts-ignore 88 let rs_ipId = new Uint16Array(res.rs_ipid); 89 // @ts-ignore 90 let rs_pid = new Uint16Array(res.rs_pid); 91 // @ts-ignore 92 let rs_name = new Int32Array(res.rs_name); 93 // @ts-ignore 94 let depth = new Uint16Array(res.depth); 95 for (let index = 0; index < len; index++) { 96 outArr.push({ 97 id: id[index], 98 ipid: ipId[index], 99 name: nameId[index], 100 app_dur: app_dur[index], 101 dur: dur[index], 102 ts: ts[index], 103 jank_tag: jank_tag[index], 104 pid: pid[index], 105 rs_ts: rsTs[index], 106 rs_vsync: rs_vsync[index], 107 rs_dur: rs_dur[index], 108 rs_ipid: rs_ipId[index], 109 rs_pid: rs_pid[index], 110 rs_name: rs_name[index], 111 depth: depth[index], 112 }); 113 } 114 return outArr; 115} 116