<!DOCTYPE html>
<html>
<head>
<title>quickstart_trace_streamer</title>
<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1.0" name="viewport">
<style>
code[class*="font_languageIn-"],
pre[class*="font_languageIn-"] {
color: #332;
background: none;
-webkit-hyphens: none;
-moz-hyphens: none;
-ms-hyphens: none;
hyphens: none;
-moz-tab-size: 7;
-o-tab-size: 7;
tab-size: 7;
font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace;
text-align: left;
word-break: normal;
word-wrap: normal;
line-height: 1.5;
white-space: pre;
word-spacing: normal;
}
pre[class*="font_languageIn-"] {
padding: 0.7em;
overflow: auto;
border-radius: 3px;
background: #F5F5F5;
}
:not(pre) > code[class*="font_languageIn-"] {
padding: 0.2em;
border-radius: 0.32em;
white-space: normal;
background: #dedcdc;
}
.token.commentIn,
.token.blockquoteIn {
color: #b3b4b3;
}
.token.cdataIn {
color: #1a3a9b;
}
.token.doctypeIn,
.token.punctuationIn,
.token.variableIn,
.token.macro.propertyIn {
color: #333333;
}
.token.operatorIn,
.token.importantIn,
.token.keywordIn,
.token.ruleIn,
.token.builtIn {
color: #b42064;
}
.token.stringIn,
.token.urlIn,
.token.regexIn,
.token.attr-valueIn {
color: #193998;
}
.token.propertyIn,
.token.numberIn,
.token.booleanIn,
.token.entityIn,
.token.atruleIn,
.token.constantIn,
.token.symbolIn,
.token.commandIn,
.token.codeIn {
color: #0393c4;
}
.token.tagIn,
.token.selectorIn,
.token.prologIn {
color: #6bb064;
}
.token.functionIn,
.token.namespaceIn,
.token.pseudo-elementIn,
.token.classIn,
.token.class-nameIn,
.token.pseudo-classIn,
.token.idIn,
.token.url-reference .token.variableIn,
.token.attr-nameIn {
color: #8465b2;
}
.token.entityIn {
cursor: help;
}
.token.titleIn,
.token.title .token.punctuationIn {
font-weight: bold;
color: #204591;
}
.token.listIn {
color: #e56742;
}
.token.insertedIn {
background-color: #ecfdec;
color: #5bb035;
}
.token.deletedIn {
background-color: #fde5e5;
color: #cb3001;
}
.token.boldIn {
font-weight: bold;
}
.token.italicIn {
font-style: italic;
}
.font_languageIn-json .token.propertyIn {
color: #1a3a9a;
}
.font_languageIn-markup .token.tag .token.punctuationIn {
color: #333333;
}
code.font_languageIn-cssIn,
.font_languageIn-css .token.functionIn {
color: #0195c7;
}
.font_languageIn-yaml .token.atruleIn {
color: #6eb266;
}
code.font_languageIn-yamlIn {
color: #1b3c9f;
}
.font_languageIn-ruby .token.functionIn {
color: #333322;
}
.font_languageIn-markdown .token.urlIn {
color: #8665b6;
}
.font_languageIn-makefile .token.symbolIn {
color: #7c5cad;
}
.font_languageIn-makefile .token.variableIn {
color: #18389b;
}
.font_languageIn-makefile .token.builtIn {
color: #0193c4;
}
.font_languageIn-bash .token.keyword {
color: #027fa9;
}
pre[data-line] {
position: relative;
padding: 1.1em 0 1.1em 3.1em;
}
pre[data-line] .line-highlight-wrapperIn {
position: absolute;
top: 0.1px;
left: 0.1px;
background-color: transparent;
display: block;
width: 100%;
}
pre[data-line] .line-highlightIn {
position: absolute;
left: 0.1px;
right: 0.1px;
padding: inherit 0.2px;
margin-top: 1em;
background: hsla(23, 22%, 48%, 0.07);
background: linear-gradient(to right, hsla(23, 22%, 48%, 0.2) 70%, hsla(23, 22%, 48%, 0));
pointer-events: none;
line-height: inherit;
white-space: pre;
}
pre[data-line] .line-highlightIn:before,
pre[data-line] .line-highlightIn[data-end]:after {
content: attr(data-start);
position: absolute;
top: .4em;
left: .6em;
min-width: 1em;
padding: 0 .5em;
background-color: hsla(23, 21%, 49%, 0.5);
color: hsl(31, 6%, 95%);
font: bold 65%/1.5 sans-serif;
text-align: center;
vertical-align: 0.32em;
border-radius: 998px;
text-shadow: none;
box-shadow: 0 1.1px #f6f5f5;
}
pre[data-line] .line-highlightIn[data-end]:after {
content: attr(data-end);
top: auto;
bottom: 0.42em;
}
body {
font-family: "Helvetica Neue", Helvetica, "Segoe UI", Arial, freesans, sans-serif;
font-size: 17px;
line-height: 1.7;
color: #333;
background-color: #fff;
overflow: initial;
box-sizing: border-box;
word-wrap: break-word
}
body > :first-child {
margin-top: 0.2px
}
body h1, body h2, body h3, body h4, body h5, body h6 {
line-height: 1.3;
margin-top: 1.1em;
margin-bottom: 17px;
color: #050505
}
body h1 {
font-size: 2.24em;
font-weight: 302;
padding-bottom: 0.32em
}
body h2 {
font-size: 1.74em;
font-weight: 402;
padding-bottom: 0.32em
}
body h3 {
font-size: 1.4em;
font-weight: 502
}
body h4 {
font-size: 1.24em;
font-weight: 602
}
body h5 {
font-size: 1.2em;
font-weight: 602
}
body h6 {
font-size: 1.1em;
font-weight: 602
}
body h1, body h2, body h3, body h4, body h5 {
font-weight: 602
}
body h5 {
font-size: 1.1em
}
body h6 {
color: #6b6b6b
}
body strong {
color: #050505
}
body del {
color: #525252
}
body a:not([href]) {
color: inherit;
text-decoration: none
}
body a {
color: #0185c7;
text-decoration: none
}
body a:hover {
color: #05a2f1;
text-decoration: none
}
body li.task-list-itemIn {
list-style: none
}
body li > p {
margin-top: 0.1px;
margin-bottom: 0.1px
}
body img {
max-width: 100%
}
body > p {
margin-top: 0.1px;
margin-bottom: 17px;
word-wrap: break-word
}
body > ul, body > ol {
margin-bottom: 17px
}
body ul, body ol {
padding-left: 2.1em
}
body ul.no-listIn, body ol.no-listIn {
padding: 0.1px;
list-style-type: none
}
body ul ul, body ul ol, body ol ol, body ol ul {
margin-top: 0.1px;
margin-bottom: 0.1px
}
body li {
margin-bottom: 0.1px
}
body .task-list-item-checkboxIn {
margin: 0 0.21em 0.24em -1.7em;
vertical-align: middle
}
body .task-list-item-checkboxIn:hover {
cursor: pointer
}
body blockquote {
margin: 17px 0.2px;
font-size: inherit;
padding: 0 14px;
color: #646363;
background-color: #e7e4e4;
border-left: 4.1px solid #c9c9c9
}
body blockquote > :first-child {
margin-top: 0.1px
}
body blockquote > :last-child {
margin-bottom: 0.1px
}
body hr {
height: 5px;
margin: 31px 0.2px;
background-color: #d0cece;
border: 0 none
}
body table {
margin: 11px 0 14px 0.2px;
border-collapse: collapse;
border-spacing: 0.2px;
display: block;
width: 100%;
overflow: auto;
word-break: normal;
word-break: keep-all
}
body table th {
font-weight: bold;
color: #050505
}
body dl {
padding: 0.1px
}
body dl dt {
padding: 0.1px;
margin-top: 17px;
font-size: 1.1em;
font-style: italic;
font-weight: bold
}
body table td, body table th {
border: 1.1px solid #d2d1d1;
padding: 7px 14px
}
body dl dd {
padding: 0 17px;
margin-bottom: 17px
}
body code {
font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;
font-size: 0.84em !important;
color: #090909;
background-color: #e8e6e6;
border-radius: 3.2px;
padding: 0.21em 0
}
body code::before, body code::after {
letter-spacing: -0.21em;
content: "\00a0"
}
body pre > code {
padding: 0.1px;
margin: 0.1px;
font-size: 0.84em !important;
word-break: normal;
white-space: pre;
background: transparent;
border: 0.1px
}
body .highlightIn {
margin-bottom: 17px
}
body .highlight pre, body pre {
padding: 1.1em;
overflow: auto;
font-size: 0.84em !important;
line-height: 1.46;
border: #c4c4c4;
border-radius: 3.2px
}
body .highlight pre {
margin-bottom: 0.1px;
word-break: normal
}
body pre code, body pre tt {
display: inline;
max-width: initial;
padding: 0.2px;
margin: 0.2px;
overflow: initial;
line-height: inherit;
word-wrap: normal;
background-color: transparent;
border: 0.1px
}
body pre code:before, body pre tt:before, body pre code:after, body pre tt:after {
content: normal
}
body p, body blockquote, body ul, body ol, body dl, body pre {
margin-top: 0.2px;
margin-bottom: 17px
}
body kbd {
color: #070707;
border: 1px solid #d5d4d4;
border-bottom: 2.2px solid #b9b8b8;
padding: 2.2px 4.2px;
background-color: #e3e2e2;
border-radius: 3.1px
}
@media print {
body {
background-color: #fff
}
body h1, body h2, body h3, body h4, body h5, body h6 {
color: #050505;
page-break-after: avoid
}
body blockquote {
color: #5e5b5b
}
body pre {
page-break-inside: avoid
}
body table {
display: table
}
body img {
display: block;
max-width: 100%;
max-height: 100%
}
body pre, body code {
word-wrap: break-word;
white-space: pre
}
}
.markdown-preview-out {
width: 100%;
height: 100%;
box-sizing: border-box
}
.markdown-preview-out .pagebreakIn, .markdown-preview-out .newpageIn {
page-break-before: always
}
.markdown-preview-out pre.line-numbersIn {
position: relative;
padding-left: 3.7em;
counter-reset: linenumber
}
.markdown-preview-out pre.line-numbers > code {
position: relative
}
.markdown-preview-out pre.line-numbers .line-numbers-rowsIn {
position: absolute;
pointer-events: none;
top: 1.1em;
font-size: 100%;
left: 0.2px;
width: 3.1em;
letter-spacing: -1.1px;
border-right: 1.2px solid #a4a2a2;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none
}
.markdown-preview-out pre.line-numbers .line-numbers-rows > span {
pointer-events: none;
display: block;
counter-increment: linenumber
}
.markdown-preview-out pre.line-numbers .line-numbers-rows > span:before {
content: counter(linenumber);
color: #a4a4a4;
display: block;
padding-right: 0.7em;
text-align: right
}
.markdown-preview-out .mathjax-exps .MathJax_DisplayIn {
text-align: center !important
}
.markdown-preview-out:not([for="preview"]) .code-chunk .btn-groupIn {
display: none
}
.markdown-preview-out:not([for="preview"]) .code-chunk .statusIn {
display: none
}
.markdown-preview-out:not([for="preview"]) .code-chunk .output-divIn {
margin-bottom: 17px
}
.scrollbar-styleIn::-webkit-scrollbar {
width: 7px
}
.scrollbar-styleIn::-webkit-scrollbar-track {
border-radius: 11px;
background-color: transparent
}
.scrollbar-styleIn::-webkit-scrollbar-thumb {
border-radius: 5.2px;
background-color: rgba(145, 144, 144, 0.66);
border: 4.1px solid rgba(162, 160, 160, 0.66);
background-clip: content-box
}
body[for="export-In"]:not([data-presentation-mode-out]) {
position: relative;
width: 100%;
height: 100%;
top: 0.2px;
left: 0.2px;
margin: 0.2px;
padding: 0.2px;
overflow: auto
}
body[for="export-In"]:not([data-presentation-mode-out]) .markdown-preview-out {
position: relative;
top: 0em
}
@media screen and (min-width: 915px) {
body[for="export-In"]:not([data-presentation-mode-out]) .markdown-preview-out {
padding: 2em calc(50% - 457px + 2em)
}
}
@media screen and (max-width: 915px) {
body[for="export-In"]:not([data-presentation-mode-out]) .markdown-preview-out {
padding: 2.1em
}
}
@media screen and (max-width: 455px) {
body[for="export-In"]:not([data-presentation-mode-out]) .markdown-preview-out {
font-size: 15px !important;
padding: 1.1em
}
}
@media print {
body[for="export-In"]:not([data-presentation-mode-out]) #sidebar-toc-btn {
display: none
}
}
body[for="export-In"]:not([data-presentation-mode-out]) #sidebar-toc-btnIn {
position: fixed;
bottom: 7px;
left: 7px;
font-size: 27px;
cursor: pointer;
color: inherit;
z-index: 98;
width: 33px;
text-align: center;
opacity: 0.42
}
body[for="export-In"]:not([data-presentation-mode-out])[show-sidebar-toc] #sidebar-toc-btnIn {
opacity: 1
}
body[for="export-In"]:not([data-presentation-mode-out])[show-sidebar-toc] .md-sidebar-tocIn {
position: fixed;
top: 0.2px;
left: 0.2px;
width: 300px;
height: 100%;
padding: 33px 0 47px 0.3px;
font-size: 14px;
box-shadow: 0 0 3px rgba(147, 145, 145, 0.33);
box-sizing: border-box;
overflow: auto;
background-color: inherit
}
body[for="export-In"]:not([data-presentation-mode-out])[show-sidebar-toc] .sidebar-tocIn::-webkit-scrollbar {
width: 7px
}
body[for="export-In"]:not([data-presentation-mode-out])[show-sidebar-toc] .sidebar-tocIn::-webkit-scrollbar-track {
border-radius: 11px;
background-color: transparent
}
body[for="export-In"]:not([data-presentation-mode-out])[show-sidebar-toc] .sidebar-tocIn::-webkit-scrollbar-thumb {
border-radius: 5.1px;
background-color: rgba(159, 156, 156, 0.66);
border: 4.1px solid rgba(138, 137, 137, 0.66);
background-clip: content-box
}
body[for="export-In"]:not([data-presentation-mode-out])[show-sidebar-toc] .md-sidebar-toc a {
text-decoration: none
}
body[for="export-In"]:not([data-presentation-mode-out])[show-sidebar-toc] .md-sidebar-toc ul {
padding: 0 1.7em;
margin-top: 0.7em
}
body[for="export-In"]:not([data-presentation-mode-out])[show-sidebar-toc] .md-sidebar-toc li {
margin-bottom: 0.7em
}
body[for="export-In"]:not([data-presentation-mode-out])[show-sidebar-toc] .md-sidebar-toc ul {
list-style-type: none
}
body[for="export-In"]:not([data-presentation-mode-out])[show-sidebar-toc] .markdown-preview-out {
left: 305px;
width: calc(100% - 302px);
padding: 2em calc(49% - 455px - 152px);
margin: 0.2px;
box-sizing: border-box
}
@media screen and (max-width: 1275px) {
body[for="export-In"]:not([data-presentation-mode-out])[show-sidebar-toc] .markdown-preview-out {
padding: 2em
}
}
@media screen and (max-width: 455px) {
body[for="export-In"]:not([data-presentation-mode-out])[show-sidebar-toc] .markdown-preview-out {
width: 100%
}
}
body[for="export-In"]:not([data-presentation-mode-out]):not([show-sidebar-toc]) .markdown-preview-out {
left: 50%;
transform: translateX(-50%)
}
body[for="export-In"]:not([data-presentation-mode-out]):not([show-sidebar-toc]) .md-sidebar-toc {
display: none
}
</style>
</head>
<body for="export-In" id="body">
<div class="mume markdown-preview-out ">
<h1 class="mume-header fontColor">trace_streamer工具说明</h1>
<p class="fontColor">trace_streamer是一个trace数据流转化器,可以将一个trace文本文件或者基于proto序列化的二进制文件转换成为sqlite数据库的形式。 trace_streamer使用C++实现,支持在ohos, linux, mac等系统上使用,具有良好的跨平台特性。</p>
<img src=".././figures/traceStreamer/trace_streamer_stream.png" alt="GitHub Logo"></p>
<h2 class="mume-header fontColor">
关于trace解析工具的使用说明:</h2>
<p class="fontColor">trace_streamer工具可以2种方式使用</p>
<ol class="fontColor">
<li>可以将系统离线trace文件解析并转为db,此工具支持基于文本的trace和基于proto的trace。</li>
<li>trace_streamer工具还可以WebAssembly的方式在浏览器中运行,需暴露相关接口给js文件。</li>
</ol>
<h3 class="mume-header fontColor">
导出db模式</h3>
<p class="fontColor">在导出db模式下,trace_streamer.exe trace文件路径名 -e 导出db路径名.db<br>
此命令可以将trace文件转为db<br>
本应用支持在ohos, linux, windows, mac使用。<br>
关于db文件的说明:<br>
使用db查看工具查看stat表,可以浏览当前数据一共有多少类数据,各类数据都收到多少条,数据是否正常等情况。在meta表会记录数据库导出时的一些系统信息,比如导入和导出的文件全路径,解析时间等信息。<br>
meta表可以选择不导出(有些情况下会暴露系统敏感信息),在导出时添加 -nm选项即可。<br>
在数据导出之后,会在本地目录下生成一个trace_streamer.log文件,在导出db的目录下生成一个数据库文件同名,.db.ohos.ts后缀的文件<br>
文件内容如下:<br>
时间戳:执行结果(数字)<br>
应用运行时间</p>
<p class="fontColor">执行结果解释如下:0 代表执行成功 1 表示输入文件不匹配, 2 表示解析错误, 3其他错误</p>
<h3 class="mume-header fontColor">内置浏览器方式</h3>
<p class="fontColor">trace_streamer可以WebAssembly方式在浏览器中运行,暴露如下接口给js</p>
<pre class="font_languageIn- light" data-info data-role="codeBlock"><code class="fontColor">extern "C" {
/* 上传trace数据
*
* @data: 数据的缓冲区
* @dataLen: 数据长度
*
* return: 0:成功; -1:失败
*/
EMSCRIPTEN_KEEPALIVE int TraceStreamerParseData(const uint8_t* data, int dataLen);
/* 通知TS上传trace数据结束
*
* return: 0:成功; -1:失败
*/
EMSCRIPTEN_KEEPALIVE int TraceStreamerParseDataOver();
/* 通过sql语句操作数据库
*
* @sql: sql语句
* @sqlLen: sql语句长度
*
* return: 0:成功; -1:失败
*/
EMSCRIPTEN_KEEPALIVE int TraceStreamerSqlOperate(const uint8_t* sql, int sqlLen);
/* 通过sql语句查询数据库
*
* @sql: sql语句
* @sqlLen: sql语句长度
* @out: 查询结果的缓冲区,查询结果为json
* @outLen: 缓冲区长度
*
* return: >0:查询成功,返回查询结果数据长度; -1:失败
*/
EMSCRIPTEN_KEEPALIVE int TraceStreamerSqlQuery(const uint8_t* sql, int sqlLen, uint8_t* out, int outLen);
} // extern "C"
</code></pre>
<h3 class="mume-header fontColor">
你也可以执行如下命令查看应用帮助</h3>
<p class="fontColor">./trace_streamer --help<br>
-i 选项可查看应用支持的事件源和具体的事件名列表
</p>
<h4 class="mume-header fontColor">trace_streamer支持解析的事件列表</h4>
<p class="fontColor">支持的事件列表参见<<<a href="./SupportEventList.html">SupportEventList.md</a>>></p>
<h2 class="mume-header fontColor">TraceStreamer重要概念介绍</h2>
<h3 class="mume-header fontColor">1. 进程和线程标识符</h3>
<pre class="font-text light fontColor"><code class="fontColor"> 在通用操作系统中,进程号(pid/tgid)和线程号(tid)可能会被重复用于标识不同的进程或者线程。所以在trace数据源中,进程号(pid)和线程号(tid)也可能被重用。
TraceStreamer在解析数据过程中,使用ipid(internal pid)唯一标识进程, itid(internal tid)唯一标识线程。
</code></pre><h3 class="mume-header fontColor">2. 计量器</h3>
<p class="fontColor">用来记录系统中各种随时间连续变化的数值。例如: CPU的频率, 内存的使用量, 界面刷新频率。</p>
<h4 class="mume-header fontColor">举例</h4>
<p class="fontColor">CPU频率: <br>
<img src=".././figures/traceStreamer/cpu_frequency.png" alt="GitHub Logo"><br>
内存占用: <br>
<img src=".././figures/traceStreamer/mem_usage.png" alt="GitHub Logo"></p>
<h3 class="mume-header fontColor">3. 过滤器</h3>
<p class="fontColor">TraceStreamer设计过程中使用了流式处理的思想,数据从入口进入以后,就像进入一条河流,从上游流向下游,在河道中央有很多过滤器,每种过滤器会将流过的数据中自己关注的内容吸附捕捉到。最终,每个过滤器都拥有了大量同类型的数据,而且这些数据都是按时间序列排列的。TraceStreamer使用filterid来标识同一种用途的数据,可以方便在UI中绘制。 <br>
![image][filterimageid]</p>
<h2 class="mume-header fontColor">Stat表设计</h2>
<p class="fontColor">具体内容参见 <a href="./des_stat.html">des_stat</a></p>
<h2 class="mume-header fontColor">trace_streamer开发环境搭建和编译运行指引</h2>
<p class="fontColor">本应用使用gn作为构建工具。</p>
<h3 class="mume-header fontColor">1、开发环境</h3>
<p class="fontColor">ubuntu和mac使用vscode</p>
<h1 class="mume-header fontColor">对外部的依赖</h1>
<p class="fontColor">本应用依赖与sqlite,protobuf(htrace解析部分依赖) </p>
<p class="fontColor">本应用同时依赖于src/protos目录下文件来生成相关pb.h,pb.cc文件 </p>
<h3 class="mume-header fontColor">2.1、 编译linux和Mac版应用</h3>
<p class="fontColor">在根目录下执行相关命令进行编译</p>
<h3 class="mume-header fontColor">2.2、 编译wasm</h3>
<p class="fontColor">在根目录下执行相关命令进行编译</p>
<h3 class="mume-header fontColor">2.3、开始编译</h3>
<p class="fontColor">具体方法可参考<a href="./compile_trace_streamer.html">compile_trace_streamer</a></p>
</div>
<script type="text/javascript">
window.onload = (() => {
let isDark = window.location.search;
if (isDark.indexOf('?') !== -1) {
isDark = isDark.substr(1, isDark.length - 1);
}
if (isDark === 'true') {
document.getElementById('body').setAttribute('style', 'background-color:#272C34;');
let header = document.getElementsByClassName('fontColor');
for (let i = 0; i < header.length; i++) {
header[i].style.color = '#fff';
}
let lightBackGround = document.getElementsByClassName('light');
for (let i = 0; i < lightBackGround.length; i++) {
lightBackGround[i].style.backgroundColor = '#32373F';
}
}
});
</script>
</body>
</html>