diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 000000000..51c63e295
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,15 @@
+*.tgz filter=lfs diff=lfs merge=lfs -text
+*.trp filter=lfs diff=lfs merge=lfs -text
+*.apk filter=lfs diff=lfs merge=lfs -text
+*.jar filter=lfs diff=lfs merge=lfs -text
+*.mp4 filter=lfs diff=lfs merge=lfs -text
+*.zip filter=lfs diff=lfs merge=lfs -text
+*.asm filter=lfs diff=lfs merge=lfs -text
+*.8svn filter=lfs diff=lfs merge=lfs -text
+*.9svn filter=lfs diff=lfs merge=lfs -text
+*.dylib filter=lfs diff=lfs merge=lfs -text
+*.exe filter=lfs diff=lfs merge=lfs -text
+*.a filter=lfs diff=lfs merge=lfs -text
+*.so filter=lfs diff=lfs merge=lfs -text
+*.bin filter=lfs diff=lfs merge=lfs -text
+*.dll filter=lfs diff=lfs merge=lfs -text
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 000000000..e454a5258
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,178 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
diff --git a/OAT.xml b/OAT.xml
new file mode 100755
index 000000000..c54dd7ef5
--- /dev/null
+++ b/OAT.xml
@@ -0,0 +1,73 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/README.en.md b/README.en.md
deleted file mode 100644
index 0f9b0a457..000000000
--- a/README.en.md
+++ /dev/null
@@ -1,36 +0,0 @@
-# developtools_profiler
-
-#### Description
-Performance profiler that provides an analytics tool for the memory, bytrace plug-in, and IDE, as well as plug-in capabilities | 性能调优模块,提供了实时内存、bytrace插件和ide侧的分析工具,并提供了插件化能力
-
-#### Software Architecture
-Software architecture description
-
-#### Installation
-
-1. xxxx
-2. xxxx
-3. xxxx
-
-#### Instructions
-
-1. xxxx
-2. xxxx
-3. xxxx
-
-#### Contribution
-
-1. Fork the repository
-2. Create Feat_xxx branch
-3. Commit your code
-4. Create Pull Request
-
-
-#### Gitee Feature
-
-1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md
-2. Gitee blog [blog.gitee.com](https://blog.gitee.com)
-3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore)
-4. The most valuable open source project [GVP](https://gitee.com/gvp)
-5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help)
-6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
diff --git a/README.md b/README.md
deleted file mode 100644
index 1b2ff8c93..000000000
--- a/README.md
+++ /dev/null
@@ -1,37 +0,0 @@
-# developtools_profiler
-
-#### 介绍
-Performance profiler that provides an analytics tool for the memory, bytrace plug-in, and IDE, as well as plug-in capabilities | 性能调优模块,提供了实时内存、bytrace插件和ide侧的分析工具,并提供了插件化能力
-
-#### 软件架构
-软件架构说明
-
-
-#### 安装教程
-
-1. xxxx
-2. xxxx
-3. xxxx
-
-#### 使用说明
-
-1. xxxx
-2. xxxx
-3. xxxx
-
-#### 参与贡献
-
-1. Fork 本仓库
-2. 新建 Feat_xxx 分支
-3. 提交代码
-4. 新建 Pull Request
-
-
-#### 特技
-
-1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
-2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com)
-3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目
-4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
-5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
-6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
diff --git a/README_zh.md b/README_zh.md
new file mode 100755
index 000000000..234d5345f
--- /dev/null
+++ b/README_zh.md
@@ -0,0 +1,374 @@
+# 性能调优组件
+
+- [简介](#section6874544183112)
+- [架构图](#section1514713331342)
+- [目录](#section1742612449345)
+- [说明](#section2165102016359)
+ - [接口说明](#section558917318367)
+ - [使用说明](#section681316903611)
+ - [调测验证:](#section35362541215)
+ - [\#ZH-CN\_TOPIC\_0000001149491319/section3753165410213](#section3753165410213)
+
+- [相关仓](#section1293495681320)
+
+## 简介
+
+性能调优组件包含系统和应用调优框架,旨在为开发者提供一套性能调优平台,可以用来分析内存、性能等问题。
+
+该组件整体分为PC端和设备端两部分,PC端最终作为deveco studio的插件进行发布,内部主要包括分为UI绘制、设备管理、进程管理、插件管理、数据导入、数据存储、 数据分析、Session管理、配置管理等模块;设备端主要包括命令行工具、服务进程、插件集合、应用程序组件等模块。设备端提供了插件扩展能力,对外提供了插件接口,基于该扩展能力可以按需定义自己的能力,并集成到框架中来,目前基于插件能力已经完成了实时内存插件和trace插件。下文会重点对设备端提供的插件能力进行介绍。
+
+## 架构图
+
+![](figures/zh-cn_image_0000001162598155.png)
+
+## 目录
+
+```
+/developtools/profiler
+├── device # 设备侧代码目录
+│ └── base
+│ ├── include # 基础功能的头文件代码目录
+│ ├── src # 基础功能的源文件代码目录
+│ ├── test # 基础功能的测试代码目录
+│ └── cmds
+│ ├── include # 对外命令行模块的头文件代码目录
+│ ├── src # 对外命令行模块的源文件代码目录
+│ ├── test # 对外命令行模块的测试代码目录
+│ └── plugins
+│ ├── api # 插件模块对外提供的接口文件代码目录
+│ └── include # 插件模块对外提供的接口头文件代码目录
+│ └── src # 插件模块对外提供的接口源文件代码目录
+│ ├── memory_plugin # 内存插件模块代码目录
+│ └── include # 内存插件模块头文件代码目录
+│ └── src # 内存插件模块源文件代码目录
+│ └── test # 内存插件模块测试代码目录
+│ ├── trace_plugin # trace插件模块代码目录
+│ └── include # trace插件模块头文件代码目录
+│ └── src # trace插件模块源文件代码目录
+│ └── test # trace插件模块测试代码目录
+├── host # 主机侧代码目录
+│ └── ohosprofiler # 主机侧调优模块代码目录
+│ └── src # 主机侧调优模块源文件代码目录
+├── protos # 项目中的proto格式文件的代码目录
+│ └── innerkits # 对内部子系统暴露的头文件存放目录
+│ └── builtin # JS应用框架对外暴露JS三方module API接口存放目录
+├── trace_analyzer # bytrace解析模块的代码目录
+│ └── include # bytrace解析模块的公共头文件存放目录
+│ └── src # bytrace解析模块功能源文件存放目录
+├── interfaces # 项目中接口的代码目录
+│ └── innerkits # 模块间接口的代码目录
+│ └── kits # 对外提供接口存放目录
+```
+
+## 说明
+
+下面针对设备端对外提供的插件扩展能力进行接口和使用说明。
+
+### 接口说明
+
+下面是设备端插件模块对外提供的接口:
+
+- PluginModuleCallbacks为插件模块对外提供的回调接口,插件管理模块通过该回调接口列表与每一个插件模块进行交互,每一个新增插件都需要实现该接口列表中的函数。
+
+**表 1** PluginModuleCallbacks接口列表
+
+
+
接口名
+ |
+类型
+ |
+描述
+ |
+
+
+PluginModuleCallbacks::onPluginSessionStart
+ |
+int (*PluginSessionStartCallback)(const uint8_t* configData, uint32_t configSize);
+ |
+
+ |
+
+PluginModuleCallbacks::onPluginReportResult
+ |
+int (*PluginReportResultCallback)(uint8_t* bufferData, uint32_t bufferSize);
+ |
+- 功能:
插件结果上报接口类型,当任务下发后,框架采集任务会周期性调用此接口请求回填数据
+ - 输入参数:
bufferData: 存放结果的内存缓冲区起始地址
+bufferSize: 存放结果的内存缓冲区的字节数
+ - 返回值:
大于0:已经填充的内存字节数
+等于0:没有填充任何内容
+小于0:失败
+
+ |
+
+PluginModuleCallbacks::onPluginSessionStop
+ |
+int (*PluginSessionStopCallback)();
+ |
+- 功能:
采集会话结束接口
+ - 返回值:
0:成功
+-1:失败
+
+ |
+
+PluginModuleCallbacks::onRegisterWriterStruct
+ |
+int (*RegisterWriterStructCallback)(WriterStruct* writer);
+ |
+
+ |
+
+
+
+
+- WriterStruct是上面onRegisterWriterStruct接口中的参数,主要实现写数据接口,将插件中采集的数据通过该接口进行写入。
+
+**表 2** WriterStruct接口列表
+
+
+接口名
+ |
+类型
+ |
+描述
+ |
+
+
+WriterStruct::write
+ |
+long (*WriteFuncPtr)(WriterStruct* writer, const void* data, size_t size);
+ |
+
+ |
+
+WriterStruct::flush
+ |
+bool (*FlushFuncPtr)(WriterStruct* writer);
+ |
+- 功能:
触发数据上传接口
+ - 输入参数:
writer:写者指针
+ - 返回值:
true:成功
+false:失败
+
+ |
+
+
+
+
+- 下面是插件模块对外提供的总入口,主要包括表1中的插件模块回调函数以及插件名称、插件模块需要申请的内存大小。
+
+**表 3** PluginModuleStruct接口列表
+
+
+接口名
+ |
+类型
+ |
+描述
+ |
+
+
+PluginModuleStruct::callbacks
+ |
+PluginModuleCallbacks*
+ |
+功能:定义插件回调函数列表
+ |
+
+PluginModuleStruct::name
+ |
+C style string
+ |
+功能:定义插件名称
+ |
+
+PluginModuleStruct::resultBufferSizeHint
+ |
+uint32_t
+ |
+功能:用于提示插件管理模块调用数据上报接口时使用的内存缓冲区字节数
+ |
+
+
+
+
+### 使用说明
+
+下面介绍在设备端基于性能调优框架提供的插件能力,新增一个插件涉及到的关键开发步骤:
+
+1. 编写proto数据定义文件_plugin\_data.proto_,定义数据源格式,数据源格式决定了插件上报哪些数据:
+
+ ```
+ message PluginData {
+ int32 pid = 1;
+ string name = 2;
+ uint64 count1 = 3;
+ uint64 count2 = 4;
+ uint64 count3 = 5;
+ ......
+ }
+ ```
+
+2. 编写数据数据源配置文件_plugin\_config.proto_,采集的行为可以根据配置进行变化,可以设置数据源上报间隔等信息:
+
+ ```
+ message PluginConfig {
+ int32 pid = 1;
+ bool report_interval = 2;
+ int report_counter_id_1 = 3;
+ int report_counter_id_2 = 4;
+ ......
+ }
+ ```
+
+3. 定义PluginModuleCallbacks实现插件回调接口;定义PluginModuleStruct类型的g\_pluginModule全局变量,注册插件信息。
+
+ ```
+ static PluginModuleCallbacks callbacks = {
+ PluginSessionStart,
+ PluginReportResult,
+ PluginSessionStop,
+ };
+ PluginModuleStruct g_pluginModule = {&callbacks, "test-plugin", MAX_BUFFER_SIZE};
+ ```
+
+4. 通过PluginSessionStart(名字可以自己定义)实现插件回调接口列表的onPluginSessionStart接口,主要处理插件的开始流程。
+
+ ```
+ int PluginSessionStart(const uint8_t* configData, uint32_t configSize)
+ {
+ ......
+ return 0;
+ }
+ ```
+
+5. 通过PluginReportResult(名字可以自己定义)实现插件回调接口列表的onPluginReportResult接口,将插件内部采集的信息通过该接口进行上报:
+
+ ```
+ int PluginReportResult(uint8_t* bufferData, uint32_t bufferSize)
+ {
+ ......
+ return 0;
+ }
+ ```
+
+6. 通过PluginSessionStop(名字可以自己定义)实现插件回调接口列表的onPluginSessionStop接口,主要进行插件停止后的操作流程。
+
+ ```
+ int PluginSessionStop()
+ {
+ ......
+ return 0;
+ }
+ ```
+
+7. 编写proto gn构建脚本, 生成protobuf源文件,protobuf源文件编译生成目标文件:
+
+ ```
+ action("plugin_cpp_gen") {
+ script = "${OHOS_PROFILER_DIR}/build/protoc.sh" //依赖的编译工具链
+ sources = [ //定义的插件相关的proto文件,比如插件配置文件、插件数据对应的proto文件
+ "plugin_data.proto",
+ "plugin_config.proto",
+ ]
+ outputs = [ //通过protoc编译生成的结果文件
+ "plugin_data.pb.h",
+ "plugin_data.pb.cc",
+ "plugin_config.pb.h",
+ "plugin_config.pb.cc",
+ ]
+ args = [
+ "--cpp_out",
+ "$proto_rel_out_dir",
+ "--proto_path",
+ rebase_path(".", root_build_dir),
+ ]
+ deps = [
+ "${OHOS_PROFILER_3RDPARTY_PROTOBUF_DIR}:protoc(${host_toolchain})",
+ ]
+ }
+ ohos_source_set("plug_cpp") { //将定义的proto文件生成cpp文件
+ deps = [
+ ":plugin_cpp_gen",
+ ]
+ public_deps = [
+ "${OHOS_PROFILER_3RDPARTY_PROTOBUF_DIR}:protobuf",
+ "${OHOS_PROFILER_3RDPARTY_PROTOBUF_DIR}:protobuf_lite",
+ ]
+ include_dirs = [ "$proto_out_dir" ]
+ sources = [ //目标plug_cpp中包括的源文件
+ "plugin_data.pb.h",
+ "plugin_data.pb.cc",
+ "plugin_config.pb.h",
+ "plugin_config.pb.cc",
+ ]
+ }
+ ```
+
+8. 编写插件GN构建脚本:
+
+ ```
+ ohos_shared_library("***plugin") {
+ output_name = "***plugin"
+ sources = [
+ "src/***plugin.cpp", //插件中的源文件
+ ]
+ include_dirs = [
+ "../api/include",
+ "${OHOS_PROFILER_DIR}/device/base/include",
+ ]
+ deps = [
+ "${OHOS_PROFILER_3RDPARTY_PROTOBUF_DIR}:protobuf_lite",
+ "${OHOS_PROFILER_3RDPARTY_PROTOBUF_DIR}:protoc_lib",
+ "${OHOS_PROFILER_DIR}/protos/types/plugins/**:plug_cpp", //上面ohos_source_set中生成的plug_cpp
+ ]
+ install_enable = true
+ subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}"
+ }
+ ```
+
+
+### 调测验证:
+
+插件动态库生成后,可以自己编写测试代码,通过dlopen加载动态库,并调用上面代码中实现的插件模块回调函数进行验证。
+
+```
+int main(int argc, char** argv)
+{
+ void* handle;
+ PluginModuleStruct* memplugin;
+ handle = dlopen("./libplugin.z.so", RTLD_LAZY); //动态打开上面生成的插件动态库
+ if (handle == nullptr) {
+ HILOGD("dlopen err:%s.", dlerror());
+ return 0;
+ }
+ memplugin = (PluginModuleStruct*)dlsym(handle, "g_pluginModule"); //获取开发步骤3中定义的g_pluginModule全局变量
+ //check memplugin->callbacks // 通过该指针调用上面开发步骤3中定义的回调函数
+ return 0;
+```
+
+## 相关仓
+
+研发工具链子系统
+
+**developtools\_profiler**
+
+developtools\_hdc\_standard
+
+developtools\_bytrace\_standard
+
diff --git a/build/config.gni b/build/config.gni
new file mode 100755
index 000000000..2721b5505
--- /dev/null
+++ b/build/config.gni
@@ -0,0 +1,35 @@
+# Copyright (c) 2021 Huawei Device Co., Ltd.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+OHOS_PROFILER_DIR = get_path_info("..", "abspath")
+OHOS_PROFILER_3RDPARTY_DIR = get_path_info("../../../third_party/", "abspath")
+OHOS_PROFILER_3RDPARTY_GRPC_DIR = "${OHOS_PROFILER_3RDPARTY_DIR}/grpc"
+OHOS_PROFILER_3RDPARTY_PROTOBUF_DIR =
+ "${OHOS_PROFILER_3RDPARTY_DIR}/protobuf"
+OHOS_PROFILER_3RDPARTY_GOOGLETEST_DIR =
+ "${OHOS_PROFILER_3RDPARTY_DIR}/googletest"
+
+OHOS_PROFILER_SUBSYS_NAME = "developtools"
+OHOS_PROFILER_PART_NAME = "profiler"
+OHOS_PROFILER_TEST_MODULE_OUTPUT_PATH = "profiler"
+
+build_l2 = false
+if (getenv("BUILD_L2") == "true") {
+ build_l2 = true
+}
+print("build_l2 =", build_l2)
+print("OHOS_PROFILER_DIR = ", OHOS_PROFILER_DIR)
+print("OHOS_PROFILER_3RDPARTY_DIR = ", OHOS_PROFILER_3RDPARTY_DIR)
+print("OHOS_PROFILER_3RDPARTY_GRPC_DIR = ", OHOS_PROFILER_3RDPARTY_GRPC_DIR)
+print("OHOS_PROFILER_3RDPARTY_PROTOBUF_DIR = ", OHOS_PROFILER_3RDPARTY_PROTOBUF_DIR)
+print("OHOS_PROFILER_3RDPARTY_GOOGLETEST_DIR", OHOS_PROFILER_3RDPARTY_GOOGLETEST_DIR)
diff --git a/build/gcov.sh b/build/gcov.sh
new file mode 100755
index 000000000..5ad6b336c
--- /dev/null
+++ b/build/gcov.sh
@@ -0,0 +1,21 @@
+#!/bin/bash
+# Copyright (c) 2021 Huawei Device Co., Ltd.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+set -e
+DIR=$(dirname $(realpath ${BASH_SOURCE[0]}))
+TOP=$(realpath $DIR/../../..)
+CLANG_DIR=$TOP/prebuilts/clang/host/linux-x86/clang-r353983c
+if [ ! -e "$CLANG_DIR" ]; then
+ CLANG_DIR=$TOP/prebuilts/clang/ohos/linux-x86_64/llvm
+fi
+$CLANG_DIR/bin/llvm-cov gcov $@
diff --git a/build/lcov.sh b/build/lcov.sh
new file mode 100755
index 000000000..39d266824
--- /dev/null
+++ b/build/lcov.sh
@@ -0,0 +1,38 @@
+#!/bin/bash
+# Copyright (c) 2021 Huawei Device Co., Ltd.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+set -e
+DIR=$(dirname $(realpath ${BASH_SOURCE[0]}))
+TOP=$(realpath $DIR/../../..)
+HOST_OUT=$TOP/hos/out/hos-arm/clang_x64
+if [ ! -e "$HOST_OUT" ]; then
+ HOST_OUT=$TOP/out/ohos-arm-release/clang_x64
+fi
+
+
+# collect and convert all gcno and gcda to test.info
+lcov -c -d $HOST_OUT -o test.info --gcov-tool $DIR/gcov.sh
+if [ $? -ne 0 ]; then
+ echo "Install lcov: sudo apt install lcov"
+fi
+
+# filter out system headers
+lcov -r test.info \
+ '/usr/include/*' \
+ '*/hos/out/*' \
+ '*/hos/third_party/*' \
+ '*/third_party/grpc/*' \
+ -o test.info
+
+# generate html report
+genhtml -o html test.info
diff --git a/build/protoc.sh b/build/protoc.sh
new file mode 100755
index 000000000..275fa09ee
--- /dev/null
+++ b/build/protoc.sh
@@ -0,0 +1,28 @@
+#!/bin/bash
+# Copyright (c) 2021 Huawei Device Co., Ltd.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+set -e
+
+THIS_DIR=$(dirname ${BASH_SOURCE[0]})
+PROJECT_TOP=$(realpath $THIS_DIR/../../..)
+
+OHOS_X64_OUT=$PROJECT_TOP/$2/clang_x64
+LIBCXX_X64_OUT=$PROJECT_TOP/$1/ndk/libcxx/linux_x86_64
+SUBSYS_X64_OUT=$PROJECT_TOP/$2/clang_x64/developtools/developtools
+PROTOC=$PROJECT_TOP/$2/clang_x64/developtools/developtools/protoc
+
+PARAMS=$*
+PARAMS_FILTER="$1 $2"
+echo "EXEC: LD_LIBRARY_PATH=$LIBCXX_X64_OUT:$SUBSYS_X64_OUT $PROTOC ${PARAMS[@]:${#PARAMS_FILTER}}"
+LD_LIBRARY_PATH=$LIBCXX_X64_OUT:$SUBSYS_X64_OUT exec $PROTOC ${PARAMS[@]:${#PARAMS_FILTER}}
diff --git a/build/run.sh b/build/run.sh
new file mode 100755
index 000000000..cd27dd1b6
--- /dev/null
+++ b/build/run.sh
@@ -0,0 +1,29 @@
+#!/bin/bash
+# Copyright (c) 2021 Huawei Device Co., Ltd.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+set -e
+DIR=$(dirname $(realpath ${BASH_SOURCE[0]}))
+TOP=$(realpath $DIR/../../..)
+SUBSYS=developtools
+HOST_OUT=$TOP/hos/out/hos-arm/clang_x64
+LIB_PATH=$LIB_PATH:$HOST_OUT/devtools/devtools
+LIB_PATH=$LIB_PATH:$HOST_OUT/$SUBSYS/$SUBSYS
+LIB_PATH=$LIB_PATH:$HOST_OUT/common/common
+LIB_PATH=$LIB_PATH:$LD_LIBRARY_PATH
+
+# remove old coverage data
+find $HOST_OUT -name '*.gcda' | xargs rm -v
+
+# run UT executable
+echo LD_LIBRARY_PATH=$LIB_PATH $@
+LD_LIBRARY_PATH=$LIB_PATH $@
diff --git a/device/.clang-format b/device/.clang-format
new file mode 120000
index 000000000..247fd6725
--- /dev/null
+++ b/device/.clang-format
@@ -0,0 +1 @@
+../tools/.clang-format
\ No newline at end of file
diff --git a/device/BUILD.gn b/device/BUILD.gn
new file mode 100755
index 000000000..16555dc98
--- /dev/null
+++ b/device/BUILD.gn
@@ -0,0 +1,38 @@
+# Copyright (C) 2021 Huawei Device Co., Ltd.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import("base/config.gni")
+
+group("hiprofiler_targets") {
+ deps = [
+ "cmds:hiprofiler_cmd",
+ "plugins/api:hiprofiler_plugins",
+ "plugins/memory_plugin:memdataplugin",
+ "services/profiler_service:hiprofilerd",
+ "services/shared_memory:shared_memory",
+ "plugins/bytrace_plugin:bytraceplugin",
+ ]
+}
+
+group("unittest") {
+ testonly = true
+ deps = [
+ "base/test:unittest",
+ "plugins/api/test:unittest",
+ "plugins/memory_plugin/test:unittest",
+ "services/ipc/test:unittest",
+ "services/plugin_service/test:unittest",
+ "services/profiler_service/test:unittest",
+ "services/shared_memory/test:unittest",
+ ]
+}
diff --git a/device/base/BUILD.gn b/device/base/BUILD.gn
new file mode 100755
index 000000000..8fbd228f4
--- /dev/null
+++ b/device/base/BUILD.gn
@@ -0,0 +1,60 @@
+# Copyright (C) 2021 Huawei Device Co., Ltd.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import("//build/ohos.gni")
+import("config.gni")
+
+# compile options for gcov
+config("hiprofiler_test_config") {
+ cflags = []
+ if (enable_debuginfo) {
+ cflags += [ "-g" ]
+ }
+
+ if (enable_coverage && current_toolchain == host_toolchain) {
+ cflags += [
+ # clang coverage options:
+ "--coverage",
+ "-mllvm",
+ "-limited-coverage-experimental=true",
+ "-fno-use-cxa-atexit",
+ ]
+ ldflags = [ "--coverage" ]
+ }
+}
+
+config("hiprofiler_base_config") {
+ include_dirs = [
+ "include",
+ "//utils/native/base/include"
+ ]
+}
+
+ohos_source_set("hiprofiler_base") {
+ sources = [
+ "src/schedule_task_manager.cpp",
+ ]
+
+ public_configs = [
+ ":hiprofiler_test_config",
+ ":hiprofiler_base_config",
+ ]
+ if (current_toolchain != host_toolchain) {
+ defines = [ "HAVE_HILOG" ]
+ if (build_l2) {
+ external_deps = [ "shared_library:libhilog" ]
+ } else {
+ external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
+ }
+ }
+}
diff --git a/device/base/config.gni b/device/base/config.gni
new file mode 100755
index 000000000..d667c8d7f
--- /dev/null
+++ b/device/base/config.gni
@@ -0,0 +1,32 @@
+# Copyright (c) 2021 Huawei Device Co., Ltd.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import("../../build/config.gni")
+
+build_tests = false
+enable_debuginfo = false
+enable_coverage = false
+
+if (getenv("BUILD_UT") == "true") {
+ build_tests = true
+ enable_debuginfo = true
+ enable_coverage = true
+}
+
+if (getenv("BUILD_MT") == "true") {
+ build_tests = true
+ enable_debuginfo = true
+}
+print("build_tests = ", build_tests)
+print("enable_debuginfo =", enable_debuginfo)
+print("enable_coverage =", enable_coverage)
diff --git a/device/base/include/logging.h b/device/base/include/logging.h
new file mode 100755
index 000000000..0c4b912de
--- /dev/null
+++ b/device/base/include/logging.h
@@ -0,0 +1,131 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef LOGGING_H
+#define LOGGING_H
+
+#ifndef LOG_TAG
+#define LOG_TAG ""
+#endif
+
+#ifdef HAVE_HILOG
+#include "hilog/log.h"
+
+#undef LOG_TAG
+#define LOG_TAG "Hiprofiler"
+
+#else
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+static inline long GetTid()
+{
+ return syscall(SYS_gettid);
+}
+
+enum {
+ HILOG_UNKNOWN = 0,
+ HILOG_DEFAULT,
+ HILOG_VERBOSE,
+ HILOG_DEBUG,
+ HILOG_INFO,
+ HILOG_WARN,
+ HILOG_ERROR,
+ HILOG_FATAL,
+ HILOG_SILENT,
+};
+
+namespace {
+constexpr int NS_PER_MS_LOG = 1000 * 1000;
+}
+
+static inline std::string GetTimeStr()
+{
+ char timeStr[64];
+ struct timespec ts;
+ struct tm tmStruct;
+ clock_gettime(CLOCK_REALTIME, &ts);
+ localtime_r(&ts.tv_sec, &tmStruct);
+ size_t used = strftime(timeStr, sizeof(timeStr), "%m-%d %H:%M:%S", &tmStruct);
+ snprintf_s(&timeStr[used], sizeof(timeStr) - used, sizeof(timeStr) - used - 1, ".%03ld",
+ ts.tv_nsec / NS_PER_MS_LOG);
+ return timeStr;
+}
+
+typedef const char *ConstCharPtr;
+
+static inline int HiLogPrintArgs(int prio, ConstCharPtr tag, ConstCharPtr fmt, va_list vargs)
+{
+ static std::mutex mtx;
+ static std::vector prioNames = {"U", " ", "V", "D", "I", "W", "E", "F", "S"};
+ std::unique_lock lock(mtx);
+ int count =
+ fprintf(stderr, "%s %7d %7ld %5s %s ", GetTimeStr().c_str(), getpid(), GetTid(), prioNames[prio].c_str(), tag);
+ count += vfprintf(stderr, fmt, vargs);
+ count += fprintf(stderr, "\n");
+ return count;
+}
+
+static inline int __hilog_log_print(int prio, ConstCharPtr tag, ConstCharPtr fmt, ...)
+{
+ int count;
+ va_list vargs;
+
+ va_start(vargs, fmt);
+ count = HiLogPrintArgs(prio, tag, fmt, vargs);
+ va_end(vargs);
+ return count;
+}
+
+#define HILOG_DEBUG(LOG_CORE, fmt, ...) __hilog_log_print(HILOG_DEBUG, LOG_TAG, fmt, ##__VA_ARGS__)
+#define HILOG_INFO(LOG_CORE, fmt, ...) __hilog_log_print(HILOG_INFO, LOG_TAG, fmt, ##__VA_ARGS__)
+#define HILOG_WARN(LOG_CORE, fmt, ...) __hilog_log_print(HILOG_WARN, LOG_TAG, fmt, ##__VA_ARGS__)
+#define HILOG_ERROR(LOG_CORE, fmt, ...) __hilog_log_print(HILOG_ERROR, LOG_TAG, fmt, ##__VA_ARGS__)
+
+#endif
+
+#define STD_PTR(K, T) std::K##_ptr
+
+#define CHECK_NOTNULL(ptr, retval, fmt, ...) \
+ do { \
+ if (ptr == nullptr) { \
+ HILOG_WARN(LOG_CORE, "CHECK_NOTNULL(%s) in %s:%d FAILED, " fmt, #ptr, __func__, __LINE__, ##__VA_ARGS__); \
+ return retval; \
+ } \
+ } while (0)
+
+#define CHECK_TRUE(expr, retval, fmt, ...) \
+ do { \
+ if (!(expr)) { \
+ HILOG_WARN(LOG_CORE, "CHECK_TRUE(%s) in %s:%d FAILED, " fmt, #expr, __func__, __LINE__, ##__VA_ARGS__); \
+ return retval; \
+ } \
+ } while (0)
+
+#define RETURN_IF(expr, retval, fmt, ...) \
+ do { \
+ if ((expr)) { \
+ HILOG_WARN(LOG_CORE, fmt, ##__VA_ARGS__); \
+ return retval; \
+ } \
+ } while (0)
+
+#endif
diff --git a/device/base/include/schedule_task_manager.h b/device/base/include/schedule_task_manager.h
new file mode 100644
index 000000000..0ce47f5dc
--- /dev/null
+++ b/device/base/include/schedule_task_manager.h
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef SCHEDULE_TASK_MANAGER_H
+#define SCHEDULE_TASK_MANAGER_H
+
+#include
+#include
+#include
+#include