add diskio and ftrace plugin

Signed-off-by: chuxuezhe11 <hanjixiao@huawei.com>
This commit is contained in:
chuxuezhe11 2021-12-08 23:46:28 -08:00
parent cdac4d219d
commit 792d43a676
575 changed files with 50117 additions and 3927 deletions

60
OAT.xml Normal file → Executable file
View File

@ -12,13 +12,13 @@
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
Notes: Notes:
This is project config file for OpenHarmony OSS Audit Tool, if you have any questions or concerns, please email chenyaxun@huawei.com. This is project config file for OpenHarmony OSS Audit Tool, if you have any questions or concerns, please email chenyaxun@huawei.com.
--> -->
<!-- OAT(OSS Audit Tool) configuration guide: <!-- OAT(OSS Audit Tool) configuration guide:
basedir: Root dir, the basedir + project path is the real source file location. basedir: Root dir, the basedir + project path is the real source file location.
licensefile: licensefile:
1.If the project don't have "LICENSE" in root dir, please define all the license files in this project in , OAT will check license files according to this rule. 1.If the project don't have "LICENSE" in root dir, please define all the license files in this project in , OAT will check license files according to this rule.
tasklist(only for batch mode): tasklist(only for batch mode):
@ -33,15 +33,15 @@ policyList:
1. policy: All policyitems will be merged to default OAT.xml rules, the name of policy doesn't affect OAT check process. 1. policy: All policyitems will be merged to default OAT.xml rules, the name of policy doesn't affect OAT check process.
2. policyitem: The fields type, name, path, desc is required, and the fields rule, group, filefilter is optional,the default value is: 2. policyitem: The fields type, name, path, desc is required, and the fields rule, group, filefilter is optional,the default value is:
<policyitem type="" name="" path="" desc="" rule="may" group="defaultGroup" filefilter="defaultPolicyFilter"/> <policyitem type="" name="" path="" desc="" rule="may" group="defaultGroup" filefilter="defaultPolicyFilter"/>
3. policyitem type: 3. policyitem type:
"compatibility" is used to check license compatibility in the specified path; "compatibility" is used to check license compatibility in the specified path;
"license" is used to check source license header in the specified path; "license" is used to check source license header in the specified path;
"copyright" is used to check source copyright header in the specified path; "copyright" is used to check source copyright header in the specified path;
"import" is used to check source dependency in the specified path, such as import ... ,include ... "import" is used to check source dependency in the specified path, such as import ... ,include ...
"filetype" is used to check file type in the specified path, supported file types: archive, binary "filetype" is used to check file type in the specified path, supported file types: archive, binary
"filename" is used to check whether the specified file exists in the specified path(support projectroot in default OAT.xml), supported file names: LICENSE, README, README.OpenSource "filename" is used to check whether the specified file exists in the specified path(support projectroot in default OAT.xml), supported file names: LICENSE, README, README.OpenSource
4. policyitem name: This field is used for define the license, copyright, "*" means match all, the "!" prefix means could not match this value. For example, "!GPL" means can not use GPL license. 4. policyitem name: This field is used for define the license, copyright, "*" means match all, the "!" prefix means could not match this value. For example, "!GPL" means can not use GPL license.
5. policyitem path: This field is used for define the source file scope to apply this policyitem, the "!" prefix means exclude the files. For example, "!.*/lib/.*" means files in lib dir will be exclude while process this policyitem. 5. policyitem path: This field is used for define the source file scope to apply this policyitem, the "!" prefix means exclude the files. For example, "!.*/lib/.*" means files in lib dir will be exclude while process this policyitem.
6. policyitem rule and group: These two fields are used together to merge policy results. "may" policyitems in the same group means any one in this group passed, the result will be passed. 6. policyitem rule and group: These two fields are used together to merge policy results. "may" policyitems in the same group means any one in this group passed, the result will be passed.
7. policyitem filefilter: Used to bind filefilter which define filter rules. 7. policyitem filefilter: Used to bind filefilter which define filter rules.
@ -55,20 +55,52 @@ Note:If the text contains special characters, please escape them according to th
> == &gt; > == &gt;
--> -->
<configuration> <configuration>
<oatconfig> <oatconfig>
<filefilterlist> <filefilterlist>
<filefilter name="defaultPolicyFilter" desc="Filters for compatibilitylicense header policies"> <filefilter name="defaultPolicyFilter" desc="Filters for compatibilitylicense header policies">
<filteritem type="filepath" name="device/plugins/memory_plugin/test/utresources/proc/.*" desc="test resource file, no license header"/> <filteritem type="filepath" name="device/plugins/memory_plugin/test/utresources/proc/.*" desc="test resource file, no license header"/>
<filteritem type="filepath" name="device/plugins/cpu_plugin/test/resources/.*" desc="test resource file, no license header"/> <filteritem type="filepath" name="device/plugins/cpu_plugin/test/resources/.*" desc="test resource file, no license header"/>
<filteritem type="filepath" name="trace_analyzer/prebuilts/mac/trace_streamer.app/Contents/Resources/empty.lproj" desc="auto generated resource file for mac app, no license header"/> <filteritem type="filepath" name="device/plugins/diskio_plugin/test/resources/.*" desc="test resource file, no license header"/>
<filteritem type="filepath" name="trace_analyzer/prebuilts/mac/trace_streamer.app/Contents/PkgInfo" desc="auto generated resource file for mac app, no license header"/> <filteritem type="filepath" name="device/plugins/network_plugin/test/utresources/.*" desc="test resource file, no license header"/>
<filteritem type="filepath" name="device/plugins/api/test/fuzztest/plugindestroysessioncmd_fuzzer/corpus/init" desc="test resource file, no license header"/>
<filteritem type="filepath" name="device/plugins/api/test/fuzztest/pluginstartsessioncmd_fuzzer/corpus/init" desc="test resource file, no license header"/>
<filteritem type="filepath" name="device/plugins/api/test/fuzztest/plugincreatesessioncmd_fuzzer/corpus/init" desc="test resource file, no license header"/>
<filteritem type="filepath" name="device/plugins/api/test/fuzztest/pluginstopsessioncmd_fuzzer/corpus/init" desc="test resource file, no license header"/>
<filteritem type="filepath" name="device/plugins/hilog_plugin/test/fuzztest/hilogstartplugin_fuzzer/corpus/init" desc="test resource file, no license header"/>
<filteritem type="filepath" name="device/plugins/cpu_plugin/test/fuzztest/cpustartplugin_fuzzer/corpus/init" desc="test resource file, no license header"/>
<filteritem type="filepath" name="device/plugins/diskio_plugin/test/fuzztest/diskiostartplugin_fuzzer/corpus/init" desc="test resource file, no license header"/>
<filteritem type="filepath" name="device/plugins/memory_plugin/test/fuzztest/memorystartplugin_fuzzer/corpus/init" desc="test resource file, no license header"/>
<filteritem type="filepath" name="device/plugins/network_plugin/test/fuzztest/networkstartplugin_fuzzer/corpus/init" desc="test resource file, no license header"/>
<filteritem type="filepath" name="device/services/profiler_service/test/fuzztest/profilerstopsession_fuzzer/corpus/init" desc="test resource file, no license header"/>
<filteritem type="filepath" name="device/services/profiler_service/test/fuzztest/profilerkeepsession_fuzzer/corpus/init" desc="test resource file, no license header"/>
<filteritem type="filepath" name="device/services/profiler_service/test/fuzztest/profilerfetchdata_fuzzer/corpus/init" desc="test resource file, no license header"/>
<filteritem type="filepath" name="device/services/profiler_service/test/fuzztest/profilercreatesession_fuzzer/corpus/init" desc="test resource file, no license header"/>
<filteritem type="filepath" name="device/services/profiler_service/test/fuzztest/profilerstartsession_fuzzer/corpus/init" desc="test resource file, no license header"/>
<filteritem type="filepath" name="device/services/profiler_service/test/fuzztest/profilergetcapabilities_fuzzer/corpus/init" desc="test resource file, no license header"/>
<filteritem type="filepath" name="device/services/profiler_service/test/fuzztest/profilerdestroysession_fuzzer/corpus/init" desc="test resource file, no license header"/>
<filteritem type="filepath" name="trace_analyzer/test/resource/.*" desc="test resource file, no license header"/> <filteritem type="filepath" name="trace_analyzer/test/resource/.*" desc="test resource file, no license header"/>
</filefilter> </filefilter>
<filefilter name="copyrightPolicyFilter" desc="Filters for copyright header policies" > <filefilter name="copyrightPolicyFilter" desc="Filters for copyright header policies" >
<filteritem type="filepath" name="device/plugins/memory_plugin/test/utresources/proc/.*" desc="test resource file, no copyright header"/> <filteritem type="filepath" name="device/plugins/memory_plugin/test/utresources/proc/.*" desc="test resource file, no copyright header"/>
<filteritem type="filepath" name="device/plugins/cpu_plugin/test/resources/.*" desc="test resource file, no copyright header"/> <filteritem type="filepath" name="device/plugins/cpu_plugin/test/resources/.*" desc="test resource file, no copyright header"/>
<filteritem type="filepath" name="trace_analyzer/prebuilts/mac/trace_streamer.app/Contents/Resources/empty.lproj" desc="auto generated resource file for mac app, no copyright header"/> <filteritem type="filepath" name="device/plugins/diskio_plugin/test/resources/.*" desc="test resource file, no copyright header"/>
<filteritem type="filepath" name="trace_analyzer/prebuilts/mac/trace_streamer.app/Contents/PkgInfo" desc="auto generated resource file for mac app, no copyright header"/> <filteritem type="filepath" name="device/plugins/network_plugin/test/utresources/.*" desc="test resource file, no copyright header"/>
<filteritem type="filepath" name="device/plugins/api/test/fuzztest/plugindestroysessioncmd_fuzzer/corpus/init" desc="test resource file, no copyright header"/>
<filteritem type="filepath" name="device/plugins/api/test/fuzztest/pluginstartsessioncmd_fuzzer/corpus/init" desc="test resource file, no copyright header"/>
<filteritem type="filepath" name="device/plugins/api/test/fuzztest/plugincreatesessioncmd_fuzzer/corpus/init" desc="test resource file, no copyright header"/>
<filteritem type="filepath" name="device/plugins/api/test/fuzztest/pluginstopsessioncmd_fuzzer/corpus/init" desc="test resource file, no copyright header"/>
<filteritem type="filepath" name="device/plugins/hilog_plugin/test/fuzztest/hilogstartplugin_fuzzer/corpus/init" desc="test resource file, no copyright header"/>
<filteritem type="filepath" name="device/plugins/cpu_plugin/test/fuzztest/cpustartplugin_fuzzer/corpus/init" desc="test resource file, no copyright header"/>
<filteritem type="filepath" name="device/plugins/diskio_plugin/test/fuzztest/diskiostartplugin_fuzzer/corpus/init" desc="test resource file, no copyright header"/>
<filteritem type="filepath" name="device/plugins/memory_plugin/test/fuzztest/memorystartplugin_fuzzer/corpus/init" desc="test resource file, no copyright header"/>
<filteritem type="filepath" name="device/plugins/network_plugin/test/fuzztest/networkstartplugin_fuzzer/corpus/init" desc="test resource file, no copyright header"/>
<filteritem type="filepath" name="device/services/profiler_service/test/fuzztest/profilerstopsession_fuzzer/corpus/init" desc="test resource file, no copyright header"/>
<filteritem type="filepath" name="device/services/profiler_service/test/fuzztest/profilerkeepsession_fuzzer/corpus/init" desc="test resource file, no copyright header"/>
<filteritem type="filepath" name="device/services/profiler_service/test/fuzztest/profilerfetchdata_fuzzer/corpus/init" desc="test resource file, no copyright header"/>
<filteritem type="filepath" name="device/services/profiler_service/test/fuzztest/profilercreatesession_fuzzer/corpus/init" desc="test resource file, no copyright header"/>
<filteritem type="filepath" name="device/services/profiler_service/test/fuzztest/profilerstartsession_fuzzer/corpus/init" desc="test resource file, no copyright header"/>
<filteritem type="filepath" name="device/services/profiler_service/test/fuzztest/profilergetcapabilities_fuzzer/corpus/init" desc="test resource file, no copyright header"/>
<filteritem type="filepath" name="device/services/profiler_service/test/fuzztest/profilerdestroysession_fuzzer/corpus/init" desc="test resource file, no copyright header"/>
<filteritem type="filepath" name="trace_analyzer/test/resource/.*" desc="test resource file, no copyright header"/> <filteritem type="filepath" name="trace_analyzer/test/resource/.*" desc="test resource file, no copyright header"/>
</filefilter> </filefilter>
<filefilter name="binaryFileTypePolicyFilter" desc="Filters for binary file policies" > <filefilter name="binaryFileTypePolicyFilter" desc="Filters for binary file policies" >
@ -78,11 +110,11 @@ Note:If the text contains special characters, please escape them according to th
<filteritem type="filepath" name="host/ohosprofiler/src/main/resources/.*.png" desc="the png file for host, the file is self-developed"/> <filteritem type="filepath" name="host/ohosprofiler/src/main/resources/.*.png" desc="the png file for host, the file is self-developed"/>
<filteritem type="filepath" name="host/ohosprofiler/src/main/resources/.*.gif" desc="the gif file for host, the file is self-developed"/> <filteritem type="filepath" name="host/ohosprofiler/src/main/resources/.*.gif" desc="the gif file for host, the file is self-developed"/>
<filteritem type="filepath" name="figures/zh-cn_image_0000001162598155.png" desc="the png file for readme, the file is self-developed"/> <filteritem type="filepath" name="figures/zh-cn_image_0000001162598155.png" desc="the png file for readme, the file is self-developed"/>
<filteritem type="filepath" name="trace_analyzer/prebuilts/trace_streamer.exe" desc="the trace_streamer.exe executable file, the file is self-developed"/>
<filteritem type="filepath" name="trace_analyzer/test/resource/htrace.bin" desc="the trace_streamer test file, the file is self-developed"/> <filteritem type="filepath" name="trace_analyzer/test/resource/htrace.bin" desc="the trace_streamer test file, the file is self-developed"/>
<filteritem type="filepath" name="trace_analyzer/prebuilts/windows/trace_streamer.exe" desc="the trace_streamer.exe executable file, the file is self-developed"/> <filteritem type="filepath" name="trace_analyzer/prebuilts/windows/trace_streamer.exe" desc="the trace_streamer.exe executable file, the file is self-developed"/>
<filteritem type="filepath" name="trace_analyzer/prebuilts/linux/trace_streamer" desc="the trace_streamer executable file, the file is self-developed"/>
<filteritem type="filepath" name="trace_analyzer/prebuilts/macx/trace_streamer" desc="the trace_streamer executable file, the file is self-developed"/>
<filteritem type="filepath" name="trace_analyzer/test/resource/htrace_gold.db" desc="the trace_streamer test file, the file is self-developed"/> <filteritem type="filepath" name="trace_analyzer/test/resource/htrace_gold.db" desc="the trace_streamer test file, the file is self-developed"/>
<filteritem type="filepath" name="trace_analyzer/prebuilts/mac/trace_streamer.app/Contents/MacOS/trace_streamer" desc="the trace_streamer executable file for mac, the file is self-developed"/>
<filteritem type="filepath" name="trace_analyzer/test/resource/ut_bytrace_input_thread_gold.db" desc="the trace_streamer test file, the file is self-developed"/> <filteritem type="filepath" name="trace_analyzer/test/resource/ut_bytrace_input_thread_gold.db" desc="the trace_streamer test file, the file is self-developed"/>
<filteritem type="filepath" name="trace_analyzer/test/resource/ut_bytrace_input_full_gold.db" desc="the trace_streamer test file, the file is self-developed"/> <filteritem type="filepath" name="trace_analyzer/test/resource/ut_bytrace_input_full_gold.db" desc="the trace_streamer test file, the file is self-developed"/>
</filefilter> </filefilter>

37
device/BUILD.gn Normal file → Executable file
View File

@ -12,15 +12,24 @@
# limitations under the License. # limitations under the License.
import("base/config.gni") import("base/config.gni")
group("hiprofiler_targets") { group("hiprofiler_targets") {
deps = [ deps = [
"cmds:hiprofiler_cmd", "cmds:hiprofiler_cmd",
"plugins/api:hiprofiler_plugins", "plugins/api:hiprofiler_plugins",
"plugins/bytrace_plugin:bytraceplugin", "plugins/bytrace_plugin:bytraceplugin",
"plugins/bytrace_plugin:test_bytrace_plugin",
"plugins/cpu_plugin:cpudataplugin", "plugins/cpu_plugin:cpudataplugin",
"plugins/cpu_plugin:cpudataplugintest", "plugins/cpu_plugin:cpudataplugintest",
"plugins/diskio_plugin:diskiodataplugin",
"plugins/diskio_plugin:diskiodataplugintest",
"plugins/ftrace_plugin:ftrace_targets",
"plugins/hilog_plugin:hilogplugin",
"plugins/memory_plugin:memdataplugin", "plugins/memory_plugin:memdataplugin",
"plugins/memory_plugin:memorytest",
"plugins/network_plugin:networkplugin",
"plugins/process_plugin:processplugin",
"plugins/sample_plugin:sampleplugin",
"plugins/stream_plugin:streamplugin",
"services/profiler_service:hiprofilerd", "services/profiler_service:hiprofilerd",
"services/shared_memory:shared_memory", "services/shared_memory:shared_memory",
] ]
@ -32,10 +41,36 @@ group("unittest") {
"base/test:unittest", "base/test:unittest",
"plugins/api/test:unittest", "plugins/api/test:unittest",
"plugins/cpu_plugin/test:unittest", "plugins/cpu_plugin/test:unittest",
"plugins/diskio_plugin/test:unittest",
"plugins/ftrace_plugin/test:unittest",
"plugins/hilog_plugin/test:unittest",
"plugins/memory_plugin/test:unittest", "plugins/memory_plugin/test:unittest",
"plugins/network_plugin/test:unittest",
"services/ipc/test:unittest", "services/ipc/test:unittest",
"services/plugin_service/test:unittest", "services/plugin_service/test:unittest",
"services/profiler_service/test:unittest", "services/profiler_service/test:unittest",
"services/shared_memory/test:unittest", "services/shared_memory/test:unittest",
] ]
} }
group("fuzztest") {
testonly = true
deps = [
"plugins/api/test/fuzztest/plugincreatesessioncmd_fuzzer:fuzztest",
"plugins/api/test/fuzztest/plugindestroysessioncmd_fuzzer:fuzztest",
"plugins/api/test/fuzztest/pluginstartsessioncmd_fuzzer:fuzztest",
"plugins/api/test/fuzztest/pluginstopsessioncmd_fuzzer:fuzztest",
"plugins/cpu_plugin/test/fuzztest/cpustartplugin_fuzzer:fuzztest",
"plugins/diskio_plugin/test/fuzztest/diskiostartplugin_fuzzer:fuzztest",
"plugins/hilog_plugin/test/fuzztest/hilogstartplugin_fuzzer:fuzztest",
"plugins/memory_plugin/test/fuzztest/memorystartplugin_fuzzer:fuzztest",
"plugins/network_plugin/test/fuzztest/networkstartplugin_fuzzer:fuzztest",
"services/profiler_service/test/fuzztest/profilercreatesession_fuzzer:fuzztest",
"services/profiler_service/test/fuzztest/profilerdestroysession_fuzzer:fuzztest",
"services/profiler_service/test/fuzztest/profilerfetchdata_fuzzer:fuzztest",
"services/profiler_service/test/fuzztest/profilergetcapabilities_fuzzer:fuzztest",
"services/profiler_service/test/fuzztest/profilerkeepsession_fuzzer:fuzztest",
"services/profiler_service/test/fuzztest/profilerstartsession_fuzzer:fuzztest",
"services/profiler_service/test/fuzztest/profilerstopsession_fuzzer:fuzztest",
]
}

View File

