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 { SampleType } from '../database/logic-worker/ProcedureLogicWorkerJsCpuProfiler';
17const ROW_TYPE = 'cpu-profiler';
18export class JsCpuProfilerUIStruct {
19  nameId: number;
20  depth: number;
21  selfTime: number;
22  totalTime: number;
23  urlId: number;
24  line: number;
25  column: number;
26  scriptName: string;
27  id: number;
28  parentId: number;
29
30  constructor(
31    id: number,
32    nameId: number,
33    depth: number,
34    selfTime: number,
35    totalTime: number,
36    urlId: number,
37    line: number,
38    column: number
39  ) {
40    this.id = id;
41    this.parentId = -1;
42    this.nameId = nameId;
43    this.depth = depth;
44    this.selfTime = selfTime;
45    this.totalTime = totalTime;
46    this.urlId = urlId;
47    this.line = line;
48    this.column = column;
49    this.scriptName = 'unknown';
50  }
51}
52
53export class JsCpuProfilerChartFrame extends JsCpuProfilerUIStruct {
54  nameId: number;
55  urlId: number;
56  startTime: number;
57  endTime: number;
58  children: Array<JsCpuProfilerChartFrame>;
59  childrenIds: Array<number>;
60  samplesIds: Array<number>;
61  isSelect: boolean = false;
62  parent?: JsCpuProfilerChartFrame;
63
64  constructor(
65    id: number,
66    nameId: number,
67    startTime: number,
68    endTime: number,
69    totalTime: number,
70    depth: number,
71    urlId: number,
72    line: number,
73    column: number
74  ) {
75    super(id, nameId, depth, 0, totalTime, urlId, line, column);
76    this.id = id;
77    this.startTime = startTime;
78    this.endTime = endTime;
79    this.nameId = nameId;
80    this.urlId = urlId;
81    this.children = new Array<JsCpuProfilerChartFrame>();
82    this.samplesIds = new Array<number>();
83    this.childrenIds = new Array<number>();
84  }
85}
86
87export class JsCpuProfilerTabStruct extends JsCpuProfilerUIStruct {
88  rowName = ROW_TYPE;
89  parent?: JsCpuProfilerTabStruct | null | undefined;
90  children: Array<JsCpuProfilerTabStruct>;
91  chartFrameChildren?: Array<JsCpuProfilerChartFrame>;
92  isSelected: boolean = false; //select data line
93  totalTimePercent: string = '';
94  selfTimePercent: string = '';
95  symbolName: string = ''; // function name + scriptName
96  selfTimeStr: string = ''; //selfTime unit conversion
97  totalTimeStr: string = ''; //totalTime unit conversion
98  isSearch: boolean = false; //filter data bold
99  status: boolean = false;
100  name: string = '';
101
102  constructor(
103    nameId: number,
104    selfTime: number,
105    totalTime: number,
106    depth: number,
107    urlId: number,
108    line: number,
109    column: number,
110    scriptName: string,
111    id: number
112  ) {
113    super(id, nameId, depth, selfTime, totalTime, urlId, line, column);
114    this.chartFrameChildren = new Array<JsCpuProfilerChartFrame>();
115    this.children = new Array<JsCpuProfilerTabStruct>();
116    this.scriptName = scriptName || 'unknown';
117  }
118}
119
120export class JsCpuProfilerStatisticsStruct {
121  type: SampleType | string;
122  time: number = 0;
123  timeStr: string = '';
124  percentage: string = '';
125  constructor(type: SampleType | string, time: number, timeStr: string, percentage: string) {
126    this.type = type;
127    this.time = time;
128    this.timeStr = timeStr;
129    this.percentage = percentage;
130  }
131}
132