• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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(ctx: any, data: CpuFreqStruct) {
30        if (data.frame) {
31            let width = data.frame.width || 0;
32            let index = data.cpu || 0
33            index += 2
34            ctx.fillStyle = ColorUtils.colorForTid(index)
35            ctx.strokeStyle = ColorUtils.colorForTid(index)
36            if (data.startNS === CpuFreqStruct.hoverCpuFreqStruct?.startNS) {
37                ctx.lineWidth = 1;
38                ctx.globalAlpha = 0.6;
39                let drawHeight: number = Math.floor(((data.value || 0) * (data.frame.height || 0) * 1.0) / CpuFreqStruct.maxFreq);
40                ctx.fillRect(data.frame.x, data.frame.y + data.frame.height - drawHeight, width, drawHeight)
41                ctx.beginPath()
42                ctx.arc(data.frame.x, data.frame.y + data.frame.height - drawHeight, 3, 0, 2 * Math.PI, true)
43                ctx.fill()
44                ctx.globalAlpha = 1.0;
45                ctx.stroke();
46                ctx.beginPath()
47                ctx.moveTo(data.frame.x + 3, data.frame.y + data.frame.height - drawHeight);
48                ctx.lineWidth = 3;
49                ctx.lineTo(data.frame.x + width, data.frame.y + data.frame.height - drawHeight)
50                ctx.stroke();
51            } else {
52                ctx.globalAlpha = 0.6;
53                ctx.lineWidth = 1;
54                let drawHeight: number = Math.floor(((data.value || 0) * (data.frame.height || 0)) / CpuFreqStruct.maxFreq);
55                ctx.fillRect(data.frame.x, data.frame.y + data.frame.height - drawHeight, width, drawHeight)
56            }
57        }
58        ctx.globalAlpha = 1.0;
59        ctx.lineWidth = 1;
60    }
61}
62
63const textPadding = 2;
64
65