106f6ba60Sopenharmony_ci/* 206f6ba60Sopenharmony_ci * Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved. 306f6ba60Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 406f6ba60Sopenharmony_ci * you may not use this file except in compliance with the License. 506f6ba60Sopenharmony_ci * You may obtain a copy of the License at 606f6ba60Sopenharmony_ci * 706f6ba60Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 806f6ba60Sopenharmony_ci * 906f6ba60Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1006f6ba60Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1106f6ba60Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1206f6ba60Sopenharmony_ci * See the License for the specific language governing permissions and 1306f6ba60Sopenharmony_ci * limitations under the License. 1406f6ba60Sopenharmony_ci */ 1506f6ba60Sopenharmony_ci 1606f6ba60Sopenharmony_ci#include "parse_plugin_config.h" 1706f6ba60Sopenharmony_ci 1806f6ba60Sopenharmony_ci#include "cpu_plugin_config_standard.pb.h" 1906f6ba60Sopenharmony_ci#include "gpu_plugin_config_standard.pb.h" 2006f6ba60Sopenharmony_ci#include "diskio_plugin_config_standard.pb.h" 2106f6ba60Sopenharmony_ci#include "hidump_plugin_config_standard.pb.h" 2206f6ba60Sopenharmony_ci#include "hiebpf_plugin_config_standard.pb.h" 2306f6ba60Sopenharmony_ci#include "hilog_plugin_config_standard.pb.h" 2406f6ba60Sopenharmony_ci#include "hiperf_plugin_config_standard.pb.h" 2506f6ba60Sopenharmony_ci#include "hisysevent_plugin_config_standard.pb.h" 2606f6ba60Sopenharmony_ci#include "memory_plugin_common_standard.pb.h" 2706f6ba60Sopenharmony_ci#include "memory_plugin_config_standard.pb.h" 2806f6ba60Sopenharmony_ci#include "native_hook_config_standard.pb.h" 2906f6ba60Sopenharmony_ci#include "network_plugin_config_standard.pb.h" 3006f6ba60Sopenharmony_ci#include "process_plugin_config_standard.pb.h" 3106f6ba60Sopenharmony_ci#include "trace_plugin_config_standard.pb.h" 3206f6ba60Sopenharmony_ci#include "xpower_plugin_config_standard.pb.h" 3306f6ba60Sopenharmony_ci#include "ffrt_profiler_config_standard.pb.h" 3406f6ba60Sopenharmony_ci#include "network_profiler_config_standard.pb.h" 3506f6ba60Sopenharmony_ci 3606f6ba60Sopenharmony_cinamespace { 3706f6ba60Sopenharmony_ciconstexpr int REMAINDER = 2; 3806f6ba60Sopenharmony_ci} 3906f6ba60Sopenharmony_ci 4006f6ba60Sopenharmony_ciParsePluginConfig::ParsePluginConfig() 4106f6ba60Sopenharmony_ci{ 4206f6ba60Sopenharmony_ci parser_.AllowUnknownField(true); 4306f6ba60Sopenharmony_ci} 4406f6ba60Sopenharmony_ci 4506f6ba60Sopenharmony_ciParsePluginConfig& ParsePluginConfig::GetInstance() 4606f6ba60Sopenharmony_ci{ 4706f6ba60Sopenharmony_ci static ParsePluginConfig parsePluginConfig; 4806f6ba60Sopenharmony_ci return parsePluginConfig; 4906f6ba60Sopenharmony_ci} 5006f6ba60Sopenharmony_ci 5106f6ba60Sopenharmony_cistd::string ParsePluginConfig::GetPluginsConfig(std::string& content) 5206f6ba60Sopenharmony_ci{ 5306f6ba60Sopenharmony_ci std::string pluginConfig = ""; 5406f6ba60Sopenharmony_ci std::string pluginName = ""; 5506f6ba60Sopenharmony_ci size_t beginPos = 0; 5606f6ba60Sopenharmony_ci size_t endPos = 0; 5706f6ba60Sopenharmony_ci for (int i = 0; content.size() > 0; i++) { 5806f6ba60Sopenharmony_ci // 先获取pluginName,再获取configData 5906f6ba60Sopenharmony_ci std::string destStr = (i % REMAINDER) ? "config_data" : "plugin_name"; 6006f6ba60Sopenharmony_ci beginPos = content.find(destStr); 6106f6ba60Sopenharmony_ci if (beginPos == std::string::npos) { 6206f6ba60Sopenharmony_ci break; 6306f6ba60Sopenharmony_ci } 6406f6ba60Sopenharmony_ci pluginConfig += content.substr(0, beginPos); 6506f6ba60Sopenharmony_ci content = content.substr(beginPos + destStr.size(), content.size()); 6606f6ba60Sopenharmony_ci destStr = (i % REMAINDER) ? "{" : "\""; 6706f6ba60Sopenharmony_ci beginPos = content.find(destStr); 6806f6ba60Sopenharmony_ci if (beginPos == std::string::npos) { 6906f6ba60Sopenharmony_ci break; 7006f6ba60Sopenharmony_ci } 7106f6ba60Sopenharmony_ci content = content.substr(beginPos + 1, content.size()); 7206f6ba60Sopenharmony_ci destStr = (i % REMAINDER) ? "}" : "\""; 7306f6ba60Sopenharmony_ci endPos = content.find(destStr); 7406f6ba60Sopenharmony_ci if (endPos == std::string::npos) { 7506f6ba60Sopenharmony_ci break; 7606f6ba60Sopenharmony_ci } 7706f6ba60Sopenharmony_ci std::string contentStr = content.substr(0, endPos); 7806f6ba60Sopenharmony_ci if (i % REMAINDER == 0) { // set plugin-name 7906f6ba60Sopenharmony_ci pluginName = contentStr; 8006f6ba60Sopenharmony_ci 8106f6ba60Sopenharmony_ci if (pluginName == "") { 8206f6ba60Sopenharmony_ci return ""; 8306f6ba60Sopenharmony_ci } 8406f6ba60Sopenharmony_ci pluginConfig += "name: \"" + pluginName + "\""; 8506f6ba60Sopenharmony_ci } else { // save config_data 8606f6ba60Sopenharmony_ci pluginConfigMap.insert({pluginName, contentStr}); 8706f6ba60Sopenharmony_ci pluginConfig += "config_data: \"\""; 8806f6ba60Sopenharmony_ci } 8906f6ba60Sopenharmony_ci 9006f6ba60Sopenharmony_ci content = content.substr(endPos + 1, content.size()); 9106f6ba60Sopenharmony_ci } 9206f6ba60Sopenharmony_ci 9306f6ba60Sopenharmony_ci pluginConfig += content; 9406f6ba60Sopenharmony_ci return pluginConfig; 9506f6ba60Sopenharmony_ci} 9606f6ba60Sopenharmony_ci 9706f6ba60Sopenharmony_cibool ParsePluginConfig::SetSerializePluginsConfig(const std::string& pluginName, ProfilerPluginConfig& pluginConfig) 9806f6ba60Sopenharmony_ci{ 9906f6ba60Sopenharmony_ci bool ret = false; 10006f6ba60Sopenharmony_ci if (pluginConfigMap.count(pluginName) == 0) { 10106f6ba60Sopenharmony_ci printf("unknown plugin: %s\n", pluginName.c_str()); 10206f6ba60Sopenharmony_ci return ret; 10306f6ba60Sopenharmony_ci } 10406f6ba60Sopenharmony_ci 10506f6ba60Sopenharmony_ci // 将pluginConfigMap中保存的configData序列化后写入pluginConfig 10606f6ba60Sopenharmony_ci if (pluginName == "cpu-plugin") { 10706f6ba60Sopenharmony_ci ret = SetSerializeCpuConfig(pluginName, pluginConfig); 10806f6ba60Sopenharmony_ci } else if (pluginName == "diskio-plugin") { 10906f6ba60Sopenharmony_ci ret = SetSerializeDiskioConfig(pluginName, pluginConfig); 11006f6ba60Sopenharmony_ci } else if (pluginName == "ftrace-plugin") { 11106f6ba60Sopenharmony_ci ret = SetSerializeFtraceConfig(pluginName, pluginConfig); 11206f6ba60Sopenharmony_ci } else if (pluginName == "hidump-plugin") { 11306f6ba60Sopenharmony_ci ret = SetSerializeHidumpConfig(pluginName, pluginConfig); 11406f6ba60Sopenharmony_ci } else if (pluginName == "hiebpf-plugin") { 11506f6ba60Sopenharmony_ci ret = SetSerializeHiebpfConfig(pluginName, pluginConfig); 11606f6ba60Sopenharmony_ci } else if (pluginName == "hilog-plugin") { 11706f6ba60Sopenharmony_ci ret = SetSerializeHilogConfig(pluginName, pluginConfig); 11806f6ba60Sopenharmony_ci } else if (pluginName == "memory-plugin") { 11906f6ba60Sopenharmony_ci ret = SetSerializeMemoryConfig(pluginName, pluginConfig); 12006f6ba60Sopenharmony_ci } else if (pluginName == "nativehook") { 12106f6ba60Sopenharmony_ci ret = SetSerializeHookConfig(pluginName, pluginConfig); 12206f6ba60Sopenharmony_ci } else if (pluginName == "network-plugin") { 12306f6ba60Sopenharmony_ci ret = SetSerializeNetworkConfig(pluginName, pluginConfig); 12406f6ba60Sopenharmony_ci } else if (pluginName == "process-plugin") { 12506f6ba60Sopenharmony_ci ret = SetSerializeProcessConfig(pluginName, pluginConfig); 12606f6ba60Sopenharmony_ci } else if (pluginName == "hiperf-plugin") { 12706f6ba60Sopenharmony_ci ret = SetSerializeHiperfConfig(pluginName, pluginConfig); 12806f6ba60Sopenharmony_ci } else if (pluginName == "hisysevent-plugin") { 12906f6ba60Sopenharmony_ci ret = SetSerializeHisyseventConfig(pluginName, pluginConfig); 13006f6ba60Sopenharmony_ci } else if (pluginName == "xpower-plugin") { 13106f6ba60Sopenharmony_ci ret = SetSerializeXpowerConfig(pluginName, pluginConfig); 13206f6ba60Sopenharmony_ci } else if (pluginName == "gpu-plugin") { 13306f6ba60Sopenharmony_ci ret = SetSerializeGpuConfig(pluginName, pluginConfig); 13406f6ba60Sopenharmony_ci } else if (pluginName == "ffrt-profiler") { 13506f6ba60Sopenharmony_ci ret = SetSerializeFfrtProfilerConfig(pluginName, pluginConfig); 13606f6ba60Sopenharmony_ci } else if (pluginName == "network-profiler") { 13706f6ba60Sopenharmony_ci ret = SetSerializeNetworkProfilerConfig(pluginName, pluginConfig); 13806f6ba60Sopenharmony_ci } else { 13906f6ba60Sopenharmony_ci printf("unsupport plugin: %s\n", pluginName.c_str()); 14006f6ba60Sopenharmony_ci } 14106f6ba60Sopenharmony_ci 14206f6ba60Sopenharmony_ci return ret; 14306f6ba60Sopenharmony_ci} 14406f6ba60Sopenharmony_ci 14506f6ba60Sopenharmony_cibool ParsePluginConfig::SetSerializeCpuConfig(const std::string& pluginName, ProfilerPluginConfig& pluginConfig) 14606f6ba60Sopenharmony_ci{ 14706f6ba60Sopenharmony_ci std::string configData = pluginConfigMap[pluginName]; 14806f6ba60Sopenharmony_ci auto cpuConfigNolite = std::make_unique<ForStandard::CpuConfig>(); 14906f6ba60Sopenharmony_ci if (!parser_.ParseFromString(configData, cpuConfigNolite.get())) { 15006f6ba60Sopenharmony_ci printf("cpu parse failed!\n"); 15106f6ba60Sopenharmony_ci return false; 15206f6ba60Sopenharmony_ci } 15306f6ba60Sopenharmony_ci 15406f6ba60Sopenharmony_ci std::vector<uint8_t> configDataVec(cpuConfigNolite->ByteSizeLong()); 15506f6ba60Sopenharmony_ci if (cpuConfigNolite->SerializeToArray(configDataVec.data(), configDataVec.size()) <= 0) { 15606f6ba60Sopenharmony_ci printf("cpu serialize failed!\n"); 15706f6ba60Sopenharmony_ci return false; 15806f6ba60Sopenharmony_ci } 15906f6ba60Sopenharmony_ci pluginConfig.set_config_data(static_cast<const void*>(configDataVec.data()), configDataVec.size()); 16006f6ba60Sopenharmony_ci return true; 16106f6ba60Sopenharmony_ci} 16206f6ba60Sopenharmony_ci 16306f6ba60Sopenharmony_cibool ParsePluginConfig::SetSerializeDiskioConfig(const std::string& pluginName, ProfilerPluginConfig& pluginConfig) 16406f6ba60Sopenharmony_ci{ 16506f6ba60Sopenharmony_ci std::string configData = pluginConfigMap[pluginName]; 16606f6ba60Sopenharmony_ci auto diskioConfigNolite = std::make_unique<ForStandard::DiskioConfig>(); 16706f6ba60Sopenharmony_ci if (!parser_.ParseFromString(configData, diskioConfigNolite.get())) { 16806f6ba60Sopenharmony_ci printf("diskio parse failed!\n"); 16906f6ba60Sopenharmony_ci return false; 17006f6ba60Sopenharmony_ci } 17106f6ba60Sopenharmony_ci 17206f6ba60Sopenharmony_ci std::vector<uint8_t> configDataVec(diskioConfigNolite->ByteSizeLong()); 17306f6ba60Sopenharmony_ci if (diskioConfigNolite->SerializeToArray(configDataVec.data(), configDataVec.size()) <= 0) { 17406f6ba60Sopenharmony_ci printf("diskio serialize failed!\n"); 17506f6ba60Sopenharmony_ci return false; 17606f6ba60Sopenharmony_ci } 17706f6ba60Sopenharmony_ci pluginConfig.set_config_data(static_cast<const void*>(configDataVec.data()), configDataVec.size()); 17806f6ba60Sopenharmony_ci return true; 17906f6ba60Sopenharmony_ci} 18006f6ba60Sopenharmony_ci 18106f6ba60Sopenharmony_cibool ParsePluginConfig::SetSerializeFtraceConfig(const std::string& pluginName, ProfilerPluginConfig& pluginConfig) 18206f6ba60Sopenharmony_ci{ 18306f6ba60Sopenharmony_ci std::string configData = pluginConfigMap[pluginName]; 18406f6ba60Sopenharmony_ci auto ftraceConfigNolite = std::make_unique<ForStandard::TracePluginConfig>(); 18506f6ba60Sopenharmony_ci if (!parser_.ParseFromString(configData, ftraceConfigNolite.get())) { 18606f6ba60Sopenharmony_ci printf("ftrace parse failed!\n"); 18706f6ba60Sopenharmony_ci return false; 18806f6ba60Sopenharmony_ci } 18906f6ba60Sopenharmony_ci 19006f6ba60Sopenharmony_ci std::vector<uint8_t> configNoLiteDataVec(ftraceConfigNolite->ByteSizeLong()); 19106f6ba60Sopenharmony_ci if (ftraceConfigNolite->SerializeToArray(configNoLiteDataVec.data(), configNoLiteDataVec.size()) <= 0) { 19206f6ba60Sopenharmony_ci printf("ftrace serialize failed!\n"); 19306f6ba60Sopenharmony_ci return false; 19406f6ba60Sopenharmony_ci } 19506f6ba60Sopenharmony_ci 19606f6ba60Sopenharmony_ci pluginConfig.set_config_data(static_cast<const void*>(configNoLiteDataVec.data()), configNoLiteDataVec.size()); 19706f6ba60Sopenharmony_ci return true; 19806f6ba60Sopenharmony_ci} 19906f6ba60Sopenharmony_ci 20006f6ba60Sopenharmony_cibool ParsePluginConfig::SetSerializeHidumpConfig(const std::string& pluginName, ProfilerPluginConfig& pluginConfig) 20106f6ba60Sopenharmony_ci{ 20206f6ba60Sopenharmony_ci std::string configData = pluginConfigMap[pluginName]; 20306f6ba60Sopenharmony_ci auto hidumpConfigNolite = std::make_unique<ForStandard::HidumpConfig>(); 20406f6ba60Sopenharmony_ci if (!parser_.ParseFromString(configData, hidumpConfigNolite.get())) { 20506f6ba60Sopenharmony_ci printf("hidump parse failed!\n"); 20606f6ba60Sopenharmony_ci return false; 20706f6ba60Sopenharmony_ci } 20806f6ba60Sopenharmony_ci 20906f6ba60Sopenharmony_ci std::vector<uint8_t> configDataVec(hidumpConfigNolite->ByteSizeLong()); 21006f6ba60Sopenharmony_ci if (hidumpConfigNolite->SerializeToArray(configDataVec.data(), configDataVec.size()) <= 0) { 21106f6ba60Sopenharmony_ci printf("hidump serialize failed!\n"); 21206f6ba60Sopenharmony_ci return false; 21306f6ba60Sopenharmony_ci } 21406f6ba60Sopenharmony_ci pluginConfig.set_config_data(static_cast<const void*>(configDataVec.data()), configDataVec.size()); 21506f6ba60Sopenharmony_ci return true; 21606f6ba60Sopenharmony_ci} 21706f6ba60Sopenharmony_ci 21806f6ba60Sopenharmony_cibool ParsePluginConfig::SetSerializeHiebpfConfig(const std::string& pluginName, ProfilerPluginConfig& pluginConfig) 21906f6ba60Sopenharmony_ci{ 22006f6ba60Sopenharmony_ci auto iter = pluginConfigMap.find(pluginName); 22106f6ba60Sopenharmony_ci if (iter == pluginConfigMap.end()) { 22206f6ba60Sopenharmony_ci printf("find %s failed\n", pluginName.c_str()); 22306f6ba60Sopenharmony_ci return false; 22406f6ba60Sopenharmony_ci } 22506f6ba60Sopenharmony_ci auto hiebpfConfigNolite = std::make_unique<ForStandard::HiebpfConfig>(); 22606f6ba60Sopenharmony_ci if (hiebpfConfigNolite == nullptr) { 22706f6ba60Sopenharmony_ci printf("hiebpfConfigNolite is nullptr\n"); 22806f6ba60Sopenharmony_ci return false; 22906f6ba60Sopenharmony_ci } 23006f6ba60Sopenharmony_ci if (!parser_.ParseFromString(iter->second, hiebpfConfigNolite.get())) { 23106f6ba60Sopenharmony_ci printf("hiebpf config parse failed!\n"); 23206f6ba60Sopenharmony_ci return false; 23306f6ba60Sopenharmony_ci } 23406f6ba60Sopenharmony_ci std::vector<uint8_t> config(hiebpfConfigNolite->ByteSizeLong()); 23506f6ba60Sopenharmony_ci if (hiebpfConfigNolite->SerializeToArray(config.data(), config.size()) <= 0) { 23606f6ba60Sopenharmony_ci printf("hiebpf serialize failed!\n"); 23706f6ba60Sopenharmony_ci return false; 23806f6ba60Sopenharmony_ci } 23906f6ba60Sopenharmony_ci pluginConfig.set_config_data(static_cast<const void*>(config.data()), config.size()); 24006f6ba60Sopenharmony_ci return true; 24106f6ba60Sopenharmony_ci} 24206f6ba60Sopenharmony_ci 24306f6ba60Sopenharmony_cibool ParsePluginConfig::SetSerializeHilogConfig(const std::string& pluginName, ProfilerPluginConfig& pluginConfig) 24406f6ba60Sopenharmony_ci{ 24506f6ba60Sopenharmony_ci std::string configData = pluginConfigMap[pluginName]; 24606f6ba60Sopenharmony_ci auto hilogConfigNolite = std::make_unique<ForStandard::HilogConfig>(); 24706f6ba60Sopenharmony_ci if (!parser_.ParseFromString(configData, hilogConfigNolite.get())) { 24806f6ba60Sopenharmony_ci printf("hilog parse failed!\n"); 24906f6ba60Sopenharmony_ci return false; 25006f6ba60Sopenharmony_ci } 25106f6ba60Sopenharmony_ci 25206f6ba60Sopenharmony_ci std::vector<uint8_t> configDataVec(hilogConfigNolite->ByteSizeLong()); 25306f6ba60Sopenharmony_ci if (hilogConfigNolite->SerializeToArray(configDataVec.data(), configDataVec.size()) <= 0) { 25406f6ba60Sopenharmony_ci printf("hilog serialize failed!\n"); 25506f6ba60Sopenharmony_ci return false; 25606f6ba60Sopenharmony_ci } 25706f6ba60Sopenharmony_ci pluginConfig.set_config_data(static_cast<const void*>(configDataVec.data()), configDataVec.size()); 25806f6ba60Sopenharmony_ci return true; 25906f6ba60Sopenharmony_ci} 26006f6ba60Sopenharmony_ci 26106f6ba60Sopenharmony_cibool ParsePluginConfig::SetSerializeMemoryConfig(const std::string& pluginName, ProfilerPluginConfig& pluginConfig) 26206f6ba60Sopenharmony_ci{ 26306f6ba60Sopenharmony_ci std::string configData = pluginConfigMap[pluginName]; 26406f6ba60Sopenharmony_ci auto memoryConfigNolite = std::make_unique<ForStandard::MemoryConfig>(); 26506f6ba60Sopenharmony_ci if (!parser_.ParseFromString(configData, memoryConfigNolite.get())) { 26606f6ba60Sopenharmony_ci printf("memory parse failed!\n"); 26706f6ba60Sopenharmony_ci return false; 26806f6ba60Sopenharmony_ci } 26906f6ba60Sopenharmony_ci 27006f6ba60Sopenharmony_ci std::vector<uint8_t> configDataVec(memoryConfigNolite->ByteSizeLong()); 27106f6ba60Sopenharmony_ci if (memoryConfigNolite->SerializeToArray(configDataVec.data(), configDataVec.size()) <= 0) { 27206f6ba60Sopenharmony_ci printf("memory serialize failed!\n"); 27306f6ba60Sopenharmony_ci return false; 27406f6ba60Sopenharmony_ci } 27506f6ba60Sopenharmony_ci pluginConfig.set_config_data(static_cast<const void*>(configDataVec.data()), configDataVec.size()); 27606f6ba60Sopenharmony_ci return true; 27706f6ba60Sopenharmony_ci} 27806f6ba60Sopenharmony_ci 27906f6ba60Sopenharmony_cibool ParsePluginConfig::SetSerializeHookConfig(const std::string& pluginName, ProfilerPluginConfig& pluginConfig) 28006f6ba60Sopenharmony_ci{ 28106f6ba60Sopenharmony_ci std::string configData = pluginConfigMap[pluginName]; 28206f6ba60Sopenharmony_ci auto hookConfigNolite = std::make_unique<ForStandard::NativeHookConfig>(); 28306f6ba60Sopenharmony_ci if (!parser_.ParseFromString(configData, hookConfigNolite.get())) { 28406f6ba60Sopenharmony_ci printf("nativedaemon parse failed!\n"); 28506f6ba60Sopenharmony_ci return false; 28606f6ba60Sopenharmony_ci } 28706f6ba60Sopenharmony_ci 28806f6ba60Sopenharmony_ci std::vector<uint8_t> configDataVec(hookConfigNolite->ByteSizeLong()); 28906f6ba60Sopenharmony_ci if (hookConfigNolite->SerializeToArray(configDataVec.data(), configDataVec.size()) <= 0) { 29006f6ba60Sopenharmony_ci printf("nativedaemon serialize failed!\n"); 29106f6ba60Sopenharmony_ci return false; 29206f6ba60Sopenharmony_ci } 29306f6ba60Sopenharmony_ci pluginConfig.set_config_data(static_cast<const void*>(configDataVec.data()), configDataVec.size()); 29406f6ba60Sopenharmony_ci return true; 29506f6ba60Sopenharmony_ci} 29606f6ba60Sopenharmony_ci 29706f6ba60Sopenharmony_cibool ParsePluginConfig::SetSerializeNetworkConfig(const std::string& pluginName, ProfilerPluginConfig& pluginConfig) 29806f6ba60Sopenharmony_ci{ 29906f6ba60Sopenharmony_ci std::string configData = pluginConfigMap[pluginName]; 30006f6ba60Sopenharmony_ci auto networkConfigNolite = std::make_unique<ForStandard::NetworkConfig>(); 30106f6ba60Sopenharmony_ci if (!parser_.ParseFromString(configData, networkConfigNolite.get())) { 30206f6ba60Sopenharmony_ci printf("network parse failed!\n"); 30306f6ba60Sopenharmony_ci return false; 30406f6ba60Sopenharmony_ci } 30506f6ba60Sopenharmony_ci 30606f6ba60Sopenharmony_ci std::vector<uint8_t> configDataVec(networkConfigNolite->ByteSizeLong()); 30706f6ba60Sopenharmony_ci if (networkConfigNolite->SerializeToArray(configDataVec.data(), configDataVec.size()) <= 0) { 30806f6ba60Sopenharmony_ci printf("network serialize failed!\n"); 30906f6ba60Sopenharmony_ci return false; 31006f6ba60Sopenharmony_ci } 31106f6ba60Sopenharmony_ci pluginConfig.set_config_data(static_cast<const void*>(configDataVec.data()), configDataVec.size()); 31206f6ba60Sopenharmony_ci return true; 31306f6ba60Sopenharmony_ci} 31406f6ba60Sopenharmony_ci 31506f6ba60Sopenharmony_cibool ParsePluginConfig::SetSerializeProcessConfig(const std::string& pluginName, ProfilerPluginConfig& pluginConfig) 31606f6ba60Sopenharmony_ci{ 31706f6ba60Sopenharmony_ci std::string configData = pluginConfigMap[pluginName]; 31806f6ba60Sopenharmony_ci auto processConfigNolite = std::make_unique<ForStandard::ProcessConfig>(); 31906f6ba60Sopenharmony_ci if (!parser_.ParseFromString(configData, processConfigNolite.get())) { 32006f6ba60Sopenharmony_ci printf("process parse failed!\n"); 32106f6ba60Sopenharmony_ci return false; 32206f6ba60Sopenharmony_ci } 32306f6ba60Sopenharmony_ci 32406f6ba60Sopenharmony_ci std::vector<uint8_t> configDataVec(processConfigNolite->ByteSizeLong()); 32506f6ba60Sopenharmony_ci if (processConfigNolite->SerializeToArray(configDataVec.data(), configDataVec.size()) <= 0) { 32606f6ba60Sopenharmony_ci printf("process serialize failed!\n"); 32706f6ba60Sopenharmony_ci return false; 32806f6ba60Sopenharmony_ci } 32906f6ba60Sopenharmony_ci pluginConfig.set_config_data(static_cast<const void*>(configDataVec.data()), configDataVec.size()); 33006f6ba60Sopenharmony_ci return true; 33106f6ba60Sopenharmony_ci} 33206f6ba60Sopenharmony_ci 33306f6ba60Sopenharmony_cibool ParsePluginConfig::SetSerializeHiperfConfig(const std::string& pluginName, ProfilerPluginConfig& pluginConfig) 33406f6ba60Sopenharmony_ci{ 33506f6ba60Sopenharmony_ci std::string configData = pluginConfigMap[pluginName]; 33606f6ba60Sopenharmony_ci auto hiperfConfigNolite = std::make_unique<ForStandard::HiperfPluginConfig>(); 33706f6ba60Sopenharmony_ci if (!parser_.ParseFromString(configData, hiperfConfigNolite.get())) { 33806f6ba60Sopenharmony_ci printf("hiperf config parse failed!\n"); 33906f6ba60Sopenharmony_ci return false; 34006f6ba60Sopenharmony_ci } 34106f6ba60Sopenharmony_ci 34206f6ba60Sopenharmony_ci std::vector<uint8_t> configDataVec(hiperfConfigNolite->ByteSizeLong()); 34306f6ba60Sopenharmony_ci if (hiperfConfigNolite->SerializeToArray(configDataVec.data(), configDataVec.size()) <= 0) { 34406f6ba60Sopenharmony_ci printf("hiperf config failed!\n"); 34506f6ba60Sopenharmony_ci return false; 34606f6ba60Sopenharmony_ci } 34706f6ba60Sopenharmony_ci pluginConfig.set_config_data(static_cast<const void*>(configDataVec.data()), configDataVec.size()); 34806f6ba60Sopenharmony_ci return true; 34906f6ba60Sopenharmony_ci} 35006f6ba60Sopenharmony_ci 35106f6ba60Sopenharmony_cibool ParsePluginConfig::SetSerializeHisyseventConfig(const std::string& pluginName, ProfilerPluginConfig& pluginConfig) 35206f6ba60Sopenharmony_ci{ 35306f6ba60Sopenharmony_ci std::string configData = pluginConfigMap[pluginName]; 35406f6ba60Sopenharmony_ci auto hisyseventConfigNolite = std::make_unique<ForStandard::HisyseventConfig>(); 35506f6ba60Sopenharmony_ci if (!parser_.ParseFromString(configData, hisyseventConfigNolite.get())) { 35606f6ba60Sopenharmony_ci printf("NODE hisysevent parse failed!\n"); 35706f6ba60Sopenharmony_ci return false; 35806f6ba60Sopenharmony_ci } 35906f6ba60Sopenharmony_ci 36006f6ba60Sopenharmony_ci std::vector<uint8_t> configDataVec(hisyseventConfigNolite->ByteSizeLong()); 36106f6ba60Sopenharmony_ci if (hisyseventConfigNolite->SerializeToArray(configDataVec.data(), configDataVec.size()) <= 0) { 36206f6ba60Sopenharmony_ci printf("NODE hisysevent serialize failed!\n"); 36306f6ba60Sopenharmony_ci return false; 36406f6ba60Sopenharmony_ci } 36506f6ba60Sopenharmony_ci pluginConfig.set_config_data(static_cast<const void*>(configDataVec.data()), configDataVec.size()); 36606f6ba60Sopenharmony_ci return true; 36706f6ba60Sopenharmony_ci} 36806f6ba60Sopenharmony_ci 36906f6ba60Sopenharmony_cibool ParsePluginConfig::SetSerializeXpowerConfig(const std::string& pluginName, ProfilerPluginConfig& pluginConfig) 37006f6ba60Sopenharmony_ci{ 37106f6ba60Sopenharmony_ci std::string configData = pluginConfigMap[pluginName]; 37206f6ba60Sopenharmony_ci auto xpowerConfigNolite = std::make_unique<ForStandard::XpowerConfig>(); 37306f6ba60Sopenharmony_ci if (!parser_.ParseFromString(configData, xpowerConfigNolite.get())) { 37406f6ba60Sopenharmony_ci return false; 37506f6ba60Sopenharmony_ci } 37606f6ba60Sopenharmony_ci 37706f6ba60Sopenharmony_ci std::vector<uint8_t> configDataVec(xpowerConfigNolite->ByteSizeLong()); 37806f6ba60Sopenharmony_ci if (xpowerConfigNolite->SerializeToArray(configDataVec.data(), configDataVec.size()) <= 0) { 37906f6ba60Sopenharmony_ci return false; 38006f6ba60Sopenharmony_ci } 38106f6ba60Sopenharmony_ci pluginConfig.set_config_data(static_cast<const void*>(configDataVec.data()), configDataVec.size()); 38206f6ba60Sopenharmony_ci return true; 38306f6ba60Sopenharmony_ci} 38406f6ba60Sopenharmony_ci 38506f6ba60Sopenharmony_cibool ParsePluginConfig::SetSerializeGpuConfig(const std::string& pluginName, ProfilerPluginConfig& pluginConfig) 38606f6ba60Sopenharmony_ci{ 38706f6ba60Sopenharmony_ci std::string configData = pluginConfigMap[pluginName]; 38806f6ba60Sopenharmony_ci auto gpuConfigNolite = std::make_unique<ForStandard::GpuConfig>(); 38906f6ba60Sopenharmony_ci if (!parser_.ParseFromString(configData, gpuConfigNolite.get())) { 39006f6ba60Sopenharmony_ci return false; 39106f6ba60Sopenharmony_ci } 39206f6ba60Sopenharmony_ci 39306f6ba60Sopenharmony_ci std::vector<uint8_t> configDataVec(gpuConfigNolite->ByteSizeLong()); 39406f6ba60Sopenharmony_ci if (gpuConfigNolite->SerializeToArray(configDataVec.data(), configDataVec.size()) <= 0) { 39506f6ba60Sopenharmony_ci return false; 39606f6ba60Sopenharmony_ci } 39706f6ba60Sopenharmony_ci pluginConfig.set_config_data(static_cast<const void*>(configDataVec.data()), configDataVec.size()); 39806f6ba60Sopenharmony_ci return true; 39906f6ba60Sopenharmony_ci} 40006f6ba60Sopenharmony_ci 40106f6ba60Sopenharmony_cibool ParsePluginConfig::SetSerializeFfrtProfilerConfig(const std::string& pluginName, 40206f6ba60Sopenharmony_ci ProfilerPluginConfig& pluginConfig) 40306f6ba60Sopenharmony_ci{ 40406f6ba60Sopenharmony_ci std::string configData = pluginConfigMap[pluginName]; 40506f6ba60Sopenharmony_ci auto ffrtConfigNolite = std::make_unique<ForStandard::FfrtProfilerConfig>(); 40606f6ba60Sopenharmony_ci if (!parser_.ParseFromString(configData, ffrtConfigNolite.get())) { 40706f6ba60Sopenharmony_ci return false; 40806f6ba60Sopenharmony_ci } 40906f6ba60Sopenharmony_ci 41006f6ba60Sopenharmony_ci std::vector<uint8_t> configDataVec(ffrtConfigNolite->ByteSizeLong()); 41106f6ba60Sopenharmony_ci if (ffrtConfigNolite->SerializeToArray(configDataVec.data(), configDataVec.size()) <= 0) { 41206f6ba60Sopenharmony_ci return false; 41306f6ba60Sopenharmony_ci } 41406f6ba60Sopenharmony_ci pluginConfig.set_config_data(static_cast<const void*>(configDataVec.data()), configDataVec.size()); 41506f6ba60Sopenharmony_ci return true; 41606f6ba60Sopenharmony_ci} 41706f6ba60Sopenharmony_ci 41806f6ba60Sopenharmony_cibool ParsePluginConfig::SetSerializeNetworkProfilerConfig(const std::string& pluginName, 41906f6ba60Sopenharmony_ci ProfilerPluginConfig& pluginConfig) 42006f6ba60Sopenharmony_ci{ 42106f6ba60Sopenharmony_ci std::string configData = pluginConfigMap[pluginName]; 42206f6ba60Sopenharmony_ci auto networkConfigNolite = std::make_unique<ForStandard::NetworkProfilerConfig>(); 42306f6ba60Sopenharmony_ci if (!parser_.ParseFromString(configData, networkConfigNolite.get())) { 42406f6ba60Sopenharmony_ci return false; 42506f6ba60Sopenharmony_ci } 42606f6ba60Sopenharmony_ci 42706f6ba60Sopenharmony_ci std::vector<uint8_t> configDataVec(networkConfigNolite->ByteSizeLong()); 42806f6ba60Sopenharmony_ci if (networkConfigNolite->SerializeToArray(configDataVec.data(), configDataVec.size()) <= 0) { 42906f6ba60Sopenharmony_ci return false; 43006f6ba60Sopenharmony_ci } 43106f6ba60Sopenharmony_ci pluginConfig.set_config_data(static_cast<const void*>(configDataVec.data()), configDataVec.size()); 43206f6ba60Sopenharmony_ci return true; 43306f6ba60Sopenharmony_ci} 434