• Home
Name Date Size #Lines LOC

..--

bin/12-May-2024-2,5632,153

figures/12-May-2024-

interfaces/12-May-2024-570329

script/12-May-2024-159129

.gitattributesD12-May-2024631 1615

LICENSED12-May-20249.9 KiB179150

OAT.xmlD12-May-20244 KiB6510

README.mdD12-May-20248.5 KiB146115

README_zh.mdD12-May-20248.1 KiB149116

bundle.jsonD12-May-20241.4 KiB5756

bytrace.gniD12-May-2024743 1915

README.md

1# ByTrace<a name="EN-US_TOPIC_0000001102209942"></a>
2
3-   [Introduction](#section152771918494)
4-   [Architecture](#section6808195518497)
5-   [Directory Structure](#section1610792125019)
6-   [Usage](#section18684185975017)
7-   [Repositories Involved](#section1849151125618)
8
9## Introduction<a name="section152771918494"></a>
10
11ByTrace 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:
12
131.  APIs: When developing an application, you can call ByTrace APIs in the application key code to perform tracing.
142.  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.
15
16## Architecture<a name="section6808195518497"></a>
17
18![](figures/architecture.png)
19
20## Directory Structure<a name="section1610792125019"></a>
21
22```
23/developtools/bytrace_standard
24├── bin           # ByTrace code
25│   └── include   # Header files
26│   └── src       # Source files
27│   └── test      # Test cases
28├── interfaces    # APIs
29│   └── innerkits # Header files of internal subsystems
30│   └── kits      # Header files exposed externally
31├── script        # Scripts
32```
33
34## Usage<a name="section18684185975017"></a>
35
36The following table lists the commands supported by ByTrace.
37
38** Table 1** Commands supported by ByTrace
39
40<a name="table16802195914247"></a>
41<table><thead align="left"><tr id="row14804759142412"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p1280465972411"><a name="p1280465972411"></a><a name="p1280465972411"></a>Option</p>
42</th>
43<th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.2"><p id="p380414595249"><a name="p380414595249"></a><a name="p380414595249"></a>Description</p>
44</th>
45</tr>
46</thead>
47<tbody><tr id="row1714512123414"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1915412133419"><a name="p1915412133419"></a><a name="p1915412133419"></a>-h, --help</p>
48</td>
49<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p6156126341"><a name="p6156126341"></a><a name="p6156126341"></a>Views the help Information.</p>
50</td>
51</tr>
52<tr id="row13804135982416"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p18051959152410"><a name="p18051959152410"></a><a name="p18051959152410"></a>-b <em id="i35979186184"><a name="i35979186184"></a><a name="i35979186184"></a>n</em>, --buffer_size <em id="i144491624181811"><a name="i144491624181811"></a><a name="i144491624181811"></a>n</em></p>
53</td>
54<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p0805165932419"><a name="p0805165932419"></a><a name="p0805165932419"></a>Sets the size of the buffer (KB) for storing and reading traces. The default buffer size is 2048 KB.</p>
55</td>
56</tr>
57<tr id="row580519592245"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p880510591241"><a name="p880510591241"></a><a name="p880510591241"></a>-t <em id="i8668143912203"><a name="i8668143912203"></a><a name="i8668143912203"></a>n</em>, --time <em id="i841433614202"><a name="i841433614202"></a><a name="i841433614202"></a>n</em></p>
58</td>
59<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p1480517591245"><a name="p1480517591245"></a><a name="p1480517591245"></a>Sets the ByTrace uptime in seconds, which depends on the time required for analysis.</p>
60</td>
61</tr>
62<tr id="row4806175913247"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p980655912242"><a name="p980655912242"></a><a name="p980655912242"></a>--trace_clock <em id="i19464452217"><a name="i19464452217"></a><a name="i19464452217"></a>clock</em></p>
63</td>
64<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p11806959142416"><a name="p11806959142416"></a><a name="p11806959142416"></a>Sets the type of the clock for adding a timestamp to a trace, which can be <strong>boot</strong> (default), <strong>global</strong>, <strong>mono</strong>, <strong>uptime</strong>, or <strong>perf</strong>.</p>
65</td>
66</tr>
67<tr id="row1280635917242"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p180715591244"><a name="p180715591244"></a><a name="p180715591244"></a>--trace_begin</p>
68</td>
69<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p480795916243"><a name="p480795916243"></a><a name="p480795916243"></a>Starts trace.</p>
70</td>
71</tr>
72<tr id="row1580717599245"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p38073598242"><a name="p38073598242"></a><a name="p38073598242"></a>--trace_dump</p>
73</td>
74<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p148077595245"><a name="p148077595245"></a><a name="p148077595245"></a>Dumps traced data to a specified position (the default position is the console).</p>
75</td>
76</tr>
77<tr id="row180811592242"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p11808165922419"><a name="p11808165922419"></a><a name="p11808165922419"></a>--trace_finish</p>
78</td>
79<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p18809559182420"><a name="p18809559182420"></a><a name="p18809559182420"></a>Stops capturing traces and dumps traced data to a specified position (the default position is the console).</p>
80</td>
81</tr>
82<tr id="row2809185972420"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p2080925922418"><a name="p2080925922418"></a><a name="p2080925922418"></a>-l, --list_categories</p>
83</td>
84<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p38091159142414"><a name="p38091159142414"></a><a name="p38091159142414"></a>Lists the ByTrace categories supported by the device.</p>
85</td>
86</tr>
87<tr id="row1880912598248"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1681014595244"><a name="p1681014595244"></a><a name="p1681014595244"></a>--overwrite</p>
88</td>
89<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p12810165914248"><a name="p12810165914248"></a><a name="p12810165914248"></a>Sets the action to take when the buffer is full. If this option is used, the latest traced data is discarded.</p>
90</td>
91</tr>
92<tr id="row1181015992414"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p168101859152415"><a name="p168101859152415"></a><a name="p168101859152415"></a>-o <em id="i1367232742113"><a name="i1367232742113"></a><a name="i1367232742113"></a>filename</em>, --output <em id="i4305133012219"><a name="i4305133012219"></a><a name="i4305133012219"></a>filename</em></p>
93</td>
94<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p9810559132410"><a name="p9810559132410"></a><a name="p9810559132410"></a>Outputs traced data to a specified file.</p>
95</td>
96</tr>
97<tr id="row8810155982415"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p381145912410"><a name="p381145912410"></a><a name="p381145912410"></a>-z</p>
98</td>
99<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p1281117592249"><a name="p1281117592249"></a><a name="p1281117592249"></a>Compresses traced data.</p>
100</td>
101</tr>
102</tbody>
103</table>
104
105The following are some example ByTrace commands:
106
107-   Run the following command to query supported labels:
108
109    ```
110    bytrace -l
111    ```
112
113    or
114
115    ```
116    bytrace --list_categories
117    ```
118
119
120-   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:
121
122    ```
123    bytrace -b 4096 -t 10 --overwrite ability > /data/mytrace.ftrace
124    ```
125
126
127-   Run the following command to set the clock type for traces to <strong>mono</strong>:
128
129    ```
130    bytrace --trace_clock mono  -b 4096 -t 10 --overwrite ability > /data/mytrace.ftrace
131    ```
132
133
134-   Run the following command to compress the traced data:
135
136    ```
137    bytrace -z  -b 4096 -t 10 --overwrite ability > /data/mytrace.ftrace
138    ```
139
140
141## Repositories Involved<a name="section1849151125618"></a>
142
143Development Tools Subsystem
144
145**developtools\_bytrace\_standard**
146

README_zh.md

1# bytrace组件<a name="ZH-CN_TOPIC_0000001102209942"></a>
2
3-   [简介](#section152771918494)
4-   [架构图](#section6808195518497)
5-   [目录](#section1610792125019)
6-   [说明](#section18684185975017)
7-   [相关仓](#section1849151125618)
8
9## 简介<a name="section152771918494"></a>
10
11bytrace是开发人员用于追踪进程轨迹、查看性能的一种工具,主要对内核ftrace进行了封装和扩展,来支持用户态的打点。该工具主要分为两部分,API和命令行:
12
131.  bytrace向应用开发人员暴露了打点的API,开发应用过程中可以在关键代码处调用对应API进行打点;
142.  命令行部分通过使能对应的label,来获取打点信息。通过该工具可以打开想要查看的用户态和内核label(通过命令行“bytrace -l”,查看支持的所有label),然后通过命令行进行抓取trace信息到指定文件中,下文有具体使用指导。
15
16## 架构图<a name="section6808195518497"></a>
17
18![](figures/architecture_zh.png)
19
20## 目录<a name="section1610792125019"></a>
21
22```
23/developtools/bytrace_standard
24├── bin           # bytrace组件代码目录
25│   └── include   # 头文件目录
26│   └── src       # 源文件目录
27│   └── test      # 测试用例目录
28├── interfaces    # 对外接口存放目录
29│   └── innerkits # 对内部子系统暴露的头文件存放目录
30│   └── kits      # 对外部暴露的头文件存放目录
31├── script        # 脚本目录
32```
33
34## 说明<a name="section18684185975017"></a>
35
36使用说明
37
38bytrace当前支持如下命令:
39
40**表 1**  命令行列表
41
42<a name="table16802195914247"></a>
43<table><thead align="left"><tr id="row14804759142412"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p1280465972411"><a name="p1280465972411"></a><a name="p1280465972411"></a>Option</p>
44</th>
45<th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.2"><p id="p380414595249"><a name="p380414595249"></a><a name="p380414595249"></a>Description</p>
46</th>
47</tr>
48</thead>
49<tbody><tr id="row1714512123414"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1915412133419"><a name="p1915412133419"></a><a name="p1915412133419"></a>-h,--help</p>
50</td>
51<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p6156126341"><a name="p6156126341"></a><a name="p6156126341"></a>查看option帮助</p>
52</td>
53</tr>
54<tr id="row13804135982416"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p18051959152410"><a name="p18051959152410"></a><a name="p18051959152410"></a>-b <em id="i35979186184"><a name="i35979186184"></a><a name="i35979186184"></a>n</em>,--buffer_size <em id="i144491624181811"><a name="i144491624181811"></a><a name="i144491624181811"></a>n</em></p>
55</td>
56<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p0805165932419"><a name="p0805165932419"></a><a name="p0805165932419"></a>指定<em id="i134241333181817"><a name="i134241333181817"></a><a name="i134241333181817"></a>n</em>(KB)内存大小用于存取trace日志,默认2048KB</p>
57</td>
58</tr>
59<tr id="row580519592245"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p880510591241"><a name="p880510591241"></a><a name="p880510591241"></a>-t <em id="i8668143912203"><a name="i8668143912203"></a><a name="i8668143912203"></a>n</em>,--time <em id="i841433614202"><a name="i841433614202"></a><a name="i841433614202"></a>n</em></p>
60</td>
61<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p1480517591245"><a name="p1480517591245"></a><a name="p1480517591245"></a>用来指定trace运行的时间(单位:s),取决于需要分析过程的时间</p>
62</td>
63</tr>
64<tr id="row4806175913247"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p980655912242"><a name="p980655912242"></a><a name="p980655912242"></a>--trace_clock <em id="i19464452217"><a name="i19464452217"></a><a name="i19464452217"></a>clock</em></p>
65</td>
66<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p11806959142416"><a name="p11806959142416"></a><a name="p11806959142416"></a>trace输出的时钟类型,一般设备支持boot、global、mono、uptime、perf等,默认为boot</p>
67</td>
68</tr>
69<tr id="row1280635917242"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p180715591244"><a name="p180715591244"></a><a name="p180715591244"></a>--trace_begin</p>
70</td>
71<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p480795916243"><a name="p480795916243"></a><a name="p480795916243"></a>启动抓trace</p>
72</td>
73</tr>
74<tr id="row1580717599245"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p38073598242"><a name="p38073598242"></a><a name="p38073598242"></a>--trace_dump</p>
75</td>
76<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p148077595245"><a name="p148077595245"></a><a name="p148077595245"></a>将数据输出到指定位置(默认控制台)</p>
77</td>
78</tr>
79<tr id="row180811592242"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p11808165922419"><a name="p11808165922419"></a><a name="p11808165922419"></a>--trace_finish</p>
80</td>
81<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p18809559182420"><a name="p18809559182420"></a><a name="p18809559182420"></a>停止抓trace,并将数据输出到指定位置(默认控制台)</p>
82</td>
83</tr>
84<tr id="row2809185972420"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p2080925922418"><a name="p2080925922418"></a><a name="p2080925922418"></a>-l,--list_categories</p>
85</td>
86<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p38091159142414"><a name="p38091159142414"></a><a name="p38091159142414"></a>输出手机能支持的trace模块</p>
87</td>
88</tr>
89<tr id="row1880912598248"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1681014595244"><a name="p1681014595244"></a><a name="p1681014595244"></a>--overwrite</p>
90</td>
91<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p12810165914248"><a name="p12810165914248"></a><a name="p12810165914248"></a>当缓冲区满的时候,将丢弃最新的信息。(默认丢弃最老的日志)</p>
92</td>
93</tr>
94<tr id="row1181015992414"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p168101859152415"><a name="p168101859152415"></a><a name="p168101859152415"></a>-o <em id="i1367232742113"><a name="i1367232742113"></a><a name="i1367232742113"></a>filename</em>,--output <em id="i4305133012219"><a name="i4305133012219"></a><a name="i4305133012219"></a>filename</em></p>
95</td>
96<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p9810559132410"><a name="p9810559132410"></a><a name="p9810559132410"></a>指定输出的目标文件名称</p>
97</td>
98</tr>
99<tr id="row8810155982415"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p381145912410"><a name="p381145912410"></a><a name="p381145912410"></a>-z</p>
100</td>
101<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p1281117592249"><a name="p1281117592249"></a><a name="p1281117592249"></a>抓取trace后进行压缩</p>
102</td>
103</tr>
104</tbody>
105</table>
106
107以下是常用bytrace命令示例,供开发者参考:
108
109-   查询支持的label。
110
111    ```
112    bytrace -l
113    ```
114
115    或者
116
117    ```
118    bytrace --list_categories
119    ```
120
121
122-   设置4M缓存,抓取10秒,抓取label为ability的trace信息。
123
124    ```
125    bytrace -b 4096 -t 10 --overwrite ability > /data/mytrace.ftrace
126    ```
127
128
129-   设置trace的输出时钟为mono。
130
131    ```
132    bytrace --trace_clock mono  -b 4096 -t 10 --overwrite ability > /data/mytrace.ftrace
133    ```
134
135
136-   抓取trace后进行压缩。
137
138    ```
139    bytrace -z  -b 4096 -t 10 --overwrite ability > /data/mytrace.ftrace
140    ```
141
142
143## 相关仓<a name="section1849151125618"></a>
144
145研发工具链子系统
146
147**developtools\_bytrace\_standard**
148
149