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 { IrqStruct } from '../ui-worker/ProcedureWorkerIrq'; 18 19export function irqDataSender(cpu: number, name: string, row: TraceRow<IrqStruct>): Promise<IrqStruct[]> { 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 argSetId: new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * MAX_COUNT), 25 depth: new SharedArrayBuffer(Uint32Array.BYTES_PER_ELEMENT * MAX_COUNT), 26 id: new SharedArrayBuffer(Uint32Array.BYTES_PER_ELEMENT * MAX_COUNT), 27 dur: new SharedArrayBuffer(Float64Array.BYTES_PER_ELEMENT * MAX_COUNT), 28 startNS: new SharedArrayBuffer(Float64Array.BYTES_PER_ELEMENT * MAX_COUNT), 29 }; 30 } 31 return new Promise((resolve): void => { 32 threadPool.submitProto( 33 QueryEnum.IrqData, 34 { 35 cpu: cpu, 36 name: name, 37 startNS: TraceRow.range?.startNS || 0, 38 endNS: TraceRow.range?.endNS || 0, 39 recordStartNS: window.recordStartNS, 40 recordEndNS: window.recordEndNS, 41 t: Date.now(), 42 width: width, 43 trafic: trafic, 44 sharedArrayBuffers: row.sharedArrayBuffers, 45 }, 46 (res: any, len: number, transfer: boolean) => 47 resolve(arrayBufferHandler(transfer ? res : row.sharedArrayBuffers, len)) 48 ); 49 }); 50} 51 52function arrayBufferHandler(buffers: any, len: number): IrqStruct[] { 53 let outArr: IrqStruct[] = []; 54 let argSetId = new Int32Array(buffers.argSetId); 55 let depth = new Uint32Array(buffers.depth); 56 let startNS = new Float64Array(buffers.startNS); 57 let dur = new Float64Array(buffers.dur); 58 let id = new Uint32Array(buffers.id); 59 for (let i = 0; i < len; i++) { 60 outArr.push({ 61 argSetId: argSetId[i], 62 depth: depth[i], 63 dur: dur[i], 64 id: id[i], 65 startNS: startNS[i], 66 } as unknown as IrqStruct); 67 } 68 return outArr; 69} 70