1a4e91f50Sopenharmony_ci# ByTrace<a name="EN-US_TOPIC_0000001102209942"></a> 2a4e91f50Sopenharmony_ci 3a4e91f50Sopenharmony_ci- [Introduction](#section152771918494) 4a4e91f50Sopenharmony_ci- [Architecture](#section6808195518497) 5a4e91f50Sopenharmony_ci- [Directory Structure](#section1610792125019) 6a4e91f50Sopenharmony_ci- [Usage](#section18684185975017) 7a4e91f50Sopenharmony_ci- [Repositories Involved](#section1849151125618) 8a4e91f50Sopenharmony_ci 9a4e91f50Sopenharmony_ci## Introduction<a name="section152771918494"></a> 10a4e91f50Sopenharmony_ci 11a4e91f50Sopenharmony_ciByTrace is a tool for you to trace processes and monitor performance. It encapsulates and extends the ftrace in the kernel and supports tracing in the user space. This tool provides APIs and commands: 12a4e91f50Sopenharmony_ci 13a4e91f50Sopenharmony_ci1. APIs: When developing an application, you can call ByTrace APIs in the application key code to perform tracing. 14a4e91f50Sopenharmony_ci2. Commands: You can enable the desired label to obtain the tracing information. With ByTrace, you can enable a user-space or kernel-space label you want to view (run the **bytrace -l** command to query all the supported labels) and run the corresponding commands to capture traces and dump them to a specified file. 15a4e91f50Sopenharmony_ci 16a4e91f50Sopenharmony_ci## Architecture<a name="section6808195518497"></a> 17a4e91f50Sopenharmony_ci 18a4e91f50Sopenharmony_ci 19a4e91f50Sopenharmony_ci 20a4e91f50Sopenharmony_ci## Directory Structure<a name="section1610792125019"></a> 21a4e91f50Sopenharmony_ci 22a4e91f50Sopenharmony_ci``` 23a4e91f50Sopenharmony_ci/developtools/bytrace 24a4e91f50Sopenharmony_ci├── bin # ByTrace code 25a4e91f50Sopenharmony_ci│ └── include # Header files 26a4e91f50Sopenharmony_ci│ └── src # Source files 27a4e91f50Sopenharmony_ci│ └── test # Test cases 28a4e91f50Sopenharmony_ci├── interfaces # APIs 29a4e91f50Sopenharmony_ci│ └── innerkits # Header files of internal subsystems 30a4e91f50Sopenharmony_ci│ └── kits # Header files exposed externally 31a4e91f50Sopenharmony_ci├── script # Scripts 32a4e91f50Sopenharmony_ci``` 33a4e91f50Sopenharmony_ci 34a4e91f50Sopenharmony_ci## Usage<a name="section18684185975017"></a> 35a4e91f50Sopenharmony_ci 36a4e91f50Sopenharmony_ciThe following table lists the commands supported by ByTrace. 37a4e91f50Sopenharmony_ci 38a4e91f50Sopenharmony_ci** Table 1** Commands supported by ByTrace 39a4e91f50Sopenharmony_ci 40a4e91f50Sopenharmony_ci| Option | Description | 41a4e91f50Sopenharmony_ci|---------|------------| 42a4e91f50Sopenharmony_ci| -h, --help | Views the help Information. | 43a4e91f50Sopenharmony_ci| -b n, --buffer_size n | Sets the size of the buffer (KB) for storing and reading traces. The default buffer size is 2048 KB. | 44a4e91f50Sopenharmony_ci| -t n, --time n | Sets the ByTrace uptime in seconds, which depends on the time required for analysis. | 45a4e91f50Sopenharmony_ci| --trace_clock clock | Sets the type of the clock for adding a timestamp to a trace, which can be boot (default), global, mono, uptime, or perf. | 46a4e91f50Sopenharmony_ci| --trace_begin | Starts trace. | 47a4e91f50Sopenharmony_ci| --trace_dump | Dumps traced data to a specified position (the default position is the console). | 48a4e91f50Sopenharmony_ci| --trace_finish | Stops capturing traces and dumps traced data to a specified position (the default position is the console). | 49a4e91f50Sopenharmony_ci| -l, --list_categories | Lists the ByTrace categories supported by the device. | 50a4e91f50Sopenharmony_ci| --overwrite | Sets the action to take when the buffer is full. If this option is used, the latest traced data is discarded. | 51a4e91f50Sopenharmony_ci| -o filename, --output filename | Outputs traced data to a specified file. | 52a4e91f50Sopenharmony_ci| -z | Compresses traced data. | 53a4e91f50Sopenharmony_ci 54a4e91f50Sopenharmony_ciThe following are some example ByTrace commands: 55a4e91f50Sopenharmony_ci 56a4e91f50Sopenharmony_ci- Run the following command to query supported labels: 57a4e91f50Sopenharmony_ci 58a4e91f50Sopenharmony_ci ``` 59a4e91f50Sopenharmony_ci bytrace -l 60a4e91f50Sopenharmony_ci ``` 61a4e91f50Sopenharmony_ci 62a4e91f50Sopenharmony_ci or 63a4e91f50Sopenharmony_ci 64a4e91f50Sopenharmony_ci ``` 65a4e91f50Sopenharmony_ci bytrace --list_categories 66a4e91f50Sopenharmony_ci ``` 67a4e91f50Sopenharmony_ci 68a4e91f50Sopenharmony_ci 69a4e91f50Sopenharmony_ci- Run the following command to capture traces whose label is <strong>ability</strong>, with the buffer size set to 4096 KB and ByTrace uptime set to 10s: 70a4e91f50Sopenharmony_ci 71a4e91f50Sopenharmony_ci ``` 72a4e91f50Sopenharmony_ci bytrace -b 4096 -t 10 --overwrite ability > /data/mytrace.ftrace 73a4e91f50Sopenharmony_ci ``` 74a4e91f50Sopenharmony_ci 75a4e91f50Sopenharmony_ci 76a4e91f50Sopenharmony_ci- Run the following command to set the clock type for traces to <strong>mono</strong>: 77a4e91f50Sopenharmony_ci 78a4e91f50Sopenharmony_ci ``` 79a4e91f50Sopenharmony_ci bytrace --trace_clock mono -b 4096 -t 10 --overwrite ability > /data/mytrace.ftrace 80a4e91f50Sopenharmony_ci ``` 81a4e91f50Sopenharmony_ci 82a4e91f50Sopenharmony_ci 83a4e91f50Sopenharmony_ci- Run the following command to compress the traced data: 84a4e91f50Sopenharmony_ci 85a4e91f50Sopenharmony_ci ``` 86a4e91f50Sopenharmony_ci bytrace -z -b 4096 -t 10 --overwrite ability > /data/mytrace.ftrace 87a4e91f50Sopenharmony_ci ``` 88a4e91f50Sopenharmony_ci 89a4e91f50Sopenharmony_ci 90a4e91f50Sopenharmony_ci## Repositories Involved<a name="section1849151125618"></a> 91a4e91f50Sopenharmony_ci 92a4e91f50Sopenharmony_ci[Development Tools Subsystem](https://gitee.com/openharmony/docs/blob/master/en/readme/development-toolchain.md) 93a4e91f50Sopenharmony_ci 94a4e91f50Sopenharmony_ci**developtools\_bytrace\_standard** 95