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 { ColorUtils } from '../component/trace/base/ColorUtils.js'; 17import { BaseStruct } from './BaseStruct.js'; 18 19export class CpuFreqStruct extends BaseStruct { 20 static maxFreq: number = 0; 21 static maxFreqName: string = '0 GHz'; 22 static hoverCpuFreqStruct: CpuFreqStruct | undefined; 23 static selectCpuFreqStruct: CpuFreqStruct | undefined; 24 cpu: number | undefined; 25 value: number | undefined; 26 startNS: number | undefined; 27 dur: number | undefined; // Self-supplementing, the database is not returned 28 29 static draw(freqBeanStructCanvasCtx: any, freqBeanStruct: CpuFreqStruct) { 30 if (freqBeanStruct.frame) { 31 let freqBeanStructWidth = freqBeanStruct.frame.width || 0; 32 let freqBeanStructIndex = freqBeanStruct.cpu || 0; 33 freqBeanStructIndex += 2; 34 freqBeanStructCanvasCtx.fillStyle = ColorUtils.colorForTid(freqBeanStructIndex); 35 freqBeanStructCanvasCtx.strokeStyle = ColorUtils.colorForTid(freqBeanStructIndex); 36 if (freqBeanStruct.startNS === CpuFreqStruct.hoverCpuFreqStruct?.startNS) { 37 freqBeanStructCanvasCtx.lineWidth = 1; 38 freqBeanStructCanvasCtx.globalAlpha = 0.6; 39 let freqBeanStructDrawHeight: number = Math.floor( 40 ((freqBeanStruct.value || 0) * (freqBeanStruct.frame.height || 0) * 1.0) / 41 CpuFreqStruct.maxFreq 42 ); 43 freqBeanStructCanvasCtx.fillRect( 44 freqBeanStruct.frame.x, 45 freqBeanStruct.frame.y + freqBeanStruct.frame.height - freqBeanStructDrawHeight, 46 freqBeanStructWidth, 47 freqBeanStructDrawHeight 48 ); 49 freqBeanStructCanvasCtx.beginPath(); 50 freqBeanStructCanvasCtx.arc( 51 freqBeanStruct.frame.x, 52 freqBeanStruct.frame.y + freqBeanStruct.frame.height - freqBeanStructDrawHeight, 53 3, 54 0, 55 2 * Math.PI, 56 true 57 ); 58 freqBeanStructCanvasCtx.fill(); 59 freqBeanStructCanvasCtx.globalAlpha = 1.0; 60 freqBeanStructCanvasCtx.stroke(); 61 freqBeanStructCanvasCtx.beginPath(); 62 freqBeanStructCanvasCtx.moveTo( 63 freqBeanStruct.frame.x + 3, 64 freqBeanStruct.frame.y + freqBeanStruct.frame.height - freqBeanStructDrawHeight 65 ); 66 freqBeanStructCanvasCtx.lineWidth = 3; 67 freqBeanStructCanvasCtx.lineTo( 68 freqBeanStruct.frame.x + freqBeanStructWidth, 69 freqBeanStruct.frame.y + freqBeanStruct.frame.height - freqBeanStructDrawHeight 70 ); 71 freqBeanStructCanvasCtx.stroke(); 72 } else { 73 freqBeanStructCanvasCtx.globalAlpha = 0.6; 74 freqBeanStructCanvasCtx.lineWidth = 1; 75 let drawHeight: number = Math.floor( 76 ((freqBeanStruct.value || 0) * (freqBeanStruct.frame.height || 0)) / 77 CpuFreqStruct.maxFreq 78 ); 79 freqBeanStructCanvasCtx.fillRect( 80 freqBeanStruct.frame.x, 81 freqBeanStruct.frame.y + freqBeanStruct.frame.height - drawHeight, 82 freqBeanStructWidth, 83 drawHeight 84 ); 85 } 86 } 87 freqBeanStructCanvasCtx.globalAlpha = 1.0; 88 freqBeanStructCanvasCtx.lineWidth = 1; 89 } 90 91} 92 93const textPadding = 2; 94