• 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 {SpSystemTrace} from "../../component/SpSystemTrace";
20
21export class AppStartupRender {
22  renderMainThread(
23    appStartReq: {
24      useCache: boolean;
25      appStartupContext: CanvasRenderingContext2D;
26      type: string;
27    },
28    appStartUpRow: TraceRow<AppStartupStruct>
29  ): void {
30    let list = appStartUpRow.dataList;
31    let appStartUpfilter = appStartUpRow.dataListCache;
32    dataFilterHandler(list, appStartUpfilter, {
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: appStartReq.useCache || !(TraceRow.range?.refresh ?? false),
41    });
42    appStartReq.appStartupContext.globalAlpha = 0.6;
43    let find = false;
44    let offset = 3;
45    for (let re of appStartUpfilter) {
46      AppStartupStruct.draw(appStartReq.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          AppStartupStruct.hoverStartupStruct = re;
54          find = true;
55        }
56      }
57    }
58    if (!find && appStartUpRow.isHover) {
59      AppStartupStruct.hoverStartupStruct = undefined;
60    }
61  }
62}
63
64const padding = 3;
65export function AppStartupStructOnClick(clickRowType: string, sp: SpSystemTrace,scrollToFuncHandler:any) {
66  return new Promise((resolve,reject) => {
67    if (clickRowType === TraceRow.ROW_TYPE_APP_STARTUP && AppStartupStruct.hoverStartupStruct) {
68      AppStartupStruct.selectStartupStruct = AppStartupStruct.hoverStartupStruct;
69      sp.traceSheetEL?.displayStartupData(AppStartupStruct.selectStartupStruct, scrollToFuncHandler);
70      sp.timerShaftEL?.modifyFlagList(undefined);
71      reject();
72    }else{
73      resolve(null);
74    }
75  });
76}
77export class AppStartupStruct extends BaseStruct {
78  static hoverStartupStruct: AppStartupStruct | undefined;
79  static selectStartupStruct: AppStartupStruct | undefined;
80  static StartUpStep: string[] = [
81    'ProcessTouchEvent',
82    'StartUIAbilityBySCB',
83    'LoadAbility',
84    'Application Launching',
85    'UI Ability Launching',
86    'UI Ability OnForeground',
87    'First Frame - APP Phase',
88    'First Frame - Render Phase',
89  ];
90  startTs: number | undefined;
91  startName: number | undefined;
92  dur: number | undefined;
93  value: string | undefined;
94  pid: number | undefined;
95  process: string | undefined;
96  tid: number | undefined;
97  itid: number | undefined;
98  endItid: number | undefined;
99  stepName: string | undefined;
100
101  static draw(ctx: CanvasRenderingContext2D, data: AppStartupStruct): void {
102    if (data.frame) {
103      ctx.globalAlpha = 1.0;
104      ctx.fillStyle = ColorUtils.colorForTid(data.startName!);
105      ctx.fillRect(data.frame.x, data.frame.y, data.frame.width, data.frame.height);
106      if (data.frame.width > 7) {
107        ctx.textBaseline = 'middle';
108        ctx.lineWidth = 1;
109        if (data.stepName === undefined) {
110          data.stepName = `${AppStartupStruct.getStartupName(data.startName)} (${(data.dur! / 1000000).toFixed(2)}ms)`;
111        }
112        let textColor =
113          ColorUtils.FUNC_COLOR[ColorUtils.hashFunc(data.stepName || '', 0, ColorUtils.FUNC_COLOR.length)];
114        ctx.fillStyle = ColorUtils.funcTextColor(textColor);
115        drawString(ctx, data.stepName, 2, data.frame, data);
116      }
117      if (data === AppStartupStruct.selectStartupStruct) {
118        ctx.strokeStyle = '#232c5d';
119        ctx.lineWidth = 2;
120        ctx.strokeRect(data.frame.x, data.frame.y, data.frame.width, data.frame.height);
121      }
122    }
123  }
124
125  static getStartupName(step: number | undefined): string {
126    if (step === undefined || step < 0 || step > 7) {
127      return 'Unknown Start Step';
128    } else {
129      return AppStartupStruct.StartUpStep[step];
130    }
131  }
132}
133