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, drawLoadingFrame } from './ProcedureWorkerCommon'; 17import { TraceRow } from '../../component/trace/base/TraceRow'; 18import { ColorUtils } from '../../component/trace/base/ColorUtils'; 19import { querySingleAppStartupsName } from '../sql/ProcessThread.sql'; 20import { SpSystemTrace } from '../../component/SpSystemTrace'; 21 22export class AllAppStartupRender { 23 renderMainThread( 24 req: { 25 appStartupContext: CanvasRenderingContext2D; 26 useCache: boolean; 27 type: string; 28 }, 29 appStartUpRow: TraceRow<AllAppStartupStruct> 30 ): void { 31 let list = appStartUpRow.dataList; 32 let filter = appStartUpRow.dataListCache; 33 dataFilterHandler(list, filter, { 34 startKey: 'startTs', 35 durKey: 'dur', 36 startNS: TraceRow.range?.startNS ?? 0, 37 endNS: TraceRow.range?.endNS ?? 0, 38 totalNS: TraceRow.range?.totalNS ?? 0, 39 frame: appStartUpRow.frame, 40 paddingTop: 5, 41 useCache: req.useCache || !(TraceRow.range?.refresh ?? false), 42 }); 43 req.appStartupContext.globalAlpha = 0.6; 44 let find = false; 45 let offset = 3; 46 drawLoadingFrame(req.appStartupContext, filter, appStartUpRow); 47 for (let re of filter) { 48 AllAppStartupStruct.draw(req.appStartupContext, re); 49 if (appStartUpRow.isHover) { 50 if ( 51 re.frame && 52 appStartUpRow.hoverX >= re.frame.x - offset && 53 appStartUpRow.hoverX <= re.frame.x + re.frame.width + offset 54 ) { 55 AllAppStartupStruct.hoverStartupStruct = re; 56 find = true; 57 } 58 } 59 } 60 if (!find && appStartUpRow.isHover) { 61 AllAppStartupStruct.hoverStartupStruct = undefined; 62 } 63 } 64} 65export function allAppStartupStructOnClick( 66 clickRowType: string, 67 sp: SpSystemTrace, 68 scrollToFuncHandler: Function, 69 entry?: AllAppStartupStruct, 70): Promise<unknown> { 71 return new Promise((resolve, reject) => { 72 if (clickRowType === TraceRow.ROW_TYPE_ALL_APPSTARTUPS && (AllAppStartupStruct.hoverStartupStruct || entry)) { 73 AllAppStartupStruct.selectStartupStruct = entry || AllAppStartupStruct.hoverStartupStruct; 74 sp.traceSheetEL?.displayAllStartupData(AllAppStartupStruct.selectStartupStruct!, scrollToFuncHandler); 75 sp.timerShaftEL?.modifyFlagList(undefined); 76 reject(new Error()); 77 } else { 78 resolve(null); 79 } 80 }); 81} 82 83export class AllAppStartupStruct extends BaseStruct { 84 static hoverStartupStruct: AllAppStartupStruct | undefined; 85 static selectStartupStruct: AllAppStartupStruct | undefined; 86 startTs: number | undefined; 87 startName: number | undefined; 88 dur: number | undefined; 89 value: string | undefined; 90 pid: number | undefined; 91 process: string | undefined; 92 tid: number | undefined; 93 itid: number | undefined; 94 endItid: number | undefined; 95 stepName: string | undefined; 96 97 static draw(ctx: CanvasRenderingContext2D, data: AllAppStartupStruct): void { 98 if (data.frame) { 99 ctx.globalAlpha = 1.0; 100 ctx.fillStyle = ColorUtils.colorForTid(data.startName!); 101 ctx.fillRect(data.frame.x, data.frame.y, data.frame.width, data.frame.height); 102 if (data.frame.width > 7) { 103 ctx.textBaseline = 'middle'; 104 ctx.lineWidth = 1; 105 let draAppName: string | undefined = ''; 106 if (data.stepName) { 107 draAppName = `${data.stepName} (${(data.dur! / 1000000).toFixed(2)}ms)`; 108 } 109 let textColor = 110 ColorUtils.FUNC_COLOR[ColorUtils.hashFunc(data.stepName || '', 0, ColorUtils.FUNC_COLOR.length)]; 111 ctx.fillStyle = ColorUtils.funcTextColor(textColor); 112 drawString(ctx, draAppName, 2, data.frame, data); 113 } 114 if (data === AllAppStartupStruct.selectStartupStruct) { 115 ctx.strokeStyle = '#232c5d'; 116 ctx.lineWidth = 2; 117 ctx.strokeRect(data.frame.x, data.frame.y, data.frame.width, data.frame.height); 118 } 119 } 120 } 121} 122