• 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 hidebug from '@ohos.hidebug'
17import DebugInfo from '../component/DebugInfo'
18
19@Entry
20@Component
21struct Index {
22  @State pssMemory: number = 0
23  @State sharedMemory: number = 0
24  @State privateMemory: number = 0
25  @State debugWindow: boolean = false
26
27  build() {
28    Column() {
29      Row() {
30        Text($r('app.string.MainAbility_label'))
31          .margin(4)
32          .fontSize(20)
33          .fontColor(Color.White)
34          .textAlign(TextAlign.Center)
35
36        Blank()
37
38        Image($r('app.media.debug'))
39          .key('btnDebug')
40          .width('10%')
41          .margin({ right: 4 })
42          .objectFit(ImageFit.Contain)
43          .onClick(() => {
44            this.debugWindow = !this.debugWindow
45            if (this.debugWindow) {
46              let pss = hidebug.getPss()
47              this.pssMemory = Number(pss !== null ? pss : -1) // -1代表getPss()接口返回值错误
48              let sharedDirty = hidebug.getSharedDirty()
49              this.sharedMemory = Number(sharedDirty !== null ? sharedDirty : -1) // -1代表getSharedDirty()接口返回值错误
50              let privateDirty = hidebug.getPrivateDirty()
51              this.privateMemory = Number(privateDirty !== null ? privateDirty : -1) // -1代表getPrivateDirty()接口返回值错误
52            }
53          })
54      }
55      .height('6%')
56      .width('100%')
57      .padding({ right: 10 })
58      .backgroundColor('#0D9FFB')
59      .constraintSize({ minHeight: 50 })
60
61      // 显示Debug信息窗口
62      DebugInfo({
63        pssMemory: this.pssMemory,
64        sharedMemory: this.sharedMemory,
65        debugWindow: this.debugWindow,
66        privateMemory: this.privateMemory
67      })
68    }
69    .width('100%')
70    .height('100%')
71  }
72}