@ -128,6 +128,9 @@ inline void StringReplace(std::string& str, const std::string& oldStr, const std
} }
} }
// let compiler check format string and variable arugments
static inline std::string StringFormat(const char* fmt, ...) __attribute__((format(printf, 1, 2)));
static inline std::string StringFormat(const char* fmt, ...) static inline std::string StringFormat(const char* fmt, ...)
{ {
va_list vargs; va_list vargs;
@ -190,7 +193,7 @@ static inline std::string StringFormat(const char* fmt, ...)
#define CHECK_NOTNULL(ptr, retval, fmt, ...) \ #define CHECK_NOTNULL(ptr, retval, fmt, ...) \
do { \ do { \
if (ptr == nullptr) { \ if (ptr == nullptr) { \
HILOG_WARN(LOG_CORE, "CHECK_NOTNULL(%{public}s) in %{public}s:%{public}d FAILED, " fmt, #ptr, __func__, \ HILOG_WARN(LOG_CORE, "CHECK_NOTNULL(%s) in %s:%d FAILED, " fmt, #ptr, __func__, \
__LINE__, ##__VA_ARGS__); \ __LINE__, ##__VA_ARGS__); \
return retval; \ return retval; \
} \ } \
@ -199,7 +202,7 @@ static inline std::string StringFormat(const char* fmt, ...)
#define CHECK_TRUE(expr, retval, fmt, ...) \ #define CHECK_TRUE(expr, retval, fmt, ...) \
do { \ do { \
if (!(expr)) { \ if (!(expr)) { \
HILOG_WARN(LOG_CORE, "CHECK_TRUE(%{public}s) in %{public}s:%{public}d FAILED, " fmt, #expr, __func__, \ HILOG_WARN(LOG_CORE, "CHECK_TRUE(%s) in %s:%d FAILED, " fmt, #expr, __func__, \
__LINE__, ##__VA_ARGS__); \ __LINE__, ##__VA_ARGS__); \
return retval; \ return retval; \
} \ } \

9
device/base/src/schedule_task_manager.cpp Normal file → Executable file
View File

@ -102,6 +102,7 @@ bool ScheduleTaskManager::ScheduleTask(const std::string& name,
timeMap_.insert(std::make_pair(task->nextRunTime, task)); timeMap_.insert(std::make_pair(task->nextRunTime, task));
taskCv_.notify_one(); taskCv_.notify_one();
DumpTask(task);
HILOG_DEBUG(LOG_CORE, "add schedule %s done, total: %zu", name.c_str(), taskMap_.size()); HILOG_DEBUG(LOG_CORE, "add schedule %s done, total: %zu", name.c_str(), taskMap_.size());
return true; return true;
} }
@ -143,7 +144,7 @@ void ScheduleTaskManager::DumpTask(const SharedTask& task)
if (task) { if (task) {
long msecs = std::chrono::duration_cast<ms>(task->nextRunTime.time_since_epoch()).count(); long msecs = std::chrono::duration_cast<ms>(task->nextRunTime.time_since_epoch()).count();
HILOG_DEBUG(LOG_CORE, HILOG_DEBUG(LOG_CORE,
"{name = %{public}s, interval = %{public}lld, delay = %{public}lld, nextRunTime = %{public}ld}", "{name = %s, interval = %lld, delay = %lld, nextRunTime = %ld}",
task->name.c_str(), task->repeatInterval.count(), task->initialDelay.count(), msecs); task->name.c_str(), task->repeatInterval.count(), task->initialDelay.count(), msecs);
} }
} }
@ -163,6 +164,7 @@ void ScheduleTaskManager::ScheduleThread()
auto taskTime = weakTask.lock(); // promote to shared_ptr auto taskTime = weakTask.lock(); // promote to shared_ptr
if (!taskTime) { if (!taskTime) {
// task cancelled with UnschduleTask or not a repeat task // task cancelled with UnschduleTask or not a repeat task
HILOG_INFO(LOG_CORE, "front task cacelled or not repeat task");
continue; continue;
} }
targetTime = taskTime->nextRunTime; targetTime = taskTime->nextRunTime;
@ -176,11 +178,14 @@ void ScheduleTaskManager::ScheduleThread()
auto taskRepeat = weakTask.lock(); auto taskRepeat = weakTask.lock();
if (!taskRepeat) { if (!taskRepeat) {
// task cancelled with UnschduleTask or not a repeat task // task cancelled with UnschduleTask
HILOG_INFO(LOG_CORE, "front task cacelled");
continue; continue;
} }
// call task callback // call task callback
HILOG_INFO(LOG_CORE, "on schedule %s, do callback!", taskRepeat->name.c_str());
DumpTask(taskRepeat);
taskRepeat->callback(); taskRepeat->callback();
taskRepeat->nextRunTime = targetTime + taskRepeat->repeatInterval; taskRepeat->nextRunTime = targetTime + taskRepeat->repeatInterval;

115
device/cmds/src/main.cpp Normal file → Executable file
View File

@ -14,11 +14,12 @@
*/ */
#include "command_line.h" #include "command_line.h"
#include "profiler_service.grpc.pb.h"
#include "google/protobuf/text_format.h" #include "google/protobuf/text_format.h"
#include "profiler_service.grpc.pb.h"
#include <grpcpp/grpcpp.h> #include <grpcpp/grpcpp.h>
#include <cinttypes>
#include <cstdio> #include <cstdio>
#include <cstring> #include <cstring>
#include <fstream> #include <fstream>
@ -29,26 +30,30 @@
#include <ifaddrs.h> #include <ifaddrs.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h>
namespace { namespace {
const int ADDR_BUFFER_SIZE = 128; constexpr int ADDR_BUFFER_SIZE = 128;
const int MS_PER_S = 1000; constexpr int MS_PER_S = 1000;
constexpr uint16_t SERVICE_PORT = 50051;
constexpr uint32_t US_PER_MS = 1000;
std::string GetIpAddr() uint32_t g_sampleDuration = 0;
std::string GetLoopbackAddress()
{ {
char addressBuffer[ADDR_BUFFER_SIZE] = {0}; char addressBuffer[ADDR_BUFFER_SIZE] = "";
struct ifaddrs* ifAddrStruct = nullptr; struct ifaddrs* ifAddrStruct = nullptr;
void* tmpAddrPtr = nullptr; void* tmpAddrPtr = nullptr;
getifaddrs(&ifAddrStruct); getifaddrs(&ifAddrStruct);
while (ifAddrStruct != nullptr) { while (ifAddrStruct != nullptr) {
if (ifAddrStruct->ifa_addr->sa_family == AF_INET) { if (ifAddrStruct->ifa_addr->sa_family == AF_INET) {
// is a valid IP4 Address // is a valid IP4 Address
tmpAddrPtr = &((reinterpret_cast<struct sockaddr_in*>(ifAddrStruct->ifa_addr))->sin_addr); tmpAddrPtr = &((reinterpret_cast<struct sockaddr_in*>(ifAddrStruct->ifa_addr))->sin_addr);
inet_ntop(AF_INET, tmpAddrPtr, addressBuffer, INET_ADDRSTRLEN); inet_ntop(AF_INET, tmpAddrPtr, addressBuffer, INET_ADDRSTRLEN);
if (strcmp(addressBuffer, "127.0.0.1") != 0) { if (strcmp(addressBuffer, "127.0.0.1") == 0) {
return addressBuffer; break;
} }
} else if (ifAddrStruct->ifa_addr->sa_family == AF_INET6) { // check it is IP6 } else if (ifAddrStruct->ifa_addr->sa_family == AF_INET6) { // check it is IP6
// is a valid IP6 Address // is a valid IP6 Address
@ -57,9 +62,16 @@ std::string GetIpAddr()
} }
ifAddrStruct = ifAddrStruct->ifa_next; ifAddrStruct = ifAddrStruct->ifa_next;
} }
freeifaddrs(ifAddrStruct);
return addressBuffer; return addressBuffer;
} }
uint16_t GetServicePort()
{
return SERVICE_PORT;
}
std::string ReadFileToString(const std::string& fileName) std::string ReadFileToString(const std::string& fileName)
{ {
std::ifstream inputString(fileName, std::ios::in); std::ifstream inputString(fileName, std::ios::in);
@ -67,41 +79,42 @@ std::string ReadFileToString(const std::string& fileName)
printf("can't open %s\n", fileName.c_str()); printf("can't open %s\n", fileName.c_str());
return ""; return "";
} }
std::string content(std::istreambuf_iterator<char> {inputString}, std::istreambuf_iterator<char> {}); std::string content(std::istreambuf_iterator<char>(inputString), {});
return content; return content;
} }
std::string ReadConfigContent(const std::string& configFileName) std::string ReadConfigContent(const std::string& configFile)
{ {
std::string content; std::string content;
if (configFileName == "-") { // Read configuration information from standard input if (configFile == "-") { // Read configuration information from standard input
std::string line; std::string line;
while (std::getline(std::cin, line)) { while (std::getline(std::cin, line)) {
content += line + "\n"; content += line + "\n";
} }
} else { } else {
content = ReadFileToString(configFileName); content = ReadFileToString(configFile);
} }
return content; return content;
} }
std::unique_ptr<CreateSessionRequest> MakeCreateRequest(const std::string& configFileName, std::unique_ptr<CreateSessionRequest> MakeCreateRequest(const std::string& configFile,
const std::string& keepSecond, const std::string& outputFileName) const std::string& keepSecond,
const std::string& outputFile)
{ {
auto request = std::make_unique<CreateSessionRequest>(); auto request = std::make_unique<CreateSessionRequest>();
if (!request) { if (!request) {
return nullptr; return nullptr;
} }
std::string content = ReadConfigContent(configFileName); std::string content = ReadConfigContent(configFile);
if (content.empty()) { if (content.empty()) {
printf("config file empty!"); printf("config file empty!");
return nullptr; return nullptr;
} }
printf("================================\n"); printf("================================\n");
printf("CONFIG: read %zu bytes from %s:\n%s", content.size(), configFileName.c_str(), content.c_str()); printf("CONFIG: read %zu bytes from %s:\n%s", content.size(), configFile.c_str(), content.c_str());
if (!google::protobuf::TextFormat::ParseFromString(content, request.get())) { if (!google::protobuf::TextFormat::ParseFromString(content, request.get())) {
printf("config file [%s] parse FAILED!\n", configFileName.c_str()); printf("config file [%s] parse FAILED!\n", configFile.c_str());
return nullptr; return nullptr;
} }
@ -112,17 +125,18 @@ std::unique_ptr<CreateSessionRequest> MakeCreateRequest(const std::string& confi
request->set_request_id(1); request->set_request_id(1);
printf("--------------------------------\n"); printf("--------------------------------\n");
printf("keepSecond: %s,\noutputFileName: %s\n", keepSecond.c_str(), outputFileName.c_str()); printf("keepSecond: %s,\noutputFileName: %s\n", keepSecond.c_str(), outputFile.c_str());
if (!keepSecond.empty()) { if (!keepSecond.empty()) {
int ks = std::stoi(keepSecond); int ks = std::stoi(keepSecond);
if (ks > 0) { if (ks > 0) {
sessionConfig->set_sample_duration(ks * MS_PER_S); sessionConfig->set_sample_duration(ks * MS_PER_S);
} }
} }
if (!outputFileName.empty()) { if (!outputFile.empty()) {
sessionConfig->set_result_file(outputFileName); sessionConfig->set_result_file(outputFile);
} }
g_sampleDuration = sessionConfig->sample_duration();
content.clear(); content.clear();
if (!google::protobuf::TextFormat::PrintToString(*request.get(), &content)) { if (!google::protobuf::TextFormat::PrintToString(*request.get(), &content)) {
printf("config message format FAILED!\n"); printf("config message format FAILED!\n");
@ -136,7 +150,8 @@ std::unique_ptr<CreateSessionRequest> MakeCreateRequest(const std::string& confi
std::unique_ptr<IProfilerService::Stub> GetProfilerServiceStub() std::unique_ptr<IProfilerService::Stub> GetProfilerServiceStub()
{ {
auto grpcChannel = grpc::CreateChannel("localhost:50051", grpc::InsecureChannelCredentials()); std::string serviceUri = GetLoopbackAddress() + ":" + std::to_string(GetServicePort());
auto grpcChannel = grpc::CreateChannel(serviceUri, grpc::InsecureChannelCredentials());
if (grpcChannel == nullptr) { if (grpcChannel == nullptr) {
printf("FAIL\nCreate gRPC channel failed!\n"); printf("FAIL\nCreate gRPC channel failed!\n");
return nullptr; return nullptr;
@ -144,8 +159,7 @@ std::unique_ptr<IProfilerService::Stub> GetProfilerServiceStub()
return IProfilerService::NewStub(grpcChannel); return IProfilerService::NewStub(grpcChannel);
} }
uint32_t CreateSession(const std::string& configFileName, uint32_t CreateSession(const std::string& configFile, const std::string& keepSecond, const std::string& outputFile)
const std::string& keepSecond, const std::string& outputFileName)
{ {
auto profilerStub = GetProfilerServiceStub(); auto profilerStub = GetProfilerServiceStub();
if (profilerStub == nullptr) { if (profilerStub == nullptr) {
@ -153,7 +167,7 @@ uint32_t CreateSession(const std::string& configFileName,
return 0; return 0;
} }
auto request = MakeCreateRequest(configFileName, keepSecond, outputFileName); auto request = MakeCreateRequest(configFile, keepSecond, outputFile);
if (!request) { if (!request) {
printf("FAIL\nMakeCreateRequest failed!\n"); printf("FAIL\nMakeCreateRequest failed!\n");
return 0; return 0;
@ -170,10 +184,9 @@ uint32_t CreateSession(const std::string& configFileName,
return createResponse.session_id(); return createResponse.session_id();
} }
bool StartSession(const std::string& configFileName, bool DoCapture(const std::string& configFile, const std::string& keepSecond, const std::string& outputFile)
const std::string& keepSecond, const std::string& outputFileName)
{ {
uint32_t sessionId = CreateSession(configFileName, keepSecond, outputFileName); uint32_t sessionId = CreateSession(configFile, keepSecond, outputFile);
auto profilerStub = GetProfilerServiceStub(); auto profilerStub = GetProfilerServiceStub();
if (profilerStub == nullptr) { if (profilerStub == nullptr) {
printf("FAIL\nGet profiler service stub failed!\n"); printf("FAIL\nGet profiler service stub failed!\n");
@ -184,13 +197,37 @@ bool StartSession(const std::string& configFileName,
StartSessionResponse startResponse; StartSessionResponse startResponse;
startRequest.set_request_id(0); startRequest.set_request_id(0);
startRequest.set_session_id(sessionId); startRequest.set_session_id(sessionId);
grpc::ClientContext startSessionContext; grpc::ClientContext startContext;
grpc::Status status = profilerStub->StartSession(&startSessionContext, startRequest, &startResponse); grpc::Status status = profilerStub->StartSession(&startContext, startRequest, &startResponse);
if (!status.ok()) { if (!status.ok()) {
printf("FAIL\nStartSession FAIL\n"); printf("FAIL\nStartSession FAIL\n");
return false; return false;
} }
printf("tracing %u ms....\n", g_sampleDuration);
usleep(g_sampleDuration * US_PER_MS);
StopSessionRequest stopRequest;
StopSessionResponse stopResponse;
grpc::ClientContext stopContext;
stopRequest.set_session_id(sessionId);
status = profilerStub->StopSession(&stopContext, stopRequest, &stopResponse);
if (!status.ok()) {
printf("FAIL\nStopSession FAIL\n");
return false;
}
printf("StopSession done!\n");
DestroySessionRequest destroyRequest;
DestroySessionResponse destroyResponse;
grpc::ClientContext destroyContext;
destroyRequest.set_session_id(sessionId);
status = profilerStub->DestroySession(&destroyContext, destroyRequest, &destroyResponse);
if (!status.ok()) {
printf("FAIL\nDestroySession FAIL\n");
return false;
}
printf("DestroySession done!\n");
return true; return true;
} }
} // namespace } // namespace
@ -202,14 +239,14 @@ int main(int argc, char* argv[])
bool isGetGrpcAddr = false; bool isGetGrpcAddr = false;
pCmdLine->AddParamSwitch("--getport", "-q", isGetGrpcAddr, "get grpc address"); pCmdLine->AddParamSwitch("--getport", "-q", isGetGrpcAddr, "get grpc address");
std::string configFileName; std::string configFile;
pCmdLine->AddParamText("--config", "-c", configFileName, "start trace by config file"); pCmdLine->AddParamText("--config", "-c", configFile, "start trace by config file");
std::string traceKeepSecond; std::string traceKeepSecond;
pCmdLine->AddParamText("--time", "-t", traceKeepSecond, "trace time"); pCmdLine->AddParamText("--time", "-t", traceKeepSecond, "trace time");
std::string outputFileName; std::string outputFile;
pCmdLine->AddParamText("--out", "-o", outputFileName, "output file name"); pCmdLine->AddParamText("--out", "-o", outputFile, "output file name");
bool isHelp = false; bool isHelp = false;
pCmdLine->AddParamSwitch("--help", "-h", isHelp, "make some help"); pCmdLine->AddParamSwitch("--help", "-h", isHelp, "make some help");
@ -240,17 +277,19 @@ int main(int argc, char* argv[])
return -1; return -1;
} }
printf("OK\nip:%s\nport:50051\n", GetIpAddr().c_str()); printf("OK\n");
printf("ip:%s\n", GetLoopbackAddress().c_str());
printf("port:%u\n", GetServicePort());
return 0; return 0;
} }
if (configFileName.empty()) { // normal case if (configFile.empty()) { // normal case
printf("FAIL\nconfig file argument must sepcified!"); printf("FAIL\nconfig file argument must sepcified!");
return 1; return 1;
} }
// Read the configFileName, call 'CreateSession', and 'StartSession' // do capture work
if (StartSession(configFileName, traceKeepSecond, outputFileName)) { if (DoCapture(configFile, traceKeepSecond, outputFile)) {
printf("OK\ntracing...\n"); printf("DONE\n");
} }
return 0; return 0;

2
device/format-code.sh Normal file → Executable file
View File

@ -23,6 +23,8 @@ GN_DIR=$TOP/prebuilts/build-tools/linux-x86/bin
export PATH=$CLANG_DIR:$GN_DIR:$PATH export PATH=$CLANG_DIR:$GN_DIR:$PATH
echo "formatting C/C++ code ..." echo "formatting C/C++ code ..."
find $@ -name '*.h' -o -name '*.cpp' | xargs dos2unix
find $@ -name '*.h' -o -name '*.cpp' | xargs chmod -x
find $@ -name '*.h' -o -name '*.cpp' | xargs clang-format --verbose -i find $@ -name '*.h' -o -name '*.cpp' | xargs clang-format --verbose -i
echo "formatting GN code ..." echo "formatting GN code ..."

134
device/ohos_test.xml Normal file → Executable file
View File

@ -30,7 +30,6 @@
<option name="push" value="developtools/developtools/libabsl_spinlock_wait.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_spinlock_wait.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_stacktrace.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_stacktrace.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_status.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_status.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_statusor.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_str_format_internal.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_str_format_internal.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_strings.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_strings.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_strings_internal.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_strings_internal.z.so -> /system/lib/" src="out"/>
@ -40,14 +39,12 @@
<option name="push" value="developtools/developtools/libabsl_time.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_time.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_time_zone.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_time_zone.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libaddress_sorting.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libaddress_sorting.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libagentplugin.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libares.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libares.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libbytraceplugin.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libbytraceplugin.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libcrypto.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libcrypto.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libgpr.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libgpr.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libgrpc.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libgrpc.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libgrpcxx.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libgrpcxx.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libhiperf_call_plugin.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libprotobuf.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libprotobuf.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libprotobuf_lite.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libprotobuf_lite.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libprotoc_lib.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libprotoc_lib.z.so -> /system/lib/" src="out"/>
@ -73,7 +70,6 @@
<option name="push" value="developtools/developtools/libabsl_spinlock_wait.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_spinlock_wait.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_stacktrace.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_stacktrace.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_status.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_status.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_statusor.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_str_format_internal.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_str_format_internal.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_strings.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_strings.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_strings_internal.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_strings_internal.z.so -> /system/lib/" src="out"/>
@ -83,14 +79,12 @@
<option name="push" value="developtools/developtools/libabsl_time.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_time.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_time_zone.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_time_zone.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libaddress_sorting.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libaddress_sorting.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libagentplugin.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libares.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libares.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libbytraceplugin.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libbytraceplugin.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libcrypto.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libcrypto.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libgpr.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libgpr.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libgrpc.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libgrpc.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libgrpcxx.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libgrpcxx.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libhiperf_call_plugin.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libprotobuf.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libprotobuf.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libprotobuf_lite.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libprotobuf_lite.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libprotoc_lib.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libprotoc_lib.z.so -> /system/lib/" src="out"/>
@ -116,7 +110,6 @@
<option name="push" value="developtools/developtools/libabsl_spinlock_wait.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_spinlock_wait.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_stacktrace.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_stacktrace.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_status.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_status.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_statusor.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_str_format_internal.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_str_format_internal.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_strings.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_strings.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_strings_internal.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_strings_internal.z.so -> /system/lib/" src="out"/>
@ -126,14 +119,12 @@
<option name="push" value="developtools/developtools/libabsl_time.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_time.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_time_zone.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_time_zone.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libaddress_sorting.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libaddress_sorting.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libagentplugin.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libares.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libares.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libbytraceplugin.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libbytraceplugin.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libcrypto.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libcrypto.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libgpr.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libgpr.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libgrpc.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libgrpc.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libgrpcxx.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libgrpcxx.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libhiperf_call_plugin.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libprotobuf.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libprotobuf.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libprotobuf_lite.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libprotobuf_lite.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libprotoc_lib.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libprotoc_lib.z.so -> /system/lib/" src="out"/>
@ -159,7 +150,6 @@
<option name="push" value="developtools/developtools/libabsl_spinlock_wait.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_spinlock_wait.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_stacktrace.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_stacktrace.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_status.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_status.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_statusor.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_str_format_internal.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_str_format_internal.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_strings.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_strings.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_strings_internal.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_strings_internal.z.so -> /system/lib/" src="out"/>
@ -169,14 +159,12 @@
<option name="push" value="developtools/developtools/libabsl_time.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_time.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_time_zone.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_time_zone.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libaddress_sorting.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libaddress_sorting.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libagentplugin.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libares.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libares.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libbytraceplugin.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libbytraceplugin.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libcrypto.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libcrypto.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libgpr.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libgpr.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libgrpc.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libgrpc.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libgrpcxx.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libgrpcxx.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libhiperf_call_plugin.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libprotobuf.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libprotobuf.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libprotobuf_lite.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libprotobuf_lite.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libprotoc_lib.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libprotoc_lib.z.so -> /system/lib/" src="out"/>
@ -202,7 +190,6 @@
<option name="push" value="developtools/developtools/libabsl_spinlock_wait.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_spinlock_wait.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_stacktrace.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_stacktrace.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_status.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_status.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_statusor.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_str_format_internal.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_str_format_internal.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_strings.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_strings.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_strings_internal.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_strings_internal.z.so -> /system/lib/" src="out"/>
@ -212,14 +199,12 @@
<option name="push" value="developtools/developtools/libabsl_time.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_time.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_time_zone.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_time_zone.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libaddress_sorting.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libaddress_sorting.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libagentplugin.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libares.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libares.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libbytraceplugin.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libbytraceplugin.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libcrypto.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libcrypto.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libgpr.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libgpr.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libgrpc.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libgrpc.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libgrpcxx.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libgrpcxx.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libhiperf_call_plugin.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libprotobuf.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libprotobuf.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libprotobuf_lite.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libprotobuf_lite.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libprotoc_lib.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libprotoc_lib.z.so -> /system/lib/" src="out"/>
@ -242,6 +227,7 @@
<option name="push" value="plugins/memory_plugin/test/utresources/proc/11/status -> /data/local/tmp/utresources/proc/11/" src="res"/> <option name="push" value="plugins/memory_plugin/test/utresources/proc/11/status -> /data/local/tmp/utresources/proc/11/" src="res"/>
<option name="push" value="plugins/memory_plugin/test/utresources/proc/cmdline -> /data/local/tmp/utresources/proc/" src="res"/> <option name="push" value="plugins/memory_plugin/test/utresources/proc/cmdline -> /data/local/tmp/utresources/proc/" src="res"/>
<option name="push" value="plugins/memory_plugin/test/utresources/proc/meminfo -> /data/local/tmp/utresources/proc/" src="res"/> <option name="push" value="plugins/memory_plugin/test/utresources/proc/meminfo -> /data/local/tmp/utresources/proc/" src="res"/>
<option name="push" value="plugins/memory_plugin/test/utresources/proc/vmstat -> /data/local/tmp/utresources/proc/" src="res"/>
<option name="push" value="developtools/developtools/libabsl_base.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_base.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_civil_time.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_civil_time.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_cord.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_cord.z.so -> /system/lib/" src="out"/>
@ -256,7 +242,6 @@
<option name="push" value="developtools/developtools/libabsl_spinlock_wait.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_spinlock_wait.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_stacktrace.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_stacktrace.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_status.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_status.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_statusor.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_str_format_internal.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_str_format_internal.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_strings.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_strings.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_strings_internal.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_strings_internal.z.so -> /system/lib/" src="out"/>
@ -266,14 +251,12 @@
<option name="push" value="developtools/developtools/libabsl_time.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_time.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_time_zone.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_time_zone.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libaddress_sorting.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libaddress_sorting.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libagentplugin.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libares.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libares.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libbytraceplugin.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libbytraceplugin.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libcrypto.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libcrypto.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libgpr.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libgpr.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libgrpc.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libgrpc.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libgrpcxx.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libgrpcxx.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libhiperf_call_plugin.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libprotobuf.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libprotobuf.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libprotobuf_lite.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libprotobuf_lite.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libprotoc_lib.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libprotoc_lib.z.so -> /system/lib/" src="out"/>
@ -281,6 +264,49 @@
<option name="push" value="developtools/developtools/./libmemdataplugin.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/./libmemdataplugin.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libshared_memory.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libshared_memory.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libssl.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libssl.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/memorytest -> /system/bin/" src="out"/>
</preparer>
</target>
<target name="smaps_stats_ut">
<preparer>
<option name="push" value="plugins/memory_plugin/test/utresources/proc/2/smaps -> /data/local/tmp/utresources/proc/2/" src="res"/>
<option name="push" value="developtools/developtools/libabsl_base.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_civil_time.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_cord.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_debugging_internal.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_demangle_internal.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_dynamic_annotations.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_graphcycles_internal.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_int128.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_log_severity.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_malloc_internal.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_raw_logging_internal.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_spinlock_wait.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_stacktrace.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_status.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_str_format_internal.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_strings.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_strings_internal.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_symbolize.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_synchronization.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_throw_delegate.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_time.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_time_zone.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libaddress_sorting.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libares.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libbytraceplugin.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libcrypto.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libgpr.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libgrpc.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libgrpcxx.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libprotobuf.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libprotobuf_lite.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libprotoc_lib.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libre2.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/./libmemdataplugin.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libshared_memory.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libssl.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/memorytest -> /system/bin/" src="out"/>
</preparer> </preparer>
</target> </target>
<target name="hiprofiler_plugins_ut"> <target name="hiprofiler_plugins_ut">
@ -299,7 +325,6 @@
<option name="push" value="developtools/developtools/libabsl_spinlock_wait.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_spinlock_wait.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_stacktrace.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_stacktrace.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_status.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_status.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_statusor.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_str_format_internal.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_str_format_internal.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_strings.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_strings.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_strings_internal.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_strings_internal.z.so -> /system/lib/" src="out"/>
@ -309,14 +334,12 @@
<option name="push" value="developtools/developtools/libabsl_time.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_time.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_time_zone.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_time_zone.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libaddress_sorting.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libaddress_sorting.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libagentplugin.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libares.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libares.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libbytraceplugin.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libbytraceplugin.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libcrypto.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libcrypto.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libgpr.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libgpr.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libgrpc.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libgrpc.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libgrpcxx.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libgrpcxx.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libhiperf_call_plugin.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libprotobuf.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libprotobuf.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libprotobuf_lite.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libprotobuf_lite.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libprotoc_lib.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libprotoc_lib.z.so -> /system/lib/" src="out"/>
@ -343,7 +366,6 @@
<option name="push" value="developtools/developtools/libabsl_spinlock_wait.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_spinlock_wait.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_stacktrace.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_stacktrace.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_status.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_status.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_statusor.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_str_format_internal.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_str_format_internal.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_strings.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_strings.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_strings_internal.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_strings_internal.z.so -> /system/lib/" src="out"/>
@ -353,20 +375,20 @@
<option name="push" value="developtools/developtools/libabsl_time.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_time.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_time_zone.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_time_zone.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libaddress_sorting.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libaddress_sorting.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libagentplugin.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libares.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libares.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libbytraceplugin.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libbytraceplugin.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libcrypto.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libcrypto.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libgpr.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libgpr.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libgrpc.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libgrpc.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libgrpcxx.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libgrpcxx.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libhiperf_call_plugin.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libprotobuf.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libprotobuf.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libprotobuf_lite.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libprotobuf_lite.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libprotoc_lib.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libprotoc_lib.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libre2.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libre2.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/./libmemdataplugin.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/./libmemdataplugin.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libshared_memory.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libshared_memory.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libsampleplugin.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libstreamplugin.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libssl.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libssl.z.so -> /system/lib/" src="out"/>
</preparer> </preparer>
</target> </target>
@ -413,7 +435,6 @@
<option name="push" value="developtools/developtools/libabsl_spinlock_wait.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_spinlock_wait.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_stacktrace.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_stacktrace.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_status.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_status.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_statusor.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_str_format_internal.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_str_format_internal.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_strings.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_strings.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_strings_internal.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_strings_internal.z.so -> /system/lib/" src="out"/>
@ -423,7 +444,6 @@
<option name="push" value="developtools/developtools/libabsl_time.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_time.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_time_zone.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_time_zone.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libaddress_sorting.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libaddress_sorting.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libagentplugin.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libares.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libares.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libbytraceplugin.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libbytraceplugin.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libcpudataplugin.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libcpudataplugin.z.so -> /system/lib/" src="out"/>
@ -432,7 +452,6 @@
<option name="push" value="developtools/developtools/libgpr.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libgpr.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libgrpc.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libgrpc.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libgrpcxx.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libgrpcxx.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libhiperf_call_plugin.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libprotobuf.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libprotobuf.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libprotobuf_lite.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libprotobuf_lite.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libprotoc_lib.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libprotoc_lib.z.so -> /system/lib/" src="out"/>
@ -459,7 +478,6 @@
<option name="push" value="developtools/developtools/libabsl_spinlock_wait.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_spinlock_wait.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_stacktrace.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_stacktrace.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_status.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_status.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_statusor.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_str_format_internal.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_str_format_internal.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_strings.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_strings.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_strings_internal.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_strings_internal.z.so -> /system/lib/" src="out"/>
@ -469,7 +487,6 @@
<option name="push" value="developtools/developtools/libabsl_time.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_time.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_time_zone.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_time_zone.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libaddress_sorting.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libaddress_sorting.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libagentplugin.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libares.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libares.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libbytraceplugin.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libbytraceplugin.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libcpudataplugin.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libcpudataplugin.z.so -> /system/lib/" src="out"/>
@ -478,7 +495,6 @@
<option name="push" value="developtools/developtools/libgpr.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libgpr.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libgrpc.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libgrpc.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libgrpcxx.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libgrpcxx.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libhiperf_call_plugin.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libprotobuf.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libprotobuf.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libprotobuf_lite.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libprotobuf_lite.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libprotoc_lib.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libprotoc_lib.z.so -> /system/lib/" src="out"/>
@ -488,7 +504,7 @@
<option name="push" value="developtools/developtools/libssl.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libssl.z.so -> /system/lib/" src="out"/>
</preparer> </preparer>
</target> </target>
<target name="networkplugin_ut"> <target name="networkplugin_ut">
<preparer> <preparer>
<option name="push" value="plugins/network_plugin/test/utresources/begin/proc/9553/status -> /data/local/tmp/utresources/begin/proc/9553/" src="res"/> <option name="push" value="plugins/network_plugin/test/utresources/begin/proc/9553/status -> /data/local/tmp/utresources/begin/proc/9553/" src="res"/>
<option name="push" value="plugins/network_plugin/test/utresources/begin/proc/net/xt_qtaguid/stats -> /data/local/tmp/utresources/begin/proc/net/xt_qtaguid/" src="res"/> <option name="push" value="plugins/network_plugin/test/utresources/begin/proc/net/xt_qtaguid/stats -> /data/local/tmp/utresources/begin/proc/net/xt_qtaguid/" src="res"/>
@ -508,7 +524,6 @@
<option name="push" value="developtools/developtools/libabsl_spinlock_wait.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_spinlock_wait.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_stacktrace.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_stacktrace.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_status.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_status.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_statusor.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_str_format_internal.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_str_format_internal.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_strings.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_strings.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_strings_internal.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_strings_internal.z.so -> /system/lib/" src="out"/>
@ -518,7 +533,6 @@
<option name="push" value="developtools/developtools/libabsl_time.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_time.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_time_zone.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_time_zone.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libaddress_sorting.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libaddress_sorting.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libagentplugin.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libares.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libares.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libbytraceplugin.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libbytraceplugin.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libcpudataplugin.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libcpudataplugin.z.so -> /system/lib/" src="out"/>
@ -527,7 +541,6 @@
<option name="push" value="developtools/developtools/libgpr.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libgpr.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libgrpc.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libgrpc.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libgrpcxx.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libgrpcxx.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libhiperf_call_plugin.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libprotobuf.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libprotobuf.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libprotobuf_lite.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libprotobuf_lite.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libprotoc_lib.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libprotoc_lib.z.so -> /system/lib/" src="out"/>
@ -535,12 +548,57 @@
<option name="push" value="developtools/developtools/./libmemdataplugin.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/./libmemdataplugin.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libshared_memory.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libshared_memory.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libssl.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libssl.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libnetworkplugin.z.so -> /system/lib/" src="out"/>
</preparer> </preparer>
</target> </target>
<target name="agent_ut"> <target name="hilogplugin_ut">
<preparer> <preparer>
<option name="push" value="developtools/developtools/libagentplugin.z.so -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_base.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/hiprofilerd -> /system/lib/" src="out"/> <option name="push" value="developtools/developtools/libabsl_civil_time.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_cord.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_debugging_internal.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_demangle_internal.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_dynamic_annotations.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_graphcycles_internal.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_int128.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_log_severity.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_malloc_internal.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_raw_logging_internal.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_spinlock_wait.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_stacktrace.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_status.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_str_format_internal.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_strings.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_strings_internal.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_symbolize.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_synchronization.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_throw_delegate.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_time.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libabsl_time_zone.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libaddress_sorting.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libares.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libbytraceplugin.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libcpudataplugin.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libcrypto.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libdiskiodataplugin.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libgpr.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libgrpc.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libgrpcxx.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libprotobuf.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libprotobuf_lite.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libprotoc_lib.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libre2.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/./libmemdataplugin.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libshared_memory.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libssl.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libnetworkplugin.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libhilogplugin.z.so -> /system/lib/" src="out"/>
</preparer> </preparer>
</target> </target>
</configuration> <target name="ftrace_plugin_ut">
<preparer>
<option name="push" value="developtools/developtools/libftrace_plugin.z.so -> /system/lib/" src="out"/>
<option name="push" value="developtools/developtools/libprotobuf_lite.z.so -> /system/lib/" src="out"/>
</preparer>
</target>
</configuration>

8
device/plugins/api/src/buffer_writer.cpp Normal file → Executable file
View File

@ -32,10 +32,10 @@ BufferWriter::BufferWriter(std::string name,
uint32_t pluginId) uint32_t pluginId)
: pluginName_(name) : pluginName_(name)
{ {
HILOG_INFO(LOG_CORE, "BufferWriter %s %d [%d] [%d]", name.c_str(), size, smbFd, eventFd); HILOG_INFO(LOG_CORE, "%s:%s %d [%d] [%d]", __func__, name.c_str(), size, smbFd, eventFd);
shareMemoryBlock_ = ShareMemoryAllocator::GetInstance().CreateMemoryBlockRemote(name, size, smbFd); shareMemoryBlock_ = ShareMemoryAllocator::GetInstance().CreateMemoryBlockRemote(name, size, smbFd);
if (shareMemoryBlock_ == nullptr) { if (shareMemoryBlock_ == nullptr) {
HILOG_DEBUG(LOG_CORE, "create shareMemoryBlock_ failed!"); HILOG_DEBUG(LOG_CORE, "%s:create shareMemoryBlock_ failed!", __func__);
} }
eventNotifier_ = EventNotifier::CreateWithFd(eventFd); eventNotifier_ = EventNotifier::CreateWithFd(eventFd);
pluginId_ = pluginId; pluginId_ = pluginId;
@ -44,14 +44,14 @@ BufferWriter::BufferWriter(std::string name,
BufferWriter::~BufferWriter() BufferWriter::~BufferWriter()
{ {
HILOG_DEBUG(LOG_CORE, "BufferWriter destroy eventfd = %d!", eventNotifier_ ? eventNotifier_->GetFd() : -1); HILOG_DEBUG(LOG_CORE, "%s:destroy eventfd = %d!", __func__, eventNotifier_ ? eventNotifier_->GetFd() : -1);
eventNotifier_ = nullptr; eventNotifier_ = nullptr;
ShareMemoryAllocator::GetInstance().ReleaseMemoryBlockRemote(pluginName_); ShareMemoryAllocator::GetInstance().ReleaseMemoryBlockRemote(pluginName_);
} }
void BufferWriter::Report() const void BufferWriter::Report() const
{ {
HILOG_DEBUG(LOG_CORE, "BufferWriter stats B: %" PRIu64 ", P: %d, W:%" PRIu64 ", F: %d", HILOG_DEBUG(LOG_CORE, "%s:stats B: %" PRIu64 ", P: %d, W:%" PRIu64 ", F: %d", __func__,
bytesCount_.load(), bytesPending_.load(), writeCount_.load(), flushCount_.load()); bytesCount_.load(), bytesPending_.load(), writeCount_.load(), flushCount_.load());
} }

4
device/plugins/api/src/buffer_writer.h Normal file → Executable file
View File

@ -23,9 +23,6 @@
#include "share_memory_allocator.h" #include "share_memory_allocator.h"
#include "writer.h" #include "writer.h"
class CommandPoller;
using CommandPollerPtr = STD_PTR(shared, CommandPoller);
class BufferWriter : public Writer { class BufferWriter : public Writer {
public: public:
@ -39,7 +36,6 @@ public:
bool Flush() override; bool Flush() override;
bool WriteMessage(const google::protobuf::Message& pmsg); bool WriteMessage(const google::protobuf::Message& pmsg);
private: private:
void DoStats(long bytes); void DoStats(long bytes);
void Report() const; void Report() const;

60
device/plugins/api/src/command_poller.cpp Normal file → Executable file
View File

@ -38,7 +38,11 @@ uint32_t CommandPoller::GetRequestId()
bool CommandPoller::OnCreateSessionCmd(const CreateSessionCmd& cmd, SocketContext& context) const bool CommandPoller::OnCreateSessionCmd(const CreateSessionCmd& cmd, SocketContext& context) const
{ {
HILOG_DEBUG(LOG_CORE, "OnCreateSessionCmd PROC"); HILOG_DEBUG(LOG_CORE, "%s:proc", __func__);
if (cmd.buffer_sizes().size() == 0 || cmd.plugin_configs().size() == 0) {
HILOG_ERROR(LOG_CORE, "%s:cmd invalid!", __func__);
return false;
}
uint32_t bufferSize = cmd.buffer_sizes(0); uint32_t bufferSize = cmd.buffer_sizes(0);
ProfilerPluginConfig config = cmd.plugin_configs(0); ProfilerPluginConfig config = cmd.plugin_configs(0);
std::vector<ProfilerPluginConfig> configVec; std::vector<ProfilerPluginConfig> configVec;
@ -48,34 +52,38 @@ bool CommandPoller::OnCreateSessionCmd(const CreateSessionCmd& cmd, SocketContex
CHECK_NOTNULL(pluginManager, false, "promote FAILED!"); CHECK_NOTNULL(pluginManager, false, "promote FAILED!");
if (!pluginManager->LoadPlugin(config.name())) { if (!pluginManager->LoadPlugin(config.name())) {
HILOG_DEBUG(LOG_CORE, "OnCreateSessionCmd FAIL 1"); HILOG_DEBUG(LOG_CORE, "%s:fail 1", __func__);
return false; return false;
} }
int smbFd = -1; int smbFd = -1;
int eventFd = -1; int eventFd = -1;
if (bufferSize != 0) { if (bufferSize != 0) {
HILOG_DEBUG(LOG_CORE, "OnCreateSessionCmd bufferSize = %d", bufferSize); HILOG_DEBUG(LOG_CORE, "%s:bufferSize = %d", __func__, bufferSize);
smbFd = context.ReceiveFileDiscriptor(); smbFd = context.ReceiveFileDiscriptor();
eventFd = context.ReceiveFileDiscriptor(); eventFd = context.ReceiveFileDiscriptor();
int flags = fcntl(eventFd, F_GETFL); int flags = fcntl(eventFd, F_GETFL);
HILOG_DEBUG(LOG_CORE, "OnCreateSessionCmd smbFd = %d, eventFd = %d", smbFd, eventFd); HILOG_DEBUG(LOG_CORE, "%s:smbFd = %d, eventFd = %d", __func__, smbFd, eventFd);
HILOG_DEBUG(LOG_CORE, "eventFd flags = %X", flags); HILOG_DEBUG(LOG_CORE, "%s:eventFd flags = %X", __func__, flags);
} }
if (!pluginManager->CreateWriter(config.name(), bufferSize, smbFd, eventFd)) { if (!pluginManager->CreateWriter(config.name(), bufferSize, smbFd, eventFd)) {
HILOG_DEBUG(LOG_CORE, "OnCreateSessionCmd CreateWriter FAIL"); HILOG_DEBUG(LOG_CORE, "%s:createWriter failed!", __func__);
return false; return false;
} }
if (!pluginManager->CreatePluginSession(configVec)) { if (!pluginManager->CreatePluginSession(configVec)) {
HILOG_DEBUG(LOG_CORE, "OnCreateSessionCmd CreatePluginSession FAIL"); HILOG_DEBUG(LOG_CORE, "%s:createPluginSession failed!", __func__);
return false; return false;
} }
HILOG_DEBUG(LOG_CORE, "OnCreateSessionCmd OK"); HILOG_DEBUG(LOG_CORE, "%s:ok", __func__);
return true; return true;
} }
bool CommandPoller::OnDestroySessionCmd(const DestroySessionCmd& cmd) const bool CommandPoller::OnDestroySessionCmd(const DestroySessionCmd& cmd) const
{ {
HILOG_DEBUG(LOG_CORE, "OnDestroySessionCmd PROC"); HILOG_DEBUG(LOG_CORE, "%s:proc", __func__);
if (cmd.plugin_ids().size() == 0) {
HILOG_ERROR(LOG_CORE, "%s:cmd invalid!", __func__);
return false;
}
uint32_t pluginId = cmd.plugin_ids(0); uint32_t pluginId = cmd.plugin_ids(0);
std::vector<uint32_t> pluginIdVec; std::vector<uint32_t> pluginIdVec;
pluginIdVec.push_back(pluginId); pluginIdVec.push_back(pluginId);
@ -84,24 +92,28 @@ bool CommandPoller::OnDestroySessionCmd(const DestroySessionCmd& cmd) const
CHECK_NOTNULL(pluginManager, false, "promote FAILED!"); CHECK_NOTNULL(pluginManager, false, "promote FAILED!");
if (!pluginManager->DestroyPluginSession(pluginIdVec)) { if (!pluginManager->DestroyPluginSession(pluginIdVec)) {
HILOG_DEBUG(LOG_CORE, "OnDestroySessionCmd DestroyPluginSession FAIL"); HILOG_DEBUG(LOG_CORE, "%s:destroyPluginSession failed!", __func__);
return false; return false;
} }
if (!pluginManager->ResetWriter(pluginId)) { if (!pluginManager->ResetWriter(pluginId)) {
HILOG_DEBUG(LOG_CORE, "OnDestroySessionCmd ResetWriter FAIL"); HILOG_DEBUG(LOG_CORE, "%s:resetWriter failed!", __func__);
return false; return false;
} }
if (!pluginManager->UnloadPlugin(pluginId)) { if (!pluginManager->UnloadPlugin(pluginId)) {
HILOG_DEBUG(LOG_CORE, "OnDestroySessionCmd UnloadPlugin FAIL"); HILOG_DEBUG(LOG_CORE, "%s:unloadPlugin failed!", __func__);
return false; return false;
} }
HILOG_DEBUG(LOG_CORE, "OnDestroySessionCmd OK"); HILOG_DEBUG(LOG_CORE, "%s:ok", __func__);
return true; return true;
} }
bool CommandPoller::OnStartSessionCmd(const StartSessionCmd& cmd) const bool CommandPoller::OnStartSessionCmd(const StartSessionCmd& cmd) const
{ {
HILOG_DEBUG(LOG_CORE, "OnStartSessionCmd PROC"); HILOG_DEBUG(LOG_CORE, "%s:proc", __func__);
if (cmd.plugin_ids().size() == 0 || cmd.plugin_configs().size() == 0) {
HILOG_ERROR(LOG_CORE, "%s:cmd invalid!", __func__);
return false;
}
std::vector<uint32_t> pluginIds; std::vector<uint32_t> pluginIds;
pluginIds.push_back(cmd.plugin_ids(0)); pluginIds.push_back(cmd.plugin_ids(0));
std::vector<ProfilerPluginConfig> configVec; std::vector<ProfilerPluginConfig> configVec;
@ -111,16 +123,20 @@ bool CommandPoller::OnStartSessionCmd(const StartSessionCmd& cmd) const
CHECK_NOTNULL(pluginManager, false, "promote FAILED!"); CHECK_NOTNULL(pluginManager, false, "promote FAILED!");
if (!pluginManager->StartPluginSession(pluginIds, configVec)) { if (!pluginManager->StartPluginSession(pluginIds, configVec)) {
HILOG_DEBUG(LOG_CORE, "OnStartSessionCmd FAIL"); HILOG_DEBUG(LOG_CORE, "%s:start Session failed!", __func__);
return false; return false;
} }
HILOG_DEBUG(LOG_CORE, "OnStartSessionCmd OK"); HILOG_DEBUG(LOG_CORE, "%s:OK", __func__);
return true; return true;
} }
bool CommandPoller::OnStopSessionCmd(const StopSessionCmd& cmd) const bool CommandPoller::OnStopSessionCmd(const StopSessionCmd& cmd) const
{ {
HILOG_DEBUG(LOG_CORE, "OnStopSessionCmd PROC"); HILOG_DEBUG(LOG_CORE, "%s:proc", __func__);
if (cmd.plugin_ids().size() == 0) {
HILOG_ERROR(LOG_CORE, "%s:cmd invalid!", __func__);
return false;
}
std::vector<uint32_t> pluginIds; std::vector<uint32_t> pluginIds;
pluginIds.push_back(cmd.plugin_ids(0)); pluginIds.push_back(cmd.plugin_ids(0));
@ -128,16 +144,16 @@ bool CommandPoller::OnStopSessionCmd(const StopSessionCmd& cmd) const
CHECK_NOTNULL(pluginManager, false, "promote FAILED!"); CHECK_NOTNULL(pluginManager, false, "promote FAILED!");
if (!pluginManager->StopPluginSession(pluginIds)) { if (!pluginManager->StopPluginSession(pluginIds)) {
HILOG_DEBUG(LOG_CORE, "OnStopSessionCmd FAIL"); HILOG_DEBUG(LOG_CORE, "%s:stop Session failed!", __func__);
return false; return false;
} }
HILOG_DEBUG(LOG_CORE, "OnStopSessionCmd OK"); HILOG_DEBUG(LOG_CORE, "%s:ok", __func__);
return true; return true;
} }
bool CommandPoller::OnGetCommandResponse(SocketContext& context, ::GetCommandResponse& response) bool CommandPoller::OnGetCommandResponse(SocketContext& context, ::GetCommandResponse& response)
{ {
HILOG_DEBUG(LOG_CORE, "OnGetCommandResponse"); HILOG_DEBUG(LOG_CORE, "%s:proc", __func__);
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME)); std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME));
NotifyResultRequest nrr; NotifyResultRequest nrr;
nrr.set_request_id(1); nrr.set_request_id(1);
@ -170,10 +186,10 @@ bool CommandPoller::OnGetCommandResponse(SocketContext& context, ::GetCommandRes
status->set_state(ProfilerPluginState::IN_SESSION); status->set_state(ProfilerPluginState::IN_SESSION);
} }
} else { } else {
HILOG_DEBUG(LOG_CORE, "OnGetCommandResponse FAIL"); HILOG_DEBUG(LOG_CORE, "%s:command Response failed!", __func__);
return false; return false;
} }
HILOG_DEBUG(LOG_CORE, "OnGetCommandResponse OK %d", nrr.command_id()); HILOG_DEBUG(LOG_CORE, "%s:ok id = %d", __func__, nrr.command_id());
NotifyResult(nrr); NotifyResult(nrr);
return true; return true;
} }

6
device/plugins/api/src/main.cpp Normal file → Executable file
View File

@ -35,7 +35,7 @@ int main(int argc, char* argv[])
{ {
std::string pluginDir(DEFAULT_PLUGIN_PATH); std::string pluginDir(DEFAULT_PLUGIN_PATH);
if (argv[1] != nullptr) { if (argv[1] != nullptr) {
HILOG_DEBUG(LOG_CORE, "pluginDir = %s", argv[1]); HILOG_DEBUG(LOG_CORE, "%s:pluginDir = %s", __func__, argv[1]);
pluginDir = argv[1]; pluginDir = argv[1];
} }
@ -48,12 +48,12 @@ int main(int argc, char* argv[])
PluginWatcher watcher(pluginManager); PluginWatcher watcher(pluginManager);
if (!watcher.ScanPlugins(pluginDir)) { if (!watcher.ScanPlugins(pluginDir)) {
HILOG_DEBUG(LOG_CORE, "Scan pluginDir:%s failed!", DEFAULT_PLUGIN_PATH); HILOG_DEBUG(LOG_CORE, "%s:scan pluginDir %s failed!", __func__, DEFAULT_PLUGIN_PATH);
return 0; return 0;
} }
if (!watcher.WatchPlugins(pluginDir)) { if (!watcher.WatchPlugins(pluginDir)) {
HILOG_DEBUG(LOG_CORE, "Monitor pluginDir:%s failed!", DEFAULT_PLUGIN_PATH); HILOG_DEBUG(LOG_CORE, "%s:monitor pluginDir %s failed!", __func__, DEFAULT_PLUGIN_PATH);
return 0; return 0;
} }

View File

@ -53,7 +53,7 @@ std::string ComputeFileSha256(const std::string& path)
result.push_back(HEX_CHARS[LHB(out[i])]); result.push_back(HEX_CHARS[LHB(out[i])]);
} }
HILOG_DEBUG(LOG_CORE, "SHA256(%s): %s", path.c_str(), result.c_str()); HILOG_DEBUG(LOG_CORE, "%s:%s-(%s)", __func__, path.c_str(), result.c_str());
return result; return result;
} }
} // namespace } // namespace
@ -70,29 +70,29 @@ bool PluginManager::AddPlugin(const std::string& pluginPath)
PluginModuleInfo info = {"", 0}; PluginModuleInfo info = {"", 0};
if (pluginIds_.find(pluginPath) != pluginIds_.end()) { if (pluginIds_.find(pluginPath) != pluginIds_.end()) {
HILOG_DEBUG(LOG_CORE, "already add"); HILOG_DEBUG(LOG_CORE, "%s:already add", __func__);
return false; return false;
} }
auto plugin = std::make_shared<PluginModule>(pluginPath); auto plugin = std::make_shared<PluginModule>(pluginPath);
if (!plugin->Load()) { if (!plugin->Load()) {
HILOG_DEBUG(LOG_CORE, "load failed"); HILOG_DEBUG(LOG_CORE, "%s:load failed!", __func__);
return false; return false;
} }
if (!plugin->BindFunctions()) { if (!plugin->BindFunctions()) {
HILOG_DEBUG(LOG_CORE, "BindFunctions failed %s", pluginPath.c_str()); HILOG_DEBUG(LOG_CORE, "%s:bindFunctions failed %s", __func__, pluginPath.c_str());
return false; return false;
} }
if (!plugin->GetInfo(info)) { if (!plugin->GetInfo(info)) {
HILOG_DEBUG(LOG_CORE, "getinfo failed"); HILOG_DEBUG(LOG_CORE, "%s:getinfo failed!", __func__);
return false; return false;
} }
HILOG_DEBUG(LOG_CORE, "add plugin name = %s", pluginPath.c_str()); HILOG_DEBUG(LOG_CORE, "%s:add plugin name = %s", __func__, pluginPath.c_str());
if (!plugin->Unload()) { if (!plugin->Unload()) {
HILOG_DEBUG(LOG_CORE, "unload failed"); HILOG_DEBUG(LOG_CORE, "%s:unload failed!", __func__);
return false; return false;
} }
@ -106,16 +106,16 @@ bool PluginManager::AddPlugin(const std::string& pluginPath)
if (commandPoller_->RegisterPlugin(request, response)) { if (commandPoller_->RegisterPlugin(request, response)) {
if (response.status() == 0) { if (response.status() == 0) {
HILOG_DEBUG(LOG_CORE, "response.plugin_id() = %d", response.plugin_id()); HILOG_DEBUG(LOG_CORE, "%s:response.plugin_id() = %d", __func__, response.plugin_id());
pluginIds_[pluginPath] = response.plugin_id(); pluginIds_[pluginPath] = response.plugin_id();
pluginModules_.insert(std::pair<uint32_t, std::shared_ptr<PluginModule>>(response.plugin_id(), plugin)); pluginModules_.insert(std::pair<uint32_t, std::shared_ptr<PluginModule>>(response.plugin_id(), plugin));
HILOG_DEBUG(LOG_CORE, "RegisterPlugin OK"); HILOG_DEBUG(LOG_CORE, "%s:registerPlugin ok", __func__);
} else { } else {
HILOG_DEBUG(LOG_CORE, "RegisterPlugin FAIL 1"); HILOG_DEBUG(LOG_CORE, "%s:registerPlugin fail 1", __func__);
return false; return false;
} }
} else { } else {
HILOG_DEBUG(LOG_CORE, "RegisterPlugin FAIL 2"); HILOG_DEBUG(LOG_CORE, "%s:registerPlugin fail 2", __func__);
return false; return false;
} }
@ -126,28 +126,53 @@ bool PluginManager::RemovePlugin(const std::string& pluginPath)
{ {
auto it = pluginIds_.find(pluginPath); auto it = pluginIds_.find(pluginPath);
if (it == pluginIds_.end()) { if (it == pluginIds_.end()) {
HILOG_DEBUG(LOG_CORE, "plugin not exist"); HILOG_DEBUG(LOG_CORE, "%s:plugin not exist", __func__);
return false; return false;
} }
uint32_t index = it->second; uint32_t index = it->second;
// stop plugin if plugin running
if (pluginModules_[index]->IsRunning()) {
HILOG_WARN(LOG_CORE, "%s:plugin delete while using, stop plugin", __func__);
// delete schedule task if POLLING mode
if (pluginModules_[index]->GetSampleMode() == PluginModule::POLLING) {
HILOG_WARN(LOG_CORE, "%s:delete schedule task plugin name = %s", __func__, pluginPath.c_str());
if (!scheduleTaskManager_.UnscheduleTask(pluginPath)) {
HILOG_WARN(LOG_CORE, "%s:delete schedule task plugin name = %s failed!", __func__, pluginPath.c_str());
}
}
if (!pluginModules_[index]->StopSession()) {
HILOG_WARN(LOG_CORE, "%s:plugin stop failed!", __func__);
}
}
// Unload plugin if plugin loaded
if (pluginModules_[index]->IsLoaded()) {
HILOG_WARN(LOG_CORE, "%s:plugin delete while using, unload plugin", __func__);
if (!pluginModules_[index]->Unload()) {
HILOG_WARN(LOG_CORE, "%s:unload plugin failed!", __func__);
}
}
UnregisterPluginRequest request; UnregisterPluginRequest request;
request.set_request_id(commandPoller_->GetRequestId()); request.set_request_id(commandPoller_->GetRequestId());
request.set_plugin_id(index); request.set_plugin_id(index);
UnregisterPluginResponse response; UnregisterPluginResponse response;
if (commandPoller_->UnregisterPlugin(request, response)) { if (commandPoller_->UnregisterPlugin(request, response)) {
if (response.status() != 0) { if (response.status() != 0) {
HILOG_DEBUG(LOG_CORE, "RegisterPlugin FAIL 1"); HILOG_DEBUG(LOG_CORE, "%s:registerPlugin fail 1", __func__);
return false; return false;
} }
} else { } else {
HILOG_DEBUG(LOG_CORE, "RegisterPlugin FAIL 2"); HILOG_DEBUG(LOG_CORE, "%s:registerPlugin fail 2", __func__);
return false; return false;
} }
auto itPluginModules = pluginModules_.find(index); auto itPluginModules = pluginModules_.find(index);
if (it == pluginIds_.end()) { if (it == pluginIds_.end()) {
HILOG_DEBUG(LOG_CORE, "plugin not exist"); HILOG_DEBUG(LOG_CORE, "%s:plugin not exist", __func__);
return false; return false;
} }
pluginModules_.erase(itPluginModules); pluginModules_.erase(itPluginModules);
@ -157,10 +182,10 @@ bool PluginManager::RemovePlugin(const std::string& pluginPath)
bool PluginManager::LoadPlugin(const std::string& pluginPath) bool PluginManager::LoadPlugin(const std::string& pluginPath)
{ {
HILOG_DEBUG(LOG_CORE, "size = %zu", pluginIds_.size()); HILOG_DEBUG(LOG_CORE, "%s:size = %zu", __func__, pluginIds_.size());
auto it = pluginIds_.find(pluginPath); auto it = pluginIds_.find(pluginPath);
if (it == pluginIds_.end()) { if (it == pluginIds_.end()) {
HILOG_DEBUG(LOG_CORE, "plugin not exist"); HILOG_DEBUG(LOG_CORE, "%s:plugin not exist", __func__);
return false; return false;
} }
uint32_t index = it->second; uint32_t index = it->second;
@ -178,7 +203,7 @@ bool PluginManager::UnloadPlugin(const std::string& pluginPath)
{ {
auto it = pluginIds_.find(pluginPath); auto it = pluginIds_.find(pluginPath);
if (it == pluginIds_.end()) { if (it == pluginIds_.end()) {
HILOG_DEBUG(LOG_CORE, "plugin not exist"); HILOG_DEBUG(LOG_CORE, "%s:plugin not exist", __func__);
return false; return false;
} }
@ -187,9 +212,9 @@ bool PluginManager::UnloadPlugin(const std::string& pluginPath)
bool PluginManager::UnloadPlugin(const uint32_t pluginId) bool PluginManager::UnloadPlugin(const uint32_t pluginId)
{ {
HILOG_INFO(LOG_CORE, "%s:UnloadPlugin ready!", __func__); HILOG_INFO(LOG_CORE, "%s:ready!", __func__);
if (pluginModules_.find(pluginId) == pluginModules_.end()) { if (pluginModules_.find(pluginId) == pluginModules_.end()) {
HILOG_DEBUG(LOG_CORE, "plugin not exist"); HILOG_DEBUG(LOG_CORE, "%s:plugin not exist", __func__);
return false; return false;
} }
if (!pluginModules_[pluginId]->Unload()) { if (!pluginModules_[pluginId]->Unload()) {
@ -200,17 +225,17 @@ bool PluginManager::UnloadPlugin(const uint32_t pluginId)
bool PluginManager::CreatePluginSession(const std::vector<ProfilerPluginConfig>& config) bool PluginManager::CreatePluginSession(const std::vector<ProfilerPluginConfig>& config)
{ {
HILOG_DEBUG(LOG_CORE, "CreatePluginSession"); HILOG_DEBUG(LOG_CORE, "%s:ready", __func__);
for (size_t idx = 0; idx < config.size(); ++idx) { for (size_t idx = 0; idx < config.size(); ++idx) {
HILOG_DEBUG(LOG_CORE, "config->name() = %s", config[idx].name().c_str()); HILOG_DEBUG(LOG_CORE, "%s:config->name() = %s", __func__, config[idx].name().c_str());
auto it = pluginIds_.find(config[idx].name()); auto it = pluginIds_.find(config[idx].name());
if (it == pluginIds_.end()) { if (it == pluginIds_.end()) {
HILOG_DEBUG(LOG_CORE, "plugin not find"); HILOG_DEBUG(LOG_CORE, "%s:plugin not find", __func__);
return false; return false;
} }
HILOG_DEBUG(LOG_CORE, "index = %d", it->second); HILOG_DEBUG(LOG_CORE, "%s:index = %d", __func__, it->second);
pluginModules_[it->second]->SetConfigData(config[idx].config_data()); pluginModules_[it->second]->SetConfigData(config[idx].config_data());
} }
return true; return true;
@ -221,7 +246,7 @@ bool PluginManager::DestroyPluginSession(const std::vector<uint32_t>& pluginIds)
for (uint32_t id : pluginIds) { for (uint32_t id : pluginIds) {
auto it = pluginModules_.find(id); auto it = pluginModules_.find(id);
if (it == pluginModules_.end()) { if (it == pluginModules_.end()) {
HILOG_DEBUG(LOG_CORE, "plugin not find"); HILOG_DEBUG(LOG_CORE, "%s:plugin not find", __func__);
return false; return false;
} }
} }
@ -231,13 +256,13 @@ bool PluginManager::DestroyPluginSession(const std::vector<uint32_t>& pluginIds)
bool PluginManager::StartPluginSession(const std::vector<uint32_t>& pluginIds, bool PluginManager::StartPluginSession(const std::vector<uint32_t>& pluginIds,
const std::vector<ProfilerPluginConfig>& config) const std::vector<ProfilerPluginConfig>& config)
{ {
HILOG_INFO(LOG_CORE, "%s: ready!", __func__); HILOG_INFO(LOG_CORE, "%s:ready!", __func__);
size_t idx = 0; size_t idx = 0;
for (uint32_t id : pluginIds) { for (uint32_t id : pluginIds) {
auto it = pluginModules_.find(id); auto it = pluginModules_.find(id);
if (it == pluginModules_.end()) { if (it == pluginModules_.end()) {
HILOG_DEBUG(LOG_CORE, "plugin not find"); HILOG_DEBUG(LOG_CORE, "%s:plugin not find", __func__);
return false; return false;
} }
auto plugin = pluginModules_[id]; auto plugin = pluginModules_[id];
@ -247,16 +272,20 @@ bool PluginManager::StartPluginSession(const std::vector<uint32_t>& pluginIds,
} }
if (plugin->GetSampleMode() == PluginModule::POLLING) { if (plugin->GetSampleMode() == PluginModule::POLLING) {
if (idx > config.size()) { if (idx > config.size()) {
HILOG_WARN(LOG_CORE, "idx %zu out of size %zu", idx, config.size()); HILOG_WARN(LOG_CORE, "%s:idx %zu out of size %zu", __func__, idx, config.size());
return false; return false;
} }
auto interval = ScheduleTaskManager::ms(config[idx].sample_interval()); auto interval = ScheduleTaskManager::ms(config[idx].sample_interval());
std::string pluginName = config[idx].name(); std::string pluginName = config[idx].name();
HILOG_DEBUG(LOG_CORE, "interval = %ld", static_cast<long>(interval.count())); HILOG_DEBUG(LOG_CORE, "%s:interval = %ld", __func__, static_cast<long>(interval.count()));
HILOG_DEBUG(LOG_CORE, "pluginName = %s", pluginName.c_str()); HILOG_DEBUG(LOG_CORE, "%s:pluginName = %s", __func__, pluginName.c_str());
auto callback = std::bind(&PluginManager::PullResult, this, id); auto callback = std::bind(&PluginManager::PullResult, this, id);
if (interval.count() == 0) {
HILOG_DEBUG(LOG_CORE, "%s:scheduleTask interval == 0 error!", __func__);
return false;
}
if (!scheduleTaskManager_.ScheduleTask(pluginName, callback, interval)) { if (!scheduleTaskManager_.ScheduleTask(pluginName, callback, interval)) {
HILOG_DEBUG(LOG_CORE, "ScheduleTask failed"); HILOG_DEBUG(LOG_CORE, "%s:scheduleTask failed!", __func__);
return false; return false;
} }
} }
@ -269,16 +298,16 @@ bool PluginManager::StartPluginSession(const std::vector<uint32_t>& pluginIds,
bool PluginManager::StopPluginSession(const std::vector<uint32_t>& pluginIds) bool PluginManager::StopPluginSession(const std::vector<uint32_t>& pluginIds)
{ {
HILOG_INFO(LOG_CORE, "%s:stop session ready!", __func__); HILOG_INFO(LOG_CORE, "%s:ready!", __func__);
for (uint32_t id : pluginIds) { for (uint32_t id : pluginIds) {
if (pluginModules_.find(id) == pluginModules_.end()) { if (pluginModules_.find(id) == pluginModules_.end()) {
HILOG_DEBUG(LOG_CORE, "plugin not find"); HILOG_DEBUG(LOG_CORE, "%s:plugin not find", __func__);
return false; return false;
} }
if (pluginModules_[id]->GetSampleMode() == PluginModule::POLLING) { if (pluginModules_[id]->GetSampleMode() == PluginModule::POLLING) {
for (auto it : pluginIds_) { for (auto it : pluginIds_) {
if (it.second == id) { if (it.second == id) {
HILOG_DEBUG(LOG_CORE, "find plugin name = %s", it.first.c_str()); HILOG_DEBUG(LOG_CORE, "%s:find plugin name = %s", __func__, it.first.c_str());
if (!scheduleTaskManager_.UnscheduleTask(it.first)) { if (!scheduleTaskManager_.UnscheduleTask(it.first)) {
return false; return false;
} }
@ -294,10 +323,10 @@ bool PluginManager::StopPluginSession(const std::vector<uint32_t>& pluginIds)
bool PluginManager::SubmitResult(const PluginResult& pluginResult) bool PluginManager::SubmitResult(const PluginResult& pluginResult)
{ {
HILOG_DEBUG(LOG_CORE, "==================SubmitResult ==============="); HILOG_INFO(LOG_CORE, "%s:ready!", __func__);
NotifyResultRequest request; NotifyResultRequest request;
if (commandPoller_ == nullptr) { if (commandPoller_ == nullptr) {
HILOG_DEBUG(LOG_CORE, "SubmitResult:commandPoller_ is null"); HILOG_DEBUG(LOG_CORE, "%s:commandPoller_ is null", __func__);
return false; return false;
} }
request.set_request_id(commandPoller_->GetRequestId()); request.set_request_id(commandPoller_->GetRequestId());
@ -306,14 +335,14 @@ bool PluginManager::SubmitResult(const PluginResult& pluginResult)
*p = pluginResult; *p = pluginResult;
NotifyResultResponse response; NotifyResultResponse response;
if (!commandPoller_->NotifyResult(request, response)) { if (!commandPoller_->NotifyResult(request, response)) {
HILOG_DEBUG(LOG_CORE, "SubmitResult FAIL 1"); HILOG_DEBUG(LOG_CORE, "%s:fail 1", __func__);
return false; return false;
} }
if (response.status() != 0) { if (response.status() != 0) {
HILOG_DEBUG(LOG_CORE, "SubmitResult FAIL 2"); HILOG_DEBUG(LOG_CORE, "%s:fail 2", __func__);
return false; return false;
} }
HILOG_DEBUG(LOG_CORE, "SubmitResult OK"); HILOG_DEBUG(LOG_CORE, "%s:ok", __func__);
return true; return true;
} }
@ -323,14 +352,14 @@ bool PluginManager::PullResult(uint32_t pluginId)
std::string name = ""; std::string name = "";
auto it = pluginModules_.find(pluginId); auto it = pluginModules_.find(pluginId);
if (it == pluginModules_.end()) { if (it == pluginModules_.end()) {
HILOG_DEBUG(LOG_CORE, "plugin not find"); HILOG_DEBUG(LOG_CORE, "%s:plugin not find", __func__);
return false; return false;
} }
pluginModules_[pluginId]->GetBufferSizeHint(size); pluginModules_[pluginId]->GetBufferSizeHint(size);
pluginModules_[pluginId]->GetPluginName(name); pluginModules_[pluginId]->GetPluginName(name);
std::unique_ptr<uint8_t[]> buffer(new (std::nothrow) uint8_t[size]); std::unique_ptr<uint8_t[]> buffer(new (std::nothrow) uint8_t[size]);
if (buffer == nullptr) { if (buffer == nullptr) {
HILOG_DEBUG(LOG_CORE, "buffer new failed!"); HILOG_DEBUG(LOG_CORE, "%s:buffer new failed!", __func__);
return false; return false;
} }
@ -363,17 +392,17 @@ bool PluginManager::CreateWriter(std::string pluginName, uint32_t bufferSize, in
{ {
auto it = pluginIds_.find(pluginName); auto it = pluginIds_.find(pluginName);
if (it == pluginIds_.end()) { if (it == pluginIds_.end()) {
HILOG_DEBUG(LOG_CORE, "plugin not exist"); HILOG_DEBUG(LOG_CORE, "%s:plugin not exist", __func__);
return false; return false;
} }
uint32_t index = it->second; uint32_t index = it->second;
if (bufferSize > 0) { if (bufferSize > 0) {
HILOG_DEBUG(LOG_CORE, "%s Use ShareMemory %d", pluginName.c_str(), bufferSize); HILOG_DEBUG(LOG_CORE, "%s:%s Use ShareMemory %d", __func__, pluginName.c_str(), bufferSize);
pluginModules_[index]->RegisterWriter( pluginModules_[index]->RegisterWriter(
std::make_shared<BufferWriter>(pluginName, bufferSize, smbFd, eventFd, index)); std::make_shared<BufferWriter>(pluginName, bufferSize, smbFd, eventFd, index));
} else { } else {
HILOG_ERROR(LOG_CORE, "no shared memory buffer allocated!"); HILOG_ERROR(LOG_CORE, "%s:no shared memory buffer allocated!", __func__);
return false; return false;
} }
return true; return true;
@ -382,10 +411,10 @@ bool PluginManager::CreateWriter(std::string pluginName, uint32_t bufferSize, in
bool PluginManager::ResetWriter(uint32_t pluginId) bool PluginManager::ResetWriter(uint32_t pluginId)
{ {
if (pluginModules_.find(pluginId) == pluginModules_.end()) { if (pluginModules_.find(pluginId) == pluginModules_.end()) {
HILOG_DEBUG(LOG_CORE, "plugin not exist"); HILOG_DEBUG(LOG_CORE, "%s:plugin not exist", __func__);
return false; return false;
} }
HILOG_DEBUG(LOG_CORE, "ResetWriter %u", pluginId); HILOG_DEBUG(LOG_CORE, "%s:resetWriter %u", __func__, pluginId);
pluginModules_[pluginId]->RegisterWriter(nullptr); pluginModules_[pluginId]->RegisterWriter(nullptr);
return true; return true;
} }

2
device/plugins/api/src/plugin_manager.h Normal file → Executable file
View File

@ -29,6 +29,8 @@ class ProfilerPluginConfig;
class PluginResult; class PluginResult;
class CommandPoller; class CommandPoller;
using CommandPollerPtr = STD_PTR(shared, CommandPoller);
class PluginManager : public ManagerInterface { class PluginManager : public ManagerInterface {
public: public:
virtual ~PluginManager(); virtual ~PluginManager();

38
device/plugins/api/src/plugin_module.cpp Normal file → Executable file
View File

@ -21,7 +21,8 @@
#include "logging.h" #include "logging.h"
#include "plugin_module_api.h" #include "plugin_module_api.h"
PluginModule::PluginModule(const std::string& path) : handle_(nullptr), path_(path), structPtr_(nullptr) {} PluginModule::PluginModule(const std::string& path) : handle_(nullptr), running_(false), path_(path),
structPtr_(nullptr) {}
PluginModule::~PluginModule() {} PluginModule::~PluginModule() {}
@ -34,19 +35,19 @@ bool PluginModule::Load()
{ {
char realPath[PATH_MAX + 1] = {0}; char realPath[PATH_MAX + 1] = {0};
if (handle_ != nullptr) { if (handle_ != nullptr) {
HILOG_DEBUG(LOG_CORE, "already open"); HILOG_DEBUG(LOG_CORE, "%s:already open", __func__);
return false; return false;
} }
if (realpath(path_.c_str(), realPath) == nullptr) { if (realpath(path_.c_str(), realPath) == nullptr) {
HILOG_ERROR(LOG_CORE, "so filename invalid, errno=%d", errno); HILOG_ERROR(LOG_CORE, "%s:so filename invalid, errno=%d", __func__, errno);
return false; return false;
} }
std::string rpath = realPath; // for SC warning std::string rpath = realPath; // for SC warning
handle_ = dlopen(rpath.c_str(), RTLD_NOW); handle_ = dlopen(rpath.c_str(), RTLD_NOW);
if (handle_ == nullptr) { if (handle_ == nullptr) {
HILOG_DEBUG(LOG_CORE, "dlopen err:%s.", dlerror()); HILOG_DEBUG(LOG_CORE, "%s:dlopen err:%s.", __func__, dlerror());
return false; return false;
} }
return true; return true;
@ -56,9 +57,8 @@ bool PluginModule::Unload()
{ {
HILOG_INFO(LOG_CORE, "%s:unload ready!", __func__); HILOG_INFO(LOG_CORE, "%s:unload ready!", __func__);
if (handle_ != nullptr) { if (handle_ != nullptr) {
HILOG_INFO(LOG_CORE, "Unload plugin");
int ret = dlclose(handle_); int ret = dlclose(handle_);
HILOG_INFO(LOG_CORE, "Unload plugin ret = %d", ret); HILOG_INFO(LOG_CORE, "%s:unload plugin ret = %d", __func__, ret);
handle_ = nullptr; handle_ = nullptr;
structPtr_ = nullptr; structPtr_ = nullptr;
return true; return true;
@ -130,28 +130,34 @@ bool PluginModule::IsLoaded()
{ {
return (handle_ != nullptr); return (handle_ != nullptr);
} }
bool PluginModule::IsRunning()
{
return running_;
}
bool PluginModule::BindFunctions() bool PluginModule::BindFunctions()
{ {
if (handle_ == nullptr) { if (handle_ == nullptr) {
HILOG_DEBUG(LOG_CORE, "plugin not load"); HILOG_DEBUG(LOG_CORE, "%s:plugin not load", __func__);
return false; return false;
} }
if (structPtr_ == nullptr) { if (structPtr_ == nullptr) {
structPtr_ = static_cast<PluginModuleStruct*>(dlsym(handle_, "g_pluginModule")); structPtr_ = static_cast<PluginModuleStruct*>(dlsym(handle_, "g_pluginModule"));
if (structPtr_ == nullptr) { if (structPtr_ == nullptr) {
HILOG_DEBUG(LOG_CORE, "structPtr_ == nullptr"); HILOG_DEBUG(LOG_CORE, "%s:structPtr_ == nullptr", __func__);
return false; return false;
} }
} }
if (structPtr_->callbacks == nullptr) { if (structPtr_->callbacks == nullptr) {
HILOG_DEBUG(LOG_CORE, "structPtr_->callbacks == nullptr"); HILOG_DEBUG(LOG_CORE, "%s:structPtr_->callbacks == nullptr", __func__);
return false; return false;
} }
if ((structPtr_->callbacks->onPluginSessionStart == nullptr) || if ((structPtr_->callbacks->onPluginSessionStart == nullptr) ||
(structPtr_->callbacks->onPluginSessionStop == nullptr)) { (structPtr_->callbacks->onPluginSessionStop == nullptr)) {
HILOG_DEBUG(LOG_CORE, "onPluginSessionStart == nullptr"); HILOG_DEBUG(LOG_CORE, "%s:onPluginSessionStart == nullptr", __func__);
return false; return false;
} }
@ -162,12 +168,13 @@ bool PluginModule::StartSession(const uint8_t* buffer, uint32_t size)
{ {
HILOG_DEBUG(LOG_CORE, "StartSession"); HILOG_DEBUG(LOG_CORE, "StartSession");
if (handle_ == nullptr) { if (handle_ == nullptr) {
HILOG_DEBUG(LOG_CORE, "plugin not load"); HILOG_DEBUG(LOG_CORE, "%s:plugin not load", __func__);
return false; return false;
} }
if (structPtr_ != nullptr && structPtr_->callbacks != nullptr) { if (structPtr_ != nullptr && structPtr_->callbacks != nullptr) {
if (structPtr_->callbacks->onPluginSessionStart) { if (structPtr_->callbacks->onPluginSessionStart) {
running_ = true;
return (structPtr_->callbacks->onPluginSessionStart(buffer, size) == 0); return (structPtr_->callbacks->onPluginSessionStart(buffer, size) == 0);
} }
} }
@ -178,11 +185,12 @@ bool PluginModule::StopSession()
{ {
HILOG_INFO(LOG_CORE, "%s:stop Session ready!", __func__); HILOG_INFO(LOG_CORE, "%s:stop Session ready!", __func__);
if (handle_ == nullptr) { if (handle_ == nullptr) {
HILOG_DEBUG(LOG_CORE, "plugin not load"); HILOG_DEBUG(LOG_CORE, "%s:plugin not load", __func__);
return false; return false;
} }
if (structPtr_ != nullptr && structPtr_->callbacks != nullptr) { if (structPtr_ != nullptr && structPtr_->callbacks != nullptr) {
if (structPtr_->callbacks->onPluginSessionStop != nullptr) { if (structPtr_->callbacks->onPluginSessionStop != nullptr) {
running_ = false;
return (structPtr_->callbacks->onPluginSessionStop() == 0); return (structPtr_->callbacks->onPluginSessionStop() == 0);
} }
} }
@ -192,7 +200,7 @@ bool PluginModule::StopSession()
int32_t PluginModule::ReportResult(uint8_t* buffer, uint32_t size) int32_t PluginModule::ReportResult(uint8_t* buffer, uint32_t size)
{ {
if (handle_ == nullptr) { if (handle_ == nullptr) {
HILOG_DEBUG(LOG_CORE, "plugin not open"); HILOG_DEBUG(LOG_CORE, "%s:plugin not open", __func__);
return -1; return -1;
} }
if (first_) { if (first_) {
@ -218,7 +226,7 @@ bool PluginModule::RegisterWriter(const BufferWriterPtr writer)
writerAdapter_->SetWriter(writer); writerAdapter_->SetWriter(writer);
if (writer == nullptr) { if (writer == nullptr) {
HILOG_INFO(LOG_CORE, "BufferWriter is null, update WriterAdapter only!"); HILOG_INFO(LOG_CORE, "%s:bufferWriter is null, update WriterAdapter only!", __func__);
return true; return true;
} }
if (structPtr_ != nullptr && structPtr_->callbacks != nullptr) { if (structPtr_ != nullptr && structPtr_->callbacks != nullptr) {
@ -232,7 +240,7 @@ bool PluginModule::RegisterWriter(const BufferWriterPtr writer)
WriterPtr PluginModule::GetWriter() WriterPtr PluginModule::GetWriter()
{ {
if (writerAdapter_ == nullptr) { if (writerAdapter_ == nullptr) {
HILOG_DEBUG(LOG_CORE, "PluginModule 111111, nullptr"); HILOG_DEBUG(LOG_CORE, "%s:pluginModule nullptr", __func__);
return nullptr; return nullptr;
} }
return writerAdapter_->GetWriter(); return writerAdapter_->GetWriter();

3
device/plugins/api/src/plugin_module.h Normal file → Executable file
View File

@ -51,7 +51,7 @@ public:
bool GetInfo(PluginModuleInfo& info); bool GetInfo(PluginModuleInfo& info);
bool GetPluginName(std::string& pluginName); bool GetPluginName(std::string& pluginName);
bool GetBufferSizeHint(uint32_t& bufferSizeHint); bool GetBufferSizeHint(uint32_t& bufferSizeHint);
bool IsRunning();
bool IsLoaded(); bool IsLoaded();
bool BindFunctions(); bool BindFunctions();
@ -67,6 +67,7 @@ public:
private: private:
void* handle_; void* handle_;
bool running_;
std::string path_; std::string path_;
std::string pluginName_; std::string pluginName_;
std::string configData_; std::string configData_;

View File

@ -36,7 +36,7 @@ PluginWatcher::PluginWatcher(const PluginManagerPtr& pluginManager)
{ {
inotifyFd_ = inotify_init1(IN_CLOEXEC | IN_NONBLOCK); inotifyFd_ = inotify_init1(IN_CLOEXEC | IN_NONBLOCK);
if (inotifyFd_ < 0) { if (inotifyFd_ < 0) {
HILOG_INFO(LOG_CORE, "%s inotify_init1 failed! inotifyFd_ : %d", __FUNCTION__, inotifyFd_); HILOG_INFO(LOG_CORE, "%s:inotify_init1 failed! inotifyFd_ : %d", __func__, inotifyFd_);
} else { } else {
monitorThread_ = std::thread(&PluginWatcher::Monitor, this); monitorThread_ = std::thread(&PluginWatcher::Monitor, this);
} }
@ -61,7 +61,7 @@ bool PluginWatcher::ScanPlugins(const std::string& pluginDir)
struct dirent* entry = nullptr; struct dirent* entry = nullptr;
char fullpath[PATH_MAX + 1] = {0}; char fullpath[PATH_MAX + 1] = {0};
realpath(pluginDir.c_str(), fullpath); realpath(pluginDir.c_str(), fullpath);
HILOG_INFO(LOG_CORE, "scan plugin from directory %s", fullpath); HILOG_INFO(LOG_CORE, "%s:scan plugin from directory %s", __func__, fullpath);
dir = opendir(fullpath); dir = opendir(fullpath);
if (dir == nullptr) { if (dir == nullptr) {
return false; return false;
@ -69,7 +69,7 @@ bool PluginWatcher::ScanPlugins(const std::string& pluginDir)
while (true) { while (true) {
entry = readdir(dir); entry = readdir(dir);
if (!entry) { if (!entry) {
HILOG_INFO(LOG_CORE, "%s readdir finish!", __FUNCTION__); HILOG_INFO(LOG_CORE, "%s:readdir finish!", __func__);
break; break;
} }
std::string fileName = entry->d_name; std::string fileName = entry->d_name;
@ -91,10 +91,10 @@ bool PluginWatcher::WatchPlugins(const std::string& pluginDir)
int wd = inotify_add_watch(inotifyFd_, fullpath, IN_ALL_EVENTS); int wd = inotify_add_watch(inotifyFd_, fullpath, IN_ALL_EVENTS);
if (wd < 0) { if (wd < 0) {
HILOG_INFO(LOG_CORE, "inotify_add_watch add directory %s failed", pluginDir.c_str()); HILOG_INFO(LOG_CORE, "%s:inotify_add_watch add directory %s failed!", __func__, pluginDir.c_str());
return false; return false;
} }
HILOG_INFO(LOG_CORE, "inotify_add_watch add directory %s success", fullpath); HILOG_INFO(LOG_CORE, "%s:inotify_add_watch add directory %s success!", __func__, fullpath);
std::lock_guard<std::mutex> guard(mtx_); std::lock_guard<std::mutex> guard(mtx_);
wdToDir_.insert(std::pair<int, std::string>(wd, std::string(fullpath))); wdToDir_.insert(std::pair<int, std::string>(wd, std::string(fullpath)));
return true; return true;
@ -136,8 +136,8 @@ bool PluginWatcher::MonitorIsSet()
break; break;
} }
} }
if (memset_s(buffer, MAX_BUF_SIZE, 0, MAX_BUF_SIZE) != 0) { if (memset_s(buffer, sizeof(buffer), 0, sizeof(buffer)) != 0) {
HILOG_ERROR(LOG_CORE, "memset_s error!"); HILOG_ERROR(LOG_CORE, "%s:memset_s error!", __func__);
} }
return true; return true;
} }
@ -171,12 +171,12 @@ void PluginWatcher::OnPluginAdded(const std::string& pluginPath)
auto pluginManager = pluginManager_.lock(); auto pluginManager = pluginManager_.lock();
if (pluginManager != nullptr) { if (pluginManager != nullptr) {
if (pluginManager->AddPlugin(pluginPath)) { if (pluginManager->AddPlugin(pluginPath)) {
HILOG_INFO(LOG_CORE, "plugin %s add success", pluginPath.c_str()); HILOG_INFO(LOG_CORE, "%s:plugin %s add success!", __func__, pluginPath.c_str());
} else { } else {
HILOG_INFO(LOG_CORE, "pluginPath %s add failed", pluginPath.c_str()); HILOG_INFO(LOG_CORE, "%s:pluginPath %s add failed!", __func__, pluginPath.c_str());
} }
} else { } else {
HILOG_INFO(LOG_CORE, "%s weak_ptr pluginManager lock failed!", __FUNCTION__); HILOG_INFO(LOG_CORE, "%s:weak_ptr pluginManager lock failed!", __func__);
} }
} }
@ -185,11 +185,11 @@ void PluginWatcher::OnPluginRemoved(const std::string& pluginPath)
auto pluginManager = pluginManager_.lock(); auto pluginManager = pluginManager_.lock();
if (pluginManager != nullptr) { if (pluginManager != nullptr) {
if (pluginManager->RemovePlugin(pluginPath)) { if (pluginManager->RemovePlugin(pluginPath)) {
HILOG_INFO(LOG_CORE, "pluginPath %s remove success", pluginPath.c_str()); HILOG_INFO(LOG_CORE, "%s:pluginPath %s remove success!", __func__, pluginPath.c_str());
} else { } else {
HILOG_INFO(LOG_CORE, "pluginPath %s remove failed", pluginPath.c_str()); HILOG_INFO(LOG_CORE, "%s:pluginPath %s remove failed!", __func__, pluginPath.c_str());
} }
} else { } else {
HILOG_INFO(LOG_CORE, "%s weak_ptr pluginManager lock failed!", __FUNCTION__); HILOG_INFO(LOG_CORE, "%s:weak_ptr pluginManager lock failed!", __func__);
} }
} }

View File

@ -0,0 +1,48 @@
# 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.
#####################hydra-fuzz###################
import("//build/test.gni")
import("../../../../../base/config.gni")
module_output_path = "${OHOS_PROFILER_TEST_MODULE_OUTPUT_PATH}/device"
##############################fuzztest##########################################
ohos_fuzztest("PluginCreateSessionTest") {
module_out_path = module_output_path
include_dirs = []
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "plugincreatesessioncmd_fuzzer.cpp" ]
deps = [
#"${OHOS_PROFILER_DIR}/device/services/plugin_service:hiprofiler_plugin_service",
#"${OHOS_PROFILER_DIR}/device/services/profiler_service:profiler_service",
"../../..:plugins_sources",
]
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
}
###############################################################################
group("fuzztest") {
testonly = true
deps = []
deps += [
# deps file
":PluginCreateSessionTest",
]
}
###############################################################################

View File

@ -0,0 +1,50 @@
/*
* 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.
*/
#include "plugincreatesessioncmd_fuzzer.h"
#include <stddef.h>
#include <stdint.h>
#include "command_poller.h"
#include "plugin_manager.h"
#include "plugin_service.ipc.h"
#include "socket_context.h"
namespace OHOS {
bool CreateSessionTest(const uint8_t* data, size_t size)
{
auto pluginManage = std::make_shared<PluginManager>();
auto commandPoller = std::make_shared<CommandPoller>(pluginManage);
pluginManage->SetCommandPoller(commandPoller);
CreateSessionCmd successCmd;
SocketContext ctx;
if (!successCmd.ParseFromArray(data, size)) {
return true;
}
commandPoller->OnCreateSessionCmd(successCmd, ctx);
return true;
}
} // namespace OHOS
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::CreateSessionTest(data, size);
return 0;
}

View File

@ -0,0 +1,23 @@
/*
* 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.
*/
#include <climits>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <fcntl.h>
#include <unistd.h>
#define FUZZ_PROJECT_NAME "plugincreatesessioncmd_fuzzer"

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->
<fuzz_config>
<fuzztest>
<!-- maximum length of a test input -->
<max_len>1000</max_len>
<!-- maximum total time in seconds to run the fuzzer -->
<max_total_time>300</max_total_time>
<!-- memory usage limit in Mb -->
<rss_limit_mb>4096</rss_limit_mb>
</fuzztest>
</fuzz_config>

View File

@ -0,0 +1,48 @@
# 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.
#####################hydra-fuzz###################
import("//build/test.gni")
import("../../../../../base/config.gni")
module_output_path = "${OHOS_PROFILER_TEST_MODULE_OUTPUT_PATH}/device"
##############################fuzztest##########################################
ohos_fuzztest("PluginDestroySessionTest") {
module_out_path = module_output_path
include_dirs = []
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "plugindestroysessioncmd_fuzzer.cpp" ]
deps = [
#"${OHOS_PROFILER_DIR}/device/services/plugin_service:hiprofiler_plugin_service",
#"${OHOS_PROFILER_DIR}/device/services/profiler_service:profiler_service",
"../../..:plugins_sources",
]
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
}
###############################################################################
group("fuzztest") {
testonly = true
deps = []
deps += [
# deps file
":PluginDestroySessionTest",
]
}
###############################################################################

View File

@ -0,0 +1,49 @@
/*
* 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.
*/
#include "plugindestroysessioncmd_fuzzer.h"
#include <stddef.h>
#include <stdint.h>
#include "command_poller.h"
#include "plugin_manager.h"
#include "plugin_service.ipc.h"
#include "socket_context.h"
namespace OHOS {
bool DestroySessionTest(const uint8_t* data, size_t size)
{
auto pluginManage = std::make_shared<PluginManager>();
auto commandPoller = std::make_shared<CommandPoller>(pluginManage);
pluginManage->SetCommandPoller(commandPoller);
DestroySessionCmd successCmd;
if (!successCmd.ParseFromArray(data, size)) {
return true;
}
commandPoller->OnDestroySessionCmd(successCmd);
return true;
}
} // namespace OHOS
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::DestroySessionTest(data, size);
return 0;
}

View File

@ -0,0 +1,23 @@
/*
* 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.
*/
#include <climits>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <fcntl.h>
#include <unistd.h>
#define FUZZ_PROJECT_NAME "plugindestroysessioncmd_fuzzer"

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->
<fuzz_config>
<fuzztest>
<!-- maximum length of a test input -->
<max_len>1000</max_len>
<!-- maximum total time in seconds to run the fuzzer -->
<max_total_time>300</max_total_time>
<!-- memory usage limit in Mb -->
<rss_limit_mb>4096</rss_limit_mb>
</fuzztest>
</fuzz_config>

View File

@ -0,0 +1,48 @@
# 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.
#####################hydra-fuzz###################
import("//build/test.gni")
import("../../../../../base/config.gni")
module_output_path = "${OHOS_PROFILER_TEST_MODULE_OUTPUT_PATH}/device"
##############################fuzztest##########################################
ohos_fuzztest("PluginStartSessionTest") {
module_out_path = module_output_path
include_dirs = []
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "pluginstartsessioncmd_fuzzer.cpp" ]
deps = [
#"${OHOS_PROFILER_DIR}/device/services/plugin_service:hiprofiler_plugin_service",
#"${OHOS_PROFILER_DIR}/device/services/profiler_service:profiler_service",
"../../..:plugins_sources",
]
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
}
###############################################################################
group("fuzztest") {
testonly = true
deps = []
deps += [
# deps file
":PluginStartSessionTest",
]
}
###############################################################################

View File

@ -0,0 +1 @@
FUZZ

View File

@ -0,0 +1,50 @@
/*
* 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.
*/
#include "pluginstartsessioncmd_fuzzer.h"
#include <stddef.h>
#include <stdint.h>
#include "command_poller.h"
#include "plugin_manager.h"
#include "plugin_service.ipc.h"
#include "socket_context.h"
namespace OHOS {
bool StartSessionTest(const uint8_t* data, size_t size)
{
auto pluginManage = std::make_shared<PluginManager>();
auto commandPoller = std::make_shared<CommandPoller>(pluginManage);
pluginManage->SetCommandPoller(commandPoller);
StartSessionCmd successCmd;
if (!successCmd.ParseFromArray(data, size)) {
return true;
}
commandPoller->OnStartSessionCmd(successCmd);
return true;
}
} // namespace OHOS
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::StartSessionTest(data, size);
return 0;
}

View File

@ -0,0 +1,23 @@
/*
* 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.
*/
#include <climits>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <fcntl.h>
#include <unistd.h>
#define FUZZ_PROJECT_NAME "pluginstartsessioncmd_fuzzer"

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->
<fuzz_config>
<fuzztest>
<!-- maximum length of a test input -->
<max_len>1000</max_len>
<!-- maximum total time in seconds to run the fuzzer -->
<max_total_time>300</max_total_time>
<!-- memory usage limit in Mb -->
<rss_limit_mb>4096</rss_limit_mb>
</fuzztest>
</fuzz_config>

View File

@ -0,0 +1,48 @@
# 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.
#####################hydra-fuzz###################
import("//build/test.gni")
import("../../../../../base/config.gni")
module_output_path = "${OHOS_PROFILER_TEST_MODULE_OUTPUT_PATH}/device"
##############################fuzztest##########################################
ohos_fuzztest("PluginStopSessionTest") {
module_out_path = module_output_path
include_dirs = []
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "pluginstopsessioncmd_fuzzer.cpp" ]
deps = [
#"${OHOS_PROFILER_DIR}/device/services/plugin_service:hiprofiler_plugin_service",
#"${OHOS_PROFILER_DIR}/device/services/profiler_service:profiler_service",
"../../..:plugins_sources",
]
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
}
###############################################################################
group("fuzztest") {
testonly = true
deps = []
deps += [
# deps file
":PluginStopSessionTest",
]
}
###############################################################################

View File

@ -0,0 +1 @@
FUZZ

View File

@ -0,0 +1,49 @@
/*
* 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.
*/
#include "pluginstopsessioncmd_fuzzer.h"
#include <stddef.h>
#include <stdint.h>
#include "command_poller.h"
#include "plugin_manager.h"
#include "plugin_service.ipc.h"
#include "socket_context.h"
namespace OHOS {
bool StopSessionTest(const uint8_t* data, size_t size)
{
auto pluginManage = std::make_shared<PluginManager>();
auto commandPoller = std::make_shared<CommandPoller>(pluginManage);
pluginManage->SetCommandPoller(commandPoller);
StopSessionCmd successCmd;
if (!successCmd.ParseFromArray(data, size)) {
return true;
}
commandPoller->OnStopSessionCmd(successCmd);
return true;
}
} // namespace OHOS
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::StopSessionTest(data, size);
return 0;
}

View File

@ -0,0 +1,23 @@
/*
* 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.
*/
#include <climits>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <fcntl.h>
#include <unistd.h>
#define FUZZ_PROJECT_NAME "pluginstopsessioncmd_fuzzer"

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->
<fuzz_config>
<fuzztest>
<!-- maximum length of a test input -->
<max_len>1000</max_len>
<!-- maximum total time in seconds to run the fuzzer -->
<max_total_time>300</max_total_time>
<!-- memory usage limit in Mb -->
<rss_limit_mb>4096</rss_limit_mb>
</fuzztest>
</fuzz_config>

4
device/plugins/api/test/unittest/buffer_write_test.cpp Normal file → Executable file
View File

@ -45,7 +45,7 @@ int InitShareMemory1()
} }
g_smbAddr1 = mmap(nullptr, SMB1_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); g_smbAddr1 = mmap(nullptr, SMB1_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (g_smbAddr1 == MAP_FAILED) { if (g_smbAddr1 == static_cast<void*>(MAP_FAILED)) {
close(fd); close(fd);
HILOG_ERROR(LOG_CORE, "CreateBlock g_smbAddr1 mmap ERR : %s", strerror(errno)); HILOG_ERROR(LOG_CORE, "CreateBlock g_smbAddr1 mmap ERR : %s", strerror(errno));
return -1; return -1;
@ -76,7 +76,7 @@ int InitShareMemory2()
} }
g_smbAddr2 = mmap(nullptr, SMB2_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); g_smbAddr2 = mmap(nullptr, SMB2_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (g_smbAddr2 == MAP_FAILED) { if (g_smbAddr2 == static_cast<void*>(MAP_FAILED)) {
close(fd); close(fd);
HILOG_ERROR(LOG_CORE, "CreateBlock g_smbAddr2 mmap ERR : %s", strerror(errno)); HILOG_ERROR(LOG_CORE, "CreateBlock g_smbAddr2 mmap ERR : %s", strerror(errno));
return -1; return -1;

View File

@ -117,14 +117,8 @@ private:
class CommandPollerTest : public ::testing::Test { class CommandPollerTest : public ::testing::Test {
protected: protected:
static void SetUpTestCase() static void SetUpTestCase() {}
{ static void TearDownTestCase() {}
setenv("RECV_NO_WAIT", "1", 0);
}
static void TearDownTestCase()
{
unsetenv("RECV_NO_WAIT");
}
}; };
HWTEST_F(CommandPollerTest, CreateCmdTest, TestSize.Level1) HWTEST_F(CommandPollerTest, CreateCmdTest, TestSize.Level1)

View File

@ -34,7 +34,7 @@ using namespace testing::ext;
namespace { namespace {
constexpr int DEFAULT_BUFFER_SIZE = 4096; constexpr int DEFAULT_BUFFER_SIZE = 4096;
constexpr int DEFAULT_SLEEP_TIME = 1000; constexpr int DEFAULT_SLEEP_TIME = 1000;
const static std::string SUCCESS_PLUGIN_NAME = "libmemdataplugin.z.so"; const std::string SUCCESS_PLUGIN_NAME = "libmemdataplugin.z.so";
std::string g_testPluginDir("/system/lib/"); std::string g_testPluginDir("/system/lib/");
int g_hiprofilerProcessNum = -1; int g_hiprofilerProcessNum = -1;
const std::string DEFAULT_HIPROFILERD_PATH("/system/lib/hiprofilerd"); const std::string DEFAULT_HIPROFILERD_PATH("/system/lib/hiprofilerd");
@ -44,7 +44,6 @@ protected:
static constexpr auto TEMP_DELAY = std::chrono::milliseconds(20); static constexpr auto TEMP_DELAY = std::chrono::milliseconds(20);
static void SetUpTestCase() static void SetUpTestCase()
{ {
setenv("RECV_NO_WAIT", "1", 0);
#if defined(__i386__) || defined(__x86_64__) #if defined(__i386__) || defined(__x86_64__)
char pluginDir[PATH_MAX + 1] = {0}; char pluginDir[PATH_MAX + 1] = {0};
if (readlink("/proc/self/exe", pluginDir, PATH_MAX) > 0) { if (readlink("/proc/self/exe", pluginDir, PATH_MAX) > 0) {
@ -79,7 +78,6 @@ protected:
static void TearDownTestCase() static void TearDownTestCase()
{ {
unsetenv("RECV_NO_WAIT");
std::string stopCmd = "kill " + std::to_string(g_hiprofilerProcessNum); std::string stopCmd = "kill " + std::to_string(g_hiprofilerProcessNum);
std::cout << "stop command : " << stopCmd << std::endl; std::cout << "stop command : " << stopCmd << std::endl;
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(stopCmd.c_str(), "r"), pclose); std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(stopCmd.c_str(), "r"), pclose);
@ -99,7 +97,7 @@ HWTEST_F(PluginManagerTest, SuccessPlugin, TestSize.Level1)
const uint8_t configData[] = {0x30, 0x01, 0x38, 0x01, 0x42, 0x01, 0x01}; const uint8_t configData[] = {0x30, 0x01, 0x38, 0x01, 0x42, 0x01, 0x01};
ProfilerPluginConfig config; ProfilerPluginConfig config;
const std::vector<uint32_t> pluginIdsVector = {1}; const std::vector<uint32_t> pluginIdsVector = {2};
config.set_name(g_testPluginDir + SUCCESS_PLUGIN_NAME); config.set_name(g_testPluginDir + SUCCESS_PLUGIN_NAME);
config.set_config_data((const void*)configData, 7); config.set_config_data((const void*)configData, 7);
config.set_sample_interval(DEFAULT_SLEEP_TIME); config.set_sample_interval(DEFAULT_SLEEP_TIME);

View File

@ -23,7 +23,7 @@
using namespace testing::ext; using namespace testing::ext;
namespace { namespace {
const static std::string SUCCESS_PLUGIN_NAME = "libmemdataplugin.z.so"; const std::string SUCCESS_PLUGIN_NAME = "libmemdataplugin.z.so";
constexpr size_t READ_BUFFER_SIZE = 4 * 1024 * 1024; constexpr size_t READ_BUFFER_SIZE = 4 * 1024 * 1024;
std::string g_testPluginDir("/system/lib/"); std::string g_testPluginDir("/system/lib/");
@ -87,7 +87,7 @@ HWTEST_F(PluginModuleTest, PluginModuleNormal, TestSize.Level1)
EXPECT_EQ(cfgData.c_str()[1], 1); EXPECT_EQ(cfgData.c_str()[1], 1);
EXPECT_EQ(cfgData.c_str()[2], 10); EXPECT_EQ(cfgData.c_str()[2], 10);
std::unique_ptr<uint8_t[]> buffer(new (std::nothrow) uint8_t[size]); std::unique_ptr<uint8_t[]> buffer = std::make_unique<uint8_t[]>(size);
EXPECT_NE(buffer, nullptr); EXPECT_NE(buffer, nullptr);
EXPECT_TRUE(plugin->StartSession(reinterpret_cast<const uint8_t*>(cfgData.c_str()), cfgData.size())); EXPECT_TRUE(plugin->StartSession(reinterpret_cast<const uint8_t*>(cfgData.c_str()), cfgData.size()));
EXPECT_NE(plugin->ReportResult(buffer.get(), size), 0); EXPECT_NE(plugin->ReportResult(buffer.get(), size), 0);
@ -133,7 +133,7 @@ HWTEST_F(PluginModuleTest, PluginModuleAbnormal, TestSize.Level1)
plugin->GetPluginName(name); plugin->GetPluginName(name);
EXPECT_STREQ(name.c_str(), ""); EXPECT_STREQ(name.c_str(), "");
std::unique_ptr<uint8_t[]> buffer(new (std::nothrow) uint8_t[size]); std::unique_ptr<uint8_t[]> buffer = std::make_unique<uint8_t[]>(size);
EXPECT_NE(buffer, nullptr); EXPECT_NE(buffer, nullptr);
EXPECT_FALSE(plugin->StartSession(nullptr, 0)); EXPECT_FALSE(plugin->StartSession(nullptr, 0));
EXPECT_EQ(plugin->ReportResult(buffer.get(), size), -1); EXPECT_EQ(plugin->ReportResult(buffer.get(), size), -1);

View File

@ -32,12 +32,12 @@ namespace {
constexpr int DEAFULT_FILE_MODE = 0777; constexpr int DEAFULT_FILE_MODE = 0777;
#if defined(__i386__) || defined(__x86_64__) #if defined(__i386__) || defined(__x86_64__)
const static std::string DEFAULT_TEST_PATH = "./"; const std::string DEFAULT_TEST_PATH = "./";
#else #else
const static std::string DEFAULT_TEST_PATH_1 = "/data/local/tmp/watchertest/1/"; const std::string DEFAULT_TEST_PATH_1 = "/data/local/tmp/watchertest/1/";
const static std::string DEFAULT_TEST_PATH_2 = "/data/local/tmp/watchertest/2/"; const std::string DEFAULT_TEST_PATH_2 = "/data/local/tmp/watchertest/2/";
const static std::string DEFAULT_TEST_PATH_3 = "/data/local/tmp/watchertest/3/"; const std::string DEFAULT_TEST_PATH_3 = "/data/local/tmp/watchertest/3/";
const static std::string NO_EXIST_TEST_PATH = "/data/local/tmp/noexist/"; const std::string NO_EXIST_TEST_PATH = "/data/local/tmp/noexist/";
#endif #endif
class PluginWatchTest : public ::testing::Test { class PluginWatchTest : public ::testing::Test {
@ -101,10 +101,16 @@ protected:
void DeleteFile(std::string dirPath) const void DeleteFile(std::string dirPath) const
{ {
for (auto it : createFileList) { for (auto it : createFileList) {
remove((dirPath + it).c_str()); if (remove((dirPath + it).c_str()) != 0) {
std::cout << "createFileList remove failed, errno=" << errno << std::endl;
return;
}
} }
for (auto it : addFileList) { for (auto it : addFileList) {
remove((dirPath + it).c_str()); if (remove((dirPath + it).c_str()) != 0) {
std::cout << "addFileList remove failed, errno=" << errno << std::endl;
return;
}
} }
} }

View File

@ -65,7 +65,7 @@ void ParseConfig(const BytracePluginConfig& config)
bool RunCommand(const std::string& cmd) bool RunCommand(const std::string& cmd)
{ {
HILOG_INFO(LOG_CORE, "BytraceCall::start running commond: %s", cmd.c_str()); HILOG_INFO(LOG_CORE, "%s:start running commond: %s", __func__, cmd.c_str());
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd.data(), "r"), pclose); std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd.data(), "r"), pclose);
CHECK_TRUE(pipe, false, "BytraceCall::RunCommand: create popen FAILED!"); CHECK_TRUE(pipe, false, "BytraceCall::RunCommand: create popen FAILED!");
@ -74,7 +74,7 @@ bool RunCommand(const std::string& cmd)
while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) { while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
result += buffer.data(); result += buffer.data();
} }
HILOG_INFO(LOG_CORE, "BytraceCall::RunCommand result: %s", result.data()); HILOG_INFO(LOG_CORE, "%s:runCommand result: %s", __func__, result.data());
return true; return true;
} }
@ -153,7 +153,7 @@ int BytracePluginSessionStop()
int BytraceRegisterWriterStruct(const WriterStruct* writer) int BytraceRegisterWriterStruct(const WriterStruct* writer)
{ {
HILOG_INFO(LOG_CORE, "writer %p", writer); HILOG_INFO(LOG_CORE, "%s:writer %p", __func__, writer);
return 0; return 0;
} }

9
device/plugins/cpu_plugin/BUILD.gn Normal file → Executable file
View File

@ -14,8 +14,7 @@
import("//build/ohos.gni") import("//build/ohos.gni")
import("../../base/config.gni") import("../../base/config.gni")
ohos_shared_library("cpudataplugin") { ohos_source_set("cpudataplugin_source") {
output_name = "cpudataplugin"
sources = [ sources = [
"../memory_plugin/src/buffer_splitter.cpp", "../memory_plugin/src/buffer_splitter.cpp",
"src/cpu_data_plugin.cpp", "src/cpu_data_plugin.cpp",
@ -42,6 +41,12 @@ ohos_shared_library("cpudataplugin") {
external_deps = [ "hiviewdfx_hilog_native:libhilog" ] external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
} }
} }
}
ohos_shared_library("cpudataplugin") {
output_name = "cpudataplugin"
deps = [ ":cpudataplugin_source" ]
public_configs = [ "${OHOS_PROFILER_DIR}/device/base:hiprofiler_test_config" ] public_configs = [ "${OHOS_PROFILER_DIR}/device/base:hiprofiler_test_config" ]
install_enable = true install_enable = true
subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}"

2
device/plugins/cpu_plugin/include/cpu_data_plugin.h Normal file → Executable file
View File

@ -68,7 +68,7 @@ private:
int64_t GetUserHz(); int64_t GetUserHz();
int64_t GetCpuUsageTime(std::vector<std::string>& cpuUsageVec); int64_t GetCpuUsageTime(std::vector<std::string>& cpuUsageVec);
void WriteProcessCpuUsage(CpuUsageInfo& cpuUsageInfo, const char* pFile, uint32_t fileLen); void WriteProcessCpuUsage(CpuUsageInfo& cpuUsageInfo, const char* pFile, uint32_t fileLen);
void GetSystemCpuTime(std::vector<std::string>& cpuUsageVec, int64_t& usageTime, int64_t& time); bool GetSystemCpuTime(std::vector<std::string>& cpuUsageVec, int64_t& usageTime, int64_t& time);
void WriteSystemCpuUsage(CpuUsageInfo& cpuUsageInfo, const char* pFile, uint32_t fileLen); void WriteSystemCpuUsage(CpuUsageInfo& cpuUsageInfo, const char* pFile, uint32_t fileLen);
void WriteCpuUsageInfo(CpuData& data); void WriteCpuUsageInfo(CpuData& data);

View File

@ -53,7 +53,7 @@ CpuDataPlugin::CpuDataPlugin()
CpuDataPlugin::~CpuDataPlugin() CpuDataPlugin::~CpuDataPlugin()
{ {
HILOG_INFO(LOG_CORE, "plugin:~CpuDataPlugin!"); HILOG_INFO(LOG_CORE, "%s:~CpuDataPlugin!", __func__);
if (buffer_ != nullptr) { if (buffer_ != nullptr) {
free(buffer_); free(buffer_);
buffer_ = nullptr; buffer_ = nullptr;
@ -71,22 +71,22 @@ int CpuDataPlugin::Start(const uint8_t* configData, uint32_t configSize)
{ {
buffer_ = malloc(READ_BUFFER_SIZE); buffer_ = malloc(READ_BUFFER_SIZE);
if (buffer_ == nullptr) { if (buffer_ == nullptr) {
HILOG_ERROR(LOG_CORE, "plugin:malloc buffer_ fail"); HILOG_ERROR(LOG_CORE, "%s:malloc buffer_ failed!", __func__);
return RET_FAIL; return RET_FAIL;
} }
if (protoConfig_.ParseFromArray(configData, configSize) <= 0) { if (protoConfig_.ParseFromArray(configData, configSize) <= 0) {
HILOG_ERROR(LOG_CORE, "plugin:ParseFromArray failed"); HILOG_ERROR(LOG_CORE, "%s:parseFromArray failed!", __func__);
return RET_FAIL; return RET_FAIL;
} }
if (protoConfig_.pid() > 0) { if (protoConfig_.pid() > 0) {
pid_ = protoConfig_.pid(); pid_ = protoConfig_.pid();
} else { } else {
HILOG_ERROR(LOG_CORE, "plugin:Invalid pid"); HILOG_ERROR(LOG_CORE, "%s:invalid pid", __func__);
return RET_FAIL; return RET_FAIL;
} }
HILOG_INFO(LOG_CORE, "plugin:start success!"); HILOG_INFO(LOG_CORE, "%s:start success!", __func__);
return RET_SUCC; return RET_SUCC;
} }
@ -119,7 +119,7 @@ int CpuDataPlugin::Stop()
prevThreadCpuTimeMap_.clear(); prevThreadCpuTimeMap_.clear();
prevCoreSystemCpuTimeMap_.clear(); prevCoreSystemCpuTimeMap_.clear();
prevCoreSystemBootTimeMap_.clear(); prevCoreSystemBootTimeMap_.clear();
HILOG_INFO(LOG_CORE, "plugin:stop success!"); HILOG_INFO(LOG_CORE, "%s:stop success!", __func__);
return 0; return 0;
} }
@ -127,21 +127,26 @@ int32_t CpuDataPlugin::ReadFile(std::string& fileName)
{ {
int fd = -1; int fd = -1;
ssize_t bytesRead = 0; ssize_t bytesRead = 0;
char filePath[PATH_MAX + 1] = {0};
char realPath[PATH_MAX + 1] = {0}; char realPath[PATH_MAX + 1] = {0};
if (realpath(fileName.c_str(), realPath) == nullptr) { if (snprintf_s(filePath, sizeof(filePath), sizeof(filePath) - 1, "%s", fileName.c_str()) < 0) {
HILOG_ERROR(LOG_CORE, "ReadFile:realpath failed, errno=%d", errno); HILOG_ERROR(LOG_CORE, "snprintf_s(%s) error, errno(%d:%s)", fileName.c_str(), errno, strerror(errno));
return RET_FAIL;
}
if (realpath(filePath, realPath) == nullptr) {
HILOG_ERROR(LOG_CORE, "realpath(%s) failed, errno(%d:%s)", fileName.c_str(), errno, strerror(errno));
return RET_FAIL; return RET_FAIL;
} }
fd = open(realPath, O_RDONLY | O_CLOEXEC); fd = open(realPath, O_RDONLY | O_CLOEXEC);
if (fd == -1) { if (fd == -1) {
HILOG_ERROR(LOG_CORE, "Failed to open(%s), errno=%d", realPath, errno); HILOG_ERROR(LOG_CORE, "%s:failed to open(%s), errno(%d:%s)", __func__, realPath, errno, strerror(errno));
err_ = errno; err_ = errno;
return RET_FAIL; return RET_FAIL;
} }
if (buffer_ == nullptr) { if (buffer_ == nullptr) {
HILOG_ERROR(LOG_CORE, "%s:Empty address, buffer_ is NULL", __func__); HILOG_ERROR(LOG_CORE, "%s:empty address, buffer_ is NULL", __func__);
err_ = RET_NULL_ADDR; err_ = RET_NULL_ADDR;
close(fd); close(fd);
return RET_FAIL; return RET_FAIL;
@ -149,7 +154,7 @@ int32_t CpuDataPlugin::ReadFile(std::string& fileName)
bytesRead = read(fd, buffer_, READ_BUFFER_SIZE - 1); bytesRead = read(fd, buffer_, READ_BUFFER_SIZE - 1);
if (bytesRead <= 0) { if (bytesRead <= 0) {
close(fd); close(fd);
HILOG_ERROR(LOG_CORE, "Failed to read(%s), errno=%d", realPath, errno); HILOG_ERROR(LOG_CORE, "%s:failed to read(%s), errno=%d", __func__, realPath, errno);
err_ = errno; err_ = errno;
return RET_FAIL; return RET_FAIL;
} }
@ -215,7 +220,7 @@ void CpuDataPlugin::WriteProcessCpuUsage(CpuUsageInfo& cpuUsageInfo, const char*
// 获取到的数据不包含utime、stime、cutime、cstime四个数值时返回 // 获取到的数据不包含utime、stime、cutime、cstime四个数值时返回
if (cpuUsageVec.size() != PROCESS_UNSPECIFIED) { if (cpuUsageVec.size() != PROCESS_UNSPECIFIED) {
HILOG_ERROR(LOG_CORE, "Failed to get process cpu usage, size=%d", cpuUsageVec.size()); HILOG_ERROR(LOG_CORE, "%s:failed to get process cpu usage, size=%zu", __func__, cpuUsageVec.size());
return; return;
} }
@ -229,9 +234,7 @@ int32_t CpuDataPlugin::GetCpuFrequency(std::string fileName)
{ {
int32_t frequency = 0; int32_t frequency = 0;
int32_t ret = ReadFile(fileName); int32_t ret = ReadFile(fileName);
if (ret == RET_FAIL) { if (ret != RET_FAIL) {
HILOG_ERROR(LOG_CORE, "read %s file failed", fileName.c_str());
} else {
frequency = atoi((char*)buffer_); frequency = atoi((char*)buffer_);
} }
return frequency; return frequency;
@ -243,7 +246,6 @@ int CpuDataPlugin::GetCpuCoreSize()
DIR* procDir = nullptr; DIR* procDir = nullptr;
procDir = OpenDestDir(freqPath_); procDir = OpenDestDir(freqPath_);
if (procDir == nullptr) { if (procDir == nullptr) {
HILOG_ERROR(LOG_CORE, "procDir is nullptr");
return -1; return -1;
} }
@ -310,12 +312,12 @@ void CpuDataPlugin::SetCpuFrequency(CpuCoreUsageInfo& cpuCore, int32_t coreNum)
frequency->set_cur_frequency_khz(curFrequency); frequency->set_cur_frequency_khz(curFrequency);
} }
void CpuDataPlugin::GetSystemCpuTime(std::vector<std::string>& cpuUsageVec, int64_t& usageTime, int64_t& time) bool CpuDataPlugin::GetSystemCpuTime(std::vector<std::string>& cpuUsageVec, int64_t& usageTime, int64_t& time)
{ {
// 获取到的数据不包含user, nice, system, idle, iowait, irq, softirq, steal八个数值时返回 // 获取到的数据不包含user, nice, system, idle, iowait, irq, softirq, steal八个数值时返回
if (cpuUsageVec.size() != SYSTEM_UNSPECIFIED) { if (cpuUsageVec.size() != SYSTEM_UNSPECIFIED) {
HILOG_ERROR(LOG_CORE, "Failed to get system cpu usage, size=%d", cpuUsageVec.size()); HILOG_ERROR(LOG_CORE, "%s:failed to get system cpu usage, size=%zu", __func__, cpuUsageVec.size());
return; return false;
} }
int64_t user, nice, system, idle, iowait, irq, softirq, steal; int64_t user, nice, system, idle, iowait, irq, softirq, steal;
@ -329,19 +331,21 @@ void CpuDataPlugin::GetSystemCpuTime(std::vector<std::string>& cpuUsageVec, int6
steal = atoi(cpuUsageVec[SYSTEM_STEAL].c_str()); steal = atoi(cpuUsageVec[SYSTEM_STEAL].c_str());
usageTime = (user + nice + system + irq + softirq + steal) * GetUserHz(); usageTime = (user + nice + system + irq + softirq + steal) * GetUserHz();
time = (usageTime + idle + iowait) * GetUserHz(); time = usageTime + (idle + iowait) * GetUserHz();
return true;
} }
void CpuDataPlugin::WriteSystemCpuUsage(CpuUsageInfo& cpuUsageInfo, const char* pFile, uint32_t fileLen) void CpuDataPlugin::WriteSystemCpuUsage(CpuUsageInfo& cpuUsageInfo, const char* pFile, uint32_t fileLen)
{ {
BufferSplitter totalbuffer(const_cast<char*>(pFile), fileLen + 1); BufferSplitter totalbuffer(const_cast<char*>(pFile), fileLen + 1);
std::vector<std::string> cpuUsageVec; std::vector<std::string> cpuUsageVec;
int64_t usageTime, time; int64_t usageTime = 0;
int64_t time = 0;
size_t cpuLength = strlen("cpu"); size_t cpuLength = strlen("cpu");
do { do {
totalbuffer.NextWord(' '); totalbuffer.NextWord(' ');
if (strncmp(totalbuffer.CurWord(), "cpu", cpuLength) != 0) { if (!totalbuffer.CurWord() || strncmp(totalbuffer.CurWord(), "cpu", cpuLength) != 0) {
return; return;
} }
@ -354,7 +358,11 @@ void CpuDataPlugin::WriteSystemCpuUsage(CpuUsageInfo& cpuUsageInfo, const char*
totalbuffer.NextWord(' '); totalbuffer.NextWord(' ');
} }
GetSystemCpuTime(cpuUsageVec, usageTime, time); // 获取数据失败返回
if (!GetSystemCpuTime(cpuUsageVec, usageTime, time)) {
return;
}
if (strcmp(cpuUsageVec[0].c_str(), "cpu") == 0) { if (strcmp(cpuUsageVec[0].c_str(), "cpu") == 0) {
cpuUsageInfo.set_prev_system_cpu_time_ms(prevSystemCpuTime_); cpuUsageInfo.set_prev_system_cpu_time_ms(prevSystemCpuTime_);
cpuUsageInfo.set_prev_system_boot_time_ms(prevSystemBootTime_); cpuUsageInfo.set_prev_system_boot_time_ms(prevSystemBootTime_);
@ -394,11 +402,9 @@ void CpuDataPlugin::WriteCpuUsageInfo(CpuData& data)
std::string fileName = path_ + std::to_string(pid_) + "/stat"; std::string fileName = path_ + std::to_string(pid_) + "/stat";
int32_t ret = ReadFile(fileName); int32_t ret = ReadFile(fileName);
if (ret == RET_FAIL) { if (ret == RET_FAIL) {
HILOG_ERROR(LOG_CORE, "read /proc/pid/stat file failed");
return; return;
} }
if ((buffer_ == nullptr) || (ret == 0)) { if ((buffer_ == nullptr) || (ret == 0)) {
HILOG_ERROR(LOG_CORE, "%s:invalid params, read buffer_ is NULL", __func__);
return; return;
} }
auto* cpuUsageInfo = data.mutable_cpu_usage_info(); auto* cpuUsageInfo = data.mutable_cpu_usage_info();
@ -408,11 +414,9 @@ void CpuDataPlugin::WriteCpuUsageInfo(CpuData& data)
fileName = path_ + "stat"; fileName = path_ + "stat";
ret = ReadFile(fileName); ret = ReadFile(fileName);
if (ret == RET_FAIL) { if (ret == RET_FAIL) {
HILOG_ERROR(LOG_CORE, "read /proc/stat file failed");
return; return;
} }
if ((buffer_ == nullptr) || (ret == 0)) { if ((buffer_ == nullptr) || (ret == 0)) {
HILOG_ERROR(LOG_CORE, "%s:invalid params, read buffer_ is NULL", __func__);
return; return;
} }
WriteSystemCpuUsage(*cpuUsageInfo, (char*)buffer_, ret); WriteSystemCpuUsage(*cpuUsageInfo, (char*)buffer_, ret);
@ -438,7 +442,7 @@ DIR* CpuDataPlugin::OpenDestDir(std::string& dirPath)
destDir = opendir(dirPath.c_str()); destDir = opendir(dirPath.c_str());
if (destDir == nullptr) { if (destDir == nullptr) {
HILOG_ERROR(LOG_CORE, "Failed to opendir(%s), errno=%d", dirPath.c_str(), errno); HILOG_ERROR(LOG_CORE, "%s:failed to opendir(%s), errno=%d", __func__, dirPath.c_str(), errno);
} }
return destDir; return destDir;
@ -490,13 +494,18 @@ void CpuDataPlugin::WriteThread(ThreadInfo& threadInfo, const char* pFile, uint3
BufferSplitter totalbuffer(const_cast<char*>(pFile), fileLen + 1); BufferSplitter totalbuffer(const_cast<char*>(pFile), fileLen + 1);
std::vector<std::string> cpuUsageVec; std::vector<std::string> cpuUsageVec;
for (int i = 0; i < STAT_COUNT; i++) { for (int i = 0; i < STAT_COUNT; i++) {
totalbuffer.NextWord(' '); if (i == THREAD_NAME_POS) { // 线程名是')'作为结束符
totalbuffer.NextWord(')');
} else {
totalbuffer.NextWord(' ');
}
if (!totalbuffer.CurWord()) { if (!totalbuffer.CurWord()) {
return; return;
} }
if (i == THREAD_NAME_POS) { if (i == THREAD_NAME_POS) {
std::string curWord = std::string(totalbuffer.CurWord() + 1, totalbuffer.CurWordSize() - sizeof(")")); std::string curWord = std::string(totalbuffer.CurWord() + 1, totalbuffer.CurWordSize() - 1);
threadInfo.set_thread_name(curWord); threadInfo.set_thread_name(curWord);
} else if (i == THREAD_STATE_POS) { } else if (i == THREAD_STATE_POS) {
std::string curWord = std::string(totalbuffer.CurWord(), totalbuffer.CurWordSize()); std::string curWord = std::string(totalbuffer.CurWord(), totalbuffer.CurWordSize());
@ -510,7 +519,7 @@ void CpuDataPlugin::WriteThread(ThreadInfo& threadInfo, const char* pFile, uint3
// 获取到的数据不包含utime、stime、cutime、cstime四个数值时返回 // 获取到的数据不包含utime、stime、cutime、cstime四个数值时返回
if (cpuUsageVec.size() != PROCESS_UNSPECIFIED) { if (cpuUsageVec.size() != PROCESS_UNSPECIFIED) {
HILOG_ERROR(LOG_CORE, "Failed to get thread cpu usage, size=%d", cpuUsageVec.size()); HILOG_ERROR(LOG_CORE, "%s:failed to get thread cpu usage, size=%zu", __func__, cpuUsageVec.size());
return; return;
} }
@ -534,11 +543,9 @@ void CpuDataPlugin::WriteSingleThreadInfo(CpuData& data, int32_t tid)
std::string fileName = path_ + std::to_string(pid_) + "/task/" + std::to_string(tid) + "/stat"; std::string fileName = path_ + std::to_string(pid_) + "/task/" + std::to_string(tid) + "/stat";
int32_t ret = ReadFile(fileName); int32_t ret = ReadFile(fileName);
if (ret == RET_FAIL) { if (ret == RET_FAIL) {
HILOG_ERROR(LOG_CORE, "%s:read tid file failed", fileName.c_str());
return; return;
} }
if ((buffer_ == nullptr) || (ret == 0)) { if ((buffer_ == nullptr) || (ret == 0)) {
HILOG_ERROR(LOG_CORE, "%s:invalid params, read buffer_ is NULL", __func__);
return; return;
} }
auto* threadInfo = data.add_thread_info(); auto* threadInfo = data.add_thread_info();

1
device/plugins/cpu_plugin/src/cpu_module.cpp Normal file → Executable file
View File

@ -40,7 +40,6 @@ static int CpuPluginReportResult(uint8_t* bufferData, uint32_t bufferSize)
static int CpuPluginSessionStop() static int CpuPluginSessionStop()
{ {
std::lock_guard<std::mutex> guard(g_taskMutex); std::lock_guard<std::mutex> guard(g_taskMutex);
HILOG_INFO(LOG_CORE, "%s:stop Session success!", __func__);
g_plugin->Stop(); g_plugin->Stop();
g_plugin = nullptr; g_plugin = nullptr;
return 0; return 0;

View File

@ -0,0 +1,54 @@
# 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.
#####################hydra-fuzz###################
import("//build/test.gni")
import("../../../../../base/config.gni")
module_output_path = "${OHOS_PROFILER_TEST_MODULE_OUTPUT_PATH}/device"
##############################fuzztest##########################################
ohos_fuzztest("CpuStartPluginFuzzTest") {
module_out_path = module_output_path
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "cpustartplugin_fuzzer.cpp" ]
deps = [
"${OHOS_PROFILER_DIR}/device/plugins/cpu_plugin:cpudataplugin_source",
"${OHOS_PROFILER_DIR}/protos/types/plugins/cpu_data:cpu_data_cpp",
"//utils/native/base:utilsecurec",
]
include_dirs = [
"../../../include",
"../../../../api/include",
"${OHOS_PROFILER_DIR}/interfaces/kits",
"${OHOS_PROFILER_DIR}/device/base/include",
"//utils/native/base/include",
]
}
###############################################################################
group("fuzztest") {
testonly = true
deps = []
deps += [
# deps file
":CpuStartPluginFuzzTest",
]
}
###############################################################################

View File

@ -0,0 +1 @@
FUZZ

View File

@ -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.
*/
#include "cpustartplugin_fuzzer.h"
#include <stddef.h>
#include <stdint.h>
#include "cpu_data_plugin.h"
namespace OHOS {
bool FuzzCpuStartPlugin(const uint8_t* data, size_t size)
{
std::unique_ptr<CpuDataPlugin> plugin = std::make_unique<CpuDataPlugin>();
plugin->Start(data, size);
return true;
}
} // namespace OHOS
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::FuzzCpuStartPlugin(data, size);
return 0;
}

View File

@ -0,0 +1,23 @@
/*
* 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.
*/
#include <climits>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <fcntl.h>
#include <unistd.h>
#define FUZZ_PROJECT_NAME "cpustartplugin_fuzzer"

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->
<fuzz_config>
<fuzztest>
<!-- maximum length of a test input -->
<max_len>1000</max_len>
<!-- maximum total time in seconds to run the fuzzer -->
<max_total_time>300</max_total_time>
<!-- memory usage limit in Mb -->
<rss_limit_mb>4096</rss_limit_mb>
</fuzztest>
</fuzz_config>

View File

@ -23,14 +23,9 @@
using namespace testing::ext; using namespace testing::ext;
namespace { namespace {
#if defined(__i386__) || defined(__x86_64__)
const std::string DEFAULT_TEST_PATH = "./resources";
#else
const std::string DEFAULT_TEST_PATH = "/data/local/tmp/resources"; const std::string DEFAULT_TEST_PATH = "/data/local/tmp/resources";
#endif
constexpr uint32_t BUF_SIZE = 4 * 1024 * 1024;
const std::string SO_PATH = "/system/lib/libcpudataplugin.z.so"; const std::string SO_PATH = "/system/lib/libcpudataplugin.z.so";
constexpr uint32_t BUF_SIZE = 4 * 1024 * 1024;
constexpr int TEST_PID = 1; constexpr int TEST_PID = 1;
std::string g_path; std::string g_path;
@ -39,6 +34,8 @@ std::vector<int> g_tidList = {1872, 1965, 1966, 1967, 1968, 1995, 1996};
constexpr int CORE_NUM = 6; constexpr int CORE_NUM = 6;
constexpr int THREAD_NUM = 7; constexpr int THREAD_NUM = 7;
constexpr int FIRST_THREAD_NUM = 5;
constexpr int SECOND_THREAD_NUM = 6;
struct TestSystemStat { struct TestSystemStat {
int32_t core; int32_t core;
@ -81,8 +78,28 @@ TestSystemStat g_systemStat[CORE_NUM + 1] = {
{4, 4566158, 601107, 2305309, 197166395, 929594, 0, 1007959, 0}, {4, 4566158, 601107, 2305309, 197166395, 929594, 0, 1007959, 0},
{5, 5395826, 658673, 2882028, 197791346, 738811, 0, 49496, 0}, {5, 5395826, 658673, 2882028, 197791346, 738811, 0, 49496, 0},
}; };
TestSystemStat g_systemStat1[CORE_NUM + 1] = {
{-1, 1234567, 2345678, 1111111, 1193291234, 3546789, 0, 2345678, 0},
{0, 2345678, 662862, 1966195, 1111111, 3571925, 0, 817371, 0},
{1, 3861506, 2345678, 1702753, 199535158, 1752008, 0, 401639, 0},
{2, 3549890, 1111111, 2345678, 1234567, 1133743, 0, 205972, 0},
{3, 3336646, 676939, 1458898, 2345678, 854578, 0, 2345678, 0},
{4, 1111111, 601107, 2305309, 3546789, 929594, 0, 1007959, 0},
{5, 3546789, 658673, 1234567, 197791346, 738811, 0, 49496, 0},
};
TestSystemStat g_systemStat2[CORE_NUM + 1] = {
{-1, 3546789, 2345678, 1111111, 1193291234, 3546789, 0, 2345678, 0},
{0, 3546789, 662862, 1966195, 2345678, 3571925, 0, 817371, 0},
{1, 3861506, 1111111, 1702753, 199535158, 1752008, 0, 401639, 0},
{2, 3549890, 2345678, 2345678, 3546789, 1111111, 0, 205972, 0},
{3, 3336646, 676939, 1458898, 2345678, 854578, 0, 2345678, 0},
{4, 2345678, 601107, 2305309, 3546789, 929594, 0, 1111111, 0},
{5, 3546789, 658673, 3546789, 197791346, 738811, 0, 49496, 0},
};
TestStat g_pidStat = {60, 10, 20, 30}; TestStat g_pidStat = {60, 10, 20, 30};
TestStat g_pidStat1 = {50, 10, 40, 10};
TestStat g_pidStat2 = {70, 0, 10, 20};
TestTidStat g_tidStat[THREAD_NUM] = { TestTidStat g_tidStat[THREAD_NUM] = {
{1872, "ibus-x11", THREAD_RUNNING, {17, 5, 10, 10}}, {1872, "ibus-x11", THREAD_RUNNING, {17, 5, 10, 10}},
@ -93,6 +110,21 @@ TestTidStat g_tidStat[THREAD_NUM] = {
{1995, "gmain", THREAD_SLEEPING, {15, 3, 0, 4}}, {1995, "gmain", THREAD_SLEEPING, {15, 3, 0, 4}},
{1996, "gdbus", THREAD_WAITING, {5, 0, 0, 0}}, {1996, "gdbus", THREAD_WAITING, {5, 0, 0, 0}},
}; };
TestTidStat g_tidStat1[THREAD_NUM] = {
{1209, "skytone:service", THREAD_RUNNING, {22, 8, 0, 0}},
{1646, "Jit thread pool", THREAD_UNSPECIFIED, {2, 1, 0, 0}},
{1654, "Signal Catcher", THREAD_STOPPED, {1, 0, 0, 0}},
{1655, "HeapTaskDaemon", THREAD_SLEEPING, {3, 0, 0, 0}},
{1656, "ReferenceQueueD", THREAD_WAITING, {0, 0, 0, 0}},
};
TestTidStat g_tidStat2[THREAD_NUM] = {
{1662, "FinalizerDaemon", THREAD_STOPPED, {0, 0, 0, 0}},
{1663, "FinalizerWatchd", THREAD_RUNNING, {0, 0, 0, 0}},
{1666, "Binder:1209_1", THREAD_RUNNING, {0, 0, 0, 0}},
{1679, "Binder:1209_2", THREAD_UNSPECIFIED, {0, 0, 0, 0}},
{1680, "Binder:1209_3", THREAD_WAITING, {54, 8, 0, 0}},
{1681, "Binder:1209_4", THREAD_SLEEPING, {0, 0, 0, 0}},
};
TestFreq g_Freq[CORE_NUM + 1] = { TestFreq g_Freq[CORE_NUM + 1] = {
{1018, 3844, 509}, {1023, 2844, 509}, {1011, 3844, 509}, {1518, 3844, 1018}, {1245, 1844, 1018}, {1767, 3044, 1018}, {1018, 3844, 509}, {1023, 2844, 509}, {1011, 3844, 509}, {1518, 3844, 1018}, {1245, 1844, 1018}, {1767, 3044, 1018},
@ -138,33 +170,6 @@ std::string GetFullPath(std::string path)
return path; return path;
} }
#if defined(__i386__) || defined(__x86_64__)
bool CreatTestResource(std::string path, std::string exepath)
{
std::string str = "cp -r " + path + " " + exepath;
printf("CreatTestResource:%s\n", str.c_str());
pid_t status = system(str.c_str());
if (-1 == status) {
printf("system error!");
} else {
printf("exit status value = [0x%x]\n", status);
if (WIFEXITED(status)) {
if (WEXITSTATUS(status) == 0) {
return true;
} else {
printf("run shell script fail, script exit code: %d\n", WEXITSTATUS(status));
return false;
}
} else {
printf("exit status = [%d]\n", WEXITSTATUS(status));
return true;
}
}
return false;
}
#endif
bool CheckTid(std::vector<int>& tidListTmp) bool CheckTid(std::vector<int>& tidListTmp)
{ {
sort(g_tidList.begin(), g_tidList.end()); sort(g_tidList.begin(), g_tidList.end());
@ -211,7 +216,7 @@ bool PluginCpuinfoStub(CpuDataPlugin& cpuPlugin, CpuData& cpuData, int pid, bool
void GetSystemCpuTime(TestSystemStat& stat, int64_t Hz, int64_t& usageTime, int64_t& time) void GetSystemCpuTime(TestSystemStat& stat, int64_t Hz, int64_t& usageTime, int64_t& time)
{ {
usageTime = (stat.user + stat.nice + stat.system + stat.irq + stat.softirq + stat.steal) * Hz; usageTime = (stat.user + stat.nice + stat.system + stat.irq + stat.softirq + stat.steal) * Hz;
time = (usageTime + stat.idle + stat.iowait) * Hz; time = usageTime + (stat.idle + stat.iowait) * Hz;
} }
/** /**
@ -225,14 +230,6 @@ HWTEST_F(CpuDataPluginTest, TestPath, TestSize.Level1)
g_testPath = g_path; g_testPath = g_path;
printf("g_path:%s\n", g_path.c_str()); printf("g_path:%s\n", g_path.c_str());
EXPECT_NE("", g_path); EXPECT_NE("", g_path);
#if defined(__i386__) || defined(__x86_64__)
if (DEFAULT_TEST_PATH != g_path) {
if ((access(g_path.c_str(), F_OK) != 0) && (access(DEFAULT_TEST_PATH.c_str(), F_OK) == 0)) {
EXPECT_TRUE(CreatTestResource(DEFAULT_TEST_PATH, g_path));
}
}
#endif
} }
/** /**
@ -391,9 +388,496 @@ HWTEST_F(CpuDataPluginTest, TestPluginRegister, TestSize.Level1)
std::vector<uint8_t> dataBuffer(cpuPlugin->resultBufferSizeHint); std::vector<uint8_t> dataBuffer(cpuPlugin->resultBufferSizeHint);
EXPECT_EQ(cpuPlugin->callbacks->onPluginSessionStart(configBuffer.data(), configLength), RET_SUCC); EXPECT_EQ(cpuPlugin->callbacks->onPluginSessionStart(configBuffer.data(), configLength), RET_SUCC);
ASSERT_GT(cpuPlugin->callbacks->onPluginReportResult(dataBuffer.data(), cpuPlugin->resultBufferSizeHint), 0); ASSERT_GT(cpuPlugin->callbacks->onPluginReportResult(dataBuffer.data(), cpuPlugin->resultBufferSizeHint), 0);
EXPECT_EQ(cpuPlugin->callbacks->onPluginSessionStop(), 0); EXPECT_EQ(cpuPlugin->callbacks->onPluginSessionStop(), RET_SUCC);
// 反序列化失败导致的start失败 // 反序列化失败导致的start失败
EXPECT_EQ(cpuPlugin->callbacks->onPluginSessionStart(configBuffer.data(), configLength+1), RET_FAIL); EXPECT_EQ(cpuPlugin->callbacks->onPluginSessionStart(configBuffer.data(), configLength+1), RET_FAIL);
} }
} // namespace
/**
* @tc.name: cpu plugin
* @tc.desc: a part of cpu process information test.
* @tc.type: FUNC
*/
HWTEST_F(CpuDataPluginTest, TestPluginProcessInfo, TestSize.Level1)
{
CpuData cpuData;
CpuDataPlugin cpuPlugin;
int64_t Hz = cpuPlugin.GetUserHz();
std::string proStr1 = "2000 (ibus-x11) S 1 1865 1780 1025 1780 4194304 3233 0 457 0 50 10 40 10 20 0 7";
std::string proStr2 = "2000 (ibus-x12) R 1 1865 1780 1025 1780 4194304 3233 0 457 0 70 0 10 20 20 0 7";
int64_t processCpuTime1 = (g_pidStat1.utime + g_pidStat1.stime + g_pidStat1.cutime + g_pidStat1.cstime) * Hz;
int64_t processCpuTime2 = (g_pidStat2.utime + g_pidStat2.stime + g_pidStat2.cutime + g_pidStat2.cstime) * Hz;
// 存入proStr1
auto* cpuUsageInfo = cpuData.mutable_cpu_usage_info();
cpuPlugin.WriteProcessCpuUsage(*cpuUsageInfo, proStr1.c_str(), proStr1.length());
CpuUsageInfo cpuUsageInfo1 = cpuData.cpu_usage_info();
EXPECT_EQ(cpuUsageInfo1.prev_process_cpu_time_ms(), 0);
EXPECT_EQ(cpuUsageInfo1.process_cpu_time_ms(), processCpuTime1);
// 存入proStr2
cpuUsageInfo = cpuData.mutable_cpu_usage_info();
cpuPlugin.WriteProcessCpuUsage(*cpuUsageInfo, proStr2.c_str(), proStr2.length());
CpuUsageInfo cpuUsageInfo2 = cpuData.cpu_usage_info();
EXPECT_EQ(cpuUsageInfo2.prev_process_cpu_time_ms(), processCpuTime1);
EXPECT_EQ(cpuUsageInfo2.process_cpu_time_ms(), processCpuTime2);
// 重复存入proStr2
cpuUsageInfo = cpuData.mutable_cpu_usage_info();
cpuPlugin.WriteProcessCpuUsage(*cpuUsageInfo, proStr2.c_str(), proStr2.length());
CpuUsageInfo cpuUsageInfo3 = cpuData.cpu_usage_info();
EXPECT_EQ(cpuUsageInfo3.prev_process_cpu_time_ms(), processCpuTime2);
EXPECT_EQ(cpuUsageInfo3.process_cpu_time_ms(), processCpuTime2);
}
/**
* @tc.name: cpu plugin
* @tc.desc: cpu process information test for abnormal parameters.
* @tc.type: FUNC
*/
HWTEST_F(CpuDataPluginTest, TestPluginProcessBoundary, TestSize.Level1)
{
CpuData cpuData;
CpuDataPlugin cpuPlugin;
std::string proStr;
int64_t Hz = cpuPlugin.GetUserHz();
int64_t processCpuTime = (g_pidStat1.utime + g_pidStat1.stime + g_pidStat1.cutime + g_pidStat1.cstime) * Hz;
// 空字符串
proStr = "";
auto* cpuUsageInfo = cpuData.mutable_cpu_usage_info();
cpuPlugin.WriteProcessCpuUsage(*cpuUsageInfo, proStr.c_str(), proStr.length());
CpuUsageInfo cpuUsageInfo1 = cpuData.cpu_usage_info();
EXPECT_EQ(cpuUsageInfo1.prev_process_cpu_time_ms(), 0);
EXPECT_EQ(cpuUsageInfo1.process_cpu_time_ms(), 0);
// 空格字符串
proStr = " ";
cpuUsageInfo = cpuData.mutable_cpu_usage_info();
cpuPlugin.WriteProcessCpuUsage(*cpuUsageInfo, proStr.c_str(), proStr.length());
cpuUsageInfo1 = cpuData.cpu_usage_info();
EXPECT_EQ(cpuUsageInfo1.prev_process_cpu_time_ms(), 0);
EXPECT_EQ(cpuUsageInfo1.process_cpu_time_ms(), 0);
// 数据错误
proStr = "2000";
cpuUsageInfo = cpuData.mutable_cpu_usage_info();
cpuPlugin.WriteProcessCpuUsage(*cpuUsageInfo, proStr.c_str(), proStr.length());
cpuUsageInfo1 = cpuData.cpu_usage_info();
EXPECT_EQ(cpuUsageInfo1.prev_process_cpu_time_ms(), 0);
EXPECT_EQ(cpuUsageInfo1.process_cpu_time_ms(), 0);
// 数据不够("2000 (ibus-x11) S 1 1865 1780 1025 1780 4194304 3233 0 457 0 50 10 40 10 20 0 7"需要的字符串是50 10 40 10
proStr = "2000 (ibus-x11) S 1 1865 1780 1025 1780 4194304 3233 0 457 0 50 10";
cpuUsageInfo = cpuData.mutable_cpu_usage_info();
cpuPlugin.WriteProcessCpuUsage(*cpuUsageInfo, proStr.c_str(), proStr.length());
cpuUsageInfo1 = cpuData.cpu_usage_info();
EXPECT_EQ(cpuUsageInfo1.prev_process_cpu_time_ms(), 0);
EXPECT_EQ(cpuUsageInfo1.process_cpu_time_ms(), 0);
// 多个空格,可以取出正确数据
proStr = "2000 (ibus-x11) S 1 1865 1780 1025 1780 4194304 3233 0 457 0 50 10 40 10 20 ";
cpuUsageInfo = cpuData.mutable_cpu_usage_info();
cpuPlugin.WriteProcessCpuUsage(*cpuUsageInfo, proStr.c_str(), proStr.length());
cpuUsageInfo1 = cpuData.cpu_usage_info();
EXPECT_EQ(cpuUsageInfo1.prev_process_cpu_time_ms(), 0);
EXPECT_EQ(cpuUsageInfo1.process_cpu_time_ms(), processCpuTime);
// 最后一个数据之后没有空格,可以取出正确数据
proStr = "2000 (ibus-x11) S 1 1865 1780 1025 1780 4194304 3233 0 457 0 50 10 40 10 20";
cpuUsageInfo = cpuData.mutable_cpu_usage_info();
cpuPlugin.WriteProcessCpuUsage(*cpuUsageInfo, proStr.c_str(), proStr.length());
cpuUsageInfo1 = cpuData.cpu_usage_info();
EXPECT_EQ(cpuUsageInfo1.prev_process_cpu_time_ms(), processCpuTime);
EXPECT_EQ(cpuUsageInfo1.process_cpu_time_ms(), processCpuTime);
}
/**
* @tc.name: cpu plugin
* @tc.desc: a part of cpu system information test.
* @tc.type: FUNC
*/
HWTEST_F(CpuDataPluginTest, TestPluginSystemInfo, TestSize.Level1)
{
std::string sysStr1 = "cpu 1234567 2345678 1111111 1193291234 3546789 0 2345678 0 0\n"
"cpu0 2345678 662862 1966195 1111111 3571925 0 817371 0 0\n"
"cpu1 3861506 2345678 1702753 199535158 1752008 0 401639 0 0\n"
"cpu2 3549890 1111111 2345678 1234567 1133743 0 205972 0 0\n"
"cpu3 3336646 676939 1458898 2345678 854578 0 2345678 0 0\n"
"cpu4 1111111 601107 2305309 3546789 929594 0 1007959 0 0\n"
"cpu5 3546789 658673 1234567 197791346 738811 0 49496 0 0\n";
std::string sysStr2 = "cpu 3546789 2345678 1111111 1193291234 3546789 0 2345678 0 0\n"
"cpu0 3546789 662862 1966195 2345678 3571925 0 817371 0 0\n"
"cpu1 3861506 1111111 1702753 199535158 1752008 0 401639 0 0\n"
"cpu2 3549890 2345678 2345678 3546789 1111111 0 205972 0 0\n"
"cpu3 3336646 676939 1458898 2345678 854578 0 2345678 0 0\n"
"cpu4 2345678 601107 2305309 3546789 929594 0 1111111 0 0\n"
"cpu5 3546789 658673 3546789 197791346 738811 0 49496 0 0\n";
CpuData cpuData;
CpuDataPlugin cpuPlugin;
int64_t Hz = cpuPlugin.GetUserHz();
// 存入sysStr1
int64_t systemCpuTime1 = 0;
int64_t systemBootTime1 = 0;
GetSystemCpuTime(g_systemStat1[0], Hz, systemCpuTime1, systemBootTime1);
auto* cpuUsageInfo = cpuData.mutable_cpu_usage_info();
cpuPlugin.WriteSystemCpuUsage(*cpuUsageInfo, sysStr1.c_str(), sysStr1.length());
CpuUsageInfo cpuUsageInfo1 = cpuData.cpu_usage_info();
EXPECT_EQ(cpuUsageInfo1.prev_system_cpu_time_ms(), 0);
EXPECT_EQ(cpuUsageInfo1.prev_system_boot_time_ms(), 0);
EXPECT_EQ(cpuUsageInfo1.system_cpu_time_ms(), systemCpuTime1);
EXPECT_EQ(cpuUsageInfo1.system_boot_time_ms(), systemBootTime1);
ASSERT_EQ(cpuUsageInfo1.cores_size(), CORE_NUM);
std::vector<int64_t> systemCpuTimeVec1(CORE_NUM);
std::vector<int64_t> systemBootTimeVec1(CORE_NUM);
for (int i = 1; i <= CORE_NUM; i++) {
CpuCoreUsageInfo cpuCoreUsageInfo1 = cpuUsageInfo1.cores()[i - 1];
GetSystemCpuTime(g_systemStat1[i], Hz, systemCpuTimeVec1[i-1], systemBootTimeVec1[i-1]);
EXPECT_EQ(cpuCoreUsageInfo1.cpu_core(), i-1);
EXPECT_EQ(cpuCoreUsageInfo1.prev_system_cpu_time_ms(), 0);
EXPECT_EQ(cpuCoreUsageInfo1.prev_system_boot_time_ms(), 0);
EXPECT_EQ(cpuCoreUsageInfo1.system_cpu_time_ms(), systemCpuTimeVec1[i-1]);
EXPECT_EQ(cpuCoreUsageInfo1.system_boot_time_ms(), systemBootTimeVec1[i-1]);
}
// 存入sysStr2
int64_t systemCpuTime2 = 0;
int64_t systemBootTime2 = 0;
GetSystemCpuTime(g_systemStat2[0], Hz, systemCpuTime2, systemBootTime2);
cpuUsageInfo = cpuData.mutable_cpu_usage_info();
cpuPlugin.WriteSystemCpuUsage(*cpuUsageInfo, sysStr2.c_str(), sysStr2.length());
CpuUsageInfo cpuUsageInfo2 = cpuData.cpu_usage_info();
EXPECT_EQ(cpuUsageInfo2.prev_system_cpu_time_ms(), systemCpuTime1);
EXPECT_EQ(cpuUsageInfo2.prev_system_boot_time_ms(), systemBootTime1);
EXPECT_EQ(cpuUsageInfo2.system_cpu_time_ms(), systemCpuTime2);
EXPECT_EQ(cpuUsageInfo2.system_boot_time_ms(), systemBootTime2);
ASSERT_EQ(cpuUsageInfo2.cores_size(), CORE_NUM*2);
std::vector<int64_t> systemCpuTimeVec2(CORE_NUM);
std::vector<int64_t> systemBootTimeVec2(CORE_NUM);
for (int i = 1; i <= CORE_NUM; i++) {
CpuCoreUsageInfo cpuCoreUsageInfo2 = cpuUsageInfo2.cores()[CORE_NUM+i-1];
GetSystemCpuTime(g_systemStat2[i], Hz, systemCpuTimeVec2[i-1], systemBootTimeVec2[i-1]);
EXPECT_EQ(cpuCoreUsageInfo2.cpu_core(), i-1);
EXPECT_EQ(cpuCoreUsageInfo2.prev_system_cpu_time_ms(), systemCpuTimeVec1[i-1]);
EXPECT_EQ(cpuCoreUsageInfo2.prev_system_boot_time_ms(), systemBootTimeVec1[i-1]);
EXPECT_EQ(cpuCoreUsageInfo2.system_cpu_time_ms(), systemCpuTimeVec2[i-1]);
EXPECT_EQ(cpuCoreUsageInfo2.system_boot_time_ms(), systemBootTimeVec2[i-1]);
}
// 重复存入sysStr2
cpuUsageInfo = cpuData.mutable_cpu_usage_info();
cpuPlugin.WriteSystemCpuUsage(*cpuUsageInfo, sysStr2.c_str(), sysStr2.length());
CpuUsageInfo cpuUsageInfo3 = cpuData.cpu_usage_info();
EXPECT_EQ(cpuUsageInfo3.prev_system_cpu_time_ms(), systemCpuTime2);
EXPECT_EQ(cpuUsageInfo3.prev_system_boot_time_ms(), systemBootTime2);
EXPECT_EQ(cpuUsageInfo3.system_cpu_time_ms(), systemCpuTime2);
EXPECT_EQ(cpuUsageInfo3.system_boot_time_ms(), systemBootTime2);
ASSERT_EQ(cpuUsageInfo3.cores_size(), CORE_NUM*3);
std::vector<int64_t> systemCpuTimeVec3(CORE_NUM);
std::vector<int64_t> systemBootTimeVec3(CORE_NUM);
for (int i = 1; i <= CORE_NUM; i++) {
CpuCoreUsageInfo cpuCoreUsageInfo3 = cpuUsageInfo3.cores()[CORE_NUM*2+i-1];
GetSystemCpuTime(g_systemStat2[i], Hz, systemCpuTimeVec3[i-1], systemBootTimeVec3[i-1]);
EXPECT_EQ(cpuCoreUsageInfo3.cpu_core(), i-1);
EXPECT_EQ(cpuCoreUsageInfo3.prev_system_cpu_time_ms(), systemCpuTimeVec2[i-1]);
EXPECT_EQ(cpuCoreUsageInfo3.prev_system_boot_time_ms(), systemBootTimeVec2[i-1]);
EXPECT_EQ(cpuCoreUsageInfo3.system_cpu_time_ms(), systemCpuTimeVec3[i-1]);
EXPECT_EQ(cpuCoreUsageInfo3.system_boot_time_ms(), systemBootTimeVec3[i-1]);
}
}
/**
* @tc.name: cpu plugin
* @tc.desc: cpu system information test for abnormal parameters.
* @tc.type: FUNC
*/
HWTEST_F(CpuDataPluginTest, TestPluginSystemBoundary, TestSize.Level1)
{
CpuData cpuData;
CpuDataPlugin cpuPlugin;
std::string sysStr;
int64_t Hz = cpuPlugin.GetUserHz();
int64_t systemCpuTime = 0;
int64_t systemBootTime = 0;
GetSystemCpuTime(g_systemStat1[0], Hz, systemCpuTime, systemBootTime);
// 空字符串
sysStr = "";
auto* cpuUsageInfo = cpuData.mutable_cpu_usage_info();
cpuPlugin.WriteSystemCpuUsage(*cpuUsageInfo, sysStr.c_str(), sysStr.length());
CpuUsageInfo cpuUsageInfo1 = cpuData.cpu_usage_info();
EXPECT_EQ(cpuUsageInfo1.prev_system_cpu_time_ms(), 0);
EXPECT_EQ(cpuUsageInfo1.prev_system_boot_time_ms(), 0);
EXPECT_EQ(cpuUsageInfo1.system_cpu_time_ms(), 0);
EXPECT_EQ(cpuUsageInfo1.system_boot_time_ms(), 0);
ASSERT_EQ(cpuUsageInfo1.cores_size(), 0);
// 空格字符串
sysStr = " ";
cpuUsageInfo = cpuData.mutable_cpu_usage_info();
cpuPlugin.WriteSystemCpuUsage(*cpuUsageInfo, sysStr.c_str(), sysStr.length());
cpuUsageInfo1 = cpuData.cpu_usage_info();
EXPECT_EQ(cpuUsageInfo1.prev_system_cpu_time_ms(), 0);
EXPECT_EQ(cpuUsageInfo1.prev_system_boot_time_ms(), 0);
EXPECT_EQ(cpuUsageInfo1.system_cpu_time_ms(), 0);
EXPECT_EQ(cpuUsageInfo1.system_boot_time_ms(), 0);
ASSERT_EQ(cpuUsageInfo1.cores_size(), 0);
// 数据错误
sysStr = "1000";
cpuUsageInfo = cpuData.mutable_cpu_usage_info();
cpuPlugin.WriteSystemCpuUsage(*cpuUsageInfo, sysStr.c_str(), sysStr.length());
cpuUsageInfo1 = cpuData.cpu_usage_info();
EXPECT_EQ(cpuUsageInfo1.prev_system_cpu_time_ms(), 0);
EXPECT_EQ(cpuUsageInfo1.prev_system_boot_time_ms(), 0);
EXPECT_EQ(cpuUsageInfo1.system_cpu_time_ms(), 0);
EXPECT_EQ(cpuUsageInfo1.system_boot_time_ms(), 0);
ASSERT_EQ(cpuUsageInfo1.cores_size(), 0);
// 数据不够
sysStr = "cpu 1234567 2345678 1111111 1193291234 3546789\n"
"cpu0 2345678 662862 1966195 1111111 3571925\n"
"cpu1 3861506 2345678 1702753 199535158 1752008\n"
"cpu2 3549890 1111111 2345678 1234567 1133743\n"
"cpu3 3336646 676939 1458898 2345678 854578\n"
"cpu4 1111111 601107 2305309 3546789 929594\n"
"cpu5 3546789 658673 1234567 197791346 738811\n";
cpuUsageInfo = cpuData.mutable_cpu_usage_info();
cpuPlugin.WriteSystemCpuUsage(*cpuUsageInfo, sysStr.c_str(), sysStr.length());
cpuUsageInfo1 = cpuData.cpu_usage_info();
EXPECT_EQ(cpuUsageInfo1.prev_system_cpu_time_ms(), 0);
EXPECT_EQ(cpuUsageInfo1.prev_system_boot_time_ms(), 0);
EXPECT_EQ(cpuUsageInfo1.system_cpu_time_ms(), 0);
EXPECT_EQ(cpuUsageInfo1.system_boot_time_ms(), 0);
ASSERT_EQ(cpuUsageInfo1.cores_size(), 0);
// 多个空格,可以取出正确数据
sysStr = "cpu 1234567 2345678 1111111 1193291234 3546789 0 2345678 0 0\n"
"cpu0 2345678 662862 1966195 1111111 3571925 0 817371 0 0\n"
"cpu1 3861506 2345678 1702753 199535158 1752008 0 401639 0 0\n"
"cpu2 3549890 1111111 2345678 1234567 1133743 0 205972 0 0\n"
"cpu3 3336646 676939 1458898 2345678 854578 0 2345678 0 0\n"
"cpu4 1111111 601107 2305309 3546789 929594 0 1007959 0 0\n"
"cpu5 3546789 658673 1234567 197791346 738811 0 49496 0 0\n";
cpuUsageInfo = cpuData.mutable_cpu_usage_info();
cpuPlugin.WriteSystemCpuUsage(*cpuUsageInfo, sysStr.c_str(), sysStr.length());
cpuUsageInfo1 = cpuData.cpu_usage_info();
EXPECT_EQ(cpuUsageInfo1.prev_system_cpu_time_ms(), 0);
EXPECT_EQ(cpuUsageInfo1.prev_system_boot_time_ms(), 0);
EXPECT_EQ(cpuUsageInfo1.system_cpu_time_ms(), systemCpuTime);
EXPECT_EQ(cpuUsageInfo1.system_boot_time_ms(), systemBootTime);
ASSERT_EQ(cpuUsageInfo1.cores_size(), CORE_NUM);
std::vector<int64_t> systemCpuTimeVec1(CORE_NUM);
std::vector<int64_t> systemBootTimeVec1(CORE_NUM);
for (int i = 1; i <= CORE_NUM; i++) {
CpuCoreUsageInfo cpuCoreUsageInfo = cpuUsageInfo1.cores()[i - 1];
GetSystemCpuTime(g_systemStat1[i], Hz, systemCpuTimeVec1[i-1], systemBootTimeVec1[i-1]);
EXPECT_EQ(cpuCoreUsageInfo.cpu_core(), i-1);
EXPECT_EQ(cpuCoreUsageInfo.prev_system_cpu_time_ms(), 0);
EXPECT_EQ(cpuCoreUsageInfo.prev_system_boot_time_ms(), 0);
EXPECT_EQ(cpuCoreUsageInfo.system_cpu_time_ms(), systemCpuTimeVec1[i-1]);
EXPECT_EQ(cpuCoreUsageInfo.system_boot_time_ms(), systemBootTimeVec1[i-1]);
}
// 最后一个数据之后没有空格,可以取出正确数据
sysStr = "cpu 1234567 2345678 1111111 1193291234 3546789 0 2345678 0 0\n"
"cpu0 2345678 662862 1966195 1111111 3571925 0 817371 0 0\n"
"cpu1 3861506 2345678 1702753 199535158 1752008 0 401639 0 0\n"
"cpu2 3549890 1111111 2345678 1234567 1133743 0 205972 0 0\n"
"cpu3 3336646 676939 1458898 2345678 854578 0 2345678 0 0\n"
"cpu4 1111111 601107 2305309 3546789 929594 0 1007959 0 0\n"
"cpu5 3546789 658673 1234567 197791346 738811 0 49496 0 0\n";
cpuUsageInfo = cpuData.mutable_cpu_usage_info();
cpuPlugin.WriteSystemCpuUsage(*cpuUsageInfo, sysStr.c_str(), sysStr.length());
cpuUsageInfo1 = cpuData.cpu_usage_info();
EXPECT_EQ(cpuUsageInfo1.prev_system_cpu_time_ms(), systemCpuTime);
EXPECT_EQ(cpuUsageInfo1.prev_system_boot_time_ms(), systemBootTime);
EXPECT_EQ(cpuUsageInfo1.system_cpu_time_ms(), systemCpuTime);
EXPECT_EQ(cpuUsageInfo1.system_boot_time_ms(), systemBootTime);
ASSERT_EQ(cpuUsageInfo1.cores_size(), CORE_NUM*2);
std::vector<int64_t> systemCpuTimeVec2(CORE_NUM);
std::vector<int64_t> systemBootTimeVec2(CORE_NUM);
for (int i = 1; i <= CORE_NUM; i++) {
CpuCoreUsageInfo cpuCoreUsageInfo = cpuUsageInfo1.cores()[CORE_NUM+i-1];
GetSystemCpuTime(g_systemStat1[i], Hz, systemCpuTimeVec2[i-1], systemBootTimeVec2[i-1]);
EXPECT_EQ(cpuCoreUsageInfo.cpu_core(), i-1);
EXPECT_EQ(cpuCoreUsageInfo.prev_system_cpu_time_ms(), systemCpuTimeVec1[i-1]);
EXPECT_EQ(cpuCoreUsageInfo.prev_system_boot_time_ms(), systemBootTimeVec1[i-1]);
EXPECT_EQ(cpuCoreUsageInfo.system_cpu_time_ms(), systemCpuTimeVec2[i-1]);
EXPECT_EQ(cpuCoreUsageInfo.system_boot_time_ms(), systemBootTimeVec2[i-1]);
}
}
/**
* @tc.name: cpu plugin
* @tc.desc: a part of cpu thread information test.
* @tc.type: FUNC
*/
HWTEST_F(CpuDataPluginTest, TestPluginThreadInfo, TestSize.Level1)
{
std::vector<std::string> threadVec1;
threadVec1.push_back("1209 (skytone:service) R 1746 1746 0 0 -1 1077936448 10399 0 1 0 22 8 0 0 20 0 19 0");
threadVec1.push_back("1646 (Jit thread pool) L 1746 1746 0 0 -1 1077936192 1831 0 0 0 2 1 0 0 20 0 19 0");
threadVec1.push_back("1654 (Signal Catcher) T 1746 1746 0 0 -1 1077936192 588 0 0 0 1 0 0 0 20 0 19 0");
threadVec1.push_back("1655 (HeapTaskDaemon) S 1746 1746 0 0 -1 1077936192 1515 0 0 0 3 0 0 0 24 4 19 0");
threadVec1.push_back("1656 (ReferenceQueueD) D 1746 1746 0 0 -1 1077936192 24 0 0 0 0 0 0 0 24 4 19 0");
std::vector<std::string> threadVec2;
threadVec2.push_back("1662 (FinalizerDaemon) T 1746 1746 0 0 -1 1077936192 18 0 0 0 0 0 0 0 24 4 19 0");
threadVec2.push_back("1663 (FinalizerWatchd) R 1746 1746 0 0 -1 1077936192 5 0 0 0 0 0 0 0 24 4 19 0");
threadVec2.push_back("1666 (Binder:1209_1) R 1746 1746 0 0 -1 1077936192 412 0 0 0 0 0 0 0 20 0 19 0");
threadVec2.push_back("1679 (Binder:1209_2) O 1746 1746 0 0 -1 1077936192 14 0 0 0 0 0 0 0 20 0 19 0");
threadVec2.push_back("1680 (Binder:1209_3) D 1746 1746 0 0 -1 1077936192 11513 0 4 0 54 8 0 0 20 0 49 0");
threadVec2.push_back("1681 (Binder:1209_4) S 1751 1751 0 0 -1 1077936192 17 0 0 0 0 0 0 0 20 0 24 0");
CpuData cpuData;
CpuDataPlugin cpuPlugin;
int64_t Hz = cpuPlugin.GetUserHz();
// 存入threadVec0-4
int32_t tid;
for (int i = 0; i < FIRST_THREAD_NUM; i++) {
auto* threadInfo = cpuData.add_thread_info();
tid = atoi(threadVec1[i].substr(0, threadVec1[i].find(" ")).c_str());
cpuPlugin.WriteThread(*threadInfo, threadVec1[i].c_str(), threadVec1[i].length(), tid);
}
ASSERT_EQ(cpuData.thread_info_size(), FIRST_THREAD_NUM);
int64_t threadCpuTime1;
for (int i = 0; i < FIRST_THREAD_NUM; i++) {
threadCpuTime1 = (g_tidStat1[i].stat.utime + g_tidStat1[i].stat.stime +
g_tidStat1[i].stat.cutime + g_tidStat1[i].stat.cstime) * Hz;
ThreadInfo threadInfo1 = cpuData.thread_info()[i];
EXPECT_EQ(threadInfo1.tid(), g_tidStat1[i].tid);
EXPECT_STREQ(threadInfo1.thread_name().c_str(), g_tidStat1[i].name.c_str());
EXPECT_EQ(threadInfo1.thread_state(), g_tidStat1[i].state);
EXPECT_EQ(threadInfo1.prev_thread_cpu_time_ms(), 0);
EXPECT_EQ(threadInfo1.thread_cpu_time_ms(), threadCpuTime1);
}
// 存入threadVec5-10
for (int i = 0; i < SECOND_THREAD_NUM; i++) {
auto* threadInfo = cpuData.add_thread_info();
tid = atoi(threadVec2[i].substr(0, threadVec2[i].find(" ")).c_str());
cpuPlugin.WriteThread(*threadInfo, threadVec2[i].c_str(), threadVec2[i].length(), tid);
}
ASSERT_EQ(cpuData.thread_info_size(), FIRST_THREAD_NUM+SECOND_THREAD_NUM);
std::vector<int64_t> threadCpuTime2;
for (int i = 0; i < SECOND_THREAD_NUM; i++) {
threadCpuTime2.push_back((g_tidStat2[i].stat.utime + g_tidStat2[i].stat.stime +
g_tidStat2[i].stat.cutime + g_tidStat2[i].stat.cstime) * Hz);
ThreadInfo threadInfo2 = cpuData.thread_info()[i+FIRST_THREAD_NUM];
EXPECT_EQ(threadInfo2.tid(), g_tidStat2[i].tid);
EXPECT_STREQ(threadInfo2.thread_name().c_str(), g_tidStat2[i].name.c_str());
EXPECT_EQ(threadInfo2.thread_state(), g_tidStat2[i].state);
EXPECT_EQ(threadInfo2.prev_thread_cpu_time_ms(), 0);
EXPECT_EQ(threadInfo2.thread_cpu_time_ms(), threadCpuTime2[i]);
}
// 重复存入threadVec5-10
for (int i = 0; i < SECOND_THREAD_NUM; i++) {
auto* threadInfo = cpuData.add_thread_info();
tid = atoi(threadVec2[i].substr(0, threadVec2[i].find(" ")).c_str());
cpuPlugin.WriteThread(*threadInfo, threadVec2[i].c_str(), threadVec2[i].length(), tid);
}
ASSERT_EQ(cpuData.thread_info_size(), FIRST_THREAD_NUM+SECOND_THREAD_NUM*2);
int64_t threadCpuTime3;
for (int i = 0; i < SECOND_THREAD_NUM; i++) {
threadCpuTime3 = (g_tidStat2[i].stat.utime + g_tidStat2[i].stat.stime +
g_tidStat2[i].stat.cutime + g_tidStat2[i].stat.cstime) * Hz;
ThreadInfo threadInfo3 = cpuData.thread_info()[i+FIRST_THREAD_NUM+SECOND_THREAD_NUM];
EXPECT_EQ(threadInfo3.tid(), g_tidStat2[i].tid);
EXPECT_STREQ(threadInfo3.thread_name().c_str(), g_tidStat2[i].name.c_str());
EXPECT_EQ(threadInfo3.thread_state(), g_tidStat2[i].state);
EXPECT_EQ(threadInfo3.prev_thread_cpu_time_ms(), threadCpuTime2[i]);
EXPECT_EQ(threadInfo3.thread_cpu_time_ms(), threadCpuTime3);
}
}
/**
* @tc.name: cpu plugin
* @tc.desc: cpu thread information test for abnormal parameters.
* @tc.type: FUNC
*/
HWTEST_F(CpuDataPluginTest, TestPluginThreadBoundary, TestSize.Level1)
{
CpuData cpuData;
CpuDataPlugin cpuPlugin;
std::string threadStr;
int thread_info_count = 0;
int64_t Hz = cpuPlugin.GetUserHz();
int64_t threadCpuTime = (g_tidStat1[0].stat.utime + g_tidStat1[0].stat.stime + g_tidStat1[0].stat.cutime
+ g_tidStat1[0].stat.cstime) * Hz;
// 空字符串
threadStr = "";
auto* threadInfo = cpuData.add_thread_info();
thread_info_count++;
cpuPlugin.WriteThread(*threadInfo, threadStr.c_str(), threadStr.length(), 0);
ASSERT_EQ(cpuData.thread_info_size(), thread_info_count);
// 空格字符串
threadStr = " ";
threadInfo = cpuData.add_thread_info();
thread_info_count++;
cpuPlugin.WriteThread(*threadInfo, threadStr.c_str(), threadStr.length(), 0);
ASSERT_EQ(cpuData.thread_info_size(), thread_info_count);
// 数据错误
threadStr = "1000";
threadInfo = cpuData.add_thread_info();
thread_info_count++;
cpuPlugin.WriteThread(*threadInfo, threadStr.c_str(), threadStr.length(), 0);
ASSERT_EQ(cpuData.thread_info_size(), thread_info_count);
// 数据不够
threadStr = "1209 (skytone:service) R 1746 1746 0 0 -1 1077936448 10399 0 1 0 22 8";
threadInfo = cpuData.add_thread_info();
thread_info_count++;
cpuPlugin.WriteThread(*threadInfo, threadStr.c_str(), threadStr.length(), 0);
ASSERT_EQ(cpuData.thread_info_size(), thread_info_count);
// 线程名缺失左括号
threadStr = "1209 skytone:service) R 1746 1746 0 0 -1 1077936448 10399 0 1 0 22 8 0 0 20 0 19 0";
int32_t tid = atoi(threadStr.substr(0, threadStr.find(" ")).c_str());
threadInfo = cpuData.add_thread_info();
thread_info_count++;
cpuPlugin.WriteThread(*threadInfo, threadStr.c_str(), threadStr.length(), tid);
ASSERT_EQ(cpuData.thread_info_size(), thread_info_count);
ThreadInfo threadInfo1 = cpuData.thread_info()[thread_info_count-1];
EXPECT_EQ(threadInfo1.tid(), g_tidStat1[0].tid);
EXPECT_STRNE(threadInfo1.thread_name().c_str(), g_tidStat1[0].name.c_str());
EXPECT_EQ(threadInfo1.thread_state(), g_tidStat1[0].state);
EXPECT_EQ(threadInfo1.prev_thread_cpu_time_ms(), 0);
EXPECT_EQ(threadInfo1.thread_cpu_time_ms(), threadCpuTime);
// 多个空格,可以取出正确数据
threadStr = "1209 (skytone:service) R 1746 1746 0 0 -1 1077936448 10399 0 1 0 22 8 0 0 20 0 19 0";
tid = atoi(threadStr.substr(0, threadStr.find(" ")).c_str());
threadInfo = cpuData.add_thread_info();
thread_info_count++;
cpuPlugin.WriteThread(*threadInfo, threadStr.c_str(), threadStr.length(), tid);
ASSERT_EQ(cpuData.thread_info_size(), thread_info_count);
threadInfo1 = cpuData.thread_info()[thread_info_count-1];
EXPECT_EQ(threadInfo1.tid(), g_tidStat1[0].tid);
EXPECT_STREQ(threadInfo1.thread_name().c_str(), g_tidStat1[0].name.c_str());
EXPECT_EQ(threadInfo1.thread_state(), g_tidStat1[0].state);
EXPECT_EQ(threadInfo1.prev_thread_cpu_time_ms(), threadCpuTime);
EXPECT_EQ(threadInfo1.thread_cpu_time_ms(), threadCpuTime);
// 最后一个数据之后没有空格,可以取出正确数据
threadStr = "1209 (skytone:service) R 1746 1746 0 0 -1 1077936448 10399 0 1 0 22 8 0 0 20";
tid = atoi(threadStr.substr(0, threadStr.find(" ")).c_str());
threadInfo = cpuData.add_thread_info();
thread_info_count++;
cpuPlugin.WriteThread(*threadInfo, threadStr.c_str(), threadStr.length(), tid);
ASSERT_EQ(cpuData.thread_info_size(), thread_info_count);
threadInfo1 = cpuData.thread_info()[thread_info_count-1];
EXPECT_EQ(threadInfo1.tid(), g_tidStat1[0].tid);
EXPECT_STREQ(threadInfo1.thread_name().c_str(), g_tidStat1[0].name.c_str());
EXPECT_EQ(threadInfo1.thread_state(), g_tidStat1[0].state);
EXPECT_EQ(threadInfo1.prev_thread_cpu_time_ms(), threadCpuTime);
EXPECT_EQ(threadInfo1.thread_cpu_time_ms(), threadCpuTime);
}
} // namespace

View File

@ -0,0 +1,80 @@
# 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("../../base/config.gni")
ohos_source_set("diskiodataplugin_source") {
sources = [
"../memory_plugin/src/buffer_splitter.cpp",
"src/diskio_data_plugin.cpp",
"src/diskio_module.cpp",
]
include_dirs = [
"include",
"../memory_plugin/include",
"${OHOS_PROFILER_DIR}/interfaces/kits",
"${OHOS_PROFILER_DIR}/device/base/include",
"//utils/native/base/include",
]
deps = [
"${OHOS_PROFILER_3RDPARTY_PROTOBUF_DIR}:protobuf_lite",
"${OHOS_PROFILER_3RDPARTY_PROTOBUF_DIR}:protoc_lib",
"${OHOS_PROFILER_DIR}/protos/types/plugins/diskio_data:diskio_data_cpp",
"//utils/native/base:utilsecurec",
]
if (current_toolchain != host_toolchain) {
defines = [ "HAVE_HILOG" ]
if (build_l2) {
external_deps = [ "shared_library:libhilog" ]
} else {
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
}
}
}
ohos_shared_library("diskiodataplugin") {
output_name = "diskiodataplugin"
deps = [ ":diskiodataplugin_source" ]
public_configs = [ "${OHOS_PROFILER_DIR}/device/base:hiprofiler_test_config" ]
install_enable = true
subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}"
}
ohos_executable("diskiodataplugintest") {
output_name = "diskiodataplugintest"
sources = [ "src/test_main.cpp" ]
include_dirs = [
"include",
"../api/include",
"${OHOS_PROFILER_DIR}/interfaces/kits",
"${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/diskio_data:diskio_data_cpp",
]
if (current_toolchain != host_toolchain) {
defines = [ "HAVE_HILOG" ]
if (build_l2) {
external_deps = [ "shared_library:libhilog" ]
} else {
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
}
}
public_configs = [ "${OHOS_PROFILER_DIR}/device/base:hiprofiler_test_config" ]
install_enable = true
subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}"
}

View File

@ -0,0 +1,70 @@
/*
* 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.
*/
// pgpgin: Total number of kilobytes the system paged in from disk.
// pgpgout: Total number of kilobytes the system paged out to disk.
// see https://man7.org/linux/man-pages/man5/proc.5.html
#ifndef DISKIO_DATA_PLUGIN_H
#define DISKIO_DATA_PLUGIN_H
#include <fcntl.h>
#include <string>
#include <unistd.h>
#include "diskio_plugin_config.pb.h"
#include "diskio_plugin_result.pb.h"
#include "logging.h"
enum ErrorType {
RET_NULL_ADDR,
RET_IVALID_PID,
RET_TGID_VALUE_NULL,
RET_FAIL = -1,
RET_SUCC = 0,
};
class DiskioDataPlugin {
public:
DiskioDataPlugin();
~DiskioDataPlugin();
int Start(const uint8_t* configData, uint32_t configSize);
int Report(uint8_t* configData, uint32_t configSize);
int Stop();
private:
int32_t ReadFile(std::string& fileName);
void SetTimestamp(CollectTimeStamp& prevTimestamp, CollectTimeStamp& timestamp);
void SetDiskioData(DiskioData& diskioData, const char* pFile, uint32_t fileLen);
void WriteDiskioData(DiskioData& diskioData);
// for UT
void SetPath(std::string path)
{
path_ = path;
}
private:
/* data */
void* buffer_;
std::string path_;
int32_t err_;
int64_t prevRdSectorsKb_;
int64_t prevWrSectorsKb_;
CollectTimeStamp prevTimestamp_;
};
#endif

View File

@ -0,0 +1,182 @@
/*
* 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.
*/
#include "diskio_data_plugin.h"
#include <ctime>
#include "buffer_splitter.h"
namespace {
constexpr size_t READ_BUFFER_SIZE = 1024 * 16;
} // namespace
DiskioDataPlugin::DiskioDataPlugin()
{
buffer_ = nullptr;
path_ = "/proc/vmstat";
err_ = -1;
prevRdSectorsKb_ = 0;
prevWrSectorsKb_ = 0;
prevTimestamp_.set_tv_sec(0);
prevTimestamp_.set_tv_nsec(0);
}
DiskioDataPlugin::~DiskioDataPlugin()
{
HILOG_INFO(LOG_CORE, "%s:~DiskioDataPlugin!", __func__);
if (buffer_ != nullptr) {
free(buffer_);
buffer_ = nullptr;
}
}
int DiskioDataPlugin::Start(const uint8_t* configData, uint32_t configSize)
{
buffer_ = malloc(READ_BUFFER_SIZE);
if (buffer_ == nullptr) {
HILOG_ERROR(LOG_CORE, "%s:malloc buffer_ failed!", __func__);
return RET_FAIL;
}
DiskioConfig protoConfig_;
if (protoConfig_.ParseFromArray(configData, configSize) <= 0) {
HILOG_ERROR(LOG_CORE, "%s:parseFromArray failed!", __func__);
return RET_FAIL;
}
HILOG_INFO(LOG_CORE, "%s:start success!", __func__);
return RET_SUCC;
}
int DiskioDataPlugin::Report(uint8_t* data, uint32_t dataSize)
{
DiskioData dataProto;
uint32_t length;
WriteDiskioData(dataProto);
length = dataProto.ByteSizeLong();
if (length > dataSize) {
return -length;
}
if (dataProto.SerializeToArray(data, length) > 0) {
return length;
}
return 0;
}
int DiskioDataPlugin::Stop()
{
if (buffer_ != nullptr) {
free(buffer_);
buffer_ = nullptr;
}
HILOG_INFO(LOG_CORE, "%s:plugin:stop success!", __func__);
return 0;
}
int32_t DiskioDataPlugin::ReadFile(std::string& fileName)
{
int fd = -1;
ssize_t bytesRead = 0;
fd = open(fileName.c_str(), O_RDONLY | O_CLOEXEC);
if (fd == -1) {
HILOG_ERROR(LOG_CORE, "%s:failed to open(%s), errno=%d", __func__, fileName.c_str(), errno);
err_ = errno;
return RET_FAIL;
}
if (buffer_ == nullptr) {
HILOG_ERROR(LOG_CORE, "%s:empty address, buffer_ is NULL", __func__);
err_ = RET_NULL_ADDR;
close(fd);
return RET_FAIL;
}
bytesRead = read(fd, buffer_, READ_BUFFER_SIZE - 1);
if (bytesRead <= 0) {
close(fd);
HILOG_ERROR(LOG_CORE, "%s:failed to read(%s), errno=%d", __func__, fileName.c_str(), errno);
err_ = errno;
return RET_FAIL;
}
close(fd);
return bytesRead;
}
void DiskioDataPlugin::SetTimestamp(CollectTimeStamp& prevTimestamp, CollectTimeStamp& timestamp)
{
timespec time;
clock_gettime(CLOCK_MONOTONIC, &time);
timestamp.set_tv_sec(time.tv_sec);
timestamp.set_tv_nsec(time.tv_nsec);
prevTimestamp.set_tv_sec(prevTimestamp_.tv_sec());
prevTimestamp.set_tv_nsec(prevTimestamp_.tv_nsec());
prevTimestamp_.set_tv_sec(time.tv_sec);
prevTimestamp_.set_tv_nsec(time.tv_nsec);
}
void DiskioDataPlugin::SetDiskioData(DiskioData& diskioData, const char* pFile, uint32_t fileLen)
{
BufferSplitter totalbuffer(const_cast<char*>(pFile), fileLen + 1);
int64_t rd_sectors_kb = 0;
int64_t wr_sectors_kb = 0;
do {
totalbuffer.NextWord(' ');
std::string curWord = std::string(totalbuffer.CurWord(), totalbuffer.CurWordSize());
if (strcmp(curWord.c_str(), "pgpgin") == 0) {
if (!totalbuffer.NextWord('\n')) {
HILOG_ERROR(LOG_CORE, "%s:failed to get pgpgin, CurWord() = %s", __func__, totalbuffer.CurWord());
break;
}
curWord = std::string(totalbuffer.CurWord(), totalbuffer.CurWordSize());
rd_sectors_kb = atoi(curWord.c_str());
} else if (strcmp(curWord.c_str(), "pgpgout") == 0) {
if (!totalbuffer.NextWord('\n')) {
HILOG_ERROR(LOG_CORE, "%s:failed to get pgpgout, CurWord() = %s", __func__, totalbuffer.CurWord());
break;
}
curWord = std::string(totalbuffer.CurWord(), totalbuffer.CurWordSize());
wr_sectors_kb = atoi(curWord.c_str());
}
} while (totalbuffer.NextLine());
// 前一次系统从磁盘调入的总KB数rd1通过时间间隔t内KB增量计算磁盘读取速率(rd2-rd1)/t
diskioData.set_prev_rd_sectors_kb(prevRdSectorsKb_);
// 前一次系统调出到磁盘的总KB数wr1通过时间间隔t内KB增量计算磁盘写入速率(wr2-wr1)/t
diskioData.set_prev_wr_sectors_kb(prevWrSectorsKb_);
diskioData.set_rd_sectors_kb(rd_sectors_kb); // 当前系统从磁盘调入的总KB数rd2
diskioData.set_wr_sectors_kb(wr_sectors_kb); // 当前系统调出到磁盘的总KB数wr2
prevRdSectorsKb_ = rd_sectors_kb;
prevWrSectorsKb_ = wr_sectors_kb;
auto* prevTimestamp = diskioData.mutable_prev_timestamp();
auto* timestamp = diskioData.mutable_timestamp();
SetTimestamp(*prevTimestamp, *timestamp); // 设置前一次时间戳和当前时间戳以便计算两次获取数据的时间间隔t
}
void DiskioDataPlugin::WriteDiskioData(DiskioData& data)
{
int32_t ret = ReadFile(path_);
if (ret == RET_FAIL) {
return;
}
if ((buffer_ == nullptr) || (ret == 0)) {
return;
}
SetDiskioData(data, (char*)buffer_, ret);
}

View File

@ -0,0 +1,54 @@
/*
* 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.
*/
#include <mutex>
#include "diskio_data_plugin.h"
#include "plugin_module_api.h"
namespace {
constexpr uint32_t MAX_BUFFER_SIZE = 4 * 1024 * 1024;
std::unique_ptr<DiskioDataPlugin> g_plugin = nullptr;
std::mutex g_taskMutex;
} // namespace
static int DiskioDataPluginSessionStart(const uint8_t* configData, uint32_t configSize)
{
std::lock_guard<std::mutex> guard(g_taskMutex);
g_plugin = std::make_unique<DiskioDataPlugin>();
return g_plugin->Start(configData, configSize);
}
static int DiskioPluginReportResult(uint8_t* bufferData, uint32_t bufferSize)
{
std::lock_guard<std::mutex> guard(g_taskMutex);
return g_plugin->Report(bufferData, bufferSize);
}
static int DiskioPluginSessionStop()
{
std::lock_guard<std::mutex> guard(g_taskMutex);
g_plugin->Stop();
g_plugin = nullptr;
return 0;
}
static PluginModuleCallbacks g_callbacks = {
DiskioDataPluginSessionStart,
DiskioPluginReportResult,
DiskioPluginSessionStop,
};
PluginModuleStruct g_pluginModule = {&g_callbacks, "diskio-plugin", MAX_BUFFER_SIZE};

View File

@ -0,0 +1,76 @@
/*
* 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.
*/
#include <dlfcn.h>
#include <unistd.h>
#include "diskio_plugin_config.pb.h"
#include "diskio_plugin_result.pb.h"
#include "plugin_module_api.h"
namespace {
int g_testCount = 10;
} // namespace
int main()
{
DiskioConfig protoConfig;
PluginModuleStruct* diskioPlugin;
void* handle = dlopen("./libdiskiodataplugin.z.so", RTLD_LAZY);
if (handle == nullptr) {
std::cout << "test:dlopen err: " << dlerror() << std::endl;
return 0;
}
std::cout << "test:handle = " << handle << std::endl;
diskioPlugin = (PluginModuleStruct*)dlsym(handle, "g_pluginModule");
std::cout << "test:name = " << diskioPlugin->name << std::endl;
std::cout << "test:buffer size = " << diskioPlugin->resultBufferSizeHint << std::endl;
// Serialize config
int configLength = protoConfig.ByteSizeLong();
std::vector<uint8_t> configBuffer(configLength);
int ret = protoConfig.SerializeToArray(configBuffer.data(), configBuffer.size());
std::cout << "test:configLength = " << configLength << std::endl;
std::cout << "test:serialize success start plugin ret = " << ret << std::endl;
// Start
std::vector<uint8_t> dataBuffer(diskioPlugin->resultBufferSizeHint);
diskioPlugin->callbacks->onPluginSessionStart(configBuffer.data(), configLength);
while (g_testCount--) {
int len = diskioPlugin->callbacks->onPluginReportResult(dataBuffer.data(), diskioPlugin->resultBufferSizeHint);
std::cout << "test:filler buffer length = " << len << std::endl;
if (len > 0) {
DiskioData diskioData;
diskioData.ParseFromArray(dataBuffer.data(), len);
std::cout << "test:ParseFromArray length = " << len << std::endl;
std::cout << "prev_rd_sectors_kb:" << diskioData.prev_rd_sectors_kb() << std::endl;
std::cout << "prev_wr_sectors_kb:" << diskioData.prev_wr_sectors_kb() << std::endl;
std::cout << "prev_timestamp.tv_sec:" << diskioData.prev_timestamp().tv_sec() << std::endl;
std::cout << "prev_timestamp.tv_nsec:" << diskioData.prev_timestamp().tv_nsec() << std::endl;
std::cout << "rd_sectors_kb:" << diskioData.rd_sectors_kb() << std::endl;
std::cout << "wr_sectors_kb:" << diskioData.wr_sectors_kb() << std::endl;
std::cout << "timestamp.tv_sec:" << diskioData.timestamp().tv_sec() << std::endl;
std::cout << "timestamp.tv_nsec:" << diskioData.timestamp().tv_nsec() << std::endl;
}
std::cout << "test:sleep...................." << std::endl;
sleep(1);
}
diskioPlugin->callbacks->onPluginSessionStop();
return 0;
}

View File

@ -0,0 +1,55 @@
# 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/test.gni")
import("../../../base/config.gni")
module_output_path = "${OHOS_PROFILER_TEST_MODULE_OUTPUT_PATH}/device"
config("module_private_config") {
visibility = [ ":*" ]
if (current_toolchain != host_toolchain) {
defines = [ "HAVE_HILOG" ]
}
}
ohos_unittest("diskiodataplugin_ut") {
module_out_path = module_output_path
sources = [ "unittest/diskio_data_plugin_unittest.cpp" ]
deps = [
"${OHOS_PROFILER_DIR}/device/plugins/diskio_plugin:diskiodataplugin",
"${OHOS_PROFILER_DIR}/protos/types/plugins/diskio_data:diskio_data_cpp",
"//third_party/googletest:gtest_main",
"//utils/native/base:utilsecurec",
]
include_dirs = [
"../include",
"../../../memory_plugin/include",
"${OHOS_PROFILER_DIR}/interfaces/kits",
"${OHOS_PROFILER_DIR}/device/base/include",
"//third_party/googletest/googletest/include/gtest",
"//utils/native/base/include",
]
cflags = [
"-Wno-inconsistent-missing-override",
"-Dprivate=public", #allow test code access private members
]
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
configs = [ ":module_private_config" ]
subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}"
resource_config_file = "${OHOS_PROFILER_DIR}/device/ohos_test.xml"
}
group("unittest") {
testonly = true
deps = [ ":diskiodataplugin_ut" ]
}

View File

@ -0,0 +1,54 @@
# 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.
#####################hydra-fuzz###################
import("//build/test.gni")
import("../../../../../base/config.gni")
module_output_path = "${OHOS_PROFILER_TEST_MODULE_OUTPUT_PATH}/device"
##############################fuzztest##########################################
ohos_fuzztest("DiskioStartPluginFuzzTest") {
module_out_path = module_output_path
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "diskiostartplugin_fuzzer.cpp" ]
deps = [
"${OHOS_PROFILER_DIR}/device/plugins/diskio_plugin:diskiodataplugin_source",
"${OHOS_PROFILER_DIR}/protos/types/plugins/diskio_data:diskio_data_cpp",
"//utils/native/base:utilsecurec",
]
include_dirs = [
"../../../include",
"../../../../api/include",
"${OHOS_PROFILER_DIR}/interfaces/kits",
"${OHOS_PROFILER_DIR}/device/base/include",
"//utils/native/base/include",
]
}
###############################################################################
group("fuzztest") {
testonly = true
deps = []
deps += [
# deps file
":DiskioStartPluginFuzzTest",
]
}
###############################################################################

View File

@ -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.
*/
#include "diskiostartplugin_fuzzer.h"
#include <stddef.h>
#include <stdint.h>
#include "diskio_data_plugin.h"
namespace OHOS {
bool FuzzDiskioStartPlugin(const uint8_t* data, size_t size)
{
std::unique_ptr<DiskioDataPlugin> plugin = std::make_unique<DiskioDataPlugin>();
plugin->Start(data, size);
return true;
}
} // namespace OHOS
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::FuzzDiskioStartPlugin(data, size);
return 0;
}

View File

@ -0,0 +1,23 @@
/*
* 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.
*/
#include <climits>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <fcntl.h>
#include <unistd.h>
#define FUZZ_PROJECT_NAME "diskiostartplugin_fuzzer"

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->
<fuzz_config>
<fuzztest>
<!-- maximum length of a test input -->
<max_len>1000</max_len>
<!-- maximum total time in seconds to run the fuzzer -->
<max_total_time>300</max_total_time>
<!-- memory usage limit in Mb -->
<rss_limit_mb>4096</rss_limit_mb>
</fuzztest>
</fuzz_config>

View File

@ -0,0 +1,96 @@
nr_free_pages 19093
nr_zone_inactive_anon 36
nr_zone_active_anon 9098
nr_zone_inactive_file 26495
nr_zone_active_file 33479
nr_zone_unevictable 0
nr_zone_write_pending 22
nr_mlock 0
nr_page_table_pages 497
nr_kernel_stack 1552
nr_bounce 0
nr_free_cma 14110
nr_inactive_anon 36
nr_active_anon 9098
nr_inactive_file 26495
nr_active_file 33479
nr_unevictable 0
nr_slab_reclaimable 13932
nr_slab_unreclaimable 18521
nr_isolated_anon 0
nr_isolated_file 0
workingset_refault 511580
workingset_activate 23889
workingset_restore 23516
workingset_nodereclaim 0
nr_anon_pages 9001
nr_mapped 1709
nr_file_pages 60113
nr_dirty 22
nr_writeback 0
nr_writeback_temp 0
nr_shmem 139
nr_shmem_hugepages 0
nr_shmem_pmdmapped 0
nr_anon_transparent_hugepages 0
nr_unstable 0
nr_vmscan_write 0
nr_vmscan_immediate_reclaim 30
nr_dirtied 6821238
nr_written 6818476
nr_dirty_threshold 15041
nr_dirty_background_threshold 3746
pgpgin 2072559
pgpgout 27543064
pswpin 0
pswpout 0
pgalloc_normal 217147388
pgalloc_high 0
pgalloc_movable 0
allocstall_normal 0
allocstall_high 0
allocstall_movable 0
pgskip_normal 0
pgskip_high 0
pgskip_movable 0
pgfree 217172980
pgactivate 575093
pgdeactivate 1036557
pglazyfree 0
pgfault 223194616
pgmajfault 1171
pglazyfreed 0
pgrefill 1049876
pgsteal_kswapd 678076
pgsteal_direct 0
pgscan_kswapd 684000
pgscan_direct 0
pgscan_direct_throttle 0
pginodesteal 0
slabs_scanned 4535296
kswapd_inodesteal 332719
kswapd_low_wmark_hit_quickly 1
kswapd_high_wmark_hit_quickly 10
pageoutrun 877
pgrotated 29
drop_pagecache 0
drop_slab 0
oom_kill 0
pgmigrate_success 0
pgmigrate_fail 0
compact_migrate_scanned 0
compact_free_scanned 0
compact_isolated 6311
compact_stall 0
compact_fail 0
compact_success 0
compact_daemon_wake 0
compact_daemon_migrate_scanned 0
compact_daemon_free_scanned 0
unevictable_pgs_culled 0
unevictable_pgs_scanned 0
unevictable_pgs_rescued 0
unevictable_pgs_mlocked 0
unevictable_pgs_munlocked 0
unevictable_pgs_cleared 0
unevictable_pgs_stranded 0

View File

@ -0,0 +1,198 @@
/*
* 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.
*/
#include <hwext/gtest-ext.h>
#include <hwext/gtest-tag.h>
#include <dlfcn.h>
#include "diskio_data_plugin.h"
#include "plugin_module_api.h"
using namespace testing::ext;
namespace {
const std::string DEFAULT_TEST_PATH = "/data/local/tmp/resources";
const std::string SO_PATH = "/system/lib/libdiskiodataplugin.z.so";
constexpr uint32_t BUF_SIZE = 4 * 1024 * 1024;
std::string g_path;
std::string g_testPath;
struct TestVmstat {
int64_t pgpgin;
int64_t pgpgout;
};
TestVmstat g_vmStat = {2072559, 27543064};
class DiskioDataPluginTest : public ::testing::Test {
public:
static void SetUpTestCase() {}
static void TearDownTestCase()
{
if (access(g_testPath.c_str(), F_OK) == 0) {
std::string str = "rm -rf " + g_testPath;
printf("TearDown--> %s\r\n", str.c_str());
system(str.c_str());
}
}
};
string Getexepath()
{
char buf[PATH_MAX] = "";
std::string path = "/proc/self/exe";
size_t rslt = readlink(path.c_str(), buf, sizeof(buf));
if (rslt < 0 || (rslt >= sizeof(buf))) {
return "";
}
buf[rslt] = '\0';
for (int i = rslt; i >= 0; i--) {
if (buf[i] == '/') {
buf[i + 1] = '\0';
break;
}
}
return buf;
}
std::string GetFullPath(std::string path)
{
if (path.size() > 0 && path[0] != '/') {
return Getexepath() + path;
}
return path;
}
bool PluginDiskioInfoStub(DiskioDataPlugin& diskioPlugin, DiskioData& diskioData, bool unusualBuff)
{
DiskioConfig protoConfig;
std::vector<uint8_t> configData(protoConfig.ByteSizeLong());
int ret = protoConfig.SerializeToArray(configData.data(), configData.size());
if (ret < 0) {
return false;
}
printf("ut: serialize config success, ret = %d\n", ret);
// start
ret = diskioPlugin.Start(configData.data(), configData.size());
if (ret < 0) {
return false;
}
printf("ut: start plugin success, ret = %d\n", ret);
// report
std::vector<uint8_t> bufferData(BUF_SIZE);
if (unusualBuff) { // buffer异常调整缓冲区长度为1测试异常情况
bufferData.resize(1, 0);
printf("ut: bufferData resize\n");
}
ret = diskioPlugin.Report(bufferData.data(), bufferData.size());
if (ret > 0) {
diskioData.ParseFromArray(bufferData.data(), ret);
return true;
}
return false;
}
/**
* @tc.name: diskio plugin
* @tc.desc: Test whether the path exists.
* @tc.type: FUNC
*/
HWTEST_F(DiskioDataPluginTest, TestPath, TestSize.Level1)
{
g_path = GetFullPath(DEFAULT_TEST_PATH);
g_testPath = g_path;
printf("g_path:%s\n", g_path.c_str());
EXPECT_NE("", g_path);
g_path += "/proc/vmstat";
printf("g_path:%s\n", g_path.c_str());
}
/**
* @tc.name: diskio plugin
* @tc.desc: diskio information test for specific path.
* @tc.type: FUNC
*/
HWTEST_F(DiskioDataPluginTest, TestPlugin, TestSize.Level1)
{
DiskioDataPlugin diskioPlugin;
DiskioData diskioData;
diskioPlugin.SetPath(g_path);
EXPECT_TRUE(PluginDiskioInfoStub(diskioPlugin, diskioData, false));
EXPECT_EQ(diskioData.prev_rd_sectors_kb(), 0);
EXPECT_EQ(diskioData.prev_wr_sectors_kb(), 0);
EXPECT_EQ(diskioData.rd_sectors_kb(), g_vmStat.pgpgin);
EXPECT_EQ(diskioData.wr_sectors_kb(), g_vmStat.pgpgout);
EXPECT_EQ(diskioPlugin.Stop(), 0);
// 缓冲区异常
EXPECT_FALSE(PluginDiskioInfoStub(diskioPlugin, diskioData, true));
EXPECT_EQ(diskioPlugin.Stop(), 0);
}
/**
* @tc.name: diskio plugin
* @tc.desc: diskio information test for unusual path.
* @tc.type: FUNC
*/
HWTEST_F(DiskioDataPluginTest, TestPluginBoundary, TestSize.Level1)
{
DiskioDataPlugin diskioPlugin;
DiskioData diskioData;
diskioPlugin.SetPath("123");
EXPECT_FALSE(PluginDiskioInfoStub(diskioPlugin, diskioData, false));
diskioPlugin.Stop();
}
/**
* @tc.name: diskio plugin
* @tc.desc: diskio plugin registration test.
* @tc.type: FUNC
*/
HWTEST_F(DiskioDataPluginTest, TestPluginRegister, TestSize.Level1)
{
void* handle = dlopen(SO_PATH.c_str(), RTLD_LAZY);
ASSERT_NE(handle, nullptr);
PluginModuleStruct* diskioPlugin = (PluginModuleStruct*)dlsym(handle, "g_pluginModule");
ASSERT_NE(diskioPlugin, nullptr);
EXPECT_STREQ(diskioPlugin->name, "diskio-plugin");
EXPECT_EQ(diskioPlugin->resultBufferSizeHint, BUF_SIZE);
// Serialize config
DiskioConfig protoConfig;
int configLength = protoConfig.ByteSizeLong();
ASSERT_EQ(configLength, 0);
std::vector<uint8_t> configBuffer(configLength);
EXPECT_TRUE(protoConfig.SerializeToArray(configBuffer.data(), configLength));
// run plugin
std::vector<uint8_t> dataBuffer(diskioPlugin->resultBufferSizeHint);
EXPECT_EQ(diskioPlugin->callbacks->onPluginSessionStart(configBuffer.data(), configLength), RET_SUCC);
ASSERT_GT(diskioPlugin->callbacks->onPluginReportResult(dataBuffer.data(), diskioPlugin->resultBufferSizeHint), 0);
EXPECT_EQ(diskioPlugin->callbacks->onPluginSessionStop(), RET_SUCC);
// 反序列化失败导致的start失败
configLength++;
std::vector<uint8_t> configBuffer2(configLength);
EXPECT_TRUE(protoConfig.SerializeToArray(configBuffer2.data(), configLength));
EXPECT_EQ(diskioPlugin->callbacks->onPluginSessionStart(configBuffer2.data(), configLength+1), RET_FAIL);
}
} // namespace

1
device/plugins/ftrace_plugin/.gitignore vendored Executable file
View File

@ -0,0 +1 @@
*.pyc

View File

@ -0,0 +1,72 @@
# 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("../../base/config.gni")
ohos_shared_library("ftrace_plugin") {
sources = [
"src/bytrace_ops.cpp",
"src/file_utils.cpp",
"src/flow_controller.cpp",
"src/ftrace_data_reader.cpp",
"src/ftrace_field_parser.cpp",
"src/ftrace_fs_ops.cpp",
"src/ftrace_module.cpp",
"src/ftrace_parser.cpp",
"src/kernel_symbols_parser.cpp",
"src/paged_mem_pool.cpp",
"src/printk_formats_parser.cpp",
"src/process_utils.cpp",
"src/result_transporter.cpp",
"src/string_utils.cpp",
"src/sub_event_parser.cpp",
"src/trace_ops.cpp",
]
defines = [ "_GNU_SOURCE" ]
include_dirs = [
"include",
"src",
"../../base/include",
"../api/include",
"${OHOS_PROFILER_DIR}/interfaces/kits",
"${OHOS_PROFILER_DIR}/device/base/include",
"//utils/native/base/include",
]
deps = [
"${OHOS_PROFILER_3RDPARTY_PROTOBUF_DIR}:protobuf_lite",
"${OHOS_PROFILER_DIR}/protos/types/plugins/ftrace_data:ftrace_data_cpp",
"src/event_parsers:ftrace_event_parsers",
"//utils/native/base:utilsecurec",
]
if (current_toolchain != host_toolchain) {
defines += [ "HAVE_HILOG" ]
if (build_l2) {
external_deps = [ "shared_library:libhilog" ]
} else {
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
}
}
public_configs = [ "${OHOS_PROFILER_DIR}/device/base:hiprofiler_test_config" ]
install_enable = true
subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}"
}
group("ftrace_targets") {
deps = [
":ftrace_plugin",
"test:busy_test",
"test:get_tzinfo",
"tools/trace_converter",
]
}

View File

@ -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.
*
* Description: BytraceOps defines
*/
#ifndef BYTRACE_OPS_H
#define BYTRACE_OPS_H
#include "trace_ops.h"
FTRACE_NS_BEGIN
class BytraceOps : public TraceOps {
public:
BytraceOps();
~BytraceOps();
private:
bool PrepareListCategoriesCmd() override;
bool PrepareEnableCategoriesCmd() override;
bool PrepareDisableCategoriesCmd() override;
};
FTRACE_NS_END
#endif // BYTRACE_OPS_H

View File

@ -0,0 +1,31 @@
/*
* 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 FILE_UTILS_H
#define FILE_UTILS_H
#include <string>
#include <vector>
class FileUtils {
public:
static std::string ReadFile(int fd);
static std::string ReadFile(const std::string& path);
static int WriteFile(const std::string& path, const std::string& content);
static int WriteFile(const std::string& path, const std::string& content, int flags);
static int WriteFile(const std::string& path, const std::string& content, int flags, int mode);
static std::vector<std::string> ListDir(const std::string& dirPath);
};
#endif // FILE_UTILS_H

View File

@ -0,0 +1,105 @@
/*
* 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.
*
* Description: FlowController define
*/
#ifndef FLOW_CONTROLLER_H
#define FLOW_CONTROLLER_H
#include "ftrace_data_reader.h"
#include "ftrace_namespace.h"
#include "ftrace_parser.h"
#include "kernel_symbols_parser.h"
#include "paged_mem_pool.h"
#include "plugin_module_api.h"
#include "result_transporter.h"
#include "trace_ops.h"
#include "trace_plugin_config.pb.h"
#include <atomic>
#include <cstdint>
#include <iostream>
#include <mutex>
#include <thread>
using WriterStructPtr = std::unique_ptr<WriterStruct>::pointer;
FTRACE_NS_BEGIN
class FlowController {
public:
FlowController(void);
~FlowController(void);
int SetWriter(const WriterStructPtr& writer);
int LoadConfig(const uint8_t configData[], uint32_t size);
int StartCapture(void);
int StopCapture(void);
private:
DISALLOW_COPY_AND_MOVE(FlowController);
bool CreateRawDataReaders();
bool CreatePagedMemoryPool();
bool CreateRawDataBuffers();
bool CreateRawDataCaches();
void SetupTraceBufferSize(uint32_t sizeKb);
void SetupTransporterFlushParams(uint32_t intervalMs, uint32_t thresholdKb);
void GenerateRawDataFileNames(const std::string& prefix);
void SetupTraceReadPeriod(uint32_t periodMs);
void CaptureWork();
long ReadEventData(int cpuid);
bool ParseEventData(int cpuid, long dataSize);
bool AddPlatformEventsToParser(void);
void EnableTraceEvents(void);
void DisableTraceEvents(void);
bool ReportClockTimes(void);
bool ParseKernelSymbols(void);
bool ParsePerCpuStatus(int stage);
bool ParseFtraceEvent(int cpuid, uint8_t page[]);
static std::unique_ptr<TraceOps> GetTraceOps();
using EventTypeName = std::pair<std::string, std::string>;
std::vector<EventTypeName> supportedEvents_ = {};
std::vector<EventTypeName> enabledEvents_ = {};
std::unique_ptr<PagedMemPool> memPool_ = nullptr;
std::unique_ptr<KernelSymbolsParser> ksymsParser_ = nullptr;
std::unique_ptr<FtraceParser> ftraceParser_ = nullptr;
std::unique_ptr<ResultTransporter> tansporter_ = nullptr;
std::unique_ptr<TraceOps> traceOps_ = nullptr;
std::vector<std::unique_ptr<FtraceDataReader>> ftraceReaders_ = {};
std::vector<std::shared_ptr<uint8_t>> ftraceBuffers_;
std::vector<std::shared_ptr<FILE>> rawDataDumpFile_;
std::atomic<bool> keepRunning_ = false;
std::thread pollThread_ = {};
// for trace plugin config fields
std::vector<std::string> requestEvents_ = {}; // 1
std::vector<std::string> traceCategories_ = {}; // 2
std::vector<std::string> traceApps_ = {}; // 3
std::vector<std::string> rawDataDumpPath_ = {}; // 13
uint32_t tracePeriodMs_ = 0; // 10
uint32_t bufferSizeKb_ = 0; // 6
bool parseKsyms_ = false; // 7
WriterStructPtr resultWriter_ = nullptr;
int platformCpuNum_ = 0;
bool getClockTimes_ = true;
bool ftraceSupported_ = false;
};
FTRACE_NS_END
#endif // FLOW_CONTROLLER_H

View File

@ -0,0 +1,150 @@
/*
* 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.
*
* Description: StreamTransporter class define
*/
#ifndef FTRACE_COMMON_TYPE_H
#define FTRACE_COMMON_TYPE_H
#include <string>
#include <vector>
#include "ftrace_namespace.h"
FTRACE_NS_BEGIN
enum PerCpuTraceStatus {
TRACE_START = 0,
TRACE_END = 1,
};
// refers kernel enum ring_buffer_type:
// https://github.com/torvalds/linux/blob/v4.19/include/linux/ring_buffer.h#L55
enum EventBufferType {
BUFFER_TYPE_PADDING = 29,
BUFFER_TYPE_TIME_EXTEND = 30,
BUFFER_TYPE_TIME_STAMP = 31,
};
// refers kernel struct ring_buffer_event:
// https://github.com/torvalds/linux/blob/v4.19/include/linux/ring_buffer.h#L15
struct FtraceEventHeader {
uint32_t typeLen : 5;
uint32_t timeDelta : 27;
uint32_t array[0];
};
// /sys/kernel/debug/tracing/events/header_page
// kernel source ring_buffer.c struct buffer_data_page
struct PageHeader {
uint64_t timestamp = 0;
uint64_t size = 0; // data size
uint8_t overwrite = 0;
uint8_t* startpos = nullptr;
uint8_t* endpos = nullptr;
};
enum ProtoFieldType {
PROTO_TYPE_UNKNOWN = 0,
PROTO_TYPE_DOUBLE,
PROTO_TYPE_FLOAT,
PROTO_TYPE_INT64,
PROTO_TYPE_UINT64,
PROTO_TYPE_INT32,
PROTO_TYPE_FIXED64,
PROTO_TYPE_FIXED32,
PROTO_TYPE_BOOL,
PROTO_TYPE_STRING,
PROTO_TYPE_GROUP, // DEPRECATED (PROTO2 ONLY)
PROTO_TYPE_MESSAGE,
PROTO_TYPE_BYTES,
PROTO_TYPE_UINT32,
PROTO_TYPE_ENUM,
PROTO_TYPE_SFIXED32,
PROTO_TYPE_SFIXED64,
PROTO_TYPE_SINT32,
PROTO_TYPE_SINT64,
PROTO_TYPE_MAX,
};
enum EventFieldType {
FIELD_TYPE_INVALID = 0,
FIELD_TYPE_BOOL,
FIELD_TYPE_INT8,
FIELD_TYPE_UINT8,
FIELD_TYPE_INT16,
FIELD_TYPE_UINT16,
FIELD_TYPE_INT32,
FIELD_TYPE_UINT32,
FIELD_TYPE_INT64,
FIELD_TYPE_UINT64,
FIELD_TYPE_FIXEDCSTRING,
FIELD_TYPE_CSTRING,
FIELD_TYPE_STRINGPTR,
FIELD_TYPE_INODE32,
FIELD_TYPE_INODE64,
FIELD_TYPE_PID32,
FIELD_TYPE_COMMONPID32,
FIELD_TYPE_DEVID32,
FIELD_TYPE_DEVID64,
FIELD_TYPE_DATALOC,
FIELD_TYPE_SYMADDR32,
FIELD_TYPE_SYMADDR64,
};
// used to store content of each cpu stats data, likes /sys/kernel/debug/tracing/per_cpu/cpu0/stats.
struct PerCpuStats {
uint64_t cpuIndex = 0;
uint64_t entries = 0;
uint64_t overrun = 0;
uint64_t commitOverrun = 0;
uint64_t bytes = 0;
double oldestEventTs = 0.0;
double nowTs = 0.0;
uint64_t droppedEvents = 0;
uint64_t readEvents = 0;
};
struct FieldFormat {
uint16_t offset = 0;
uint16_t size = 0;
uint8_t isSigned = 0;
EventFieldType filedType = FIELD_TYPE_INVALID;
ProtoFieldType protoType = PROTO_TYPE_UNKNOWN;
std::string name = "";
std::string typeName = "";
};
struct CommonFiledIndex {
static constexpr int INVALID_IDX = -1;
int type = INVALID_IDX;
int flags = INVALID_IDX;
int preemt = INVALID_IDX;
int pid = INVALID_IDX;
};
struct EventFormat {
uint32_t eventId = 0;
uint32_t eventSize = 0;
std::string eventName = "";
std::string eventType = "";
std::vector<FieldFormat> fields = {};
std::vector<FieldFormat> commonFields = {};
CommonFiledIndex commonIndex = {};
};
struct PageHeaderFormat {
FieldFormat timestamp = {};
FieldFormat commit = {};
FieldFormat overwrite = {};
};
FTRACE_NS_END
#endif

View File

@ -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.
*
* Description: FtraceDataReader define
*/
#ifndef FTRACE_DATA_READER_H
#define FTRACE_DATA_READER_H
#include <string>
#include "ftrace_namespace.h"
FTRACE_NS_BEGIN
class FtraceDataReader {
public:
explicit FtraceDataReader(const std::string& path);
~FtraceDataReader();
long Read(uint8_t data[], uint32_t size);
private:
DISALLOW_COPY_AND_MOVE(FtraceDataReader);
std::string path_;
int readFd_;
};
FTRACE_NS_END
#endif

View File

@ -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.
*/
#ifndef FTRACE_PARSE_HELPERS_H
#define FTRACE_PARSE_HELPERS_H
#include <string>
#include <vector>
#include "ftrace_common_type.h"
FTRACE_NS_BEGIN
using VoidPtr = std::unique_ptr<void>::pointer;
class FtraceFieldParser {
public:
template <typename T> static T ParseIntField(const FieldFormat& format, uint8_t data[], size_t size)
{
static_assert(std::is_integral<T>::value, "Integral type T required.");
T retval = {};
auto end = data + size;
auto start = data + format.offset;
ReadData(start, end, &retval, format.size);
return retval;
}
template <typename T>
static T ParseIntField(const std::vector<FieldFormat>& fields, size_t id, uint8_t data[], size_t size)
{
static_assert(std::is_integral<T>::value, "Integral type T required.");
if (fields.size() > id) {
return ParseIntField<T>(fields[id], data, size);
}
return {};
}
static std::string ParseStrField(const FieldFormat& format, uint8_t data[], size_t size);
static std::string ParseStrField(const std::vector<FieldFormat>& fields, size_t id, uint8_t data[], size_t size)
{
if (fields.size() > id) {
return ParseStrField(fields[id], data, size);
}
return "";
}
private:
static bool ReadData(const uint8_t start[], const uint8_t end[], VoidPtr out, size_t size);
};
FTRACE_NS_END
#endif

View File

@ -0,0 +1,79 @@
/*
* 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 FTRACE_FS_OPS_H
#define FTRACE_FS_OPS_H
#include <string>
#include <vector>
#include "ftrace_namespace.h"
#ifndef MOCKABLE
#define MOCKABLE virtual
#endif
FTRACE_NS_BEGIN
class FtraceFsOps {
public:
static FtraceFsOps& GetInstance();
static std::string GetFtraceRoot();
MOCKABLE std::string GetKernelSymbols() const;
MOCKABLE std::string GetPrintkFormats() const;
MOCKABLE std::string GetProcessComm(int pid);
MOCKABLE std::string GetThreadComm(int pid, int tid);
// for ftrace status nodes
MOCKABLE std::string GetSavedCmdLines() const;
MOCKABLE std::string GetSavedTgids() const;
MOCKABLE std::string GetPerCpuStats(int cpu) const;
MOCKABLE std::string GetRawTracePath(int cpu) const;
MOCKABLE std::string GetPageHeaderFormat() const;
MOCKABLE std::string GetEventDataFormat(const std::string& type, const std::string& name) const;
MOCKABLE std::vector<std::pair<std::string, std::string>> GetPlatformEvents();
// for ftrace control nodes
MOCKABLE bool ClearTraceBuffer();
MOCKABLE bool SetRecordCmdOption(bool enable);
MOCKABLE bool SetRecordTgidOption(bool enable);
MOCKABLE bool SetBufferSizeKb(int sizeKb);
MOCKABLE bool SetTraceClock(const std::string& clock);
MOCKABLE std::string GetTraceClock();
MOCKABLE bool AppendSetEvent(const std::string& type, const std::string& name);
MOCKABLE bool ClearSetEvent();
MOCKABLE bool EnableEvent(const std::string& type, const std::string& name);
MOCKABLE bool DisableEvent(const std::string& type, const std::string& name);
MOCKABLE bool EnableTracing();
MOCKABLE bool DisableTracing();
// for UT
void SetFtraceRoot(std::string path)
{
ftraceRoot_ = path;
}
private:
FtraceFsOps();
MOCKABLE ~FtraceFsOps();
DISALLOW_COPY_AND_MOVE(FtraceFsOps);
private:
std::string ftraceRoot_;
};
FTRACE_NS_END
#endif // FTRACE_FS_OPS_H

View File

@ -0,0 +1,31 @@
/*
* 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.
*
* Description: AtraceOps define
*/
#ifndef FTRACE_MODULE_H
#define FTRACE_MODULE_H
#include <cstdint>
#include "ftrace_namespace.h"
#include "plugin_module_api.h"
int TracePluginStartSession(const uint8_t configData[], const uint32_t configSize);
int TracePluginRegisterWriter(const WriterStruct* writer);
int TracePluginStopSession(void);
#endif // FTRACE_MODULE_H

View File

@ -0,0 +1,39 @@
/*
* 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 FTRACE_NAMESPACE_H
#define FTRACE_NAMESPACE_H
#include "nocopyable.h"
#if __cplusplus >= 201703L
#define FTRACE_NS_BEGIN namespace OHOS::Profiler::Plugins {
#else
#define FTRACE_NS_BEGIN \
namespace OHOS { \
namespace Profiler { \
namespace Plugins {
#endif
#if __cplusplus >= 201703L
#define FTRACE_NS_END } /* OHOS::Profiler::Plugins */
#else
#define FTRACE_NS_END \
} /* Plugins */ \
} /* Profiler */ \
} /* OHOS */
#endif
#define FTRACE_NS OHOS::Profiler::Plugins
#endif // FTRACE_NAMESPACE_H

View File

@ -0,0 +1,88 @@
/*
* 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.
*
* Description: FtraceParser class define
*/
#ifndef FTRACE_EVENT_CONTAINER_H
#define FTRACE_EVENT_CONTAINER_H
#include <memory>
#include <regex>
#include <string>
#include <vector>
#include "ftrace_common_type.h"
#include "ftrace_field_parser.h"
#include "printk_formats_parser.h"
#include "sub_event_parser.h"
FTRACE_NS_BEGIN
class FtraceParser {
public:
FtraceParser();
~FtraceParser();
bool Init();
bool SetupEvent(const std::string& type, const std::string& name);
bool ParsePerCpuStatus(PerCpuStats& stats, const std::string& perCpuStats);
bool ParsePage(FtraceCpuDetailMsg& cpuDetailMsg, uint8_t page[], size_t size);
bool ParseSavedTgid(const std::string& savedTgid);
bool ParseSavedCmdlines(const std::string& savedCmdlines);
void SetDebugOn(bool value);
private:
bool GetEventFormat(uint32_t id, EventFormat& format);
int GetHeaderPageCommitSize(void);
bool ParseHeaderPageFormat(const std::string& formatDesc);
bool ParseEventFormat(const std::string& formatDesc, EventFormat& format);
bool ParseFieldFormat(const std::string& fieldLine, EventFormat& format);
bool ParseFieldType(const std::string& type, FieldFormat& field);
void PrintFieldInfo(const FieldFormat& info);
static void ParseProtoType(FieldFormat& field);
bool ParsePageHeader();
// parse different page types
bool ParsePaddingData(const FtraceEventHeader& eventHeader);
bool ParseTimeExtend(const FtraceEventHeader& eventHeader);
bool ParseTimeStamp(const FtraceEventHeader& eventHeader);
bool ParseDataRecord(const FtraceEventHeader& eventHeader, FtraceCpuDetailMsg& cpuDetailMsg);
bool ParseFtraceEvent(FtraceEvent& ftraceEvent, uint8_t data[], size_t dataSize, const EventFormat& format);
bool ParseFtraceCommonFields(FtraceEvent& ftraceEvent, uint8_t data[], size_t dataSize, const EventFormat& format);
private:
DISALLOW_COPY_AND_MOVE(FtraceParser);
bool debugOn_ = false;
std::regex fixedCharArrayRegex_;
std::regex flexDataLocArrayRegex_;
std::unordered_map<uint32_t, EventFormat> eventDict_ = {};
PageHeaderFormat pageHeaderFormat_ = {};
std::string savedTgidPath_ = "";
std::string savedCmdlines_ = "";
uint8_t* cur_ = nullptr;
uint8_t* page_ = nullptr; // page start
uint8_t* endOfData_ = nullptr; // end of event data
uint8_t* endOfPage_ = nullptr; // end of full page
uint64_t timestamp_ = 0;
PageHeader pageHeader_ = {};
std::unordered_map<int32_t, int32_t> tgidDict_ = {};
std::unordered_map<int32_t, std::string> commDict_ = {};
};
FTRACE_NS_END
#endif

View File

@ -0,0 +1,51 @@
/*
* 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.
*
* Description: KernelSymbolsParser class define
*/
#ifndef KERNEL_SYMBOLS_PARSER_H
#define KERNEL_SYMBOLS_PARSER_H
#include <functional>
#include <string>
#include <vector> // for std::vector
#include "ftrace_namespace.h"
FTRACE_NS_BEGIN
struct KernelSymbol {
uint64_t addr = 0;
char type = 0;
std::string name;
};
class KernelSymbolsParser {
public:
KernelSymbolsParser();
~KernelSymbolsParser();
bool Parse(const std::string& kallsyms);
void Accept(const std::function<void(const KernelSymbol&)>& visitor);
private:
DISALLOW_COPY_AND_MOVE(KernelSymbolsParser);
static bool IsValidTextSymbol(const KernelSymbol& a);
static bool CompareSymbolInfo(const KernelSymbol& a, const KernelSymbol& b);
private:
std::vector<KernelSymbol> kernelSymbols_;
};
FTRACE_NS_END
#endif // KERNEL_SYMBOLS_PARSER_H

View File

@ -0,0 +1,47 @@
/*
* 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 PAGED_MEM_POOL_H
#define PAGED_MEM_POOL_H
#include <set>
#include <vector>
#include "ftrace_namespace.h"
FTRACE_NS_BEGIN
class PagedMemPool {
public:
PagedMemPool(size_t pagePerBlock = 1, size_t maxCacheSize = 0);
~PagedMemPool();
void* Allocate();
bool Recycle(void* block);
size_t GetBlockSize() const;
private:
DISALLOW_COPY_AND_MOVE(PagedMemPool);
bool Free(void* block);
bool Valid(void* block);
private:
size_t blockSize_ = 1;
size_t maxCacheSize_ = 0;
std::vector<void*> freeList_;
std::set<void*> blockSet_;
};
FTRACE_NS_END
#endif // PAGED_MEM_POOL_H

View File

@ -0,0 +1,39 @@
/*
* 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 PRINTK_FORMAT_PARSER_H
#define PRINTK_FORMAT_PARSER_H
#include <string>
#include <unordered_map> // for std::unordered_map
#include "ftrace_namespace.h"
FTRACE_NS_BEGIN
class PrintkFormatsParser {
public:
static PrintkFormatsParser& GetInstance();
std::string GetSymbol(uint64_t addr);
bool Parse(const std::string& printkFormats);
private:
PrintkFormatsParser();
~PrintkFormatsParser();
DISALLOW_COPY_AND_MOVE(PrintkFormatsParser);
std::unordered_map<uint64_t, std::string> printkFormats_ = {};
};
FTRACE_NS_END
#endif // PRINTK_FORMAT_PARSER_H

View File

@ -0,0 +1,33 @@
/*
* 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 PROCESS_UTILS_H
#define PROCESS_UTILS_H
#include <string>
#include <vector>
struct ExecuteArgs {
std::string bin_;
std::vector<std::string> argv_;
bool out2pipe_ = true;
bool err2pipe_ = false;
};
class ProcessUtils {
public:
static int Execute(const ExecuteArgs& args, std::string& output);
};
#endif // PROCESS_UTILS_H

View File

@ -0,0 +1,67 @@
/*
* 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.
*
* Description: StreamTransporter class define
*/
#ifndef RESULT_TRANSPORTER_H
#define RESULT_TRANSPORTER_H
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <fcntl.h>
#include <iostream>
#include <memory>
#include <mutex>
#include <thread>
#include <vector>
#include "ftrace_namespace.h"
#include "plugin_module_api.h"
#include "trace_plugin_result.pb.h"
FTRACE_NS_BEGIN
using ResultPtr = std::unique_ptr<TracePluginResult>;
class ResultTransporter {
public:
using WriterStructPtr = std::unique_ptr<WriterStruct>::pointer;
ResultTransporter(const std::string& name, WriterStructPtr writer);
~ResultTransporter();
bool Submit(ResultPtr&& result);
void SetFlushInterval(int ms);
void SetFlushThreshold(uint32_t nbytes);
protected:
long Write(ResultPtr&& packet);
void Flush();
private:
DISALLOW_COPY_AND_MOVE(ResultTransporter);
bool IsFlushTime() const;
void Report();
std::string name_;
std::atomic<uint64_t> bytesCount_ = 0;
std::atomic<uint32_t> bytesPending_ = 0;
std::atomic<uint64_t> timeCostUs_ = 0;
std::atomic<uint32_t> writeCount_ = 0;
std::atomic<uint32_t> flushThreshold_ = 0;
std::chrono::milliseconds flushInterval_;
WriterStructPtr writer_ = nullptr;
std::vector<char> buffer_;
};
FTRACE_NS_END
#endif // RESULT_TRANSPORTER_H

View File

@ -0,0 +1,31 @@
/*
* 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 STRING_UTILS_H
#define STRING_UTILS_H
#include <string>
#include <vector>
class StringUtils {
public:
static bool EndsWith(const std::string& str, const std::string& postfix);
static bool StartsWith(const std::string& str, const std::string& prefix);
static bool Contains(const std::string& str, const std::string& target);
static std::string Strip(const std::string& str);
static std::string Join(const std::vector<std::string>& strs, const std::string& sep);
static std::vector<std::string> Split(const std::string& str, const std::string& sep);
};
#endif // STRING_UTILS_H

View File

@ -0,0 +1,63 @@
/*
* 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 SUB_EVENT_PARSER_H
#define SUB_EVENT_PARSER_H
#include <cstdint>
#include <functional>
#include <map>
#include "ftrace_field_parser.h"
#include "trace_plugin_result.pb.h"
FTRACE_NS_BEGIN
class SubEventParserRegisterar;
class SubEventParser {
public:
static SubEventParser& GetInstance();
bool IsSupport(uint32_t eventId) const;
bool IsSupport(const std::string& eventName) const;
bool ParseEvent(FtraceEvent& event, uint8_t data[], size_t size, const EventFormat& format) const;
bool SetupEvent(const EventFormat& format);
using ParseFunction = std::function<void(FtraceEvent&, uint8_t[], size_t, const EventFormat&)>;
protected:
friend class SubEventParserRegisterar;
void RegisterParseFunction(const std::string& name, ParseFunction&& func);
void UnregisterParseFunction(const std::string& name);
private:
SubEventParser();
~SubEventParser();
DISALLOW_COPY_AND_MOVE(SubEventParser);
std::map<uint32_t, ParseFunction> idToFunctions_;
std::map<std::string, ParseFunction> nameToFunctions_;
};
class SubEventParserRegisterar {
public:
SubEventParserRegisterar(const std::string& name, SubEventParser::ParseFunction&& func);
~SubEventParserRegisterar();
private:
DISALLOW_COPY_AND_MOVE(SubEventParserRegisterar);
std::string name_;
};
FTRACE_NS_END
#define REGISTER_FTRACE_EVENT_PARSE_FUNCTION(name, func) \
static FTRACE_NS::SubEventParserRegisterar g_eventRegisterar##name(#name, func)
#endif // SUB_EVENT_PARSER_H

View File

@ -0,0 +1,64 @@
/*
* 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.
*
* Description: TraceOps defines
*/
#ifndef COMMON_TRACE_OPS_H
#define COMMON_TRACE_OPS_H
#include <string>
#include <vector>
#include "ftrace_namespace.h"
FTRACE_NS_BEGIN
class TraceOps {
public:
DISALLOW_COPY_AND_MOVE(TraceOps);
enum TraceType {
UNKNOW = 0,
BYTRACE,
};
TraceOps(const std::string& path, const std::string& arg0, TraceType type);
virtual ~TraceOps();
bool IsSupported();
bool HasCategory(const std::string& name);
bool EnableCategories(const std::vector<std::string>& categories);
bool DisableCategories();
std::string GetCommand() const;
TraceType GetTraceType() const;
protected:
virtual std::vector<std::string> ListCategories();
virtual bool PrepareListCategoriesCmd();
virtual bool PrepareEnableCategoriesCmd();
virtual bool PrepareDisableCategoriesCmd();
int ExecuteCommand(bool out2pipe = true, bool err2pipe = true);
protected:
std::string arg0_;
std::string bin_;
TraceType type_ = UNKNOW;
std::vector<std::string> targetCategories_;
std::vector<std::string> supportedCategories_;
std::vector<std::string> args_;
std::string output_;
};
FTRACE_NS_END
#endif // COMMON_TRACE_OPS_H

View File

@ -0,0 +1,50 @@
/*
* 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.
*
* Description: BytraceOps implements
*/
#include "bytrace_ops.h"
#include "logging.h"
#include "string_utils.h"
FTRACE_NS_BEGIN
BytraceOps::BytraceOps() : TraceOps("/system/bin/bytrace", "bytrace", BYTRACE) {}
BytraceOps::~BytraceOps() {}
bool BytraceOps::PrepareListCategoriesCmd()
{
args_.push_back("-l");
return true;
}
bool BytraceOps::PrepareEnableCategoriesCmd()
{
args_.push_back("--trace_begin");
args_.push_back("-t");
args_.push_back("1");
for (auto& category : targetCategories_) {
args_.push_back(category);
}
return true;
}
bool BytraceOps::PrepareDisableCategoriesCmd()
{
args_.push_back("--trace_finish");
return true;
}
FTRACE_NS_END

View File

@ -0,0 +1,41 @@
# THIS FILE IS GENERATE BY {}, PLEASE DON'T EDIT IT!
# 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("../../../../base/config.gni")
import("autogenerated.gni")
ohos_source_set("ftrace_event_parsers") {
sources = auto_generated_cpp_sources
include_dirs = [
".",
"..",
"../../include",
"${OHOS_PROFILER_DIR}/device/base/include",
"//utils/native/base/include",
]
deps = [
"${OHOS_PROFILER_3RDPARTY_PROTOBUF_DIR}:protobuf_lite",
"${OHOS_PROFILER_DIR}/protos/types/plugins/ftrace_data:ftrace_data_cpp",
]
if (current_toolchain != host_toolchain) {
defines = [ "HAVE_HILOG" ]
if (build_l2) {
external_deps = [ "shared_library:libhilog" ]
} else {
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
}
}
public_configs = [ "${OHOS_PROFILER_DIR}/device/base:hiprofiler_test_config" ]
subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}"
}

View File

@ -0,0 +1,48 @@
# THIS FILE IS GENERATE BY ftrace_cpp_generator.py, PLEASE DON'T EDIT IT!
# 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.
auto_generated_cpp_sources = [
"ftrace_binder_event_parser.cpp",
"ftrace_block_event_parser.cpp",
"ftrace_cgroup_event_parser.cpp",
"ftrace_clk_event_parser.cpp",
"ftrace_compaction_event_parser.cpp",
"ftrace_cpuhp_event_parser.cpp",
"ftrace_dma_fence_event_parser.cpp",
"ftrace_ext4_event_parser.cpp",
"ftrace_filelock_event_parser.cpp",
"ftrace_filemap_event_parser.cpp",
"ftrace_ftrace_event_parser.cpp",
"ftrace_gpio_event_parser.cpp",
"ftrace_i2c_event_parser.cpp",
"ftrace_ipi_event_parser.cpp",
"ftrace_irq_event_parser.cpp",
"ftrace_kmem_event_parser.cpp",
"ftrace_net_event_parser.cpp",
"ftrace_oom_event_parser.cpp",
"ftrace_pagemap_event_parser.cpp",
"ftrace_power_event_parser.cpp",
"ftrace_printk_event_parser.cpp",
"ftrace_raw_syscalls_event_parser.cpp",
"ftrace_rcu_event_parser.cpp",
"ftrace_sched_event_parser.cpp",
"ftrace_signal_event_parser.cpp",
"ftrace_sunrpc_event_parser.cpp",
"ftrace_task_event_parser.cpp",
"ftrace_timer_event_parser.cpp",
"ftrace_v4l2_event_parser.cpp",
"ftrace_vmscan_event_parser.cpp",
"ftrace_workqueue_event_parser.cpp",
"ftrace_writeback_event_parser.cpp",
]

View File

@ -0,0 +1,305 @@
/* THIS FILE IS GENERATE BY ftrace_cpp_generator.py, PLEASE DON'T EDIT IT!
* 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.
*/
#include "sub_event_parser.h"
FTRACE_NS_BEGIN
namespace {
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
binder_alloc_lru_end,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_binder_alloc_lru_end_format();
msg->set_proc(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_page_index(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
binder_alloc_lru_start,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_binder_alloc_lru_start_format();
msg->set_proc(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_page_index(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
binder_alloc_page_end,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_binder_alloc_page_end_format();
msg->set_proc(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_page_index(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
binder_alloc_page_start,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_binder_alloc_page_start_format();
msg->set_proc(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_page_index(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
binder_command,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_binder_command_format();
msg->set_cmd(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
binder_free_lru_end,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_binder_free_lru_end_format();
msg->set_proc(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_page_index(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
binder_free_lru_start,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_binder_free_lru_start_format();
msg->set_proc(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_page_index(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
binder_ioctl,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_binder_ioctl_format();
msg->set_cmd(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_arg(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
binder_ioctl_done,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_binder_ioctl_done_format();
msg->set_ret(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
binder_lock,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_binder_lock_format();
msg->set_tag(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
binder_locked,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_binder_locked_format();
msg->set_tag(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
binder_read_done,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_binder_read_done_format();
msg->set_ret(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
binder_return,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_binder_return_format();
msg->set_cmd(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
binder_transaction,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_binder_transaction_format();
msg->set_debug_id(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_target_node(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_to_proc(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_to_thread(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_reply(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_code(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_flags(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
binder_transaction_alloc_buf,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_binder_transaction_alloc_buf_format();
msg->set_debug_id(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_data_size(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_offsets_size(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_extra_buffers_size(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
binder_transaction_buffer_release,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_binder_transaction_buffer_release_format();
msg->set_debug_id(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_data_size(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_offsets_size(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_extra_buffers_size(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
binder_transaction_failed_buffer_release,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_binder_transaction_failed_buffer_release_format();
msg->set_debug_id(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_data_size(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_offsets_size(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_extra_buffers_size(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
binder_transaction_fd,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_binder_transaction_fd_format();
msg->set_debug_id(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_src_fd(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_dest_fd(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
binder_transaction_node_to_ref,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_binder_transaction_node_to_ref_format();
msg->set_debug_id(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_node_debug_id(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_node_ptr(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_ref_debug_id(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_ref_desc(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
binder_transaction_received,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_binder_transaction_received_format();
msg->set_debug_id(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
binder_transaction_ref_to_node,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_binder_transaction_ref_to_node_format();
msg->set_debug_id(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_ref_debug_id(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_ref_desc(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_node_debug_id(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_node_ptr(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
binder_transaction_ref_to_ref,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_binder_transaction_ref_to_ref_format();
msg->set_debug_id(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_node_debug_id(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_src_ref_debug_id(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_src_ref_desc(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_dest_ref_debug_id(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_dest_ref_desc(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
binder_unlock,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_binder_unlock_format();
msg->set_tag(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
binder_unmap_kernel_end,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_binder_unmap_kernel_end_format();
msg->set_proc(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_page_index(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
binder_unmap_kernel_start,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_binder_unmap_kernel_start_format();
msg->set_proc(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_page_index(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
binder_unmap_user_end,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_binder_unmap_user_end_format();
msg->set_proc(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_page_index(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
binder_unmap_user_start,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_binder_unmap_user_start_format();
msg->set_proc(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_page_index(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
binder_update_page_range,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_binder_update_page_range_format();
msg->set_proc(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_allocate(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_offset(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_size(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
binder_wait_for_work,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_binder_wait_for_work_format();
msg->set_proc_work(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_transaction_stack(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_thread_todo(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
binder_write_done,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_binder_write_done_format();
msg->set_ret(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
});
} // namespace
FTRACE_NS_END

View File

@ -0,0 +1,232 @@
/* THIS FILE IS GENERATE BY ftrace_cpp_generator.py, PLEASE DON'T EDIT IT!
* 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.
*/
#include "sub_event_parser.h"
FTRACE_NS_BEGIN
namespace {
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
block_bio_backmerge,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_block_bio_backmerge_format();
msg->set_dev(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_sector(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_nr_sector(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_rwbs(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
msg->set_comm(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
block_bio_bounce,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_block_bio_bounce_format();
msg->set_dev(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_sector(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_nr_sector(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_rwbs(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
msg->set_comm(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
block_bio_complete,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_block_bio_complete_format();
msg->set_dev(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_sector(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_nr_sector(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_error(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_rwbs(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
block_bio_frontmerge,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_block_bio_frontmerge_format();
msg->set_dev(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_sector(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_nr_sector(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_rwbs(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
msg->set_comm(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
block_bio_queue,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_block_bio_queue_format();
msg->set_dev(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_sector(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_nr_sector(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_rwbs(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
msg->set_comm(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
block_bio_remap,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_block_bio_remap_format();
msg->set_dev(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_sector(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_nr_sector(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_old_dev(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_old_sector(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_rwbs(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
block_dirty_buffer,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_block_dirty_buffer_format();
msg->set_dev(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_sector(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_size(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
block_getrq,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_block_getrq_format();
msg->set_dev(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_sector(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_nr_sector(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_rwbs(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
msg->set_comm(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
block_plug,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_block_plug_format();
msg->set_comm(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
block_rq_complete,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_block_rq_complete_format();
msg->set_dev(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_sector(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_nr_sector(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_error(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_rwbs(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
msg->set_cmd(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
block_rq_insert,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_block_rq_insert_format();
msg->set_dev(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_sector(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_nr_sector(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_bytes(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_rwbs(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
msg->set_comm(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
msg->set_cmd(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
block_rq_issue,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_block_rq_issue_format();
msg->set_dev(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_sector(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_nr_sector(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_bytes(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_rwbs(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
msg->set_comm(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
msg->set_cmd(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
block_rq_remap,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_block_rq_remap_format();
msg->set_dev(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_sector(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_nr_sector(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_old_dev(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_old_sector(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_nr_bios(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_rwbs(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
block_rq_requeue,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_block_rq_requeue_format();
msg->set_dev(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_sector(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_nr_sector(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_rwbs(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
msg->set_cmd(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
block_sleeprq,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_block_sleeprq_format();
msg->set_dev(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_sector(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_nr_sector(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_rwbs(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
msg->set_comm(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
block_split,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_block_split_format();
msg->set_dev(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_sector(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_new_sector(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_rwbs(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
msg->set_comm(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
block_touch_buffer,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_block_touch_buffer_format();
msg->set_dev(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_sector(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_size(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
block_unplug,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_block_unplug_format();
msg->set_nr_rq(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_comm(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
});
} // namespace
FTRACE_NS_END

View File

@ -0,0 +1,119 @@
/* THIS FILE IS GENERATE BY ftrace_cpp_generator.py, PLEASE DON'T EDIT IT!
* 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.
*/
#include "sub_event_parser.h"
FTRACE_NS_BEGIN
namespace {
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
cgroup_attach_task,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_cgroup_attach_task_format();
msg->set_dst_root(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_dst_id(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_dst_level(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_pid(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_dst_path(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
msg->set_comm(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
cgroup_destroy_root,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_cgroup_destroy_root_format();
msg->set_root(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_ss_mask(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_name(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
cgroup_mkdir,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_cgroup_mkdir_format();
msg->set_root(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_id(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_level(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_path(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
cgroup_release,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_cgroup_release_format();
msg->set_root(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_id(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_level(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_path(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
cgroup_remount,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_cgroup_remount_format();
msg->set_root(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_ss_mask(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_name(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
cgroup_rename,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_cgroup_rename_format();
msg->set_root(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_id(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_level(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_path(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
cgroup_rmdir,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_cgroup_rmdir_format();
msg->set_root(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_id(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_level(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_path(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
cgroup_setup_root,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_cgroup_setup_root_format();
msg->set_root(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_ss_mask(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_name(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
cgroup_transfer_tasks,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_cgroup_transfer_tasks_format();
msg->set_dst_root(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_dst_id(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_dst_level(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_pid(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_dst_path(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
msg->set_comm(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
});
} // namespace
FTRACE_NS_END

View File

@ -0,0 +1,137 @@
/* THIS FILE IS GENERATE BY ftrace_cpp_generator.py, PLEASE DON'T EDIT IT!
* 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.
*/
#include "sub_event_parser.h"
FTRACE_NS_BEGIN
namespace {
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
clk_disable,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_clk_disable_format();
msg->set_name(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
clk_disable_complete,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_clk_disable_complete_format();
msg->set_name(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
clk_enable,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_clk_enable_format();
msg->set_name(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
clk_enable_complete,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_clk_enable_complete_format();
msg->set_name(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
clk_prepare,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_clk_prepare_format();
msg->set_name(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
clk_prepare_complete,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_clk_prepare_complete_format();
msg->set_name(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
clk_set_parent,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_clk_set_parent_format();
msg->set_name(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
msg->set_pname(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
clk_set_parent_complete,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_clk_set_parent_complete_format();
msg->set_name(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
msg->set_pname(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
clk_set_phase,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_clk_set_phase_format();
msg->set_name(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
msg->set_phase(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
clk_set_phase_complete,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_clk_set_phase_complete_format();
msg->set_name(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
msg->set_phase(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
clk_set_rate,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_clk_set_rate_format();
msg->set_name(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
msg->set_rate(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
clk_set_rate_complete,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_clk_set_rate_complete_format();
msg->set_name(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
msg->set_rate(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
clk_unprepare,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_clk_unprepare_format();
msg->set_name(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
clk_unprepare_complete,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_clk_unprepare_complete_format();
msg->set_name(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
});
} // namespace
FTRACE_NS_END

View File

@ -0,0 +1,146 @@
/* THIS FILE IS GENERATE BY ftrace_cpp_generator.py, PLEASE DON'T EDIT IT!
* 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.
*/
#include "sub_event_parser.h"
FTRACE_NS_BEGIN
namespace {
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
mm_compaction_begin,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_mm_compaction_begin_format();
msg->set_zone_start(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_migrate_pfn(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_free_pfn(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_zone_end(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_sync(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
mm_compaction_defer_compaction,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_mm_compaction_defer_compaction_format();
msg->set_nid(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_idx(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_order(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_considered(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_defer_shift(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_order_failed(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
mm_compaction_defer_reset,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_mm_compaction_defer_reset_format();
msg->set_nid(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_idx(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_order(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_considered(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_defer_shift(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_order_failed(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
mm_compaction_deferred,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_mm_compaction_deferred_format();
msg->set_nid(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_idx(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_order(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_considered(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_defer_shift(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_order_failed(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
mm_compaction_end,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_mm_compaction_end_format();
msg->set_zone_start(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_migrate_pfn(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_free_pfn(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_zone_end(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_sync(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_status(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
mm_compaction_finished,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_mm_compaction_finished_format();
msg->set_nid(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_idx(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_order(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_ret(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
mm_compaction_isolate_freepages,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_mm_compaction_isolate_freepages_format();
msg->set_start_pfn(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_end_pfn(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_nr_scanned(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_nr_taken(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
mm_compaction_isolate_migratepages,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_mm_compaction_isolate_migratepages_format();
msg->set_start_pfn(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_end_pfn(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_nr_scanned(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_nr_taken(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
mm_compaction_migratepages,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_mm_compaction_migratepages_format();
msg->set_nr_migrated(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_nr_failed(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
mm_compaction_suitable,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_mm_compaction_suitable_format();
msg->set_nid(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_idx(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_order(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_ret(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
mm_compaction_try_to_compact_pages,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_mm_compaction_try_to_compact_pages_format();
msg->set_order(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_gfp_mask(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_prio(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
});
} // namespace
FTRACE_NS_END

View File

@ -0,0 +1,52 @@
/* THIS FILE IS GENERATE BY ftrace_cpp_generator.py, PLEASE DON'T EDIT IT!
* 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.
*/
#include "sub_event_parser.h"
FTRACE_NS_BEGIN
namespace {
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
cpuhp_enter,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_cpuhp_enter_format();
msg->set_cpu(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_target(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_idx(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_fun(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
cpuhp_exit,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_cpuhp_exit_format();
msg->set_cpu(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_state(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_idx(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_ret(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
cpuhp_multi_enter,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_cpuhp_multi_enter_format();
msg->set_cpu(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_target(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_idx(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_fun(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
});
} // namespace
FTRACE_NS_END

View File

@ -0,0 +1,96 @@
/* THIS FILE IS GENERATE BY ftrace_cpp_generator.py, PLEASE DON'T EDIT IT!
* 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.
*/
#include "sub_event_parser.h"
FTRACE_NS_BEGIN
namespace {
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
dma_fence_destroy,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_dma_fence_destroy_format();
msg->set_driver(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
msg->set_timeline(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
msg->set_context(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_seqno(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
dma_fence_emit,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_dma_fence_emit_format();
msg->set_driver(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
msg->set_timeline(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
msg->set_context(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_seqno(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
dma_fence_enable_signal,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_dma_fence_enable_signal_format();
msg->set_driver(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
msg->set_timeline(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
msg->set_context(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_seqno(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
dma_fence_init,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_dma_fence_init_format();
msg->set_driver(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
msg->set_timeline(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
msg->set_context(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_seqno(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
dma_fence_signaled,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_dma_fence_signaled_format();
msg->set_driver(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
msg->set_timeline(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
msg->set_context(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_seqno(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
dma_fence_wait_end,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_dma_fence_wait_end_format();
msg->set_driver(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
msg->set_timeline(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
msg->set_context(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_seqno(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
dma_fence_wait_start,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_dma_fence_wait_start_format();
msg->set_driver(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
msg->set_timeline(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
msg->set_context(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_seqno(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
});
} // namespace
FTRACE_NS_END

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,114 @@
/* THIS FILE IS GENERATE BY ftrace_cpp_generator.py, PLEASE DON'T EDIT IT!
* 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.
*/
#include "sub_event_parser.h"
FTRACE_NS_BEGIN
namespace {
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
break_lease_block,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_break_lease_block_format();
msg->set_fl(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_i_ino(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_s_dev(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_fl_next(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_fl_owner(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_fl_flags(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_fl_type(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_fl_break_time(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_fl_downgrade_time(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
break_lease_noblock,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_break_lease_noblock_format();
msg->set_fl(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_i_ino(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_s_dev(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_fl_next(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_fl_owner(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_fl_flags(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_fl_type(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_fl_break_time(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_fl_downgrade_time(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
break_lease_unblock,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_break_lease_unblock_format();
msg->set_fl(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_i_ino(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_s_dev(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_fl_next(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_fl_owner(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_fl_flags(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_fl_type(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_fl_break_time(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_fl_downgrade_time(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
generic_add_lease,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_generic_add_lease_format();
msg->set_i_ino(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_wcount(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_dcount(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_icount(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_s_dev(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_fl_owner(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_fl_flags(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_fl_type(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
generic_delete_lease,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_generic_delete_lease_format();
msg->set_fl(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_i_ino(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_s_dev(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_fl_next(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_fl_owner(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_fl_flags(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_fl_type(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_fl_break_time(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_fl_downgrade_time(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
time_out_leases,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_time_out_leases_format();
msg->set_fl(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_i_ino(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_s_dev(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_fl_next(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_fl_owner(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_fl_flags(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_fl_type(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_fl_break_time(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_fl_downgrade_time(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
});
} // namespace
FTRACE_NS_END

View File

@ -0,0 +1,41 @@
/* THIS FILE IS GENERATE BY ftrace_cpp_generator.py, PLEASE DON'T EDIT IT!
* 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.
*/
#include "sub_event_parser.h"
FTRACE_NS_BEGIN
namespace {
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
mm_filemap_add_to_page_cache,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_mm_filemap_add_to_page_cache_format();
msg->set_pfn(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_i_ino(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_index(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_s_dev(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
mm_filemap_delete_from_page_cache,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_mm_filemap_delete_from_page_cache_format();
msg->set_pfn(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_i_ino(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_index(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_s_dev(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
});
} // namespace
FTRACE_NS_END

View File

@ -0,0 +1,150 @@
/* THIS FILE IS GENERATE BY ftrace_cpp_generator.py, PLEASE DON'T EDIT IT!
* 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.
*/
#include "sub_event_parser.h"
FTRACE_NS_BEGIN
namespace {
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
bputs,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_bputs_format();
msg->set_ip(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_str(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
branch,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_branch_format();
msg->set_line(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_func(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
msg->set_file(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
msg->set_correct(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_constant(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
context_switch,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_context_switch_format();
msg->set_prev_pid(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_next_pid(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_next_cpu(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_prev_prio(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_prev_state(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_next_prio(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_next_state(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
funcgraph_entry,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_funcgraph_entry_format();
msg->set_func(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_depth(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
funcgraph_exit,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_funcgraph_exit_format();
msg->set_func(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_calltime(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_rettime(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_overrun(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_depth(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
function,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_function_format();
msg->set_ip(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_parent_ip(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
kernel_stack,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_kernel_stack_format();
msg->set_size(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_caller(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
mmiotrace_map,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_mmiotrace_map_format();
msg->set_phys(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_virt(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_len(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_map_id(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_opcode(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
mmiotrace_rw,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_mmiotrace_rw_format();
msg->set_phys(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_value(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_pc(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_map_id(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_opcode(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_width(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
print,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_print_format();
msg->set_ip(FtraceFieldParser::ParseIntField<uint64_t>(format.fields, i++, data, size));
msg->set_buf(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
user_stack,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_user_stack_format();
msg->set_tgid(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_caller(FtraceFieldParser::ParseStrField(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
wakeup,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_wakeup_format();
msg->set_prev_pid(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_next_pid(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_next_cpu(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_prev_prio(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_prev_state(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_next_prio(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_next_state(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
});
} // namespace
FTRACE_NS_END

View File

@ -0,0 +1,39 @@
/* THIS FILE IS GENERATE BY ftrace_cpp_generator.py, PLEASE DON'T EDIT IT!
* 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.
*/
#include "sub_event_parser.h"
FTRACE_NS_BEGIN
namespace {
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
gpio_direction,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_gpio_direction_format();
msg->set_gpio(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_in(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_err(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
});
REGISTER_FTRACE_EVENT_PARSE_FUNCTION(
gpio_value,
[](FtraceEvent& ftraceEvent, uint8_t data[], size_t size, const EventFormat& format) {
int i = 0;
auto msg = ftraceEvent.mutable_gpio_value_format();
msg->set_gpio(FtraceFieldParser::ParseIntField<uint32_t>(format.fields, i++, data, size));
msg->set_get(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
msg->set_value(FtraceFieldParser::ParseIntField<int32_t>(format.fields, i++, data, size));
});
} // namespace
FTRACE_NS_END

Some files were not shown because too many files have changed in this diff Show More