1fb726d48Sopenharmony_ci/* 2fb726d48Sopenharmony_ci * Copyright (C) 2022 Huawei Device Co., Ltd. 3fb726d48Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4fb726d48Sopenharmony_ci * you may not use this file except in compliance with the License. 5fb726d48Sopenharmony_ci * You may obtain a copy of the License at 6fb726d48Sopenharmony_ci * 7fb726d48Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8fb726d48Sopenharmony_ci * 9fb726d48Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10fb726d48Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11fb726d48Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12fb726d48Sopenharmony_ci * See the License for the specific language governing permissions and 13fb726d48Sopenharmony_ci * limitations under the License. 14fb726d48Sopenharmony_ci */ 15fb726d48Sopenharmony_ci 16fb726d48Sopenharmony_ciimport { BaseStruct } from './BaseStruct'; 17fb726d48Sopenharmony_ciimport { Rect } from '../component/trace/timer-shaft/Rect'; 18fb726d48Sopenharmony_ciimport { ColorUtils } from '../component/trace/base/ColorUtils'; 19fb726d48Sopenharmony_ciimport { drawString } from '../database/ui-worker/ProcedureWorkerCommon'; 20fb726d48Sopenharmony_ci 21fb726d48Sopenharmony_ciexport class FuncStruct extends BaseStruct { 22fb726d48Sopenharmony_ci static hoverFuncStruct: FuncStruct | undefined; 23fb726d48Sopenharmony_ci static selectFuncStruct: FuncStruct | undefined; 24fb726d48Sopenharmony_ci argsetid: number | undefined; 25fb726d48Sopenharmony_ci depth: number | undefined; 26fb726d48Sopenharmony_ci dur: number | undefined; 27fb726d48Sopenharmony_ci funName: string | undefined; 28fb726d48Sopenharmony_ci id: number | undefined; 29fb726d48Sopenharmony_ci callid: number | undefined; 30fb726d48Sopenharmony_ci is_main_thread: number | undefined; 31fb726d48Sopenharmony_ci parent_id: number | undefined; 32fb726d48Sopenharmony_ci startTs: number | undefined; 33fb726d48Sopenharmony_ci threadName: string | undefined; 34fb726d48Sopenharmony_ci tid: number | undefined; 35fb726d48Sopenharmony_ci itid: number | undefined; 36fb726d48Sopenharmony_ci ipid: number | undefined; 37fb726d48Sopenharmony_ci identify: number | undefined; 38fb726d48Sopenharmony_ci track_id: number | undefined; 39fb726d48Sopenharmony_ci nofinish: boolean = false; 40fb726d48Sopenharmony_ci // distributed relation chain 41fb726d48Sopenharmony_ci ts: number | undefined; 42fb726d48Sopenharmony_ci pid: number | undefined; 43fb726d48Sopenharmony_ci traceId: string | undefined; 44fb726d48Sopenharmony_ci chainId: string | undefined; 45fb726d48Sopenharmony_ci chainName: string | undefined; 46fb726d48Sopenharmony_ci spanId: string | undefined; 47fb726d48Sopenharmony_ci parentSpanId: string | undefined; 48fb726d48Sopenharmony_ci chainFlag: string | undefined; 49fb726d48Sopenharmony_ci 50fb726d48Sopenharmony_ci static draw(funcBeanStructCanvasCtx: CanvasRenderingContext2D, funcBeanStruct: FuncStruct): void { 51fb726d48Sopenharmony_ci if (funcBeanStruct.frame) { 52fb726d48Sopenharmony_ci if ( 53fb726d48Sopenharmony_ci funcBeanStruct.dur === undefined || 54fb726d48Sopenharmony_ci funcBeanStruct.dur === null || 55fb726d48Sopenharmony_ci funcBeanStruct.dur === 0 || 56fb726d48Sopenharmony_ci FuncStruct.isBinder(funcBeanStruct) 57fb726d48Sopenharmony_ci ) { 58fb726d48Sopenharmony_ci } else { 59fb726d48Sopenharmony_ci funcBeanStructCanvasCtx.fillStyle = 60fb726d48Sopenharmony_ci ColorUtils.FUNC_COLOR[funcBeanStruct.depth || 0 % ColorUtils.FUNC_COLOR.length]; 61fb726d48Sopenharmony_ci let miniHeight = 20; 62fb726d48Sopenharmony_ci funcBeanStructCanvasCtx.fillRect( 63fb726d48Sopenharmony_ci funcBeanStruct.frame.x, 64fb726d48Sopenharmony_ci funcBeanStruct.frame.y, 65fb726d48Sopenharmony_ci funcBeanStruct.frame.width, 66fb726d48Sopenharmony_ci miniHeight - padding * 2 67fb726d48Sopenharmony_ci ); 68fb726d48Sopenharmony_ci funcBeanStructCanvasCtx.fillStyle = '#fff'; 69fb726d48Sopenharmony_ci drawString(funcBeanStructCanvasCtx, funcBeanStruct.funName || '', 5, funcBeanStruct.frame, funcBeanStruct); 70fb726d48Sopenharmony_ci if (FuncStruct.isSelected(funcBeanStruct)) { 71fb726d48Sopenharmony_ci funcBeanStructCanvasCtx.strokeStyle = '#000'; 72fb726d48Sopenharmony_ci funcBeanStructCanvasCtx.lineWidth = 1; 73fb726d48Sopenharmony_ci funcBeanStructCanvasCtx.strokeRect( 74fb726d48Sopenharmony_ci funcBeanStruct.frame.x, 75fb726d48Sopenharmony_ci funcBeanStruct.frame.y, 76fb726d48Sopenharmony_ci funcBeanStruct.frame.width, 77fb726d48Sopenharmony_ci miniHeight - padding * 2 78fb726d48Sopenharmony_ci ); 79fb726d48Sopenharmony_ci } 80fb726d48Sopenharmony_ci } 81fb726d48Sopenharmony_ci } 82fb726d48Sopenharmony_ci } 83fb726d48Sopenharmony_ci 84fb726d48Sopenharmony_ci static isSelected(data: FuncStruct): boolean { 85fb726d48Sopenharmony_ci return ( 86fb726d48Sopenharmony_ci FuncStruct.selectFuncStruct !== undefined && 87fb726d48Sopenharmony_ci FuncStruct.selectFuncStruct.startTs === data.startTs && 88fb726d48Sopenharmony_ci FuncStruct.selectFuncStruct.dur === data.dur && 89fb726d48Sopenharmony_ci FuncStruct.selectFuncStruct.funName === data.funName 90fb726d48Sopenharmony_ci ); 91fb726d48Sopenharmony_ci } 92fb726d48Sopenharmony_ci 93fb726d48Sopenharmony_ci static isBinder(data: FuncStruct): boolean { 94fb726d48Sopenharmony_ci if ( 95fb726d48Sopenharmony_ci data.funName && 96fb726d48Sopenharmony_ci (data.funName.toLowerCase().startsWith('binder transaction') || 97fb726d48Sopenharmony_ci data.funName.toLowerCase().startsWith('binder async') || 98fb726d48Sopenharmony_ci data.funName.toLowerCase().startsWith('binder reply')) 99fb726d48Sopenharmony_ci ) { 100fb726d48Sopenharmony_ci return true; 101fb726d48Sopenharmony_ci } else { 102fb726d48Sopenharmony_ci return false; 103fb726d48Sopenharmony_ci } 104fb726d48Sopenharmony_ci } 105fb726d48Sopenharmony_ci 106fb726d48Sopenharmony_ci static isBinderAsync(data: FuncStruct): boolean { 107fb726d48Sopenharmony_ci if (data.funName && data.funName.toLowerCase().includes('async')) { 108fb726d48Sopenharmony_ci return true; 109fb726d48Sopenharmony_ci } else { 110fb726d48Sopenharmony_ci return false; 111fb726d48Sopenharmony_ci } 112fb726d48Sopenharmony_ci } 113fb726d48Sopenharmony_ci} 114fb726d48Sopenharmony_ci 115fb726d48Sopenharmony_ciconst padding = 1; 116