1/* 2 * Copyright (c) 2021 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 hiperf from '@ohos.hiperf'; 17 18export default { 19 data: { 20 clickTimes: 0, 21 total: 20, 22 output: '', 23 sleepTicks: 0, 24 }, 25 26 onInit() { 27 this.output = this.clickTimes; 28 }, 29 30 sleep(delay) { 31 let start = (new Date()).getTime(); 32 while (((new Date()).getTime() - start) < delay) { 33 this.sleepTicks++; 34 } 35 }, 36 37 optionOnclick: function () { 38 const PERIOD_NUM = 100; 39 const STOP_TIME = 2; 40 const FREQ_NUM = 500; 41 const CPU_PERCENT = 25; 42 this.clickTimes++; 43 console.info('optionOnclick' + this.clickTimes); 44 let result; 45 this.output = ''; 46 47 result = hiperf.resetOption(); 48 this.output += ('ResetOption: ' + result + '\n'); 49 50 result = hiperf.setOutputFilename('/data/accounts/account_0/appdata/com.example.hiperfdemo/files/perf.data'); 51 this.output += ('SetOutputFilename: ' + result + '\n'); 52 53 result = hiperf.getOutputFileName(); 54 this.output += ('GetOutputFileName: ' + result + '\n'); 55 56 result = hiperf.setTargetSystemWide(true); 57 58 result = hiperf.setCompressData(true); 59 60 result = hiperf.setSelectCpus('1,2,3,4'); 61 62 result = hiperf.setTimeStopSec(STOP_TIME); 63 64 result = hiperf.setFrequency(FREQ_NUM); 65 66 result = hiperf.setPeriod(PERIOD_NUM); 67 68 result = hiperf.setSelectEvents('hw-cpu-cycles,hw-instructions'); 69 70 result = hiperf.setSelectGroups('hw-cpu-cycles,hw-instructions'); 71 72 result = hiperf.setNoInherit(true); 73 74 result = hiperf.setSelectPids('1,2,3'); 75 76 result = hiperf.setSelectTids('1,2,3'); 77 78 result = hiperf.setExcludePerf(true); 79 80 result = hiperf.setCpuPercent(CPU_PERCENT); 81 82 result = hiperf.setOffCPU(false); 83 84 result = hiperf.setCallGraph('dwarf'); 85 86 result = hiperf.setDelayUnwind(true); 87 88 result = hiperf.setDisableUnwind(true); 89 90 result = hiperf.setDisableCallstackMerge(true); 91 92 result = hiperf.setSymbolDir('/data/local/tmp'); 93 94 result = hiperf.setDataLimit('10M'); 95 96 result = hiperf.setAppPackage('com.example.hiperfdemo'); 97 98 result = hiperf.setClockId('monotonic'); 99 100 result = hiperf.setVecBranchSampleTypes('any_call'); 101 102 result = hiperf.setMmapPages(1024); 103 104 result = hiperf.getOptionVecString(); 105 this.output += ('GetOptionVecString: ' + result + '\n'); 106 107 result = hiperf.startWithOption(); 108 this.output += ('StartWithOption: ' + result + '\n'); 109 }, 110 111 recordOnclick: function () { 112 const SLEEP_TIME = 1000; 113 this.clickTimes++; 114 console.info('onclick recordOnclick' + this.clickTimes); 115 this.output = ('recordOnclick\n' + this.clickTimes + '\n'); 116 117 let result; 118 119 result = hiperf.setDebugMode(); 120 this.output += ('SetDebugMode: ' + result + '\n'); 121 if (!result) { 122 return; 123 } 124 125 result = hiperf.setup('/data/accounts/account_0/appdata/com.example.hiperfdemo/files'); 126 this.output += ('Setup: ' + result + '\n'); 127 if (!result) { 128 return; 129 } 130 131 result = hiperf.isReady(); 132 this.output += ('IsReady: ' + result + '\n'); 133 134 if (!result) { 135 return; 136 } 137 138 result = hiperf.getOutputPerfDataPath(); 139 this.output += ('GetOutputPerfDataPath: ' + result + '\n'); 140 141 result = hiperf.getCommandPath(); 142 this.output += ('GetCommandPath: ' + result + '\n'); 143 144 result = hiperf.start(); 145 this.output += ('Start: ' + result + '\n'); 146 if (!result) { 147 return; 148 } 149 this.sleep(SLEEP_TIME); 150 151 result = hiperf.pause(); 152 this.output += ('Pause: ' + result + '\n'); 153 if (!result) { 154 return; 155 } 156 this.sleep(SLEEP_TIME); 157 158 result = hiperf.resume(); 159 this.output += ('Resume: ' + result + '\n'); 160 if (!result) { 161 return; 162 } 163 this.sleep(SLEEP_TIME); 164 165 result = hiperf.stop(); 166 this.output += ('Stop: ' + result + '\n'); 167 }, 168 169 testOnclick: function () 170 { 171 this.clickTimes++; 172 console.info('onclick testOnclick' + this.clickTimes); 173 this.output = this.clickTimes; 174 } 175}