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): Promise<unknown> { 70 return new Promise((resolve, reject) => { 71 if (clickRowType === TraceRow.ROW_TYPE_ALL_APPSTARTUPS && AllAppStartupStruct.hoverStartupStruct) { 72 AllAppStartupStruct.selectStartupStruct = AllAppStartupStruct.hoverStartupStruct; 73 sp.traceSheetEL?.displayAllStartupData(AllAppStartupStruct.selectStartupStruct, scrollToFuncHandler); 74 sp.timerShaftEL?.modifyFlagList(undefined); 75 reject(new Error()); 76 } else { 77 resolve(null); 78 } 79 }); 80} 81 82export class AllAppStartupStruct extends BaseStruct { 83 static hoverStartupStruct: AllAppStartupStruct | undefined; 84 static selectStartupStruct: AllAppStartupStruct | undefined; 85 startTs: number | undefined; 86 startName: number | undefined; 87 dur: number | undefined; 88 value: string | undefined; 89 pid: number | undefined; 90 process: string | undefined; 91 tid: number | undefined; 92 itid: number | undefined; 93 endItid: number | undefined; 94 stepName: string | undefined; 95 96 static draw(ctx: CanvasRenderingContext2D, data: AllAppStartupStruct): void { 97 if (data.frame) { 98 ctx.globalAlpha = 1.0; 99 ctx.fillStyle = ColorUtils.colorForTid(data.startName!); 100 ctx.fillRect(data.frame.x, data.frame.y, data.frame.width, data.frame.height); 101 if (data.frame.width > 7) { 102 ctx.textBaseline = 'middle'; 103 ctx.lineWidth = 1; 104 let draAppName: string | undefined = ''; 105 if (data.stepName) { 106 draAppName = `${data.stepName} (${(data.dur! / 1000000).toFixed(2)}ms)`; 107 } 108 let textColor = 109 ColorUtils.FUNC_COLOR[ColorUtils.hashFunc(data.stepName || '', 0, ColorUtils.FUNC_COLOR.length)]; 110 ctx.fillStyle = ColorUtils.funcTextColor(textColor); 111 drawString(ctx, draAppName, 2, data.frame, data); 112 } 113 if (data === AllAppStartupStruct.selectStartupStruct) { 114 ctx.strokeStyle = '#232c5d'; 115 ctx.lineWidth = 2; 116 ctx.strokeRect(data.frame.x, data.frame.y, data.frame.width, data.frame.height); 117 } 118 } 119 } 120} 121