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 RAMLineChartPage { 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 pss: number= 0 //数值 25 26 offsetX: number = -1 //悬浮框移动触摸点 X 27 offsetY: number = -1 //悬浮框移动触摸点 X 28 private floatName: string= "RAM" 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.pss == undefined || isNaN(globalThis.pss)) { 40 this.pss = 0 41 } else { 42 this.pss = globalThis.pss 43 44 if (this.pss == 0) { 45 this.data.push(0) 46 } else { 47 let lineCount: number = this.pss / 1500 48 49 this.data.push(Math.abs(lineCount)) //在末尾填充一个元素 50 51 } 52 this.random = Math.random() 53 } 54 } else { 55 //暂停 56 } 57 }, 1000) 58 } 59 60 build() { 61 Stack({ alignContent: Alignment.Top }) { 62 FloatWindowComponent({ title: `sp_RAM`, data: this.data }) 63 Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) { 64 Text(this.floatName + ":" ) 65 .fontSize('10fp') 66 .fontColor($r("app.color.color_fff")) 67 .margin({ left: 5, top: 1 }) //文本显示 68 Text( this.pss + "KB") 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_RAM") 78 79 }).align(Alignment.TopEnd) 80 }.height('20vp').width('100%') 81 } 82 } 83}