• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 { BaseStruct, dataFilterHandler, drawString } from './ProcedureWorkerCommon';
17import { TraceRow } from '../../component/trace/base/TraceRow';
18import { ColorUtils } from '../../component/trace/base/ColorUtils';
19import {querySingleAppStartupsName} from "../sql/ProcessThread.sql";
20
21export class AllAppStartupRender {
22  renderMainThread(
23    req: {
24      appStartupContext: CanvasRenderingContext2D;
25      useCache: boolean;
26      type: string;
27    },
28    appStartUpRow: TraceRow<AllAppStartupStruct>
29  ): void {
30    let list = appStartUpRow.dataList;
31    let filter = appStartUpRow.dataListCache;
32    dataFilterHandler(list, filter, {
33      startKey: 'startTs',
34      durKey: 'dur',
35      startNS: TraceRow.range?.startNS ?? 0,
36      endNS: TraceRow.range?.endNS ?? 0,
37      totalNS: TraceRow.range?.totalNS ?? 0,
38      frame: appStartUpRow.frame,
39      paddingTop: 5,
40      useCache: req.useCache || !(TraceRow.range?.refresh ?? false),
41    });
42    req.appStartupContext.globalAlpha = 0.6;
43    let find = false;
44    let offset = 3;
45    for (let re of filter) {
46      AllAppStartupStruct.draw(req.appStartupContext, re);
47      if (appStartUpRow.isHover) {
48        if (
49          re.frame &&
50          appStartUpRow.hoverX >= re.frame.x - offset &&
51          appStartUpRow.hoverX <= re.frame.x + re.frame.width + offset
52        ) {
53          AllAppStartupStruct.hoverStartupStruct = re;
54          find = true;
55        }
56      }
57    }
58    if (!find && appStartUpRow.isHover) {
59      AllAppStartupStruct.hoverStartupStruct = undefined;
60    }
61  }
62}
63
64
65export class AllAppStartupStruct extends BaseStruct {
66  static hoverStartupStruct: AllAppStartupStruct | undefined;
67  static selectStartupStruct: AllAppStartupStruct | undefined;
68  dur: number | undefined;
69  startTs: number | undefined;
70  startName: number | undefined;
71  stepName: string | undefined;
72
73  static draw(ctx: CanvasRenderingContext2D, data: AllAppStartupStruct): void {
74    if (data.frame) {
75      ctx.globalAlpha = 1.0;
76      ctx.fillStyle = ColorUtils.colorForTid(data.startName!);
77      ctx.fillRect(data.frame.x, data.frame.y, data.frame.width, data.frame.height);
78      if (data.frame.width > 7) {
79        ctx.textBaseline = 'middle';
80        ctx.lineWidth = 1;
81        let draAppName: string | undefined = '';
82        if (data.stepName) {
83          draAppName = `${data.stepName} (${(data.dur! / 1000000).toFixed(2)}ms)`;
84        }
85        let textColor =
86          ColorUtils.FUNC_COLOR[ColorUtils.hashFunc(data.stepName || '', 0, ColorUtils.FUNC_COLOR.length)];
87        ctx.fillStyle = ColorUtils.funcTextColor(textColor);
88        drawString(ctx, draAppName, 2, data.frame, data);
89      }
90      if (data === AllAppStartupStruct.selectStartupStruct) {
91        ctx.strokeStyle = '#232c5d';
92        ctx.lineWidth = 2;
93        ctx.strokeRect(data.frame.x, data.frame.y, data.frame.width, data.frame.height);
94      }
95    }
96  }
97
98}
99