• 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 { TraceRow } from '../../../component/trace/base/TraceRow';
15import { CHART_OFFSET_LEFT, MAX_COUNT, QueryEnum, TraficEnum } from '../utils/QueryEnum';
16import { threadPool } from '../../SqlLite';
17import { HiPerfThreadStruct } from '../../ui-worker/hiperf/ProcedureWorkerHiPerfThread2';
18
19export function hiperfThreadDataSender(
20  tid: number,
21  drawType: number,
22  intervalPerf: number,
23  scale: number,
24  row: TraceRow<any>
25): Promise<any[]> {
26  let trafic: number = TraficEnum.ProtoBuffer;
27  let width = row.clientWidth - CHART_OFFSET_LEFT;
28  if (trafic === TraficEnum.SharedArrayBuffer && !row.sharedArrayBuffers) {
29    row.sharedArrayBuffers = {
30      eventTypeId: new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * MAX_COUNT),
31      startNS: new SharedArrayBuffer(Float64Array.BYTES_PER_ELEMENT * MAX_COUNT),
32      eventCount: new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * MAX_COUNT),
33      sampleCount: new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * MAX_COUNT),
34      callChainId: new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * MAX_COUNT),
35      height: new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * MAX_COUNT),
36    };
37  }
38  return new Promise((resolve): void => {
39    threadPool.submitProto(
40      QueryEnum.HiperfThreadData,
41      {
42        scale: scale,
43        drawType: drawType,
44        intervalPerf: intervalPerf,
45        startNS: TraceRow.range?.startNS || 0,
46        endNS: TraceRow.range?.endNS || 0,
47        recordStartNS: window.recordStartNS,
48        recordEndNS: window.recordEndNS,
49        width: width,
50        trafic: trafic,
51        sharedArrayBuffers: row.sharedArrayBuffers,
52        tid: tid,
53        maxCpuCount: -1,
54      },
55      (res: any, len: number, transfer: boolean): void => {
56        resolve(arrayBufferHandler(transfer ? res : row.sharedArrayBuffers, len));
57      }
58    );
59  });
60}
61
62function arrayBufferHandler(buffers: any, len: number): HiPerfThreadStruct[] {
63  let outArr: HiPerfThreadStruct[] = [];
64  let startNS = new Float64Array(buffers.startNS);
65  let eventCount = new Int32Array(buffers.eventCount);
66  let sampleCount = new Int32Array(buffers.sampleCount);
67  let eventTypeId = new Int32Array(buffers.eventTypeId);
68  let callChainId = new Int32Array(buffers.callChainId);
69  let height = new Int32Array(buffers.height);
70  for (let i = 0; i < len; i++) {
71    outArr.push({
72      dur: 10_000_000,
73      startNS: startNS[i],
74      event_count: eventCount[i],
75      sampleCount: sampleCount[i],
76      event_type_id: eventTypeId[i],
77      callchain_id: callChainId[i],
78      height: height[i],
79    } as unknown as HiPerfThreadStruct);
80  }
81  return outArr;
82}
83