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 DDRNowLineChartPage { 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 DDR: number= 0 //数值 25 26 offsetX: number = -1 //悬浮框移动触摸点 X 27 offsetY: number = -1 //悬浮框移动触摸点 X 28 private floatName: string= "ddr频率" 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 if (this.data.length >= 22) { 36 37 this.data.shift() //移除第一个元素 38 } 39 if (globalThis.ddrFrequency == undefined) { 40 this.DDR = 0 41 } else { 42 this.DDR = Number(globalThis.ddrFrequency / 1e6).valueOf() 43 44 if (this.DDR == 0) { 45 this.data.push(0) 46 } else { 47 let lineCount: number = this.DDR / 20 48 this.data.push(Math.abs(lineCount)) //在末尾填充一个元素 49 } 50 this.random = Math.random() 51 } 52 } else { 53 //暂停 54 } 55 }, 1000) 56 } 57 58 build() { 59 Stack({ alignContent: Alignment.Top }) { 60 FloatWindowComponent({ title: `sp_ddrFrequency`, data: this.data }) 61 Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) { 62 Text(this.floatName + ":" ) 63 .fontSize('10fp') 64 .fontColor($r("app.color.color_fff")) 65 .margin({ left: 5, top: 1 }) //文本显示 66 Text( this.DDR + "MHz") 67 .fontSize('20fp') 68 .fontColor('#FF0000') 69 .fontWeight(5) 70 .margin({ left: 1,top: 1 }) //文本显示 71 Text(this.random + "") 72 .fontSize('1fp') 73 .fontColor($r("app.color.color_fff")).visibility(Visibility.None) 74 Image($r("app.media.icon_close_small")).width('20vp').height('20vp').onClick(() => { 75 hideFloatWindow("sp_ddrFrequency") 76 77 console.log("hideFloatWindow---------------------" + this.floatName) 78 }).align(Alignment.TopEnd) 79 }.height('20vp').width('100%') 80 81 } 82 } 83}