• 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.
13import { QueryEnum, TraficEnum } from '../utils/QueryEnum';
14import { threadPool } from '../../SqlLite';
15import { TraceRow } from '../../../component/trace/base/TraceRow';
16import { FuncStruct } from '../../ui-worker/ProcedureWorkerFunc';
17import { SpSystemTrace } from '../../../component/SpSystemTrace';
18
19export function hiperfCallChartDataSender(
20  row: TraceRow<any>,
21  setting: {
22    startTime: number;
23    eventTypeId: number;
24    type: number;
25    id: number;
26  }
27): Promise<any> {
28  return new Promise((resolve, reject) => {
29    threadPool.submitProto(
30      QueryEnum.HiperfCallChart,
31      {
32        startNS: TraceRow.range?.startNS || 0,
33        endNS: TraceRow.range?.endNS || 0,
34        totalNS: (TraceRow.range?.endNS || 0) - (TraceRow.range?.startNS || 0),
35        frame: row.frame,
36        expand: row.funcExpand,
37        isComplete: row.isComplete,
38        startTime: setting.startTime,
39        eventTypeId: setting.eventTypeId,
40        type: setting.type,
41        id: setting.id,
42      },
43      (res: any, len: number): void => {
44        resolve(arrayBufferHandler(res, len));
45      }
46    );
47  });
48}
49
50export function hiperfCallStackCacheSender(): Promise<any> {
51  return new Promise((resolve, reject) => {
52    threadPool.submitProto(
53      QueryEnum.HiperfCallStack,
54      {
55        recordStartNS: window.recordStartNS,
56        isCache: true,
57        trafic: TraficEnum.TransferArrayBuffer,
58      },
59      (res: any, len: number): void => {
60        resolve('ok');
61      }
62    );
63  });
64}
65
66export function hiperfCallChartDataCacheSender(): Promise<any> {
67  return new Promise((resolve, reject) => {
68    threadPool.submitProto(
69      QueryEnum.HiperfCallChart,
70      {
71        recordStartNS: window.recordStartNS,
72        trafic: TraficEnum.TransferArrayBuffer,
73        isCache: true,
74        endNS: (TraceRow.range?.endNS || 0) - (TraceRow.range?.startNS || 0),
75      },
76      (res: any, len: number): void => {
77        resolve('ok');
78      }
79    );
80  });
81}
82
83function arrayBufferHandler(res: any, len: number) {
84  let startTs = new Float64Array(res.startTs);
85  let dur = new Float64Array(res.dur);
86  let depth = new Int32Array(res.depth);
87  let eventCount = new Int32Array(res.eventCount);
88  let symbolId = new Int32Array(res.symbolId);
89  let fileId = new Int32Array(res.fileId);
90  let callchainId = new Int32Array(res.callchainId);
91  let selfDur = new Int32Array(res.selfDur);
92  let name = new Int32Array(res.name);
93  let outArr: any[] = [];
94  for (let i = 0; i < len; i++) {
95    outArr.push({
96      startTime: startTs[i],
97      totalTime: dur[i],
98      endTime: startTs[i] + dur[i],
99      depth: depth[i],
100      eventCount: eventCount[i],
101      fileId: fileId[i],
102      symbolId: symbolId[i],
103      callchain_id: callchainId[i],
104      selfDur: selfDur[i],
105      name: SpSystemTrace.DATA_DICT.get(name[i]),
106    } as any);
107  }
108  return {
109    maxDepth: res.maxDepth,
110    dataList: outArr,
111  };
112}
113