• 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 */
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 CPU0LineChartPage {
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 cpu0Frequency: number= 0 //数值
25
26  offsetX: number = -1 //悬浮框移动触摸点 X
27  offsetY: number = -1 //悬浮框移动触摸点 X
28  private floatName: string= "cpu0频率"
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          this.data.shift() //移除第一个元素
37        }
38        if (globalThis.cpu0Frequency == undefined) {
39          this.cpu0Frequency = 0
40        } else {
41          this.cpu0Frequency = parseInt(globalThis.cpu0Frequency) / 1e3
42
43          if (this.cpu0Frequency == 0) {
44            this.data.push(0)
45          } else {
46            let lineCount: number = this.cpu0Frequency / 30
47            this.data.push(Math.abs(lineCount)) //在末尾填充一个元素
48          }
49          this.random = Math.random()
50        }
51      } else {
52        //暂停
53      }
54
55    }, 1000)
56  }
57
58  build() {
59    Stack({ alignContent: Alignment.Top }) {
60      FloatWindowComponent({ title: `sp_cpu0Frequency`, 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.cpu0Frequency + "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_cpu0Frequency")
76
77        }).align(Alignment.TopEnd)
78      }.height('20vp').width('100%')
79
80    }
81  }
82}