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 { FuncStruct } from '../../ui-worker/ProcedureWorkerFunc'; 18 19export function processDeliverInputEventDataSender(tid: number, row: TraceRow<FuncStruct>): Promise<FuncStruct[]> { 20 let trafic: number = TraficEnum.ProtoBuffer; 21 let width = row.clientWidth - CHART_OFFSET_LEFT; 22 if (trafic === TraficEnum.SharedArrayBuffer && !row.sharedArrayBuffers) { 23 row.sharedArrayBuffers = { 24 tid: new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * MAX_COUNT), 25 pid: new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * MAX_COUNT), 26 is_main_thread: new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * MAX_COUNT), 27 track_id: new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * MAX_COUNT), 28 startTs: new SharedArrayBuffer(Float64Array.BYTES_PER_ELEMENT * MAX_COUNT), 29 dur: new SharedArrayBuffer(Float64Array.BYTES_PER_ELEMENT * MAX_COUNT), 30 parent_id: new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * MAX_COUNT), 31 id: new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * MAX_COUNT), 32 cookie: new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * MAX_COUNT), 33 depth: new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * MAX_COUNT), 34 argsetid: new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * MAX_COUNT), 35 }; 36 } 37 return new Promise((resolve) => { 38 threadPool.submitProto( 39 QueryEnum.processDeliverInputEventData, 40 { 41 startNS: TraceRow.range?.startNS || 0, 42 endNS: TraceRow.range?.endNS || 0, 43 recordStartNS: window.recordStartNS, 44 recordEndNS: window.recordEndNS, 45 t: Date.now(), 46 width: width, 47 trafic: trafic, 48 sharedArrayBuffers: row.sharedArrayBuffers, 49 tid: tid, 50 }, 51 (res: any, len: number, transfer: boolean) => { 52 resolve(arrayBufferHandler(transfer ? res : row.sharedArrayBuffers, len)); 53 } 54 ); 55 }); 56} 57 58function arrayBufferHandler(buffers: any, len: number): FuncStruct[] { 59 let outArr: FuncStruct[] = []; 60 let tid = new Int32Array(buffers.tid); 61 let pid = new Int32Array(buffers.pid); 62 let is_main_thread = new Int8Array(buffers.is_main_thread); 63 let track_id = new Int32Array(buffers.track_id); 64 let startTs = new Float64Array(buffers.startTs); 65 let dur = new Float64Array(buffers.dur); 66 let parent_id = new Int32Array(buffers.tid); 67 let id = new Int32Array(buffers.id); 68 let cookie = new Int32Array(buffers.cookie); 69 let depth = new Int32Array(buffers.depth); 70 let argsetid = new Int32Array(buffers.argsetid); 71 for (let i = 0; i < len; i++) { 72 outArr.push({ 73 tid: tid[i], 74 pid: pid[i], 75 is_main_thread: is_main_thread[i], 76 track_id: track_id[i], 77 startTs: startTs[i], 78 dur: dur[i], 79 parent_id: parent_id[i], 80 id: id[i], 81 cookie: cookie[i], 82 depth: depth[i], 83 argsetid: argsetid[i], 84 } as unknown as FuncStruct); 85 } 86 return outArr; 87} 88