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 */ 15import { hideFloatWindow } from '../common/ui/floatwindow/utils/FloatWindowUtils' 16import { FloatWindowComponent } from '../common/FloatWindowComponent' 17import { TaskStatus } from '../common/profiler/base/ProfilerConstant'; 18 19@Entry 20@Component 21struct GPULineChartPage { 22 data: number[]= [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] //数据集合 23 @State random: number= 0 //用于刷新的随机数 24 @State gpuFrequency: number= 0 //数值 25 26 offsetX: number = -1 //悬浮框移动触摸点 X 27 offsetY: number = -1 //悬浮框移动触摸点 X 28 private floatName: string= "gpu频点" 29 task_state = 1 30 31 aboutToAppear() { 32 globalThis.LineChartCollect = setInterval(() => { 33 this.task_state = globalThis.task_status 34 if (this.task_state == TaskStatus.task_running) { 35 36 if (this.data.length >= 22) { 37 38 this.data.shift() //移除第一个元素 39 } 40 if (globalThis.gpuFrequency == undefined) { 41 this.gpuFrequency = 0 42 } else { 43 this.gpuFrequency = Number((globalThis.gpuFrequency / 1e6).toFixed(2)).valueOf() 44 45 if (this.gpuFrequency == 0) { 46 this.data.push(0) 47 } else { 48 let lineCount: number = this.gpuFrequency / 10 49 this.data.push(Math.abs(lineCount)) //在末尾填充一个元素 50 } 51 this.random = Math.random() 52 } 53 } else { 54 //暂停 55 } 56 }, 1000) 57 } 58 59 build() { 60 Stack({ alignContent: Alignment.Top }) { 61 FloatWindowComponent({ title: `sp_gpuFrequency`, data: this.data }) 62 Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) { 63 64 Text(this.floatName + ":" ) 65 .fontSize('10fp') 66 .fontColor($r("app.color.color_fff")) 67 .margin({ left: 5, top: 1 }) //文本显示 68 Text( this.gpuFrequency + "MHz") 69 .fontSize('20fp') 70 .fontColor('#FF0000') 71 .fontWeight(5) 72 .margin({ left: 1,top: 1 }) //文本显示 73 Text(this.random + "") 74 .fontSize('1fp') 75 .fontColor($r("app.color.color_fff")).visibility(Visibility.None) 76 Image($r("app.media.icon_close_small")).width('20vp').height('20vp').onClick(() => { 77 hideFloatWindow("sp_gpuFrequency") 78 79 80 }).align(Alignment.TopEnd) 81 }.height('20vp').width('100%') 82 83 } 84 } 85}