1/* 2 * Copyright (C) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import { TraceRow } from '../../component/trace/base/TraceRow'; 17import { threadPool } from '../SqlLite'; 18import { JsCpuProfilerStruct } from '../ui-worker/ProcedureWorkerCpuProfiler'; 19import { CHART_OFFSET_LEFT, QueryEnum, TraficEnum } from './utils/QueryEnum'; 20 21export function cpuProfilerDataSender(row: TraceRow<JsCpuProfilerStruct>) { 22 let trafic: number = TraficEnum.ProtoBuffer; 23 let width = row.clientWidth - CHART_OFFSET_LEFT; 24 return new Promise((resolve, reject) => { 25 threadPool.submitProto( 26 QueryEnum.CpuProfilerData, 27 { 28 startNS: TraceRow.range?.startNS || 0, 29 endNS: TraceRow.range?.endNS || 0, 30 recordStartNS: window.recordStartNS, 31 recordEndNS: window.recordEndNS, 32 width: width, 33 trafic: trafic, 34 }, 35 (res: any, len: number): void => { 36 resolve(arrayBufferHandler(res, len)); 37 } 38 ); 39 }); 40} 41 42function arrayBufferHandler(res: any, len: number) { 43 let outArr: any[] = []; 44 let column = new Int32Array(res.column); 45 let depth = new Int32Array(res.depth); 46 let endTime = new Float64Array(res.endTime); 47 let id = new Int32Array(res.id); 48 let line = new Int32Array(res.line); 49 let nameId = new Int32Array(res.nameId); 50 let parentId = new Int32Array(res.parentId); 51 let selfTime = new Float64Array(res.selfTime); 52 let startTime = new Float64Array(res.startTime); 53 let totalTime = new Float64Array(res.totalTime); 54 let urlId = new Int32Array(res.urlId); 55 for (let i = 0; i < len; i++) { 56 outArr.push({ 57 column: column[i], 58 depth: depth[i], 59 endTime: endTime[i], 60 id: id[i], 61 line: line[i], 62 nameId: nameId[i], 63 parentId: parentId[i], 64 samplesIds: res.samplesIds[i], 65 selfTime: selfTime[i], 66 startTime: startTime[i], 67 totalTime: totalTime[i], 68 urlId: urlId[i], 69 childrenIds: res.childrenIds[i], 70 } as any); 71 } 72 return { 73 maxDepth: res.maxDepth, 74 dataList: outArr, 75 }; 76} 77