* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { ColorUtils } from '../component/trace/base/ColorUtils';
import { BaseStruct } from './BaseStruct';
export class CpuFreqStruct extends BaseStruct {
static maxFreq: number = 0;
static maxFreqName: string = '0 GHz';
static hoverCpuFreqStruct: CpuFreqStruct | undefined;
static selectCpuFreqStruct: CpuFreqStruct | undefined;
cpu: number | undefined;
value: number | undefined;
startNS: number | undefined;
dur: number | undefined;
static draw(freqCtx: unknown, freqData: CpuFreqStruct): void {
if (freqData.frame) {
let freqWidth = freqData.frame.width || 0;
let freqIndex = freqData.cpu || 0;
freqIndex += 2;
freqCtx.fillStyle = ColorUtils.colorForTid(freqIndex);
freqCtx.strokeStyle = ColorUtils.colorForTid(freqIndex);
if (freqData.startNS === CpuFreqStruct.hoverCpuFreqStruct?.startNS) {
freqCtx.lineWidth = 1;
freqCtx.globalAlpha = 0.6;
let drawHeight: number = Math.floor(
((freqData.value || 0) * (freqData.frame.height || 0) * 1.0) / CpuFreqStruct.maxFreq
);
freqCtx.fillRect(
freqData.frame.x,
freqData.frame.y + freqData.frame.height - drawHeight,
freqWidth,
drawHeight
);
freqCtx.beginPath();
freqCtx.arc(freqData.frame.x, freqData.frame.y + freqData.frame.height - drawHeight, 3, 0, 2 * Math.PI, true);
freqCtx.fill();
freqCtx.globalAlpha = 1.0;
freqCtx.stroke();
freqCtx.beginPath();
freqCtx.moveTo(freqData.frame.x + 3, freqData.frame.y + freqData.frame.height - drawHeight);
freqCtx.lineWidth = 3;
freqCtx.lineTo(freqData.frame.x + freqWidth, freqData.frame.y + freqData.frame.height - drawHeight);
freqCtx.stroke();
} else {
freqCtx.globalAlpha = 0.6;
freqCtx.lineWidth = 1;
let drawHeight: number = Math.floor(
((freqData.value || 0) * (freqData.frame.height || 0)) / CpuFreqStruct.maxFreq
);
freqCtx.fillRect(
freqData.frame.x,
freqData.frame.y + freqData.frame.height - drawHeight,
freqWidth,
drawHeight
);
}
}
freqCtx.globalAlpha = 1.0;
freqCtx.lineWidth = 1;
}
}