<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p343715244814"><aname="p343715244814"></a><aname="p343715244814"></a>Lists the hardware events supported by the performance monitoring unit (PMU).</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p84377213482"><aname="p84377213482"></a><aname="p84377213482"></a>Lists the cache events supported by the PMU.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p44372274819"><aname="p44372274819"></a><aname="p44372274819"></a>Lists the raw PMU events supported.</p>
| -c | Specifies the IDs of the CPUs to monitor. Use commas (,) to separate multiple CPU IDs, for example **0,1,2**. |
</th>
| -d <_sec_> | Specifies the monitoring period, in seconds. |
</tr>
| -i <_ms_> | Specifies the interval for printing the monitored events, in milliseconds. |
</thead>
| -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. |
| -g | Specifies a group of events to monitor. The events in the same group are monitored by the same PMU. |
</td>
| --no-inherit | Leaves the sub-threads of the target thread or process not monitored. |
<tdclass="cellrowborder"valign="top"width="50.06%"headers="mcps1.1.3.1.2 "><pid="p36451134216"><aname="p36451134216"></a><aname="p36451134216"></a>Collects the values of all threads and default performance counters of the system.</p>
| -p | Specifies the process IDs (PIDs) to monitor. |
</td>
| -t | Specifies the thread IDs (TIDs) to monitor. |
</tr>
| --verbose | Displays detailed report, including raw time data. |
<tdclass="cellrowborder"valign="top"width="50.06%"headers="mcps1.1.3.1.2 "><pid="p147074321111"><aname="p147074321111"></a><aname="p147074321111"></a>Specifies the IDs of the CPUs to monitor. Use commas (,) to separate multiple CPU IDs, for example <strongid="b88710447518"><aname="b88710447518"></a><aname="b88710447518"></a>0,1,2</strong>.</p>
<tdclass="cellrowborder"valign="top"width="50.06%"headers="mcps1.1.3.1.2 "><pid="p117073321117"><aname="p117073321117"></a><aname="p117073321117"></a>Specifies the monitoring period, in seconds.</p>
<tdclass="cellrowborder"valign="top"width="50.06%"headers="mcps1.1.3.1.2 "><pid="p13707173261112"><aname="p13707173261112"></a><aname="p13707173261112"></a>Specifies the interval for printing the monitored events, in milliseconds.</p>
<tdclass="cellrowborder"valign="top"width="50.06%"headers="mcps1.1.3.1.2 "><pid="p16443201119320"><aname="p16443201119320"></a><aname="p16443201119320"></a>Specifies the events to monitor. You can run the <strongid="b9161172815551"><aname="b9161172815551"></a><aname="b9161172815551"></a>list</strong> command to list all the events supported. <strongid="b111611225613"><aname="b111611225613"></a><aname="b111611225613"></a>event:u</strong> indicates an event in the user space, and <strongid="b2282748195610"><aname="b2282748195610"></a><aname="b2282748195610"></a>event:k</strong> indicates an event in the kernel space.</p>
<tdclass="cellrowborder"valign="top"width="50.06%"headers="mcps1.1.3.1.2 "><pid="p20870204817311"><aname="p20870204817311"></a><aname="p20870204817311"></a>Specifies a group of events to monitor. The events in the same group are monitored by the same PMU.</p>
<tdclass="cellrowborder"valign="top"width="50.06%"headers="mcps1.1.3.1.2 "><pid="p13323958634"><aname="p13323958634"></a><aname="p13323958634"></a>Leaves the sub-threads of the target thread or process not monitored.</p>
<tdclass="cellrowborder"valign="top"width="50.06%"headers="mcps1.1.3.1.2 "><pid="p1270803261116"><aname="p1270803261116"></a><aname="p1270803261116"></a>Specifies the process IDs (PIDs) to monitor.</p>
<tdclass="cellrowborder"valign="top"width="50.06%"headers="mcps1.1.3.1.2 "><pid="p47081632101118"><aname="p47081632101118"></a><aname="p47081632101118"></a>Specifies the thread IDs (TIDs) to monitor.</p>
<tdclass="cellrowborder"valign="top"width="50.06%"headers="mcps1.1.3.1.2 "><pid="p137083323111"><aname="p137083323111"></a><aname="p137083323111"></a>Displays detailed report, including raw time data.</p>
</td>
</tr>
</tbody>
</table>
### Example<a name="section1132495515502"></a>
### Example<a name="section1132495515502"></a>
...
@@ -163,35 +91,13 @@ Timeout exit (total 3009 ms)
...
@@ -163,35 +91,13 @@ Timeout exit (total 3009 ms)
### Field Description<a name="section1958985055118"></a>
### Field Description<a name="section1958985055118"></a>
| 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. |
</th>
| 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**. |
</tr>
| 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. |
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p47259563126"><aname="p47259563126"></a><aname="p47259563126"></a>Indicates the times that an event occurred.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p10725756151210"><aname="p10725756151210"></a><aname="p10725756151210"></a>Indicates the event name. You can run the <strongid="b1275144172219"><aname="b1275144172219"></a><aname="b1275144172219"></a>list</strong> command to list all the supported events. <strongid="b146319013236"><aname="b146319013236"></a><aname="b146319013236"></a>hw</strong> stands for hardware, and <strongid="b21781210132315"><aname="b21781210132315"></a><aname="b21781210132315"></a>sw</strong> stands for software.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p972514566125"><aname="p972514566125"></a><aname="p972514566125"></a>Provides values calculated from those in the <strongid="b3976203310251"><aname="b3976203310251"></a><aname="b3976203310251"></a>Count</strong> column for easy understanding. For example, the CPU frequency (<strongid="b17911439162616"><aname="b17911439162616"></a><aname="b17911439162616"></a>hw-cpu-cycles</strong>) is converted to <strongid="b415132419274"><aname="b415132419274"></a><aname="b415132419274"></a>0.832068</strong> GHz from <strongid="b1471832922712"><aname="b1471832922712"></a><aname="b1471832922712"></a>6994768</strong>.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p3725105621211"><aname="p3725105621211"></a><aname="p3725105621211"></a>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.</p>
| -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. |
</td>
| --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. |
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p835041795311"><aname="p835041795311"></a><aname="p835041795311"></a>Samples all processes and threads in the system.</p>
| -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. |
</td>
| -g | Specifies a group of events to monitor. The events in the same group are monitored by the same PMU. |
</tr>
| --no-inherit | Leaves the sub-threads of the target thread or process not monitored. |
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p2035071717539"><aname="p2035071717539"></a><aname="p2035071717539"></a>Leaves the hiperf process not sampled.</p>
| --offcpu | Monitors the CPU scheduling event, which is equivalent to the **--period 1 -e sched:sched_switch** event. |
</td>
| -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. |
</tr>
| -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**. |
| --delay-unwind | Delays the stack unwinding till the sampling is complete. |
</td>
| --disable-unwind | Disables stack unwinding. The user register and stack data is stored in **perf.data** for offline stack unwinding. |
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p8350117145310"><aname="p8350117145310"></a><aname="p8350117145310"></a>Specifies the IDs of the CPUs to sample.</p>
| --disable-callstack-expend | Disables the unwound call stack information from being combined or extended. |
</td>
| --clockid <_clock type_> | Sets the clock source for the sampling data. The options are **monotonic**, **boottime**, and **realtime**. |
</tr>
| --symbol-dir <_dir_> | Specifies the directory of the symbol table. The specified symbol table will be preferentially used in stack unwinding. |
| -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. |
</td>
| --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. |
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p0350171719531"><aname="p0350171719531"></a><aname="p0350171719531"></a>Specifies the maximum percentage of CPU resources occupied by the sampling.</p>
| --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. |
</td>
| -o <_output file name_> | Specifies the name of the sampling result file. It is **/data/local/tmp/perf.data** by default. |
| --verbose | Displays detailed log information during sampling. |
</td>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p73502017145313"><aname="p73502017145313"></a><aname="p73502017145313"></a>Specifies the sampling duration, in seconds.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p144811511083"><aname="p144811511083"></a><aname="p144811511083"></a>Specifies how often a sampling event is triggered. The default value is 4000 times/second.</p>
<pid="p1035001711532"><aname="p1035001711532"></a><aname="p1035001711532"></a>Note: A higher value indicates heavier CPU load but more sampling data.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p5350131725316"><aname="p5350131725316"></a><aname="p5350131725316"></a>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.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p20351171713531"><aname="p20351171713531"></a><aname="p20351171713531"></a>Specifies the events to monitor. You can run the <strongid="b176932255522"><aname="b176932255522"></a><aname="b176932255522"></a>list</strong> command to list all the events supported. <strongid="b2693625205220"><aname="b2693625205220"></a><aname="b2693625205220"></a>event:u</strong> indicates an event in the user space, and <strongid="b14693225145212"><aname="b14693225145212"></a><aname="b14693225145212"></a>event:k</strong> indicates an event in the kernel space.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p335181718535"><aname="p335181718535"></a><aname="p335181718535"></a>Specifies a group of events to monitor. The events in the same group are monitored by the same PMU.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p17351121712533"><aname="p17351121712533"></a><aname="p17351121712533"></a>Leaves the sub-threads of the target thread or process not monitored.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p535119176531"><aname="p535119176531"></a><aname="p535119176531"></a>Specifies the processes to monitor.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p1735111716534"><aname="p1735111716534"></a><aname="p1735111716534"></a>Specifies the threads to monitor.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p23511017135310"><aname="p23511017135310"></a><aname="p23511017135310"></a>Monitors the CPU scheduling event, which is equivalent to the <strongid="b83471327125516"><aname="b83471327125516"></a><aname="b83471327125516"></a>--period 1 -e sched:sched_switch</strong> event.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p15351217125317"><aname="p15351217125317"></a><aname="p15351217125317"></a>Monitors the branch prediction events. Branch prediction tries to predict the next instruction to be executed if there are multiple <strongid="b1515010251521"><aname="b1515010251521"></a><aname="b1515010251521"></a>if else</strong> conditions.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p14351111735316"><aname="p14351111735316"></a><aname="p14351111735316"></a>Sets the user stack unwinding mode, which can be <strongid="b99242538156"><aname="b99242538156"></a><aname="b99242538156"></a>fp</strong> or <strongid="b18703165914151"><aname="b18703165914151"></a><aname="b18703165914151"></a>dwarf</strong>. If <strongid="b293334361618"><aname="b293334361618"></a><aname="b293334361618"></a>dwarf</strong> is used, you can specify the size of the user stack to be sampled. The default value is <strongid="b162942143188"><aname="b162942143188"></a><aname="b162942143188"></a>65528</strong>.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p1135112171532"><aname="p1135112171532"></a><aname="p1135112171532"></a>Delays the stack unwinding till the sampling is complete.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p17351717115317"><aname="p17351717115317"></a><aname="p17351717115317"></a>Disables stack unwinding. The user register and stack data is stored in <strongid="b628502918229"><aname="b628502918229"></a><aname="b628502918229"></a>perf.data</strong> for offline stack unwinding.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p335171745314"><aname="p335171745314"></a><aname="p335171745314"></a>Disables the unwound call stack information from being combined or extended.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p7351717115312"><aname="p7351717115312"></a><aname="p7351717115312"></a>Sets the clock source for the sampling data. The options are <strongid="b11324454271"><aname="b11324454271"></a><aname="b11324454271"></a>monotonic</strong>, <strongid="b2095984822716"><aname="b2095984822716"></a><aname="b2095984822716"></a>boottime</strong>, and <strongid="b173918568274"><aname="b173918568274"></a><aname="b173918568274"></a>realtime</strong>.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p1351181716532"><aname="p1351181716532"></a><aname="p1351181716532"></a>Specifies the directory of the symbol table. The specified symbol table will be preferentially used in stack unwinding.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p33521617165316"><aname="p33521617165316"></a><aname="p33521617165316"></a>Specifies the cache size, in pages. The default value is <strongid="b1541914432911"><aname="b1541914432911"></a><aname="b1541914432911"></a>1024</strong>. The parameter value must be a power of <strongid="b1731417117306"><aname="b1731417117306"></a><aname="b1731417117306"></a>2</strong>. The value range is [2 - 1024].</p>
<pid="p18627133351018"><aname="p18627133351018"></a><aname="p18627133351018"></a>Note: A higher value indicates a lower event loss rate but higher memory usage.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p1035251755316"><aname="p1035251755316"></a><aname="p1035251755316"></a>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.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p135211718536"><aname="p135211718536"></a><aname="p135211718536"></a>Specifies the maximum size of the sampling result, in KB, MB, or GB. By default, there is no limit on the size.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p935241711539"><aname="p935241711539"></a><aname="p935241711539"></a>Specifies the name of the sampling result file. It is <strongid="b1714216402339"><aname="b1714216402339"></a><aname="b1714216402339"></a>/data/local/tmp/perf.data</strong> by default.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p10352117175319"><aname="p10352117175319"></a><aname="p10352117175319"></a>Saves the output file in .gzip format.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p63529178537"><aname="p63529178537"></a><aname="p63529178537"></a>Displays detailed log information during sampling.</p>
| --limit-percent <_number_> | Specifies the minimum percentage of the result to display. The result that is lower than the minimum percentage is not displayed. |
| --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. |
</thead>
| --proto | Converts the **perf.data** file into the proto format. The default file name is **perf.proto**. |
| --json | Converts the **perf.data** file into the JSON format. The default file name is **perf.json**. |
</td>
| --branch | Displays the report based on the branch prediction result address instead of the IP address of the call stack. |
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p174873421063"><aname="p174873421063"></a><aname="p174873421063"></a>Specifies the directory of the symbol table.</p>
| --<_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**. |
</td>
| --sort <_key1_>[,_key2_][,...] | Sorts and displays information based on specified keywords, such as **pid**, **tid**, and **comm**. Multiple keywords can be specified. |
</tr>
| -i <_filename_> | Specifies the sampling data (**perf.data** by default). |
| -o <_filename_> | Specifies the name of the report to output. |
</td>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p14487184216619"><aname="p14487184216619"></a><aname="p14487184216619"></a>Specifies the minimum percentage of the result to display. The result that is lower than the minimum percentage is not displayed.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p194879426610"><aname="p194879426610"></a><aname="p194879426610"></a>Specifies the minimum percentage of the call stack to display. The call stack that is lower than the minimum percentage is not displayed.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p174877426611"><aname="p174877426611"></a><aname="p174877426611"></a>Converts the <strongid="b7360121984613"><aname="b7360121984613"></a><aname="b7360121984613"></a>perf.data</strong> file into the proto format. The default file name is <strongid="b255114336468"><aname="b255114336468"></a><aname="b255114336468"></a>perf.proto</strong>.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p048720421068"><aname="p048720421068"></a><aname="p048720421068"></a>Converts the <strongid="b10736748154614"><aname="b10736748154614"></a><aname="b10736748154614"></a>perf.data</strong> file into the JSON format. The default file name is <strongid="b12526557144615"><aname="b12526557144615"></a><aname="b12526557144615"></a>perf.json</strong>.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p13487942561"><aname="p13487942561"></a><aname="p13487942561"></a>Displays the report based on the branch prediction result address instead of the IP address of the call stack.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p14871342165"><aname="p14871342165"></a><aname="p14871342165"></a>Filters and displays reports based on the given keywords. <strongid="b1718471815494"><aname="b1718471815494"></a><aname="b1718471815494"></a>keys</strong> can be <strongid="b652162620493"><aname="b652162620493"></a><aname="b652162620493"></a>comms</strong>, <strongid="b1926582944916"><aname="b1926582944916"></a><aname="b1926582944916"></a>pids</strong>, and <strongid="b12471434134911"><aname="b12471434134911"></a><aname="b12471434134911"></a>tids</strong>. For example, <strongid="b1794418482490"><aname="b1794418482490"></a><aname="b1794418482490"></a>--comms hiperf,hilog</strong> displays only the records whose process or thread name is <strongid="b195761830195014"><aname="b195761830195014"></a><aname="b195761830195014"></a>hiperf</strong> or <strongid="b2036334115014"><aname="b2036334115014"></a><aname="b2036334115014"></a>hilog</strong>.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p94870428610"><aname="p94870428610"></a><aname="p94870428610"></a>Sorts and displays information based on specified keywords, such as <strongid="b114664210512"><aname="b114664210512"></a><aname="b114664210512"></a>pid</strong>, <strongid="b319919248518"><aname="b319919248518"></a><aname="b319919248518"></a>tid</strong>, and <strongid="b1140053135118"><aname="b1140053135118"></a><aname="b1140053135118"></a>comm</strong>. Multiple keywords can be specified.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p948816422618"><aname="p948816422618"></a><aname="p948816422618"></a>Specifies the sampling data (<strongid="b165437587515"><aname="b165437587515"></a><aname="b165437587515"></a>perf.data</strong> by default).</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p74882421167"><aname="p74882421167"></a><aname="p74882421167"></a>Specifies the name of the report to output.</p>
@@ -8,9 +8,10 @@ USB devices are classified into two types: USB host and USB device. On OpenHarmo
...
@@ -8,9 +8,10 @@ USB devices are classified into two types: USB host and USB device. On OpenHarmo
**Figure 1** USB service architecture
**Figure 1** USB service architecture
![USB service architecture](figure/en-us_image_0000001267088285.png)
![USB service architecture](figure/en-us_image_0000001267088285.png)
The USB service architecture consists of three layers:
- USB API: a layer that provides JS APIs for the upper layer through NAPI.
- USB API: a layer that provides JS APIs for the upper layer through NAPI.
- USB Service: a layer implemented by using the C++ programming language and logically divided into the Host, Device, and Port modules. HDI-based APIs provided by USB Service are mainly used to implement management of USB device list, USB functions, USB ports, and USB device access permissions.
- USB service: a layer implemented by using the C++ programming language and logically divided into the Host, Device, and Port modules. HDI-based APIs provided by USB Service are mainly used to implement management of USB device list, USB functions, USB ports, and USB device access permissions.
- USB HAL: a layer implemented by using the C programming language. Based on the Host Driver Development Kit (SDK) and Device DDK, USB HAL encapsulates basic USB device operations, provides C++ APIs for the upper layer, and receives information from the kernel through the Hardware Driver Foundation (HDF) framework.
- USB HAL: a layer implemented by using the C programming language. Based on the Host Driver Development Kit (SDK) and Device DDK, USB HAL encapsulates basic USB device operations, provides C++ APIs for the upper layer, and receives information from the kernel through the Hardware Driver Foundation (HDF) framework.
## 1. Failure in running the KV store on the LiteOS Cortex-A kernel \(Hi3516 or Hi3518\) due to incorrect path setting for the KV store<a name="section2041345718513"></a>
## 1. Failed to run the KV store on the LiteOS Cortex-A kernel \(Hi3516 or Hi3518\) due to incorrect path setting for the KV store<a name="section2041345718513"></a>
**Problem**
**Symptom**
When the LiteOS Cortex-A kernel \(Hi3516 or Hi3518 platform\) directly calls the API provided by the KV store, the compiled executable program fails to run.
When the LiteOS Cortex-A kernel \(Hi3516 or Hi3518 platform\) directly calls the API provided by the KV store, the compiled executable program fails to run.
| int UtilsFileClose(int fd) | Closes a file with a specified file descriptor. |
</th>
| int UtilsFileRead(int fd, char *buf, unsigned int len) | Reads a specified length of data from a file with the specified file descriptor and writes the data into the buffer. |
</tr>
| int UtilsFileWrite(int fd, const char *buf, unsigned int len) | Writes a specified length of data into a file with the specified file descriptor. |
</thead>
| int UtilsFileDelete(const char *path) | Deletes a specified file. |
<tbody><trid="row671818445506"><tdclass="cellrowborder"valign="top"width="45.540000000000006%"headers="mcps1.2.3.1.1 "><pid="p871814441501"><aname="p871814441501"></a><aname="p871814441501"></a>int UtilsFileOpen(const char* path, int oflag, int mode)</p>
| int UtilsFileStat(const char *path, unsigned int *fileSize) | Obtains the file size. |
</td>
| int UtilsFileSeek(int fd, int offset, unsigned int whence) | Adjusts the read and write position offset in a file. |
<tdclass="cellrowborder"valign="top"width="54.459999999999994%"headers="mcps1.2.3.1.2 "><pid="p127181444165016"><aname="p127181444165016"></a><aname="p127181444165016"></a>Opens or creates a file.</p>
| int UtilsFileCopy(const char* src, const char* dest) | Copies the source file to a target file. |
</td>
| int UtilsFileMove(const char* src, const char* dest) | Moves the source file into a target file. |
<tdclass="cellrowborder"valign="top"width="54.459999999999994%"headers="mcps1.2.3.1.2 "><pid="p1071884416504"><aname="p1071884416504"></a><aname="p1071884416504"></a>Closes a file with a specified file descriptor.</p>
</td>
</tr>
<trid="row6718744105017"><tdclass="cellrowborder"valign="top"width="45.540000000000006%"headers="mcps1.2.3.1.1 "><pid="p137181644145015"><aname="p137181644145015"></a><aname="p137181644145015"></a>int UtilsFileRead(int fd, char *buf, unsigned int len)</p>
</td>
<tdclass="cellrowborder"valign="top"width="54.459999999999994%"headers="mcps1.2.3.1.2 "><pid="p1171854410509"><aname="p1171854410509"></a><aname="p1171854410509"></a>Reads a specified length of data from a file with the specified file descriptor and writes the data into the buffer.</p>
</td>
</tr>
<trid="row2071817440509"><tdclass="cellrowborder"valign="top"width="45.540000000000006%"headers="mcps1.2.3.1.1 "><pid="p17718144465012"><aname="p17718144465012"></a><aname="p17718144465012"></a>int UtilsFileWrite(int fd, const char *buf, unsigned int len)</p>
</td>
<tdclass="cellrowborder"valign="top"width="54.459999999999994%"headers="mcps1.2.3.1.2 "><pid="p67191444145012"><aname="p67191444145012"></a><aname="p67191444145012"></a>Writes a specified length of data into a file with the specified file descriptor.</p>
<tdclass="cellrowborder"valign="top"width="54.459999999999994%"headers="mcps1.2.3.1.2 "><pid="p2071919446507"><aname="p2071919446507"></a><aname="p2071919446507"></a>Deletes a specified file.</p>
</td>
</tr>
<trid="row1071964425013"><tdclass="cellrowborder"valign="top"width="45.540000000000006%"headers="mcps1.2.3.1.1 "><pid="p20719114405010"><aname="p20719114405010"></a><aname="p20719114405010"></a>int UtilsFileStat(const char *path, unsigned int *fileSize)</p>
</td>
<tdclass="cellrowborder"valign="top"width="54.459999999999994%"headers="mcps1.2.3.1.2 "><pid="p8719144435015"><aname="p8719144435015"></a><aname="p8719144435015"></a>Obtains the file size.</p>
</td>
</tr>
<trid="row2071924417504"><tdclass="cellrowborder"valign="top"width="45.540000000000006%"headers="mcps1.2.3.1.1 "><pid="p57193447501"><aname="p57193447501"></a><aname="p57193447501"></a>int UtilsFileSeek(int fd, int offset, unsigned int whence)</p>
</td>
<tdclass="cellrowborder"valign="top"width="54.459999999999994%"headers="mcps1.2.3.1.2 "><pid="p1071934495014"><aname="p1071934495014"></a><aname="p1071934495014"></a>Adjusts the read and write position offset in a file.</p>
<tdclass="cellrowborder"valign="top"width="54.459999999999994%"headers="mcps1.2.3.1.2 "><pid="p113501041155511"><aname="p113501041155511"></a><aname="p113501041155511"></a>Copies the source file to a target file.</p>
<tdclass="cellrowborder"valign="top"width="54.459999999999994%"headers="mcps1.2.3.1.2 "><pid="p921744595517"><aname="p921744595517"></a><aname="p921744595517"></a>Moves the source file into a target file.</p>
</td>
</tr>
</tbody>
</table>
Sample code for file operations:
Sample code for file operations:
...
@@ -92,30 +50,12 @@ printf("delete ret = %d\n", ret);
...
@@ -92,30 +50,12 @@ printf("delete ret = %d\n", ret);
| int UtilsSetValue(const char* key, const char* value) | Adds or updates the value matching a specified key in the file system or cache. |
</th>
| int UtilsDeleteValue(const char* key) | Deletes the value matching a specified key from the file system or cache. |
</tr>
</thead>
<tbody><trid="row34145016535"><tdclass="cellrowborder"valign="top"width="57.38999999999999%"headers="mcps1.2.3.1.1 "><pid="p980953910190"><aname="p980953910190"></a><aname="p980953910190"></a>int UtilsGetValue(const char* key, char* value, unsigned int len)</p>
</td>
<tdclass="cellrowborder"valign="top"width="42.61%"headers="mcps1.2.3.1.2 "><pid="p13562171015712"><aname="p13562171015712"></a><aname="p13562171015712"></a>Obtains the value matching a specified key from the file system or cache.</p>
<tdclass="cellrowborder"valign="top"width="42.61%"headers="mcps1.2.3.1.2 "><pid="p2431455765"><aname="p2431455765"></a><aname="p2431455765"></a>Adds or updates the value matching a specified key in the file system or cache.</p>
<tdclass="cellrowborder"valign="top"width="42.61%"headers="mcps1.2.3.1.2 "><pid="p126575774517"><aname="p126575774517"></a><aname="p126575774517"></a>Deletes the value matching a specified key from the file system or cache.</p>
</td>
</tr>
</tbody>
</table>
Sample code for the KV store:
Sample code for the KV store:
...
@@ -280,5 +220,3 @@ printf("UtilsDeleteValue delete ret = %d\n", ret);
...
@@ -280,5 +220,3 @@ printf("UtilsDeleteValue delete ret = %d\n", ret);
**Figure 2** Output of the system attribute dumping command for the LiteOS Cortex-A kernel<a name="fig2179718143018"></a>
**Figure 2** Output of the system attribute dumping command for the LiteOS Cortex-A kernel<a name="fig2179718143018"></a>
The Utils library stores common basic components of OpenHarmony. These basic components can be used by OpenHarmony service subsystems and upper-layer applications.
The Utils library stores basic OpenHarmony components that are commonly used by OpenHarmony service subsystems and upper-layer applications.
The Utils library provides the following capabilities on different platforms:
This library provides the following capabilities on different platforms:
LiteOS Cortex-M \(Hi3861 platform\): KV store, file operations, IoT peripheral control, and system attribute dumping
-LiteOS Cortex-M \(Hi3861 platform\): KV store, file operations, IoT peripheral control, and system attribute dumping
LiteOS Cortex-A \(Hi3516 or Hi3518 platform\): KV store, timer, JavaScript APIs for data and file storage, and system attribute dumping
-LiteOS Cortex-A \(Hi3516 or Hi3518 platform\): KV store, timer, JavaScript APIs for data and file storage, and system attribute dumping