1# hiperf<a name="EN-US_TOPIC_0000001186476620"></a> 2 3hiperf is a performance sampling and analysis tool provided for developers. It extends the user-mode capabilities based on the kernel perf mechanism and can conduct performance sampling of the specified application or the entire system. 4 5You can run the **hiperf -h** command to display the commands supported by hiperf. 6 7The following describes the common commands \(**list**, **stat**, **record**, and **report**\) supported by hiperf. 8 9## list<a name="section121805449461"></a> 10 11### Parameters<a name="section42124492494"></a> 12 13The **list** command lists all the perf events supported by the device. The event names are used for the **-e** and **-g** parameters of the **stat** and **record** commands. 14 15``` 16hiperf list [event type] 17``` 18 19| Parameter | Description | 20| ----------- | ---------------- | 21| hw | Lists the hardware events supported by the performance monitoring unit (PMU). | 22| sw | Lists the software events supported. | 23| tp | Lists the tracepotint events supported. | 24| cache | Lists the cache events supported by the PMU. | 25| raw | Lists the raw PMU events supported. | 26 27 28### Example<a name="section122129443486"></a> 29 30List the hardware events supported by the PMU. The command also lists the events that are not supported by the PMU. 31 32``` 33hiperf list hw 34event not support hw-stalled-cycles-backend 35event not support hw-stalled-cycles-frontend 36event not support hw-ref-cpu-cycles 37 38Supported events for hardware: 39 hw-cpu-cycles 40 hw-instructions 41 hw-cache-references 42 hw-cache-misses 43 hw-branch-instructions 44 hw-branch-misses 45 hw-bus-cycles 46``` 47 48## stat<a name="section12940163061016"></a> 49 50### Parameters<a name="section36541920145018"></a> 51 52The **stat** command monitors the specified application and periodically prints the values of performance counters. 53 54``` 55hiperf stat [options] 56 Collect performance counter information. 57``` 58 59| Parameter | Description | 60| ----------- | ---------------- | 61| -a | Collects the values of all threads and default performance counters of the system. | 62| -c | Specifies the IDs of the CPUs to monitor. Use commas (,) to separate multiple CPU IDs, for example **0,1,2**. | 63| -d <_sec_> | Specifies the monitoring period, in seconds. | 64| -i <_ms_> | Specifies the interval for printing the monitored events, in milliseconds. | 65| -e | Specifies the events to monitor. You can run the **list** command to list all the events supported. **event:u** indicates an event in the user space, and **event:k** indicates an event in the kernel space. | 66| -g | Specifies a group of events to monitor. The events in the same group are monitored by the same PMU. | 67| --no-inherit | Leaves the sub-threads of the target thread or process not monitored. | 68| -p | Specifies the process IDs (PIDs) to monitor. | 69| -t | Specifies the thread IDs (TIDs) to monitor. | 70| --verbose | Displays detailed report, including raw time data. | 71 72 73### Example<a name="section1132495515502"></a> 74 75Monitor the entire system for 3 seconds. 76 77``` 78hiperf stat -d 3 -a 79this is root mode, perfEventParanoid assume as -1 80Start Profiling... 81Timeout exit (total 3009 ms) 82 count name | comment | coverage 83 132523 hw-branch-instructions | 15.750 M/sec | (100%) 84 62554 hw-branch-misses | 47.202372% miss rate | (100%) 85 6994768 hw-cpu-cycles | 0.832068 GHz | (100%) 86 1237627 hw-instructions | 5.651758 cycles per instruction | (100%) 87 248 sw-context-switches | 29.959 K/sec | (100%) 88 0 sw-page-faults | 0.000 /sec | (100%) 89 9402580 sw-task-clock | 0.002758 cpus used | (100%) 90``` 91 92### Field Description<a name="section1958985055118"></a> 93 94| Field | Description | 95| ----------- | ---------------- | 96| count | Indicates the times that an event occurred. | 97| name | Indicates the event name. You can run the **list** command to list all the supported events. **hw** stands for hardware, and **sw** stands for software. | 98| comment | Provides values calculated from those in the **Count** column for easy understanding. For example, the CPU frequency (**hw-cpu-cycles**) is converted to **0.832068** GHz from **6994768**. | 99| coverage | Indicates the percentage of PMU resources occupied by the event. The number of events to be monitored by a PMU varies depending on the number of PMUs. | 100 101 102## record<a name="section168751927524"></a> 103 104### Parameters<a name="section113617912522"></a> 105 106The **record** command samples the specified application and saves the sampling data to a file \(**perf.data** by default\). 107 108``` 109hiperf record [options] 110 Collect performance sampling information. 111``` 112 113| Parameter | Description | 114| ----------- | ---------------- | 115| -a | Samples all processes and threads in the system. | 116| --exclude-hiperf | Leaves the hiperf process not sampled. | 117| -c | Specifies the IDs of the CPUs to sample. | 118| --cpu-limit <_percent_> | Specifies the maximum percentage of CPU resources occupied by the sampling. | 119| -d <sec> | Specifies the sampling duration, in seconds. | 120| -f <freq> | Specifies how often a sampling event is triggered. The default value is 4000 times/second. <br>Note: <br>A higher value indicates heavier CPU load but more sampling data. | 121| --period <_num_> | Specifies the number of occurrence times of an event that triggers a sampling. That is, a sampling is performed once when the event occurs the specified number of times. | 122| -e | Specifies the events to monitor. You can run the list command to list all the events supported. **event:u** indicates an event in the user space, and **event:k** indicates an event in the kernel space. | 123| -g | Specifies a group of events to monitor. The events in the same group are monitored by the same PMU. | 124| --no-inherit | Leaves the sub-threads of the target thread or process not monitored. | 125| -p | Specifies the processes to monitor. | 126| -t | Specifies the threads to monitor. | 127| --offcpu | Monitors the CPU scheduling event, which is equivalent to the **--period 1 -e sched:sched_switch** event. | 128| -j <_branch_filter1_>[,_branch_filter2_]... | Monitors the branch prediction events. Branch prediction tries to predict the next instruction to be executed if there are multiple if else conditions. | 129| -s / --call-stack <_fp \\| dwarf[,size]_> | Sets the user stack unwinding mode, which can be **fp** or **dwarf**. If **dwarf** is used, you can specify the size of the user stack to be sampled. The default value is **65528**. | 130| --delay-unwind | Delays the stack unwinding till the sampling is complete. | 131| --disable-unwind | Disables stack unwinding. The user register and stack data is stored in **perf.data** for offline stack unwinding. | 132| --disable-callstack-expend | Disables the unwound call stack information from being combined or extended. | 133| --clockid <_clock type_> | Sets the clock source for the sampling data. The options are **monotonic**, **boottime**, and **realtime**. | 134| --symbol-dir <_dir_> | Specifies the directory of the symbol table. The specified symbol table will be preferentially used in stack unwinding. | 135| -m <_mmap pages_> | Specifies the cache size, in pages. The default value is **1024**. The parameter value must be a power of 2. The value range is [2 - 1024].<br>Note: <br>A higher value indicates a lower event loss rate but higher memory usage. | 136| --app <_package name_> | Specifies the bundle name of the target application to be sampled. The default timeout interval is 10 seconds. If the specified application does not exist, the hiperf process exits after 10 seconds. | 137| --data-limit <_SIZE[K\|M\|G]_> | Specifies the maximum size of the sampling result, in KB, MB, or GB. By default, there is no limit on the size. | 138| -o <_output file name_> | Specifies the name of the sampling result file. It is **/data/local/tmp/perf.data** by default. | 139| -z | Saves the output file in .gzip format. | 140| --verbose | Displays detailed log information during sampling. | 141 142 143### Example<a name="section15998181516549"></a> 144 145- Sample all processes in the system for 3 seconds and display detailed log information during the sampling process. 146 147 ``` 148 hiperf record -d 3 -a --verbose 149 ``` 150 151 152- Enable stack unwinding in fp mode. 153 154 ``` 155 hiperf record -s fp -d 3 -a 156 ``` 157 158- Enable stack unwinding in dwarf mode. 159 160 ``` 161 hiperf record -s dwarf -d 3 -a 162 ``` 163 164- Sample offcpu events. 165 166 ``` 167 hiperf record --offcpu -s dwarf -d 3 -a 168 ``` 169 170- Delay stack unwinding. 171 172 ``` 173 hiperf record -d 3 -s dwarf --delay-unwind -a 174 ``` 175 176- Disable stack unwinding. In this case, the stack data is saved to the **perf.data** file. 177 178 ``` 179 hiperf record -d 3 -s dwarf --disable-unwind -a 180 ``` 181 182- Monitor the **com.ohos.launch** application. The hiperf process exits after 10 seconds if the process corresponding to the specified bundle name does not exist. 183 184 ``` 185 hiperf record -d 3 -s dwarf --app com.ohos.launch 186 ``` 187 188- Compress the sampling results. 189 190 ``` 191 hiperf record -z -s dwarf -d 3 -a 192 ``` 193 194 195## report<a name="section16327635174818"></a> 196 197The **report** command displays the sampling data that is captured by using **record**. 198 199``` 200hiperf report [option] 201 Report sampling information from perf.data. 202``` 203 204| Parameter | Description | 205| ----------- | ---------------- | 206| --symbol-dir <_dir_> | Specifies the directory of the symbol table. | 207| --limit-percent <_number_> | Specifies the minimum percentage of the result to display. The result that is lower than the minimum percentage is not displayed. | 208| -s / --call-stack | Displays detailed call stack information. | 209| --call-stack-limit-percent <_number_> | Specifies the minimum percentage of the call stack to display. The call stack that is lower than the minimum percentage is not displayed. | 210| --proto | Converts the **perf.data** file into the proto format. The default file name is **perf.proto**. | 211| --json | Converts the **perf.data** file into the JSON format. The default file name is **perf.json**. | 212| --branch | Displays the report based on the branch prediction result address instead of the IP address of the call stack. | 213| --<_keys_> <_keyname1_>[,_keyname2_][,...] | Filters and displays reports based on the given keywords. keys can be comms, pids, and tids. For example, **--comms hiperf,hilog** displays only the records whose process or thread name is **hiperf** or **hilog**. | 214| --sort <_key1_>[,_key2_][,...] | Sorts and displays information based on specified keywords, such as **pid**, **tid**, and **comm**. Multiple keywords can be specified. | 215| -i <_filename_> | Specifies the sampling data (**perf.data** by default). | 216| -o <_filename_> | Specifies the name of the report to output. | 217 218 219## Example<a name="section1197655116513"></a> 220 221- Output the report of the sampling data \(**perf.data** by default\). 222 223 ``` 224 hiperf report 225 ``` 226 227 Output \(example\): 228 229 ``` 230 Heating count comm pid tid dso func 231 5.68% 15073949 hiperf_example_ 1085 1091 /system/lib/ld-musl-arm.so.1 malloc 232 2.57% 6834119 hiperf_example_ 1085 1091 [kernel.kallsyms] vector_swi 233 2.27% 6013910 hiperf_example_ 1085 1087 /system/lib/ld-musl-arm.so.1 malloc 234 2.19% 5805738 hiperf_example_ 1085 1091 /system/lib/ld-musl-arm.so.1 vfprintf 235 2.09% 5543362 hiperf_example_ 1085 1091 [kernel.kallsyms] ktime_get_ts64 236 report done 237 ``` 238 239- Output the call stack report of the sampling data. 240 241 ``` 242 hiperf report -s 243 ``` 244 245- Set the symbol table directory. 246 247 ``` 248 hiperf report -s --symbol-dir /data/local/tmp 249 ``` 250 251- Display only the information containing **libutils.z.so**. 252 253 ``` 254 hiperf report --dsos libuitls.z.so 255 ``` 256 257- Sort the result by **dso**. 258 259 ``` 260 hiperf report --sort dso 261 ``` 262